oneProduct.vue 12 KB

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