ProductModalMultiple.vue 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269
  1. <template>
  2. <el-dialog
  3. :title="title"
  4. :visible.sync="visible"
  5. v-if="visible"
  6. :before-close="handleClose"
  7. :close-on-click-modal="false"
  8. :close-on-press-escape="false"
  9. append-to-body
  10. width="75%"
  11. >
  12. <el-card shadow="never">
  13. <ProductSearch @search="reload" ref="searchRef" />
  14. <ele-split-layout
  15. width="244px"
  16. allow-collapse
  17. :right-style="{ overflow: 'hidden' }"
  18. >
  19. <div class="ele-border-lighter split-layout-right-content">
  20. <el-tree
  21. :data="treeList"
  22. :props="defaultProps"
  23. ref="treeRef"
  24. :default-expanded-keys="current && current.id ? [current.id] : []"
  25. :highlight-current="true"
  26. node-key="id"
  27. @node-click="handleNodeClick"
  28. ></el-tree>
  29. </div>
  30. <!-- 表格 -->
  31. <template v-slot:content>
  32. <ele-pro-table
  33. ref="table"
  34. :columns="columns"
  35. :datasource="datasource"
  36. :selection.sync="selection"
  37. row-key="id"
  38. height="calc(100vh - 350px)"
  39. class="dict-table"
  40. >
  41. </ele-pro-table>
  42. </template>
  43. </ele-split-layout>
  44. </el-card>
  45. <div class="btns">
  46. <el-button type="primary" size="small" @click="selected">选择</el-button>
  47. <el-button size="small" @click="handleClose">关闭</el-button>
  48. </div>
  49. </el-dialog>
  50. </template>
  51. <script>
  52. import ProductSearch from '@/components/select/bom/product-search.vue';
  53. import { getMaterialList } from '@/api/material/list.js';
  54. import { getTreeByGroup } from '@/api/classifyManage';
  55. export default {
  56. components: { ProductSearch },
  57. data() {
  58. return {
  59. visible: false,
  60. type: 1,
  61. selection: [],
  62. // 表格列配置
  63. columns: [
  64. {
  65. columnKey: 'selection',
  66. type: 'selection',
  67. width: 45,
  68. align: 'center'
  69. },
  70. {
  71. columnKey: 'index',
  72. type: 'index',
  73. width: 45,
  74. align: 'center',
  75. reserveSelection: true
  76. },
  77. {
  78. prop: 'code',
  79. label: '编码'
  80. },
  81. {
  82. prop: 'name',
  83. label: '名称',
  84. showOverflowTooltip: true
  85. },
  86. {
  87. prop: 'brandNum',
  88. label: '牌号'
  89. },
  90. {
  91. prop: 'modelType',
  92. label: '型号',
  93. align: 'center',
  94. showOverflowTooltip: true
  95. },
  96. {
  97. prop: 'specification',
  98. label: '规格',
  99. align: 'center',
  100. showOverflowTooltip: true
  101. },
  102. {
  103. prop: 'measuringUnit',
  104. label: '计量单位',
  105. showOverflowTooltip: true,
  106. minWidth: 90
  107. },
  108. {
  109. prop: 'weightUnit',
  110. label: '重量单位',
  111. showOverflowTooltip: true,
  112. minWidth: 90
  113. },
  114. {
  115. prop: 'roughWeight',
  116. label: '毛重',
  117. showOverflowTooltip: true,
  118. minWidth: 90
  119. },
  120. {
  121. prop: 'netWeight',
  122. label: '净重',
  123. showOverflowTooltip: true,
  124. minWidth: 90
  125. },
  126. {
  127. prop: 'packingUnit',
  128. align: 'center',
  129. label: '包装单位',
  130. showOverflowTooltip: true
  131. },
  132. {
  133. prop: 'categoryLevelPath',
  134. label: '分类',
  135. align: 'center',
  136. showOverflowTooltip: true
  137. },
  138. {
  139. action: 'action',
  140. slot: 'action',
  141. align: 'center',
  142. label: '选择'
  143. }
  144. ],
  145. title: null,
  146. categoryLevelId: null,
  147. radio: null,
  148. idx: null,
  149. isCategory: true,
  150. current: {},
  151. treeList: [],
  152. treeLoading: false,
  153. defaultProps: {
  154. children: 'children',
  155. label: 'name'
  156. }
  157. };
  158. },
  159. watch: {},
  160. methods: {
  161. /* 表格数据源 */
  162. datasource({ page, where, limit }) {
  163. return getMaterialList({
  164. ...where,
  165. pageNum: page,
  166. size: limit,
  167. categoryLevelId: this.isCategory ? this.categoryLevelId : null
  168. });
  169. },
  170. handleNodeClick(data) {
  171. this.isCategory = true;
  172. this.categoryLevelId = data.id;
  173. this.$refs.table.reload({ pageNum: 1, where: {} });
  174. this.$refs.searchRef.reset2();
  175. },
  176. /* 刷新表格 */
  177. reload(where) {
  178. this.isCategory = false;
  179. this.$refs.table.reload({ pageNum: 1, where: where });
  180. },
  181. open(type) {
  182. this.type = type;
  183. this.getTreeData();
  184. this.visible = true;
  185. },
  186. async getTreeData() {
  187. try {
  188. this.treeLoading = true;
  189. const res = await getTreeByGroup({ type: this.type });
  190. this.treeLoading = false;
  191. if (res?.code === '0') {
  192. this.treeList = res.data;
  193. this.$nextTick(() => {
  194. // 默认高亮第一级树节点
  195. if (this.treeList[0]) {
  196. this.rootTreeId = this.treeList[0].id;
  197. this.$nextTick(() => {
  198. this.$refs.treeRef.setCurrentKey(this.treeList[0].id);
  199. });
  200. }
  201. });
  202. return this.treeList;
  203. }
  204. } catch (error) {}
  205. this.treeLoading = false;
  206. },
  207. handleClose() {
  208. this.visible = false;
  209. this.current = null;
  210. this.radio = '';
  211. },
  212. selected() {
  213. if (this.selection.length <= 0) {
  214. return this.$message.warning('请至少选择一条数据');
  215. }
  216. this.$emit('selection', this.selection);
  217. this.handleClose();
  218. }
  219. }
  220. };
  221. </script>
  222. <style lang="scss" scoped>
  223. .tree_col {
  224. border: 1px solid #eee;
  225. padding: 10px 0;
  226. box-sizing: border-box;
  227. height: 500px;
  228. overflow: auto;
  229. }
  230. .table_col {
  231. padding-left: 10px;
  232. ::v-deep .el-table th.el-table__cell {
  233. background: #f2f2f2;
  234. }
  235. }
  236. .pagination {
  237. text-align: right;
  238. padding: 10px 0;
  239. }
  240. .btns {
  241. text-align: center;
  242. padding: 10px 0;
  243. }
  244. .topsearch {
  245. margin-bottom: 15px;
  246. }
  247. </style>