oneProduct.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366
  1. <template>
  2. <div class="ele-body">
  3. <el-card shadow="never">
  4. <ele-split-layout
  5. width="300px"
  6. allow-collapse
  7. :right-style="{ overflow: 'hidden' }"
  8. >
  9. <div class="ele-border-lighter sys-organization-list">
  10. <el-tree
  11. :data="treeList"
  12. :props="defaultProps"
  13. ref="treeRef"
  14. :default-expanded-keys="current && current.id ? [current.id] : []"
  15. :highlight-current="true"
  16. node-key="id"
  17. @node-click="handleNodeClick"
  18. ></el-tree>
  19. </div>
  20. <template v-slot:content>
  21. <div class="ele-border-lighter form-content" v-loading="loading">
  22. <div class="form-wrapper">
  23. <el-form size="mini" label-width="100px" class="ele-form-detail">
  24. <el-row :gutter="15" v-if="current.parentId == 0">
  25. <el-col v-bind="styleResponsive ? { sm: 6 } : { span: 6 }">
  26. <el-form-item label="类型编码:">
  27. <div class="ele-text-secondary">
  28. {{ current.code }}
  29. </div>
  30. </el-form-item>
  31. </el-col>
  32. <el-col v-bind="styleResponsive ? { sm: 6 } : { span: 6 }">
  33. <el-form-item label="类型名称:">
  34. <div class="ele-text-secondary">
  35. {{ current.name }}
  36. </div>
  37. </el-form-item>
  38. </el-col>
  39. <el-col v-bind="styleResponsive ? { sm: 8 } : { span: 8 }">
  40. <el-form-item label="描述:">
  41. <div class="ele-text-secondary">
  42. {{ current.remark }}
  43. </div>
  44. </el-form-item>
  45. </el-col>
  46. <el-col v-bind="styleResponsive ? { sm: 4 } : { span: 4 }">
  47. <el-form-item label="状态:">
  48. <div class="ele-text-secondary">
  49. {{
  50. current.isEnabled == 0
  51. ? '停用'
  52. : current.isEnabled == 1
  53. ? '启用'
  54. : ''
  55. }}
  56. </div>
  57. </el-form-item>
  58. </el-col>
  59. </el-row>
  60. <el-row :gutter="15" v-else>
  61. <el-col v-bind="styleResponsive ? { sm: 6 } : { span: 6 }">
  62. <el-form-item label="节点编码:">
  63. <div class="ele-text-secondary">
  64. {{ current.code }}
  65. </div>
  66. </el-form-item>
  67. </el-col>
  68. <el-col v-bind="styleResponsive ? { sm: 6 } : { span: 6 }">
  69. <el-form-item label="节点名称:">
  70. <div class="ele-text-secondary">
  71. {{ current.name }}
  72. </div>
  73. </el-form-item>
  74. </el-col>
  75. <el-col v-bind="styleResponsive ? { sm: 8 } : { span: 8 }">
  76. <el-form-item label="层级全览:">
  77. <div class="ele-text-secondary">
  78. {{ currentData.categoryLevelPath }}
  79. </div>
  80. </el-form-item>
  81. </el-col>
  82. <el-col v-bind="styleResponsive ? { sm: 4 } : { span: 4 }">
  83. <el-form-item label="状态:">
  84. <div class="ele-text-secondary">
  85. {{
  86. current.isEnabled == 0
  87. ? '停用'
  88. : current.isEnabled == 1
  89. ? '启用'
  90. : ''
  91. }}
  92. </div>
  93. </el-form-item>
  94. </el-col>
  95. </el-row>
  96. </el-form>
  97. </div>
  98. <IndexSearch ref="searchRef" @search="reload" />
  99. <!-- //产品 -->
  100. <IndexData
  101. ref="listData"
  102. v-if="current"
  103. :current-id="current.id"
  104. :data="current"
  105. :rootTreeId="rootTreeId"
  106. :currentData="currentData"
  107. :rootId="rootId"
  108. :oneProduct="true"
  109. cacheKeyUrl="57ac3878-product-oneProduct"
  110. lyType="cp"
  111. >
  112. </IndexData>
  113. </div>
  114. </template>
  115. </ele-split-layout>fv
  116. </el-card>
  117. </div>
  118. </template>
  119. <script>
  120. import IndexData from './components/index-data.vue';
  121. import IndexSearch from './components/index-search.vue';
  122. import dictMixins from '@/mixins/dictMixins';
  123. import { getTreeByPid } from '@/api/classifyManage';
  124. import { getInfoById } from '@/api/classifyManage';
  125. import { deepClone } from '@/utils';
  126. export default {
  127. components: {
  128. IndexData,
  129. IndexSearch
  130. },
  131. mixins: [dictMixins],
  132. data() {
  133. return {
  134. loading: false,
  135. current: {},
  136. curNode: {},
  137. currentData: {},
  138. treeList: [],
  139. treeLoading: false,
  140. formData: {},
  141. rootTreeId: null,
  142. defaultProps: {
  143. children: 'children',
  144. label: 'name'
  145. }
  146. };
  147. },
  148. computed: {
  149. // 是否开启响应式布局
  150. styleResponsive() {
  151. return this.$store.state.theme.styleResponsive;
  152. },
  153. rootId() {
  154. return this.$route.query.id;
  155. },
  156. fullName() {
  157. let str = '';
  158. let codeStr = '';
  159. let node = this.curNode;
  160. while (node?.data?.name) {
  161. str = node.data.name + '-' + str;
  162. codeStr = node.data.code + '-' + codeStr;
  163. node = node?.parent;
  164. }
  165. return str.substring(str, str.length - 1);
  166. }
  167. },
  168. created() {
  169. this.getTreeData();
  170. },
  171. methods: {
  172. async getTreeData() {
  173. try {
  174. this.treeLoading = true;
  175. const res = await getTreeByPid(9);
  176. this.treeLoading = false;
  177. if (res?.code === '0') {
  178. this.treeList = res.data;
  179. if (!this.$route.query.categoryLevelId) {
  180. this.$nextTick(() => {
  181. //默认高亮第一级树节点;
  182. if (this.treeList[0]) {
  183. this.rootTreeId = this.treeList[0].id;
  184. this.getDetail(this.treeList[0].id);
  185. console.log(this.treeList[0].id, 'rootTreeId');
  186. this.publicfun(this.treeList[0]);
  187. }
  188. });
  189. } else {
  190. this.getDetail(this.$route.query.categoryLevelId);
  191. this.$nextTick(() => {
  192. this.$refs.treeRef.setCurrentKey(
  193. this.$route.query.categoryLevelId
  194. );
  195. });
  196. const objByid = this.findNodeById(
  197. this.treeList,
  198. this.$route.query.categoryLevelId
  199. );
  200. console.log(objByid, '当前选择的产品');
  201. this.publicfun(objByid);
  202. }
  203. return this.treeList;
  204. }
  205. } catch (error) {}
  206. this.treeLoading = false;
  207. },
  208. async getDetail(id) {
  209. this.loading = true;
  210. const res = await getInfoById(id);
  211. this.loading = false;
  212. if (res.code == '0') {
  213. this.current = res.data;
  214. this.$nextTick(() => {
  215. this.$refs.treeRef.setCurrentKey(this.current.id);
  216. });
  217. }
  218. },
  219. findNodeById(tree, targetId) {
  220. function traverse(nodes) {
  221. for (let node of nodes) {
  222. if (node.id === targetId) {
  223. return node;
  224. } else if (node.children && node.children.length > 0) {
  225. const foundNode = traverse(node.children);
  226. if (foundNode) {
  227. return foundNode;
  228. }
  229. }
  230. }
  231. return null;
  232. }
  233. return traverse(tree);
  234. },
  235. handleNodeClick(data, node) {
  236. this.$route.query.categoryLevelId = '';
  237. if (this.$refs.searchRef) {
  238. this.$refs.searchRef.resetAllSearch();
  239. }
  240. this.curNode = node;
  241. this.publicfun(data);
  242. this.getDetail(data.id);
  243. },
  244. publicfun(data) {
  245. this.pathList = this.findParent([], data, this.treeList);
  246. this.rootTreeId = null;
  247. if (this.pathList.length == 0) {
  248. this.rootTreeId = data.id;
  249. } else {
  250. this.rootTreeId =
  251. this.pathList[this.pathList.length - 1] &&
  252. this.pathList[this.pathList.length - 1].id;
  253. }
  254. let ruleCode = null;
  255. if (this.pathList.length == 0) {
  256. ruleCode = data.ruleCode;
  257. } else {
  258. ruleCode =
  259. this.pathList[this.pathList.length - 1] &&
  260. this.pathList[this.pathList.length - 1].ruleCode;
  261. }
  262. this.pathList.unshift(data);
  263. const PathInfo = {
  264. categoryLevelPath: '',
  265. categoryLevelPathId: [],
  266. // rootCategoryLevelId: null,
  267. categoryLevelId: '',
  268. categoryLevelName: '',
  269. ruleCode: ''
  270. };
  271. const pathName = [];
  272. this.pathList.map((item) => {
  273. pathName.unshift(item.name);
  274. PathInfo.categoryLevelPathId.unshift(item.id);
  275. // PathInfo.rootCategoryLevelId = item.rootCategoryLevelId;
  276. });
  277. PathInfo.categoryLevelPath = pathName.join('-');
  278. PathInfo.categoryLevelPathId = PathInfo.categoryLevelPathId.join(',');
  279. PathInfo.categoryLevelId = data.id;
  280. PathInfo.categoryLevelName = data.name;
  281. PathInfo.ruleCode = ruleCode;
  282. this.currentData = deepClone(PathInfo);
  283. console.log(this.currentData, '选中的产品分类');
  284. },
  285. /* 刷新表格 */
  286. reload(where) {
  287. this.$refs.listData.reload(where);
  288. },
  289. // parents:用于返回的数组,childNode:要查询的节点,treeList:json树形数据
  290. findParent(parents, childNode, treeList) {
  291. for (let i = 0; i < treeList.length; i++) {
  292. // 父节点查询条件
  293. if (treeList[i].id === childNode.parentId) {
  294. // 如果找到结果,保存当前节点
  295. parents.push(treeList[i]);
  296. // 用当前节点再去原数据查找当前节点的父节点
  297. this.findParent(parents, treeList[i], this.treeList);
  298. break;
  299. } else {
  300. if (treeList[i].children instanceof Array) {
  301. // 没找到,遍历该节点的子节点
  302. this.findParent(parents, childNode, treeList[i].children);
  303. }
  304. }
  305. }
  306. return parents;
  307. }
  308. }
  309. };
  310. </script>
  311. <style lang="scss" scoped>
  312. .sys-organization-list {
  313. height: calc(100vh - 165px);
  314. box-sizing: border-box;
  315. border-width: 1px;
  316. border-style: solid;
  317. overflow: auto;
  318. }
  319. .sys-organization-list :deep(.el-tree-node__content) {
  320. height: 30px;
  321. & > .el-tree-node__expand-icon {
  322. margin-left: 10px;
  323. }
  324. }
  325. .form-content {
  326. height: 50px;
  327. border: 1px solid;
  328. box-sizing: border-box;
  329. }
  330. .form-wrapper {
  331. padding: 12px 24px;
  332. }
  333. </style>