ProductModal.vue 6.7 KB

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