ProductModal.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400
  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="isMultiple ? columnsMultiple : columns"
  35. :datasource="datasource"
  36. :selection.sync="selection"
  37. row-key="id"
  38. height="calc(100vh - 350px)"
  39. class="dict-table"
  40. @cell-click="cellClick"
  41. >
  42. <!-- 表头工具栏 -->
  43. <template v-slot:action="{ row }">
  44. <el-radio
  45. v-if="!isMultiple"
  46. class="radio"
  47. v-model="radio"
  48. :label="row.id"
  49. ><i></i
  50. ></el-radio>
  51. </template>
  52. </ele-pro-table>
  53. </template>
  54. </ele-split-layout>
  55. </el-card>
  56. <div class="btns">
  57. <el-button type="primary" size="small" @click="selected">选择</el-button>
  58. <el-button size="small" @click="handleClose">关闭</el-button>
  59. </div>
  60. </el-dialog>
  61. </template>
  62. <script>
  63. import ProductSearch from './product-search.vue';
  64. import { getMaterialList } from '@/api/material/list.js';
  65. import { getTreeByGroup } from '@/api/classifyManage';
  66. export default {
  67. components: { ProductSearch },
  68. data() {
  69. return {
  70. visible: false,
  71. // 多选模式标记
  72. isMultiple: false,
  73. // 多选模式选中的行
  74. selection: [],
  75. // 多选模式禁用勾选的物料 id 列表(已在父表里存在)
  76. existingIds: [],
  77. // 表格列配置(单选)
  78. columns: [
  79. {
  80. columnKey: 'index',
  81. type: 'index',
  82. width: 45,
  83. align: 'center',
  84. reserveSelection: true
  85. },
  86. {
  87. prop: 'code',
  88. label: '编码'
  89. },
  90. {
  91. prop: 'name',
  92. label: '名称',
  93. showOverflowTooltip: true
  94. },
  95. {
  96. prop: 'brandNum',
  97. label: '牌号'
  98. },
  99. {
  100. prop: 'modelType',
  101. label: '型号',
  102. align: 'center',
  103. showOverflowTooltip: true
  104. },
  105. {
  106. prop: 'specification',
  107. label: '规格',
  108. align: 'center',
  109. showOverflowTooltip: true
  110. },
  111. {
  112. prop: 'measuringUnit',
  113. label: '计量单位',
  114. showOverflowTooltip: true,
  115. minWidth: 90
  116. },
  117. {
  118. prop: 'weightUnit',
  119. label: '重量单位',
  120. showOverflowTooltip: true,
  121. minWidth: 90
  122. },
  123. {
  124. prop: 'roughWeight',
  125. label: '毛重',
  126. showOverflowTooltip: true,
  127. minWidth: 90
  128. },
  129. {
  130. prop: 'netWeight',
  131. label: '净重',
  132. showOverflowTooltip: true,
  133. minWidth: 90
  134. },
  135. {
  136. prop: 'packingUnit',
  137. align: 'center',
  138. label: '包装单位',
  139. showOverflowTooltip: true
  140. },
  141. {
  142. prop: 'categoryLevelPath',
  143. label: '分类',
  144. align: 'center',
  145. showOverflowTooltip: true
  146. },
  147. {
  148. action: 'action',
  149. slot: 'action',
  150. align: 'center',
  151. label: '选择'
  152. }
  153. ],
  154. // 表格列配置(多选):在单选列配置前插入 checkbox 列
  155. columnsMultiple: [
  156. {
  157. columnKey: 'selection',
  158. type: 'selection',
  159. width: 45,
  160. align: 'center',
  161. selectable: (row) => {
  162. // 已在父表里存在的物料,禁止勾选
  163. return !this.existingIds.includes(row.id);
  164. },
  165. reserveSelection: true
  166. },
  167. {
  168. columnKey: 'index',
  169. type: 'index',
  170. width: 45,
  171. align: 'center',
  172. reserveSelection: true
  173. },
  174. {
  175. prop: 'code',
  176. label: '编码'
  177. },
  178. {
  179. prop: 'name',
  180. label: '名称',
  181. showOverflowTooltip: true
  182. },
  183. {
  184. prop: 'brandNum',
  185. label: '牌号'
  186. },
  187. {
  188. prop: 'modelType',
  189. label: '型号',
  190. align: 'center',
  191. showOverflowTooltip: true
  192. },
  193. {
  194. prop: 'specification',
  195. label: '规格',
  196. align: 'center',
  197. showOverflowTooltip: true
  198. },
  199. {
  200. prop: 'measuringUnit',
  201. label: '计量单位',
  202. showOverflowTooltip: true,
  203. minWidth: 90
  204. },
  205. {
  206. prop: 'weightUnit',
  207. label: '重量单位',
  208. showOverflowTooltip: true,
  209. minWidth: 90
  210. },
  211. {
  212. prop: 'roughWeight',
  213. label: '毛重',
  214. showOverflowTooltip: true,
  215. minWidth: 90
  216. },
  217. {
  218. prop: 'netWeight',
  219. label: '净重',
  220. showOverflowTooltip: true,
  221. minWidth: 90
  222. },
  223. {
  224. prop: 'packingUnit',
  225. align: 'center',
  226. label: '包装单位',
  227. showOverflowTooltip: true
  228. },
  229. {
  230. prop: 'categoryLevelPath',
  231. label: '分类',
  232. align: 'center',
  233. showOverflowTooltip: true
  234. }
  235. ],
  236. title: null,
  237. categoryLevelId: null,
  238. radio: null,
  239. idx: null,
  240. isCategory: true,
  241. current: {},
  242. treeList: [],
  243. treeLoading: false,
  244. defaultProps: {
  245. children: 'children',
  246. label: 'name'
  247. }
  248. };
  249. },
  250. watch: {},
  251. methods: {
  252. /* 表格数据源 */
  253. datasource({ page, where, limit }) {
  254. return getMaterialList({
  255. ...where,
  256. pageNum: page,
  257. size: limit,
  258. categoryLevelId: this.isCategory ? this.categoryLevelId : null
  259. });
  260. },
  261. handleNodeClick(data) {
  262. this.isCategory = true;
  263. this.categoryLevelId = data.id;
  264. this.$refs.table.reload({ pageNum: 1, where: {} });
  265. this.$refs.searchRef.reset2();
  266. },
  267. /* 刷新表格 */
  268. reload(where) {
  269. this.isCategory = false;
  270. this.$refs.table.reload({ pageNum: 1, where: where });
  271. },
  272. open(item, title, type, idx, isMultiple = false, existingIds = []) {
  273. // 每次打开都清空上次的多选残留
  274. this.isMultiple = !!isMultiple;
  275. this.selection = [];
  276. this.existingIds = Array.isArray(existingIds) ? existingIds : [];
  277. // title/type/idx 始终赋值,避免 item=null(空表批量选择)时丢失
  278. this.title = title;
  279. this.type = type;
  280. this.idx = idx;
  281. if (item) {
  282. this.current = {
  283. id: item.categoryId,
  284. name: item.categoryName,
  285. code: item.categoryCode
  286. };
  287. this.radio = item.categoryId;
  288. } else {
  289. this.current = {};
  290. this.radio = '';
  291. }
  292. this.getTreeData();
  293. this.visible = true;
  294. },
  295. async getTreeData() {
  296. try {
  297. this.treeLoading = true;
  298. const res = await getTreeByGroup({ type: this.type });
  299. this.treeLoading = false;
  300. if (res?.code === '0') {
  301. this.treeList = res.data;
  302. this.$nextTick(() => {
  303. // 默认高亮第一级树节点
  304. if (this.treeList[0]) {
  305. this.rootTreeId = this.treeList[0].id;
  306. this.$nextTick(() => {
  307. this.$refs.treeRef.setCurrentKey(this.treeList[0].id);
  308. });
  309. }
  310. });
  311. return this.treeList;
  312. }
  313. } catch (error) {
  314. console.log(error);
  315. }
  316. this.treeLoading = false;
  317. },
  318. // 单击获取id
  319. cellClick(row) {
  320. this.current = row;
  321. this.radio = row.id;
  322. },
  323. handleClose() {
  324. this.visible = false;
  325. this.current = null;
  326. this.radio = '';
  327. this.selection = [];
  328. this.isMultiple = false;
  329. this.existingIds = [];
  330. },
  331. selected() {
  332. if (this.isMultiple) {
  333. if (this.selection.length <= 0) {
  334. return this.$message.warning('请至少选择一条数据');
  335. }
  336. // 多选:传数组(事件名复用 changeProduct,由父组件按 Array.isArray 区分)
  337. this.$emit('changeProduct', this.title, this.selection, this.idx);
  338. } else {
  339. if (!this.current) {
  340. return this.$message.warning('请选择工作中心');
  341. }
  342. // 单选:传单条
  343. this.$emit('changeProduct', this.title, this.current, this.idx);
  344. }
  345. this.handleClose();
  346. }
  347. }
  348. };
  349. </script>
  350. <style lang="scss" scoped>
  351. .tree_col {
  352. border: 1px solid #eee;
  353. padding: 10px 0;
  354. box-sizing: border-box;
  355. height: 500px;
  356. overflow: auto;
  357. }
  358. .table_col {
  359. padding-left: 10px;
  360. ::v-deep .el-table th.el-table__cell {
  361. background: #f2f2f2;
  362. }
  363. }
  364. .pagination {
  365. text-align: right;
  366. padding: 10px 0;
  367. }
  368. .btns {
  369. text-align: center;
  370. padding: 10px 0;
  371. }
  372. .topsearch {
  373. margin-bottom: 15px;
  374. }
  375. </style>