classifyEnlistV2.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363
  1. <template>
  2. <div class="classify-page">
  3. <div class="top-wrap">
  4. <div class="type-box">
  5. <div class="item" @click="$emit('typeChange','1')">中文分类</div>
  6. <div class="item active">英文分类</div>
  7. </div>
  8. <div style="display:flex;padding:10px;gap:10px">
  9. <el-button
  10. type="primary"
  11. @click="addClassify"
  12. v-permission="permissionBtn.enClassifyBtn.classifyList_enClassify_add"
  13. >添加分类</el-button>
  14. <el-input placeholder="分类名称" v-model="searchVal" style="max-width: 262px;" @change="getList" clearable>
  15. <i slot="prefix" class="el-input__icon el-icon-search"></i>
  16. </el-input>
  17. </div>
  18. </div>
  19. <div class="content-box">
  20. <el-tree
  21. :data="list"
  22. node-key="Id"
  23. :props="{
  24. label: 'ClassifyName',
  25. children: 'Child'
  26. }"
  27. check-strictly
  28. empty-text="暂无数据"
  29. draggable
  30. indent='76'
  31. :allow-drop="canDropHandle"
  32. @node-drop="dropOverHandle"
  33. >
  34. <div
  35. class="classify-item-wrap"
  36. slot-scope="{ node, data }"
  37. >
  38. <div>
  39. <span :class="['tag', data.Enabled==1?'open':'close']" @click.stop="handleEnableSet(data)">{{data.Enabled==1?'启用':'禁用'}}</span>
  40. <span>{{data.ClassifyName}}</span>
  41. </div>
  42. <div class="opt-box">
  43. <img class="icon-drag" src="~@/assets/img/data_m/move_ico2.png" alt="">
  44. <img class="icon-set" src="~@/assets/img/icons/variety_set.png" alt="" @click.stop="handleEdit(data,node)" v-permission="permissionBtn.enClassifyBtn.classifyList_enClassify_edit">
  45. </div>
  46. </div>
  47. </el-tree>
  48. </div>
  49. <!-- 分类弹窗 -->
  50. <m-dialog
  51. :title="classifyForm.classify_id?'编辑分类':'新增分类'"
  52. :show.sync="classifyForm.show"
  53. width="650px"
  54. >
  55. <div style="padding-left: 50px">
  56. <el-form
  57. :model="classifyForm"
  58. :rules="formRules"
  59. ref="formRef"
  60. label-position="left"
  61. hide-required-asterisk
  62. label-width="90px">
  63. <el-form-item prop="classify_name" label="分类名称">
  64. <el-input
  65. type="text"
  66. v-model="classifyForm.classify_name"
  67. placeholder="请输入分类名称"
  68. style="width:400px;"
  69. />
  70. </el-form-item>
  71. <el-form-item prop="parent_id" label="上级分类">
  72. <el-cascader :options="classifyparentArr" v-model="classifyForm.parent_id" placeholder="请选择"
  73. :props="{value:'Id',label:'ClassifyName',children:'Child',checkStrictly:true,emitPath:false}" style="min-width:400px;"></el-cascader>
  74. </el-form-item>
  75. <el-form-item prop="variety" label="关联品种" v-if="classifyForm.level==3&&permissionBtn.enClassifyBtn.classifyList_enClassify_connect_variety">
  76. <template slot="label">
  77. <el-tooltip class="item" effect="dark" content="控制报告阅读权限">
  78. <div>
  79. <span>关联品种</span>
  80. <i class="el-icon-info"></i>
  81. </div>
  82. </el-tooltip>
  83. </template>
  84. <el-cascader
  85. :options="reportVarietyList"
  86. v-model="classifyForm.variety"
  87. placeholder="请选择"
  88. collapse-tags
  89. :props="{value:'PermissionId',label:'PermissionName',children:'Child',multiple: true,emitPath:false}"
  90. style="min-width:400px;"
  91. ></el-cascader>
  92. </el-form-item>
  93. </el-form>
  94. </div>
  95. <div slot="footer" style="margin-top: 20px;">
  96. <el-button
  97. @click="cancelClassify"
  98. style="width: 132px; height: 40px"
  99. >取消</el-button>
  100. <el-button
  101. @click="setClassifyHandle"
  102. type="primary"
  103. style="width: 132px; height: 40px"
  104. >保存</el-button>
  105. </div>
  106. </m-dialog>
  107. </div>
  108. </template>
  109. <script>
  110. import draggable from 'vuedraggable';
  111. import mDialog from '@/components/mDialog.vue';
  112. import {reportVarietyENInterence} from '@/api/modules/reportVariety'
  113. import * as classifyEnInterface from "@/api/modules/classifyEnApi.js";
  114. export default {
  115. components:{draggable,mDialog},
  116. data() {
  117. return {
  118. typeVal:1,
  119. searchVal:'',
  120. list:[],
  121. classifyForm:{
  122. show:false,
  123. classify_id:0,
  124. classify_name:"",
  125. parent_id: '',
  126. variety:'',//关联的品种
  127. level:1
  128. },
  129. formRules: {
  130. classify_name: [{ required:true,message:'请输入分类名称',trigger:'blur'}]
  131. },
  132. classifyparentArr:[],
  133. reportVarietyList:[],//英文品种列表
  134. }
  135. },
  136. mounted(){
  137. this.getList('init')
  138. this.getReportVarietyList()
  139. },
  140. methods: {
  141. async getList(type){
  142. const res=await classifyEnInterface.classifyList({
  143. KeyWord:this.searchVal
  144. })
  145. if(res.Ret===200){
  146. this.list=res.Data.List||[]
  147. if(type==='init'){
  148. const arr=JSON.parse(JSON.stringify(this.list))
  149. this.classifyparentArr=arr.map(item=>{
  150. item.Child&&item.Child.forEach(_item=>{
  151. _item.Child=null
  152. })
  153. return {
  154. ...item
  155. }
  156. })
  157. this.classifyparentArr.unshift({Id:'0',ClassifyName:'无',Child:null})
  158. }
  159. }
  160. },
  161. //启用\禁用设置
  162. handleEnableSet(item){
  163. // 判断权限
  164. const {enClassifyBtn,checkPermissionBtn} = this.permissionBtn
  165. if(!checkPermissionBtn(enClassifyBtn.classifyList_enClassify_enable)) return
  166. classifyEnInterface.enableSet({
  167. ClassifyId:item.Id,
  168. Enabled:item.Enabled==1?0:1
  169. }).then(res=>{
  170. if(res.Ret===200){
  171. this.$message.success('设置成功')
  172. this.getList('init')
  173. }
  174. })
  175. },
  176. addClassify(){
  177. this.classifyForm={
  178. show:true,
  179. classify_id:0,
  180. classify_name:"",
  181. parent_id: '0',
  182. variety:'',//关联的品种
  183. }
  184. },
  185. handleEdit(item,node){
  186. this.classifyForm={
  187. show:true,
  188. classify_id:item.Id,
  189. classify_name:item.ClassifyName,
  190. parent_id: item.ParentId||'0',
  191. variety:item.EnPermissions||'',//关联的品种
  192. level:node.level
  193. }
  194. },
  195. async setClassifyHandle(){
  196. await this.$refs.formRef.validate();
  197. const { classify_name,parent_id,sort,classify_id } = this.classifyForm;
  198. let params = {
  199. ClassifyName: classify_name,
  200. ParentId: Number(parent_id)||0,
  201. EnPermissions:this.classifyForm.variety||[]
  202. }
  203. // console.log(params);
  204. const { Ret,Msg } = classify_id
  205. ? await classifyEnInterface.classifyEdit({...params,ClassifyId: classify_id})
  206. : await classifyEnInterface.classifyAdd(params)
  207. if(Ret !== 200) return
  208. this.$message.success(Msg)
  209. this.cancelClassify();
  210. this.getList('init');
  211. },
  212. /* 取消 */
  213. cancelClassify() {
  214. this.$refs.formRef.resetFields();
  215. this.classifyForm.show = false;
  216. },
  217. // 获取品种数据
  218. getReportVarietyList(){
  219. reportVarietyENInterence.filterVarietyOpts().then(res=>{
  220. this.reportVarietyList=res.Data||[]
  221. })
  222. },
  223. //控制只能同级拖动
  224. canDropHandle(draggingNode, dropNode, type){
  225. if(type==='inner') return false //禁止向内部拖动
  226. if(draggingNode.level!=dropNode.level) return false
  227. if(draggingNode.data.ParentId!=dropNode.data.ParentId) return false
  228. return true
  229. },
  230. //拖动结束
  231. dropOverHandle(b,a,i,e) {
  232. // 被拖拽节点对应的 Node、结束拖拽时最后进入的节点、被拖拽节点的放置位置
  233. const classifyId=b.data.Id
  234. let list=a.parent.childNodes;
  235. let PrevClassifyId=0,NextClassifyId=0,targetIndex=0;
  236. list.forEach((item,index) => {
  237. if(item.data.Id===classifyId){
  238. targetIndex=index
  239. }
  240. });
  241. if(targetIndex===0){
  242. NextClassifyId=list[1].data.Id
  243. }else if(targetIndex===list.length-1){
  244. PrevClassifyId=list[list.length-1].data.Id
  245. }else{
  246. PrevClassifyId=list[targetIndex-1].data.Id
  247. NextClassifyId=list[targetIndex+1].data.Id
  248. }
  249. const params={
  250. ClassifyId:classifyId,
  251. PrevClassifyId,
  252. NextClassifyId
  253. }
  254. console.log(params);
  255. classifyEnInterface.moveSort(params).then(res=>{
  256. if(res.Ret===200){
  257. this.$message.success('移动成功')
  258. }else{
  259. this.getList()
  260. }
  261. })
  262. },
  263. },
  264. }
  265. </script>
  266. <style lang="scss">
  267. .el-cascader .el-input{
  268. width: 100%;
  269. }
  270. .classify-page{
  271. .content-box{
  272. .el-tree-node__content{
  273. padding-top: 10px;
  274. padding-bottom: 10px;
  275. border-bottom: 1px solid #C8CDD9;
  276. }
  277. }
  278. }
  279. </style>
  280. <style lang="scss" scoped>
  281. .top-wrap{
  282. display: flex;
  283. justify-content: space-between;
  284. background: #FFFFFF;
  285. border-radius: 4px;
  286. .type-box{
  287. display: flex;
  288. .item{
  289. position: relative;
  290. cursor: pointer;
  291. color: #666;
  292. min-width: 88px;
  293. line-height: 60px;
  294. text-align: center;
  295. }
  296. .active{
  297. color: #0052D9;
  298. &::after{
  299. content: '';
  300. display: block;
  301. width: 100%;
  302. height: 2px;
  303. position: absolute;
  304. bottom: 0px;
  305. left: 0;
  306. background-color: #0052D9;
  307. }
  308. }
  309. }
  310. }
  311. .content-box{
  312. padding: 20px;
  313. margin-top: 20px;
  314. height: calc(100vh - 230px);
  315. overflow-y: auto;
  316. background-color: #FFFFFF;
  317. .classify-item-wrap{
  318. flex: 1;
  319. padding-right: 20px;
  320. display: flex;
  321. justify-content: space-between;
  322. align-items: center;
  323. .tag{
  324. display: inline-block;
  325. min-width: 76px;
  326. line-height: 30px;
  327. text-align: center;
  328. &.open{
  329. background-color: #ECF2FE;
  330. color: #0052D9;
  331. }
  332. &.close{
  333. background-color: #0052D9;
  334. color: #fff;
  335. }
  336. }
  337. .opt-box{
  338. .icon-drag,.icon-set{
  339. width: 16px;
  340. height: 16px;
  341. margin-left: 10px;
  342. }
  343. }
  344. }
  345. }
  346. </style>