audit-maintain-catalog.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373
  1. <template>
  2. <div :class="$style.wrapHeight">
  3. <div :class="$style.rowHeight">
  4. <audit-maintain-classify-tree
  5. ref="auditMaintainCatalogTree"
  6. show-line
  7. top-node-text="审计模型"
  8. :is-select-dep="true"
  9. :draggable="true"
  10. :cate="true"
  11. @treeSelect="treeSelect"
  12. @depChanged="depChanged"
  13. ></audit-maintain-classify-tree>
  14. <div :class="$style.rightcard">
  15. <a-card>
  16. <sd-data-table-ex
  17. :key="key"
  18. ref="dataTable"
  19. :editnode="editnode"
  20. form-id="iamModelCategory"
  21. page-id="audit/maintain/iamModelCategory"
  22. :columns="columns1"
  23. :actions="actions"
  24. :search-fields="['categoryName']"
  25. :filter-expressions="expressions"
  26. :show-selection="(item) => item.editAndDeleteAuth !== 0"
  27. :custom-delete-fun="deleteRows"
  28. @recordSaved="onRecordSaved"
  29. @formBtnClick="formBtnClick"
  30. >
  31. <template slot="categoryName" slot-scope="text, record">
  32. <a
  33. v-if="record.editAndDeleteAuth !== 0"
  34. @click="
  35. () => {
  36. $refs.dataTable.showDetailModal(record.id, 'audit/maintain/iamModelCategory')
  37. }
  38. "
  39. >{{ text }}</a
  40. >
  41. <span v-else>{{ text }}</span>
  42. </template>
  43. <!-- 详情表单 -->
  44. <template v-slot:form="{ model }" v-sd-watermark="waterMark" @saved="onSaved">
  45. <!-- 一般字段直接写name即可 -->
  46. <a-form-model-item
  47. prop="id"
  48. label="分类编号"
  49. :rules="[
  50. { validator: validator },
  51. {
  52. required: true,
  53. trigger: ['change', 'blur'],
  54. },
  55. ]"
  56. >
  57. <a-input v-model.trim="model.categoryId" />
  58. </a-form-model-item>
  59. <sd-form-item name="categoryName" />
  60. <sd-form-item name="categoryDesc">
  61. <a-textarea v-model="model.categoryDesc" :rows="3" />
  62. </sd-form-item>
  63. <sd-form-item name="isLeaf" />
  64. <sd-form-item name="sortNum" />
  65. <sd-form-item
  66. :hidden="true"
  67. name="parentId"
  68. :input-props="{ defaultValue: parentId, disabled: true }"
  69. />
  70. <sd-form-item
  71. :hidden="true"
  72. name="auditOrgId"
  73. :input-props="{ defaultValue: auditOrgId, disabled: true }"
  74. />
  75. <!-- <sd-form-item
  76. :hidden="true"
  77. name="catalogPath"
  78. :input-props="{ defaultValue: catalogPath, disabled: true }"
  79. /> -->
  80. </template>
  81. </sd-data-table-ex>
  82. </a-card>
  83. </div>
  84. </div>
  85. </div>
  86. </template>
  87. <script>
  88. import { Modal, message } from 'ant-design-vue'
  89. import TableColumnTypes from '@/common/services/table-column-types'
  90. import systemManage from '@/system-manage/system-manage'
  91. import debounce from 'lodash.debounce'
  92. import axios from '@/common/services/axios-instance'
  93. import TableActionTypes from '@/common/services/table-action-types'
  94. import auditMaintainClassifyTree from './audit-maintain-classify-tree'
  95. import auditMaintainService from './audit-maintain-service'
  96. import components from './_import-components/audit-maintain-catalog-import'
  97. export default {
  98. name: 'AuditMaintainCatalog',
  99. metaInfo: {
  100. title: '模型分类配置',
  101. },
  102. components: {
  103. ...components,
  104. auditMaintainClassifyTree,
  105. },
  106. data() {
  107. return {
  108. editnode: true, // 列表是否可以新建
  109. key: 0,
  110. waterMark: systemManage.getFormWaterMark(),
  111. treeData: [],
  112. columns1: [
  113. {
  114. dataIndex: 'id',
  115. sdHidden: true,
  116. },
  117. {
  118. dataIndex: 'parentId',
  119. sdHidden: true,
  120. },
  121. {
  122. title: '排序号',
  123. dataIndex: 'sortNum',
  124. defaultSortOrder: 'ascend',
  125. width: '100px',
  126. },
  127. {
  128. title: '分类编号',
  129. // dataIndex: 'id',
  130. // categoryId
  131. dataIndex: 'categoryId',
  132. },
  133. {
  134. title: '分类名称',
  135. dataIndex: 'categoryName',
  136. scopedSlots: { customRender: 'categoryName' },
  137. },
  138. {
  139. title: '创建时间',
  140. dataIndex: 'creationTime',
  141. sorter: true,
  142. sdRender: TableColumnTypes.date,
  143. },
  144. {
  145. title: '是否末级分类',
  146. dataIndex: 'isLeaf',
  147. },
  148. ],
  149. actions: [],
  150. actionscsh: [
  151. {
  152. label: '新建',
  153. type: 'primary',
  154. callback: this.create,
  155. permission: null,
  156. },
  157. {
  158. label: '删除',
  159. id: 'delete',
  160. permission: null,
  161. type: 'delete',
  162. callback: this.deleteRows,
  163. },
  164. ],
  165. expressions: [
  166. {
  167. dataType: 'long',
  168. name: 'parentId',
  169. op: 'eq',
  170. longValue: null,
  171. },
  172. // {
  173. // dataType: 'long',
  174. // name: 'auditOrgId',
  175. // op: 'eq',
  176. // longValue: null,
  177. // },
  178. ],
  179. parentId: null,
  180. auditOrgId: null,
  181. parentName: '业务类型',
  182. catalogPath: null,
  183. isEnd: null,
  184. isroot: true,
  185. }
  186. },
  187. created() {},
  188. methods: {
  189. treeSelect(selectedKeys, info) {
  190. this.parentId = null
  191. if (selectedKeys.length === 0) return
  192. this.catalogPath = null
  193. // 父级id
  194. if (info != null && info.selectedNodes[0]) {
  195. if (info.node.dataRef.props.isroot) {
  196. this.isroot = true
  197. this.parentId = 0
  198. } else {
  199. this.isroot = false
  200. this.parentId = Number(info.selectedNodes[0].data.props.id)
  201. }
  202. this.parentName = info.selectedNodes[0].data.props.text // 父级名称
  203. // this.orgId = Number(info.selectedNodes[0].data.props.id)
  204. this.editnode = info.selectedNodes[0].data.props.edit
  205. if (info.selectedNodes[0].data.props.props) {
  206. this.isEnd = info.selectedNodes[0].data.props.props.isEnd
  207. }
  208. // 判断父节点不为根节点
  209. if (this.parentId !== this.$refs.auditMaintainCatalogTree.depvalue) {
  210. this.catalogPath = this.parentId
  211. }
  212. } else {
  213. if (selectedKeys.id) {
  214. this.parentId = Number(selectedKeys.id)
  215. this.parentName = selectedKeys.text // 父级名称
  216. } else {
  217. this.parentId = 0
  218. }
  219. }
  220. // 如果是末级,则隐藏新建按钮
  221. this.expressions.forEach((item) => {
  222. if (item.name === 'parentId') {
  223. item.longValue = this.parentId
  224. }
  225. })
  226. this.expressions = [...this.expressions]
  227. // this.auditOrgId = this.parentId
  228. },
  229. // 部门下拉框选择事件
  230. depChanged(value, info) {
  231. // this.auditOrgId = this.$refs.auditMaintainCatalogTree.depvalue
  232. // this.auditOrgId = value
  233. // 获取当前节点权限 判断按钮是否显示
  234. // if (typeof this.auditOrgId !== 'number' && this.auditOrgId.indexOf('o_') > -1) {
  235. // this.showeditbutton(this.auditOrgId.replaceAll('o_', ''))
  236. // } else {
  237. // this.showeditbutton(this.auditOrgId)
  238. this.showeditbutton()
  239. // }
  240. },
  241. // 新建保存回调刷新树
  242. onRecordSaved() {
  243. this.$refs.auditMaintainCatalogTree.refreshNode(this.parentId)
  244. },
  245. // 删除回调
  246. onRecordsDeleted() {
  247. message.success('删除成功')
  248. this.$refs.auditMaintainCatalogTree.refreshNode(this.parentId)
  249. },
  250. formBtnClick(evt, btn) {},
  251. validator(rule, value, callback) {
  252. let id = -1
  253. if (this.$refs.dataTable.recordId) {
  254. id = this.$refs.dataTable.recordId
  255. }
  256. value = encodeURIComponent(value)
  257. const url =
  258. `api/xcoa-mobile/v1/iammodelcategory/check-category-code?catalogCode=${value}&parentId=${this.parentId}&id=` +
  259. id
  260. debounce(() => {
  261. axios.get(url).then((res) => {
  262. if (res.data) {
  263. callback()
  264. } else {
  265. callback('已存在分类编码,不可以重复')
  266. }
  267. })
  268. }, 500)()
  269. },
  270. deleteRows() {
  271. const ids = this.$refs.dataTable.getSelectedRowKeys()
  272. // 判断是否有下级
  273. auditMaintainService.deleteCheckCategory(ids).then((res) => {
  274. if (!res) {
  275. return new Promise((resolve) => {
  276. Modal.confirm({
  277. title: '您确定删除这项内容吗?',
  278. content: '该层级下存在子分类或模型数据,是否全部删除?',
  279. cancelText: '取消',
  280. okText: '删除',
  281. okType: 'danger',
  282. onOk: () => {
  283. this.deleteCategory(ids, resolve)
  284. },
  285. onCancel: () => {
  286. resolve()
  287. },
  288. })
  289. })
  290. } else {
  291. this.deleteCategory(ids, null)
  292. }
  293. })
  294. },
  295. create() {
  296. if (this.parentId === null) {
  297. message.error('请选择节点!')
  298. } else {
  299. if (this.isEnd !== '1' && this.isEnd !== 1) {
  300. this.$refs.dataTable.showDetailModal(null, 'audit/maintain/iamModelCategory')
  301. } else {
  302. message.error('末级分类下不可再新建分类')
  303. }
  304. }
  305. },
  306. deleteCategory(ids, resolve) {
  307. auditMaintainService
  308. .deleteCategory(ids)
  309. .then(() => {
  310. this.onRecordsDeleted()
  311. this.refresh()
  312. })
  313. .finally(resolve)
  314. },
  315. refresh() {
  316. this.$refs.dataTable.refresh()
  317. },
  318. // 判断按钮显示
  319. showeditbutton(deptId) {
  320. // axios({
  321. // url: 'api/xcoa-mobile/v1/iammodelmaintain/getRole?selectOrgId=' + deptId,
  322. // method: 'get',
  323. // }).then((res) => {
  324. // if (res.data === true) {
  325. // if (this.actions.length === 0) {
  326. // todo暂时放开权限
  327. // this.actionscsh.forEach((a) => {
  328. // this.actions.push(a)
  329. // })
  330. // }
  331. // } else {
  332. // this.actions = []
  333. // }
  334. // })
  335. this.actions = this.actionscsh
  336. },
  337. },
  338. }
  339. </script>
  340. <style module lang="scss">
  341. @use '@/common/design' as *;
  342. .wrap-height {
  343. height: 100%;
  344. .row-height {
  345. display: flex;
  346. flex: auto;
  347. height: 100%;
  348. .rightcard {
  349. flex: 1;
  350. width: calc(100% - 20%);
  351. height: 100%;
  352. }
  353. }
  354. }
  355. </style>