ProductModal.vue 6.1 KB

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