details.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368
  1. <template>
  2. <div class="ele-body">
  3. <el-card shadow="never">
  4. <ele-split-layout
  5. width="356px"
  6. allow-collapse
  7. :right-style="{ overflow: 'hidden' }"
  8. >
  9. <div>
  10. <!-- 操作按钮 -->
  11. <ele-toolbar class="ele-toolbar-actions">
  12. <div style="margin: 5px 0">
  13. <div>
  14. <el-button
  15. size="small"
  16. type="primary"
  17. icon="el-icon-plus"
  18. class="ele-btn-icon"
  19. @click="openEdit(true)"
  20. v-if="$hasPermission('main:categorylevel:save')"
  21. >
  22. 新建下级节点
  23. </el-button>
  24. <el-button
  25. size="small"
  26. type="warning"
  27. icon="el-icon-edit"
  28. class="ele-btn-icon"
  29. :disabled="!current.id || current.id == rootId"
  30. @click="openEdit(false)"
  31. v-if="$hasPermission('main:categorylevel:update')"
  32. >
  33. 编辑节点
  34. </el-button>
  35. <el-button
  36. size="small"
  37. type="danger"
  38. icon="el-icon-delete"
  39. class="ele-btn-icon"
  40. :disabled="!current.id || current.id == rootId"
  41. @click="deleteCategory"
  42. v-if="$hasPermission('main:categorylevel:delete')"
  43. >
  44. 删除
  45. </el-button></div
  46. >
  47. <div>
  48. <el-button
  49. size="small"
  50. type="primary"
  51. icon="el-icon-download"
  52. class="ele-btn-icon"
  53. @click="importProfession"
  54. style="margin-top: 5px"
  55. v-if="$hasPermission('main:categorylevel:update')"
  56. >
  57. 导入
  58. </el-button></div
  59. >
  60. </div>
  61. </ele-toolbar>
  62. <div class="ele-border-lighter sys-organization-list">
  63. <el-tree
  64. :data="treeData"
  65. :props="defaultProps"
  66. ref="treeRef"
  67. :default-expanded-keys="current && current.id ? [current.id] : []"
  68. :highlight-current="true"
  69. node-key="id"
  70. @node-click="handleNodeClick"
  71. >
  72. <span class="custom-tree-node" slot-scope="{ node, data }">
  73. {{ (isCode == 1 ? data.code : '') + ' ' + data.name }}
  74. </span>
  75. </el-tree>
  76. </div>
  77. </div>
  78. <template v-slot:content>
  79. <div class="ele-border-lighter form-content" v-loading="loading">
  80. <ele-toolbar class="ele-toolbar-actions">
  81. <h4 style="margin: 5px 0"> 节点信息 </h4>
  82. <el-button
  83. size="small"
  84. type="primary"
  85. class="ele-btn-icon"
  86. @click="back()"
  87. >
  88. 返回
  89. </el-button>
  90. </ele-toolbar>
  91. <div class="form-wrapper">
  92. <el-form size="mini" label-width="100px" class="ele-form-detail">
  93. <el-row :gutter="15" v-if="current.id == rootId">
  94. <el-col v-bind="styleResponsive ? { sm: 12 } : { span: 12 }">
  95. <el-form-item label="类型编码:">
  96. <div class="ele-text-secondary">
  97. {{ current.code }}
  98. </div>
  99. </el-form-item>
  100. </el-col>
  101. <el-col v-bind="styleResponsive ? { sm: 12 } : { span: 12 }">
  102. <el-form-item label="类型名称:">
  103. <div class="ele-text-secondary">
  104. {{ current.name }}
  105. </div>
  106. </el-form-item>
  107. </el-col>
  108. <el-col v-bind="styleResponsive ? { sm: 12 } : { span: 12 }">
  109. <el-form-item label="类型用途:">
  110. <div class="ele-text-secondary">
  111. {{ getDictValue('类型用途', current.type + '') }}
  112. </div>
  113. </el-form-item>
  114. </el-col>
  115. <el-col v-bind="styleResponsive ? { sm: 12 } : { span: 12 }">
  116. <el-form-item label="描述:">
  117. <div class="ele-text-secondary">
  118. {{ current.remark }}
  119. </div>
  120. </el-form-item>
  121. </el-col>
  122. <el-col v-bind="styleResponsive ? { sm: 12 } : { span: 12 }">
  123. <el-form-item label="状态:">
  124. <div class="ele-text-secondary">
  125. {{ current.isEnabled === 0 ? '停用' : '启用' }}
  126. </div>
  127. </el-form-item>
  128. </el-col>
  129. </el-row>
  130. <el-row :gutter="15" v-else>
  131. <el-col v-bind="styleResponsive ? { sm: 12 } : { span: 12 }">
  132. <el-form-item label="父级节点:">
  133. <div class="ele-text-secondary">
  134. {{ current.parentName }}
  135. </div>
  136. </el-form-item>
  137. </el-col>
  138. <el-col v-bind="styleResponsive ? { sm: 12 } : { span: 12 }">
  139. <el-form-item label="层级全览:">
  140. <div class="ele-text-secondary">
  141. {{ fullName }}
  142. </div>
  143. </el-form-item>
  144. </el-col>
  145. <el-col v-bind="styleResponsive ? { sm: 12 } : { span: 12 }">
  146. <el-form-item label="节点编码:">
  147. <div class="ele-text-secondary">
  148. {{ current.code }}
  149. </div>
  150. </el-form-item>
  151. </el-col>
  152. <el-col v-bind="styleResponsive ? { sm: 12 } : { span: 12 }">
  153. <el-form-item label="节点名称:">
  154. <div class="ele-text-secondary">
  155. {{ current.name }}
  156. </div>
  157. </el-form-item>
  158. </el-col>
  159. <el-col v-bind="styleResponsive ? { sm: 12 } : { span: 12 }">
  160. <el-form-item label="与下层分隔:">
  161. <div class="ele-text-secondary">
  162. {{ current.separatorChar }}
  163. </div>
  164. </el-form-item>
  165. </el-col>
  166. <el-col v-bind="styleResponsive ? { sm: 12 } : { span: 12 }">
  167. <el-form-item label="状态:">
  168. <div class="ele-text-secondary">
  169. {{ current.isEnabled === 0 ? '停用' : '启用' }}
  170. </div>
  171. </el-form-item>
  172. </el-col>
  173. </el-row>
  174. </el-form>
  175. </div>
  176. </div>
  177. </template>
  178. </ele-split-layout>
  179. </el-card>
  180. <!-- 编辑弹窗 -->
  181. <list-edit
  182. ref="editRef"
  183. @done="reload"
  184. :rootId="rootId"
  185. :curNode="curNode"
  186. />
  187. <importDialog
  188. ref="importDialogRef"
  189. :apiUrl="'/main/factoryworkstation/importBatch'"
  190. :fileUrl="'/main/factoryworkstation/downLoadTemplate'"
  191. fileName="分类导入模板"
  192. @success="reload"
  193. :param="{
  194. id: current.id
  195. }"
  196. />
  197. </div>
  198. </template>
  199. <script>
  200. import ListEdit from './components/list-edit.vue';
  201. import classifyManageEdit from './components/classifyManageEdit.vue';
  202. import dictMixins from '@/mixins/dictMixins';
  203. import {
  204. getTreeByPid,
  205. getInfoById,
  206. deleteCategory
  207. } from '@/api/classifyManage';
  208. import { parameterGetByCode } from '@/api/system/dictionary/index.js';
  209. import importDialog from '@/components/upload/import-dialogNew.vue';
  210. export default {
  211. components: {
  212. classifyManageEdit,
  213. ListEdit,
  214. importDialog
  215. },
  216. mixins: [dictMixins],
  217. data() {
  218. return {
  219. loading: false,
  220. current: {},
  221. curNode: {},
  222. treeData: [],
  223. formData: {},
  224. isCode: 0,
  225. defaultProps: {
  226. children: 'children',
  227. label: 'name'
  228. }
  229. };
  230. },
  231. computed: {
  232. // 是否开启响应式布局
  233. styleResponsive() {
  234. return this.$store.state.theme.styleResponsive;
  235. },
  236. rootId() {
  237. return this.$route.query.id;
  238. },
  239. fullName() {
  240. let str = '';
  241. let codeStr = '';
  242. let node = this.curNode;
  243. while (node?.data?.name) {
  244. str = node.data.name + '-' + str;
  245. codeStr = node.data.code + '-' + codeStr;
  246. node = node?.parent;
  247. }
  248. return (
  249. str.substring(str, str.length - 1) +
  250. `(${codeStr.substring(str, str.length - 1)})`
  251. );
  252. }
  253. },
  254. created() {
  255. this.requestDict('类型用途');
  256. this.requestDict('分隔符');
  257. this.getTree().then(() => {
  258. this.$nextTick(() => {
  259. this.getDetail(this.treeData[0]?.id);
  260. });
  261. });
  262. //是否显示code
  263. parameterGetByCode({
  264. code: 'mian_treeClassify_code'
  265. }).then((res) => {
  266. if (res.value) {
  267. this.isCode = res.value;
  268. }
  269. });
  270. },
  271. methods: {
  272. importProfession() {
  273. this.$refs.importDialogRef.open();
  274. },
  275. async reload(isEdit) {
  276. if (isEdit) {
  277. this.getTree().then(() => {
  278. this.getDetail(this.current.id);
  279. });
  280. } else {
  281. this.getTree();
  282. }
  283. },
  284. back() {
  285. this.$router.push('/treeClassify');
  286. },
  287. handlOpen() {
  288. this.$refs.addDialog.open();
  289. },
  290. deleteCategory() {
  291. this.$confirm('确定要删除选中节点吗?', '提示', {
  292. type: 'warning'
  293. }).then(async () => {
  294. const res = await deleteCategory(this.current.id);
  295. if (res?.code == '0') {
  296. this.getTree().then(() => {
  297. this.$nextTick(() => {
  298. this.getDetail(this.treeData[0]?.id);
  299. });
  300. });
  301. this.$message.success('删除成功!');
  302. }
  303. });
  304. },
  305. async getTree() {
  306. const res = await getTreeByPid(this.rootId);
  307. if (res.code == '0') {
  308. this.treeData = res.data;
  309. return;
  310. }
  311. return Promise.reject();
  312. },
  313. async getDetail(id) {
  314. this.loading = true;
  315. const res = await getInfoById(id);
  316. this.loading = false;
  317. if (res.code == '0') {
  318. this.current = res.data;
  319. this.$nextTick(() => {
  320. this.$refs.treeRef.setCurrentKey(this.current.id);
  321. });
  322. }
  323. },
  324. openEdit(isAdd = true) {
  325. this.$refs.editRef.open(isAdd ? null : this.current, this.current);
  326. },
  327. handleNodeClick(data, node) {
  328. this.curNode = node;
  329. this.getDetail(data.id);
  330. }
  331. }
  332. };
  333. </script>
  334. <style lang="scss" scoped>
  335. .sys-organization-list {
  336. height: calc(100vh - 264px);
  337. box-sizing: border-box;
  338. border-width: 1px;
  339. border-style: solid;
  340. overflow: auto;
  341. }
  342. .sys-organization-list :deep(.el-tree-node__content) {
  343. height: 30px;
  344. & > .el-tree-node__expand-icon {
  345. margin-left: 10px;
  346. }
  347. }
  348. .form-content {
  349. height: 100%;
  350. border: 1px solid;
  351. box-sizing: border-box;
  352. }
  353. .form-wrapper {
  354. padding: 24px;
  355. }
  356. .ele-toolbar-actions :deep(.ele-table-tool-title-content) {
  357. display: flex;
  358. justify-content: space-between;
  359. }
  360. </style>