ProductModal2.vue 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274
  1. <template>
  2. <el-dialog :title="title" :visible.sync="visible" :before-close="handleClose" :close-on-click-modal="true"
  3. :close-on-press-escape="false" append-to-body width="70%">
  4. <el-card shadow="never">
  5. <ProductSearch @search="reload" ref="searchRef" />
  6. <ele-split-layout width="244px" allow-collapse :right-style="{ overflow: 'hidden' }">
  7. <div class="ele-border-lighter split-layout-right-content">
  8. <el-tree :data="treeList" :props="defaultProps" ref="treeRef"
  9. :default-expanded-keys="categoryId ? [categoryId] : []" :highlight-current="true" node-key="id"
  10. @node-click="handleNodeClick"></el-tree>
  11. </div>
  12. <!-- 数据表格 -->
  13. <template v-slot:content>
  14. <ele-pro-table style="min-height: 400px;" ref="table" :columns="columns" :datasource="datasource"
  15. :selection.sync="selection" row-key="id">
  16. </ele-pro-table>
  17. </template>
  18. </ele-split-layout>
  19. </el-card>
  20. <div class="rx-sc">
  21. <el-button type="primary" size="small" @click="selected">选择</el-button>
  22. <el-button size="small" @click="handleClose">关闭</el-button>
  23. </div>
  24. </el-dialog>
  25. </template>
  26. <script>
  27. import { getMaterialList, getTaskListById } from '@/api/materialPlan/index';
  28. import ProductSearch from './product-search.vue'
  29. import { getTreeByGroup } from '@/api/classifyManage';
  30. export default {
  31. components: {
  32. ProductSearch
  33. },
  34. data() {
  35. return {
  36. visible: false,
  37. title: '选择物料',
  38. categoryLevelId: null,
  39. categoryId: 1,
  40. treeList: [],
  41. treeLoading: false,
  42. defaultProps: {
  43. children: 'children',
  44. label: 'name'
  45. },
  46. type: null,
  47. // 表格列配置
  48. columns: [
  49. {
  50. columnKey: 'selection',
  51. type: 'selection',
  52. width: 45,
  53. align: 'center',
  54. selectable: (row, index) => {
  55. return !this.processData.some((it) => false);
  56. },
  57. reserveSelection: true,
  58. fixed: 'left'
  59. },
  60. {
  61. label: '物料名称',
  62. prop: 'name',
  63. },
  64. {
  65. label: '物料编码',
  66. prop: 'code'
  67. },
  68. {
  69. label: '牌号',
  70. prop: 'brandNum'
  71. },
  72. {
  73. label: '型号',
  74. prop: 'modelType'
  75. },
  76. {
  77. prop: 'availableCountBase',
  78. label: '包装库存',
  79. sortable: 'custom',
  80. },
  81. {
  82. label: '单位',
  83. prop: 'weightUnit'
  84. },
  85. {
  86. prop: 'packingCountBase',
  87. label: '计量库存',
  88. sortable: 'custom',
  89. },
  90. {
  91. label: '计量单位',
  92. prop: 'unit'
  93. },
  94. {
  95. label: '数量',
  96. prop: 'count'
  97. },
  98. ],
  99. // 表格选中数据
  100. selection: [],
  101. processData: [],
  102. current: null,
  103. produceList: []
  104. }
  105. },
  106. watch: {
  107. },
  108. methods: {
  109. /* 表格数据源 */
  110. async datasource({ page, limit, where }) {
  111. const res = await getMaterialList({
  112. ...where,
  113. pageNum: page,
  114. size: limit,
  115. categoryLevelId: this.categoryLevelId,
  116. dimension: 1
  117. });
  118. return res;
  119. },
  120. open(item, row, type) {
  121. this.type = type
  122. this.processData = item || []
  123. this.current = row;
  124. this.visible = true
  125. this.getTreeData();
  126. this.getTaskList()
  127. },
  128. async getTreeData() {
  129. try {
  130. this.treeLoading = true;
  131. const res = await getTreeByGroup({ type: 3 });
  132. this.treeLoading = false;
  133. if (res?.code === '0') {
  134. this.treeList = res.data;
  135. this.$nextTick(() => {
  136. // 默认高亮第一级树节点
  137. if (this.treeList[0]) {
  138. this.rootTreeId = this.treeList[0].id
  139. this.categoryLevelId = this.treeList[0].id
  140. this.$nextTick(() => {
  141. this.$refs.treeRef.setCurrentKey(this.treeList[0].id);
  142. });
  143. }
  144. });
  145. return this.treeList;
  146. }
  147. } catch (error) { }
  148. this.treeLoading = false;
  149. },
  150. getTaskList() {
  151. getTaskListById(this.current.produceRoutingId).then(res => {
  152. this.produceList = res
  153. })
  154. },
  155. handleNodeClick(data) {
  156. this.categoryLevelId = data.id;
  157. this.$refs.table.reload({ pageNum: 1, where: {} });
  158. },
  159. /* 刷新表格 */
  160. reload(where) {
  161. this.$refs.table.reload({ page: 1, where: where });
  162. },
  163. handleClose() {
  164. this.visible = false
  165. this.$refs.table.setSelectedRows([]);
  166. this.selection = []
  167. },
  168. selected() {
  169. let _arr = []
  170. if (!this.selection.length) {
  171. this.$message.error('请至少选择一条数据');
  172. return;
  173. }
  174. _arr = this.selection.map(m => {
  175. m.produceRoutingList = this.produceList
  176. m.categoryId = m.id + '-' + new Date().getTime()
  177. m.inventoryQuantity = m.availableCountBase
  178. m.produceSelect = true
  179. m.taskId = ''
  180. this.type == 'add' ? delete m.id : ''
  181. return {
  182. ...m
  183. }
  184. })
  185. this.$emit('chooseModal', _arr, this.current)
  186. this.handleClose()
  187. },
  188. }
  189. }
  190. </script>
  191. <style lang="scss" scoped>
  192. .rx-sc {
  193. display: flex;
  194. align-items: center;
  195. justify-content: center;
  196. }
  197. .ml60 {
  198. margin-left: 60px;
  199. }
  200. </style>