details.vue 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292
  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. <el-button
  14. size="small"
  15. type="primary"
  16. icon="el-icon-plus"
  17. class="ele-btn-icon"
  18. @click="openEdit(true)"
  19. >
  20. 新建下级节点
  21. </el-button>
  22. <el-button
  23. size="small"
  24. type="warning"
  25. icon="el-icon-edit"
  26. class="ele-btn-icon"
  27. :disabled="!current.id || current.id == rootId"
  28. @click="openEdit(false)"
  29. >
  30. 编辑节点
  31. </el-button>
  32. <el-button
  33. size="small"
  34. type="danger"
  35. icon="el-icon-delete"
  36. class="ele-btn-icon"
  37. :disabled="!current.id || current.id == rootId"
  38. @click="deleteCategory"
  39. >
  40. 删除
  41. </el-button>
  42. </div>
  43. </ele-toolbar>
  44. <div class="ele-border-lighter sys-organization-list">
  45. <el-tree
  46. :data="treeData"
  47. :props="defaultProps"
  48. ref="treeRef"
  49. :default-expanded-keys="current && current.id ? [current.id] : []"
  50. :highlight-current="true"
  51. node-key="id"
  52. @node-click="handleNodeClick"
  53. ></el-tree>
  54. </div>
  55. </div>
  56. <template v-slot:content>
  57. <div class="ele-border-lighter form-content" v-loading="loading">
  58. <ele-toolbar class="ele-toolbar-actions">
  59. <h4 style="margin: 5px 0"> 节点信息 </h4>
  60. </ele-toolbar>
  61. <div class="form-wrapper">
  62. <el-form size="mini" label-width="100px" class="ele-form-detail">
  63. <el-row :gutter="15" v-if="current.id == rootId">
  64. <el-col v-bind="styleResponsive ? { sm: 12 } : { span: 12 }">
  65. <el-form-item label="类型编码:">
  66. <div class="ele-text-secondary">
  67. {{ current.code }}
  68. </div>
  69. </el-form-item>
  70. </el-col>
  71. <el-col v-bind="styleResponsive ? { sm: 12 } : { span: 12 }">
  72. <el-form-item label="类型名称:">
  73. <div class="ele-text-secondary">
  74. {{ current.name }}
  75. </div>
  76. </el-form-item>
  77. </el-col>
  78. <el-col v-bind="styleResponsive ? { sm: 12 } : { span: 12 }">
  79. <el-form-item label="类型用途:">
  80. <div class="ele-text-secondary">
  81. {{ getDictValue('类型用途', current.type + '') }}
  82. </div>
  83. </el-form-item>
  84. </el-col>
  85. <el-col v-bind="styleResponsive ? { sm: 12 } : { span: 12 }">
  86. <el-form-item label="描述:">
  87. <div class="ele-text-secondary">
  88. {{ current.remark }}
  89. </div>
  90. </el-form-item>
  91. </el-col>
  92. </el-row>
  93. <el-row :gutter="15" v-else>
  94. <el-col v-bind="styleResponsive ? { sm: 12 } : { span: 12 }">
  95. <el-form-item label="父级节点:">
  96. <div class="ele-text-secondary">
  97. {{ current.parentName }}
  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. {{ fullName }}
  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. {{ current.code }}
  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.name }}
  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.separate }}
  126. </div>
  127. </el-form-item>
  128. </el-col>
  129. </el-row>
  130. </el-form>
  131. </div>
  132. </div>
  133. </template>
  134. </ele-split-layout>
  135. </el-card>
  136. <!-- 编辑弹窗 -->
  137. <list-edit
  138. ref="editRef"
  139. @done="reload"
  140. :rootId="rootId"
  141. :curNode="curNode"
  142. />
  143. <!-- <classify-manage-edit ref="editRef" @done="reload" /> -->
  144. </div>
  145. </template>
  146. <script>
  147. import ListEdit from './components/list-edit.vue';
  148. import classifyManageEdit from './components/classifyManageEdit.vue';
  149. import dictMixins from '@/mixins/dictMixins';
  150. import {
  151. getTreeByPid,
  152. getInfoById,
  153. deleteCategory
  154. } from '@/api/classifyManage';
  155. export default {
  156. components: {
  157. classifyManageEdit,
  158. ListEdit
  159. },
  160. mixins: [dictMixins],
  161. data () {
  162. return {
  163. loading: false,
  164. current: {},
  165. curNode: {},
  166. treeData: [],
  167. formData: {},
  168. defaultProps: {
  169. children: 'children',
  170. label: 'name'
  171. }
  172. };
  173. },
  174. computed: {
  175. // 是否开启响应式布局
  176. styleResponsive () {
  177. return this.$store.state.theme.styleResponsive;
  178. },
  179. rootId () {
  180. return this.$route.query.id;
  181. },
  182. fullName () {
  183. let str = '';
  184. let codeStr = '';
  185. let node = this.curNode;
  186. while (node?.data?.name) {
  187. str = node.data.name + '-' + str;
  188. codeStr = node.data.code + '-' + codeStr;
  189. node = node?.parent;
  190. }
  191. return (
  192. str.substring(str, str.length - 1) +
  193. `(${codeStr.substring(str, str.length - 1)})`
  194. );
  195. }
  196. },
  197. created () {
  198. this.requestDict('类型用途');
  199. this.requestDict('分隔符');
  200. this.getTree().then(() => {
  201. this.$nextTick(() => {
  202. this.getDetail(this.treeData[0]?.id);
  203. });
  204. });
  205. },
  206. methods: {
  207. async reload (isEdit) {
  208. if (isEdit) {
  209. this.getTree().then(() => {
  210. this.getDetail(this.current.id);
  211. });
  212. } else {
  213. this.getTree();
  214. }
  215. },
  216. handlOpen () {
  217. this.$refs.addDialog.open();
  218. },
  219. deleteCategory () {
  220. this.$confirm('确定要删除选中节点吗?', '提示', {
  221. type: 'warning'
  222. }).then(async () => {
  223. const res = await deleteCategory(this.current.id);
  224. if (res?.code == '0') {
  225. this.getTree().then(() => {
  226. this.$nextTick(() => {
  227. this.getDetail(this.treeData[0]?.id);
  228. });
  229. });
  230. this.$message.success('删除成功!');
  231. }
  232. });
  233. },
  234. async getTree () {
  235. const res = await getTreeByPid(this.rootId);
  236. if (res.code == '0') {
  237. this.treeData = res.data;
  238. return;
  239. }
  240. return Promise.reject();
  241. },
  242. async getDetail (id) {
  243. this.loading = true;
  244. const res = await getInfoById(id);
  245. this.loading = false;
  246. if (res.code == '0') {
  247. this.current = res.data;
  248. this.$nextTick(() => {
  249. this.$refs.treeRef.setCurrentKey(this.current.id);
  250. });
  251. }
  252. },
  253. openEdit (isAdd = true) {
  254. this.$refs.editRef.open(isAdd ? null : this.current, this.current);
  255. },
  256. handleNodeClick (data, node) {
  257. this.curNode = node;
  258. this.getDetail(data.id);
  259. }
  260. }
  261. };
  262. </script>
  263. <style lang="scss" scoped>
  264. .sys-organization-list {
  265. height: calc(100vh - 264px);
  266. box-sizing: border-box;
  267. border-width: 1px;
  268. border-style: solid;
  269. overflow: auto;
  270. }
  271. .sys-organization-list :deep(.el-tree-node__content) {
  272. height: 30px;
  273. & > .el-tree-node__expand-icon {
  274. margin-left: 10px;
  275. }
  276. }
  277. .form-content {
  278. height: 100%;
  279. border: 1px solid;
  280. box-sizing: border-box;
  281. }
  282. .form-wrapper {
  283. padding: 24px;
  284. }
  285. </style>