ProductModal.vue 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245
  1. <template>
  2. <el-dialog :title="title" :visible.sync="visible" :before-close="handleClose" :close-on-click-modal="false"
  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="btns">
  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 { getList } from '@/api/classifyManage/itemInformation';
  28. import ProductSearch from './product-search.vue'
  29. import { getTreeByPid } 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) => it.id == row.id || it.categoryId == row.id);
  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: 'measuringUnit',
  78. label: '计量单位',
  79. showOverflowTooltip: true,
  80. },
  81. {
  82. prop: 'weightUnit',
  83. label: '重量单位',
  84. showOverflowTooltip: true,
  85. },
  86. {
  87. prop: 'roughWeight',
  88. label: '毛重',
  89. showOverflowTooltip: true,
  90. minWidth: 90
  91. },
  92. {
  93. prop: 'netWeight',
  94. label: '净重',
  95. showOverflowTooltip: true,
  96. minWidth: 90
  97. },
  98. ],
  99. // 表格选中数据
  100. selection: [],
  101. processData: [],
  102. current: null
  103. }
  104. },
  105. watch: {
  106. },
  107. methods: {
  108. /* 表格数据源 */
  109. async datasource({ page, limit, where }) {
  110. const res = await getList({
  111. ...where,
  112. pageNum: page,
  113. size: limit,
  114. categoryLevelId: 1,
  115. });
  116. return res;
  117. },
  118. open(item, row, type) {
  119. this.type = type
  120. this.processData = item || []
  121. this.current = row;
  122. this.visible = true
  123. this.getTreeData();
  124. },
  125. async getTreeData() {
  126. try {
  127. this.treeLoading = true;
  128. const res = await getTreeByPid(1);
  129. this.treeLoading = false;
  130. if (res?.code === '0') {
  131. this.treeList = res.data;
  132. this.$nextTick(() => {
  133. // 默认高亮第一级树节点
  134. if (this.treeList[0]) {
  135. this.rootTreeId = this.treeList[0].id
  136. this.$nextTick(() => {
  137. this.$refs.treeRef.setCurrentKey(this.treeList[0].id);
  138. });
  139. }
  140. });
  141. return this.treeList;
  142. }
  143. } catch (error) { }
  144. this.treeLoading = false;
  145. },
  146. handleNodeClick(data) {
  147. this.categoryLevelId = data.id;
  148. this.$refs.table.reload({ pageNum: 1, where: {} });
  149. },
  150. /* 刷新表格 */
  151. reload(where) {
  152. this.$refs.table.reload({ page: 1, where: where });
  153. },
  154. handleClose() {
  155. this.visible = false
  156. this.$refs.table.setSelectedRows([]);
  157. this.selection = []
  158. },
  159. selected() {
  160. let _arr = []
  161. if (!this.selection.length) {
  162. this.$message.error('请至少选择一条数据');
  163. return;
  164. }
  165. if (this.type == 'add') {
  166. _arr = this.selection.map(m => {
  167. m.categoryId = m.id
  168. delete m.id
  169. return {
  170. ...m
  171. }
  172. })
  173. }
  174. this.$emit('chooseModal', _arr, this.current)
  175. this.handleClose()
  176. },
  177. }
  178. }
  179. </script>
  180. <style lang="scss" scoped>
  181. .btns {
  182. text-align: center;
  183. padding: 10px 0;
  184. }
  185. </style>