classifylistV2.vue 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522
  1. <template>
  2. <div class="classify-page">
  3. <div class="top-wrap">
  4. <div class="type-box">
  5. <!-- 中文分类 -->
  6. <div class="item active"
  7. v-permission="[
  8. permissionBtn.classifyBtn.classifyList_cnClassify,
  9. permissionBtn.enClassifyBtn.classifyList_enClassify,
  10. 'and'
  11. ]">
  12. {{ $t('ReportManage.CategoryList.chinese_tabs') }}
  13. </div>
  14. <!-- 英文分类 -->
  15. <div class="item" @click="$emit('typeChange','2')" style="margin-left: 20px;"
  16. v-permission="permissionBtn.enClassifyBtn.classifyList_enClassify">
  17. {{ $t('ReportManage.CategoryList.english_tabs') }}
  18. </div>
  19. </div>
  20. <div style="display:flex;padding:10px;gap:10px">
  21. <!-- <el-button type="primary" @click="transferReport">分类报告转移</el-button> -->
  22. <!-- 添加分类 -->
  23. <el-button
  24. type="primary"
  25. @click="addClassify"
  26. v-permission="permissionBtn.classifyBtn.classifyList_cnClassify_classifyAdd"
  27. >
  28. {{$t('ReportManage.CategoryList.add_category')}}
  29. </el-button>
  30. <el-input :placeholder="$t('ReportManage.CategoryList.category_name')" v-model="searchVal" style="max-width: 262px;" @change="getList" clearable>
  31. <i slot="prefix" class="el-input__icon el-icon-search"></i>
  32. </el-input>
  33. </div>
  34. </div>
  35. <div class="content-box">
  36. <el-tree
  37. :data="list"
  38. node-key="Id"
  39. :props="{
  40. label: 'ClassifyName',
  41. children: 'Child'
  42. }"
  43. check-strictly
  44. :empty-text="$t('Common.no_classify_msg')"
  45. draggable
  46. indent='76'
  47. :allow-drop="canDropHandle"
  48. @node-drop="dropOverHandle"
  49. >
  50. <div
  51. class="classify-item-wrap"
  52. slot-scope="{ data }"
  53. >
  54. <div>
  55. <span
  56. :class="['tag', data.Enabled==1?'open':'close']"
  57. @click.stop="handleEnableSet(data)">
  58. {{data.Enabled==1?$t('Common.enable'):$t('Common.disable')}}
  59. </span>
  60. <span>{{data.ClassifyName}}</span>
  61. </div>
  62. <div class="opt-box">
  63. <!-- 章节设置 -->
  64. <span class="editsty"
  65. v-if="!data.Child || (data.Child&&!data.Child.length)"
  66. @click="chapterSetting(data)"
  67. v-permission="permissionBtn.classifyBtn.classifyList_cnClassify_chapterSetting">
  68. {{ $t('ReportManage.CategoryList.section_settings') }}
  69. </span>
  70. <img class="icon-drag" src="~@/assets/img/data_m/move_ico2.png" alt="">
  71. <img class="icon-set" src="~@/assets/img/icons/variety_set.png" alt="" @click.stop="handleEdit(data)" v-permission="permissionBtn.classifyBtn.classifyList_cnClassify_classifyEdit">
  72. </div>
  73. </div>
  74. </el-tree>
  75. </div>
  76. <!-- 分类弹窗 -->
  77. <m-dialog
  78. :title="classifyForm.classify_id?$t('ReportManage.CategoryList.edit_category'):$t('ReportManage.CategoryList.add_category')"
  79. :show.sync="classifyForm.show"
  80. v-if="classifyForm.show"
  81. width="650px"
  82. >
  83. <div style="padding-left: 50px">
  84. <el-form
  85. :model="classifyForm"
  86. :rules="formRules"
  87. ref="formRef"
  88. hide-required-asterisk
  89. label-width="auto">
  90. <!-- 分类名称 -->
  91. <el-form-item prop="classify_name" :label="$t('ReportManage.CategoryList.category_name')">
  92. <el-input
  93. type="text"
  94. v-model="classifyForm.classify_name"
  95. :placeholder="$t('ReportManage.CategoryList.category_name_hint')"
  96. style="width:400px;"
  97. />
  98. </el-form-item>
  99. <!-- 上级分类 -->
  100. <el-form-item prop="parent_id" :label="$t('ReportManage.CategoryList.parent_category')">
  101. <el-cascader
  102. v-model="classifyForm.parent_id"
  103. :options="classifyparentArr"
  104. :disabled="classifyForm.classify_id"
  105. style="width:400px;"
  106. ref="classifyRef"
  107. :props="{
  108. checkStrictly: true,
  109. value: 'Id',
  110. label: 'ClassifyName',
  111. children:'Child',
  112. emitPath:false
  113. }"
  114. clearable
  115. @change="changeClassify"
  116. >
  117. </el-cascader>
  118. </el-form-item>
  119. <!-- 关联品种 -->
  120. <el-form-item prop="variety" :label="$t('ReportManage.CategoryList.related_variety')" v-if="canSetPermission">
  121. <template slot="label">
  122. <el-tooltip class="item" effect="dark" :content="$t('ReportManage.CategoryList.related_variety_hint')">
  123. <div>
  124. <span>{{ $t('ReportManage.CategoryList.related_variety') }}</span>
  125. <i class="el-icon-info"></i>
  126. </div>
  127. </el-tooltip>
  128. </template>
  129. <el-cascader
  130. :options="reportVarietyList"
  131. v-model="classifyForm.variety"
  132. :placeholder="$t('ReportManage.CategoryList.related_variety_inputhint')"
  133. collapse-tags
  134. :props="{value:'PermissionId',label:'PermissionName',children:'Child',multiple: true,emitPath:false}"
  135. style="min-width:400px;"
  136. ></el-cascader>
  137. </el-form-item>
  138. </el-form>
  139. <div v-html="tips" style="color:#999;"></div>
  140. </div>
  141. <div slot="footer" style="margin-top: 20px;">
  142. <el-button
  143. @click="cancelClassify"
  144. style="width: 132px; height: 40px"
  145. >{{ $t('Dialog.cancel_btn') }}</el-button>
  146. <el-button
  147. @click="setClassifyHandle"
  148. type="primary"
  149. style="width: 132px; height: 40px"
  150. >{{ $t('Dialog.confirm_save_btn') }}</el-button>
  151. </div>
  152. </m-dialog>
  153. <!-- 转移报告弹窗 -->
  154. <m-dialog
  155. title="分类报告转移"
  156. :show.sync="isTransferReport"
  157. width="650px"
  158. >
  159. <div>
  160. <el-form
  161. :model="transferForm"
  162. hide-required-asterisk
  163. label-width="auto"
  164. >
  165. <el-form-item prop="classify_name" label="原分类">
  166. <el-cascader
  167. v-model="transferForm.oldClassify"
  168. @change="filterChange"
  169. :options="classifyparentArr"
  170. clearable
  171. placeholder="请选择分类"
  172. style="width:100%;"
  173. ></el-cascader>
  174. </el-form-item>
  175. <!-- 上级分类 -->
  176. <el-form-item prop="parent_id" label="转移至分类">
  177. <el-cascader
  178. v-model="transferForm.newClassify"
  179. @change="filterChange"
  180. :options="classifyparentArr"
  181. clearable
  182. placeholder="请选择分类"
  183. style="width:100%;"
  184. ></el-cascader>
  185. </el-form-item>
  186. </el-form>
  187. </div>
  188. <div slot="footer" style="margin-top: 20px;">
  189. <el-button
  190. @click="isTransferReport=false"
  191. style="width: 132px; height: 40px"
  192. >{{ $t('Dialog.cancel_btn') }}</el-button>
  193. <el-button
  194. @click="handleSaveTransferReport"
  195. type="primary"
  196. style="width: 132px; height: 40px"
  197. >{{ $t('Dialog.confirm_save_btn') }}</el-button>
  198. </div>
  199. </m-dialog>
  200. </div>
  201. </template>
  202. <script>
  203. import mDialog from '@/components/mDialog.vue';
  204. import { classifylist,classifyparent,classifyadd,classifyedit } from 'api/api.js';
  205. import {reportVarietyInterence} from '@/api/modules/reportVariety'
  206. import {classifyPermissionInterface} from '@/api/modules/classifyApi.js'
  207. import { reportV2Interface } from '@/api/modules/reportV2.js'
  208. export default {
  209. components:{mDialog},
  210. computed: {
  211. canSetPermission() {
  212. /* 编辑最小级分类可设置品种 新增分类可设置跑品种 */
  213. if(!this.permissionBtn.classifyBtn.classifyList_cnClassify_connect_variety) return false
  214. if(this.classifyForm.classify_id) {
  215. return this.classifyForm.isLastLevel?true:false
  216. }else {
  217. return true
  218. }
  219. }
  220. },
  221. data() {
  222. return {
  223. typeVal:1,
  224. searchVal:'',
  225. list:[],
  226. classifyForm:{
  227. show:false,
  228. classify_id:0,
  229. classify_name:"",
  230. parent_id: 0,
  231. variety:'',//关联的品种
  232. },
  233. formRules: {
  234. classify_name: [{ required:true,message:this.$t('ReportManage.CategoryList.category_name_hint'),trigger:'blur'}]
  235. },
  236. classifyparentArr:[],
  237. reportVarietyList:[],//中文品种列表
  238. /* 转移报告弹窗 */
  239. isTransferReport: false,
  240. transferForm: {},
  241. tips: `注:若上级分类已关联报告,则新建的第一个子分类默认继承上级分类(父分类)关联的品种、报告、审批流,且关联品种支持编辑。 `
  242. }
  243. },
  244. mounted(){
  245. this.getList()
  246. this.getReportVarietyList()
  247. },
  248. methods: {
  249. /* 报告转移 */
  250. transferReport() {
  251. this.isTransferReport = true;
  252. this.transferForm = {
  253. oldClassify: '',
  254. newClassify: ''
  255. }
  256. },
  257. handleSaveTransferReport() {
  258. },
  259. async getList(type){
  260. const res=await classifylist({
  261. KeyWord:this.searchVal,
  262. })
  263. if(res.Ret===200){
  264. this.list=res.Data.List||[]
  265. this.classifyparentArr=_.cloneDeep(this.list)
  266. this.filterNodes(this.classifyparentArr)
  267. }
  268. },
  269. /* 添加分类默认关联父级品种 */
  270. async changeClassify(id) {
  271. if(!this.classifyForm.classify_id) {
  272. let item = this.$refs.classifyRef.getCheckedNodes(true)
  273. console.log(item)
  274. if(item&&item.length) {
  275. this.classifyForm.variety = item[0].data.ChartPermissionIdList
  276. }
  277. }
  278. },
  279. // 去设置章节
  280. chapterSetting(row){
  281. this.$router.push({path:'chapterSetting',query:{ id:row.Id,classifyName: row.ClassifyName }})
  282. },
  283. filterNodes(arr) {
  284. arr.length && arr.forEach(item => {
  285. item.Child && item.Child.length && this.filterNodes(item.Child)
  286. if(!item.Child || (item.Child&&!item.Child.length) || item.Level===2) {
  287. delete item.Child
  288. }
  289. })
  290. },
  291. async addClassify(){
  292. this.classifyForm={
  293. show:true,
  294. classify_id:0,
  295. classify_name:"",
  296. parent_id: 0,
  297. variety:'',//关联的品种
  298. }
  299. },
  300. async handleEdit(item){
  301. this.classifyForm={
  302. show:true,
  303. classify_id:item.Id,
  304. classify_name:item.ClassifyName,
  305. parent_id: item.ParentId,
  306. variety:item.ChartPermissionIdList||'',//关联的品种
  307. isLastLevel: !item.Child
  308. }
  309. },
  310. async setClassifyHandle(){
  311. await this.$refs.formRef.validate();
  312. const { classify_name,parent_id,classify_id } = this.classifyForm;
  313. let params = {
  314. ClassifyName: classify_name,
  315. ParentId: parent_id,
  316. ChartPermissionIdList:this.classifyForm.variety||[]
  317. }
  318. const { Ret,Msg } = classify_id
  319. ? await classifyedit({...params,ClassifyId: classify_id})
  320. : await classifyadd(params)
  321. if(Ret !== 200) return
  322. //this.$message.success(Msg)
  323. this.$message.success(
  324. classify_id
  325. ?this.$t('ReportManage.CategoryList.modification_successful')
  326. :this.$t('ReportManage.CategoryList.addition_successful')
  327. )
  328. this.cancelClassify();
  329. this.getList();
  330. },
  331. /* 取消 */
  332. cancelClassify() {
  333. this.$refs.formRef.resetFields();
  334. this.classifyForm.show = false;
  335. },
  336. // 获取品种数据
  337. getReportVarietyList(){
  338. reportVarietyInterence.filterVarietyOpts().then(res=>{
  339. console.log(res);
  340. this.reportVarietyList=res.Data||[]
  341. })
  342. },
  343. //启用\禁用设置
  344. handleEnableSet(item){
  345. // 判断权限
  346. const {classifyBtn,checkPermissionBtn} = this.permissionBtn
  347. if(!checkPermissionBtn(classifyBtn.classifyList_cnClassify_enable)) return
  348. classifyPermissionInterface.enableSet({
  349. ClassifyId:item.Id,
  350. Enabled:item.Enabled==1?0:1
  351. }).then(res=>{
  352. if(res.Ret===200){
  353. //设置成功
  354. this.$message.success(this.$t('ReportManage.CategoryList.setup_successful'))
  355. this.getList()
  356. }
  357. })
  358. },
  359. //控制只能同级拖动
  360. canDropHandle(draggingNode, dropNode, type){
  361. if(type==='inner') return false //禁止向内部拖动
  362. if(draggingNode.level!=dropNode.level) return false
  363. if(draggingNode.data.ParentId!=dropNode.data.ParentId) return false
  364. return true
  365. },
  366. //拖动结束
  367. dropOverHandle(b,a,i,e) {
  368. // 被拖拽节点对应的 Node、结束拖拽时最后进入的节点、被拖拽节点的放置位置
  369. const classifyId=b.data.Id
  370. let list=a.parent.childNodes;
  371. let PrevClassifyId=0,NextClassifyId=0,targetIndex=0;
  372. list.forEach((item,index) => {
  373. if(item.data.Id===classifyId){
  374. targetIndex=index
  375. }
  376. });
  377. if(targetIndex===0){
  378. NextClassifyId=list[1].data.Id
  379. }else if(targetIndex===list.length-1){
  380. PrevClassifyId=list[list.length-1].data.Id
  381. }else{
  382. PrevClassifyId=list[targetIndex-1].data.Id
  383. NextClassifyId=list[targetIndex+1].data.Id
  384. }
  385. const params={
  386. ClassifyId:classifyId,
  387. PrevClassifyId,
  388. NextClassifyId
  389. }
  390. console.log(params);
  391. classifyPermissionInterface.moveSort(params).then(res=>{
  392. if(res.Ret===200){
  393. this.$message.success(this.$t('ReportManage.CategoryList.move_successful'))
  394. }else{
  395. this.getList()
  396. }
  397. })
  398. },
  399. },
  400. }
  401. </script>
  402. <style lang="scss">
  403. .el-cascader .el-input{
  404. width: 100%;
  405. }
  406. .classify-page{
  407. .content-box{
  408. .el-tree-node__content{
  409. height: fit-content;
  410. padding-top: 10px;
  411. padding-bottom: 10px;
  412. border-bottom: 1px solid #C8CDD9;
  413. }
  414. }
  415. }
  416. </style>
  417. <style lang="scss" scoped>
  418. .top-wrap{
  419. display: flex;
  420. justify-content: space-between;
  421. background: #FFFFFF;
  422. border-radius: 4px;
  423. .type-box{
  424. display: flex;
  425. .item{
  426. position: relative;
  427. cursor: pointer;
  428. color: #666;
  429. min-width: 88px;
  430. line-height: 60px;
  431. text-align: center;
  432. }
  433. .active{
  434. color: #0052D9;
  435. &::after{
  436. content: '';
  437. display: block;
  438. width: 100%;
  439. height: 2px;
  440. position: absolute;
  441. bottom: 0px;
  442. left: 0;
  443. background-color: #0052D9;
  444. }
  445. }
  446. }
  447. }
  448. .content-box{
  449. padding: 20px;
  450. margin-top: 20px;
  451. height: calc(100vh - 230px);
  452. overflow-y: auto;
  453. background-color: #FFFFFF;
  454. .classify-item-wrap{
  455. flex: 1;
  456. padding-right: 20px;
  457. display: flex;
  458. justify-content: space-between;
  459. align-items: center;
  460. .tag{
  461. display: inline-block;
  462. min-width: 76px;
  463. line-height: 30px;
  464. text-align: center;
  465. &.open{
  466. background-color: #ECF2FE;
  467. color: #0052D9;
  468. }
  469. &.close{
  470. background-color: #0052D9;
  471. color: #fff;
  472. }
  473. }
  474. .opt-box{
  475. .icon-drag,.icon-set{
  476. width: 16px;
  477. height: 16px;
  478. margin-left: 10px;
  479. }
  480. }
  481. }
  482. }
  483. </style>