阅行客电子档案
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

228 lines
8.0 KiB

  1. <template>
  2. <div class="app-container category-container">
  3. <!-- 门类列表 -->
  4. <div class="container-main">
  5. <div class="elect-cont-left">
  6. <div class="head-container">
  7. <crudOperation :permission="permission">
  8. <template v-slot:left>
  9. <!-- crud.selections.length === 0 || crud.selections[0].isType === 2 || crud.selections[0].isType === 3 || crud.selections[0].isType === 5 -->
  10. <el-button v-permission="permission.add" size="mini" :disabled="crud.selections.length === 0 || crud.selections[0].isType === 3" @click="crud.toAdd">
  11. <i class="iconfont icon-xinzeng" />
  12. 新增
  13. </el-button>
  14. <el-button v-permission="permission.edit" size="mini" :disabled="crud.selections.length !== 1 || crud.selections[0].pid === '0'" @click="crud.toEdit(crud.selections[0])">
  15. <i class="iconfont icon-bianji" />
  16. 编辑
  17. </el-button>
  18. </template>
  19. <template v-slot:right>
  20. <el-button v-permission="permission.del" size="mini" :loading="crud.delAllLoading" :disabled="crud.selections.length === 0 || (crud.selections.length === 1 && crud.selections[0].pid === '0' )" @click="toDelete(crud.selections)">
  21. <i class="iconfont icon-shanchu" />
  22. 删除
  23. </el-button>
  24. <el-button v-permission="permission.sort" icon="el-icon-sort" size="mini" :loading="sortLoading" :disabled="brotherNodeNum <= 1 || crud.selections[0].pid === '0' " @click="toSort(crud.selections)">排序</el-button>
  25. </template>
  26. </crudOperation>
  27. </div>
  28. <div class="container-left">
  29. <span class="right-top-line" />
  30. <span class="left-bottom-line" />
  31. <!--门类树状结构-->
  32. <div class="tree-scroll">
  33. <el-tree ref="tree" v-loading="crud.loading" :data="crud.data" :props="defaultProps" node-key="id" :expand-on-click-node="false" highlight-current @node-click="handleNodeClick">
  34. <span slot-scope="{ node, data }" class="custom-tree-node">
  35. <span v-if="data.isType === 1" class="iconFolder">
  36. {{ data.cnName }}
  37. </span>
  38. <span v-if="data.isType === 2" class="iconStoreHouse">
  39. {{ data.cnName }}
  40. </span>
  41. <span v-if="data.isType === 3" class="iconArea">
  42. {{ data.cnName }}
  43. </span>
  44. </span>
  45. </el-tree>
  46. </div>
  47. </div>
  48. </div>
  49. <!-- 门类管理tab -->
  50. <div class="elect-cont-right">
  51. <div class="container-right">
  52. <span class="right-top-line" />
  53. <span class="left-bottom-line" />
  54. </div>
  55. </div>
  56. <!--修改新增表单组件-->
  57. <eForm ref="eform" :selected-store="selectedStore" />
  58. <!--排序对话框组件-->
  59. <!-- <sortDialog ref="sort" @treeNodeSort="treeNodeSort" /> -->
  60. </div>
  61. </div>
  62. </template>
  63. <script>
  64. import crudCategory from '@/api/system/category/category'
  65. import CRUD, { presenter, header } from '@crud/crud'
  66. import crudOperation from '@crud/CRUD.operation'
  67. import eForm from './form'
  68. import Vue from 'vue'
  69. import dataJson from './data.json'
  70. export default {
  71. name: 'DeviceManage',
  72. components: { crudOperation, eForm },
  73. cruds() {
  74. return [
  75. CRUD({
  76. title: '库房设备管理', url: 'api/category/menu',
  77. crudMethod: { ...crudCategory },
  78. optShow: {
  79. add: false,
  80. edit: false,
  81. del: false,
  82. download: false,
  83. group: false
  84. }
  85. })
  86. ]
  87. },
  88. mixins: [presenter(), header()],
  89. data() {
  90. return {
  91. permission: {
  92. add: ['admin', 'device:add'],
  93. edit: ['admin', 'device:edit'],
  94. del: ['admin', 'device:del'],
  95. sort: ['admin', 'device:sort']
  96. },
  97. defaultProps: {
  98. children: 'children',
  99. label: 'cnName'
  100. },
  101. deleteVisible: false,
  102. reconfirmDeleteVisible: false,
  103. selectedStore: {},
  104. deleteData: {},
  105. sortLoading: false,
  106. brotherNodeNum: 0,
  107. sortTableData: []
  108. }
  109. },
  110. created() {
  111. },
  112. methods: {
  113. // 逆归实现 获取指定元素
  114. findNode(tree, func) {
  115. for (const node of tree) {
  116. if (func(node)) return node
  117. if (node.children) {
  118. const res = this.findNode(node.children, func)
  119. if (res) return res
  120. }
  121. }
  122. return null
  123. },
  124. // 展开选中的父级
  125. expandParents(node) {
  126. node.expanded = true
  127. if (node.parent) {
  128. this.expandParents(node.parent)
  129. }
  130. },
  131. [CRUD.HOOK.afterRefresh]() {
  132. this.crud.data = dataJson.data
  133. let currentKey
  134. if (localStorage.getItem('currentStoreKey')) {
  135. currentKey = JSON.parse(localStorage.getItem('currentStoreKey'))
  136. } else {
  137. if (this.crud.data[0].isType === 1) {
  138. currentKey = this.findNode(this.crud.data[0].children, (node) => {
  139. return node.isType !== 1
  140. })
  141. } else {
  142. currentKey = this.crud.data[0]
  143. }
  144. }
  145. // 设置某个节点的当前选中状态
  146. this.$refs.tree.setCurrentKey(currentKey.id)
  147. this.$nextTick(() => {
  148. // 设置某个节点的父级展开
  149. const selectedKey = this.$refs.tree.getCurrentNode()
  150. if (this.$refs.tree.getNode(selectedKey) && this.$refs.tree.getNode(selectedKey).parent) {
  151. this.expandParents(this.$refs.tree.getNode(selectedKey).parent)
  152. }
  153. // 选中节点的门类详情
  154. this.handleNodeClick(selectedKey)
  155. })
  156. },
  157. // 选中门类后,设置门类详情数据
  158. handleNodeClick(val) {
  159. if (val) {
  160. this.crud.selectionChangeHandler([val])
  161. this.$refs.eform.pid = val.id
  162. this.selectedStore = val
  163. if (val.pid !== '0') {
  164. Vue.set(this.selectedStore, 'parentName', this.$refs.tree.getNode(val.pid).data.cnName)
  165. }
  166. // 缓存当前的选中的
  167. localStorage.setItem('currentStoreKey', JSON.stringify(val))
  168. if (this.$refs.tree.getNode(val.pid) && this.$refs.tree.getNode(val.pid).childNodes) {
  169. this.brotherNodeNum = this.$refs.tree.getNode(val.pid).childNodes.length
  170. }
  171. }
  172. },
  173. // 新增 - 判断当前节点类型,卷内/文件不可新建
  174. [CRUD.HOOK.beforeToAdd](crud, form, btn) {
  175. const isCanAddKey = JSON.parse(localStorage.getItem('currentStoreKey'))
  176. if (isCanAddKey.isType === 4 || isCanAddKey.isType === 5) {
  177. this.$message({
  178. message: '此门类下不可新建门类',
  179. type: 'error',
  180. duration: 2500
  181. })
  182. return false
  183. }
  184. this.$refs.eform.beforeToAdd()
  185. },
  186. // 新增/编辑后 - 新增后默认选中新增的库房
  187. [CRUD.HOOK.afterSubmit](crud, addedCategory) {
  188. if (addedCategory) {
  189. // 缓存当前的选中的
  190. localStorage.setItem('currentStoreKey', JSON.stringify(addedCategory))
  191. }
  192. },
  193. treeNodeSort(data) {
  194. this.$refs.tree.updateKeyChildren(data[0].pid, JSON.parse(JSON.stringify(data)))
  195. },
  196. // 删除门类
  197. toDelete(data) {
  198. this.deleteData = data
  199. this.$confirm('此操作将删除当前所选区域及其子集' + '<span>你是否还要继续?</span>', '提示', {
  200. confirmButtonText: '继续',
  201. cancelButtonText: '取消',
  202. type: 'warning',
  203. dangerouslyUseHTMLString: true
  204. }).then(() => {
  205. }).catch(() => {
  206. })
  207. },
  208. handleClose(done) {
  209. this.deleteData = {}
  210. done()
  211. },
  212. toSort(data) {
  213. this.$refs.sort.sortTableData = this.$refs.tree.getNode(data[0].pid).data.children
  214. this.$refs.sort.sortVisible = true
  215. }
  216. }
  217. }
  218. </script>
  219. <style lang="scss" scoped>
  220. .tree-scroll{
  221. font-size: 14px;
  222. }
  223. </style>