toolModal.vue 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307
  1. <template>
  2. <ele-modal
  3. :title="title"
  4. :visible.sync="visible"
  5. :before-close="handleClose"
  6. :close-on-click-modal="false"
  7. :close-on-press-escape="false"
  8. append-to-body
  9. width="70%"
  10. :maxable="true"
  11. >
  12. <el-card shadow="never">
  13. <ele-split-layout
  14. width="236px"
  15. allow-collapse
  16. :right-style="{ overflow: 'hidden' }"
  17. >
  18. <div>
  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="categoryId ? [categoryId] : []"
  25. :highlight-current="true"
  26. node-key="id"
  27. @node-click="handleNodeClick"
  28. ></el-tree>
  29. </div>
  30. </div>
  31. <!-- 数据表格 -->
  32. <template v-slot:content>
  33. <seekPage :seekList="seekList" @search="reload" />
  34. <ele-pro-table
  35. height="calc(100vh - 480px)"
  36. ref="table"
  37. :columns="columns"
  38. :datasource="datasource"
  39. :selection.sync="selection"
  40. row-key="id"
  41. >
  42. <template #radio="{ row }">
  43. <el-radio
  44. v-model="currentId"
  45. :label="row.id"
  46. @change="current = row"
  47. class="radio"
  48. >
  49. <i></i>
  50. </el-radio>
  51. </template>
  52. </ele-pro-table>
  53. </template>
  54. </ele-split-layout>
  55. </el-card>
  56. <div class="rx-sc">
  57. <el-button type="primary" size="small" @click="selected">选择</el-button>
  58. <el-button size="small" @click="handleClose">关闭</el-button>
  59. </div>
  60. </ele-modal>
  61. </template>
  62. <script>
  63. import ProductSearch from './product-search.vue';
  64. import { getMaterialList, getProduceTreeByPid } from '@/api/material/list';
  65. export default {
  66. components: {
  67. ProductSearch
  68. },
  69. props: {
  70. // 是否多选
  71. multiple: {
  72. type: Boolean,
  73. default: true
  74. }
  75. },
  76. computed: {
  77. seekList() {
  78. return [
  79. {
  80. label: '编码',
  81. value: 'code',
  82. type: 'input',
  83. placeholder: '请输入'
  84. },
  85. {
  86. label: '名称',
  87. value: 'name',
  88. type: 'input',
  89. placeholder: '请输入'
  90. },
  91. {
  92. label: '型号',
  93. value: 'modelType',
  94. type: 'input',
  95. placeholder: '请输入'
  96. }
  97. ];
  98. },
  99. // 表格列配置
  100. columns() {
  101. const list = [
  102. {
  103. label: '物料名称',
  104. prop: 'name'
  105. },
  106. {
  107. label: '物料编码',
  108. prop: 'code'
  109. },
  110. {
  111. label: '牌号',
  112. prop: 'brandNum'
  113. },
  114. {
  115. label: '型号',
  116. prop: 'modelType'
  117. },
  118. {
  119. prop: 'availableCountBase',
  120. label: '包装库存',
  121. sortable: 'custom'
  122. },
  123. {
  124. label: '单位',
  125. prop: 'weightUnit'
  126. },
  127. {
  128. prop: 'packingCountBase',
  129. label: '计量库存',
  130. sortable: 'custom'
  131. },
  132. {
  133. label: '计量单位',
  134. prop: 'unit'
  135. },
  136. {
  137. label: '数量',
  138. prop: 'count'
  139. }
  140. ];
  141. if (this.multiple) {
  142. list.unshift({
  143. columnKey: 'selection',
  144. type: 'selection',
  145. width: 45,
  146. align: 'center',
  147. selectable: (row, index) => {
  148. return !this.processData.some((it) => row.id == it.categoryId);
  149. },
  150. reserveSelection: true,
  151. fixed: 'left'
  152. });
  153. } else {
  154. list.unshift({
  155. prop: 'radio',
  156. slot: 'radio',
  157. width: 50,
  158. align: 'center',
  159. fixed: 'left'
  160. });
  161. }
  162. return list;
  163. }
  164. },
  165. data() {
  166. return {
  167. visible: false,
  168. title: '选择工具',
  169. categoryLevelId: null,
  170. categoryId: 1,
  171. treeList: [],
  172. treeLoading: false,
  173. defaultProps: {
  174. children: 'children',
  175. label: 'name'
  176. },
  177. type: null,
  178. // 表格选中数据
  179. selection: [],
  180. processData: [],
  181. currentId: '',
  182. current: null
  183. };
  184. },
  185. watch: {},
  186. methods: {
  187. /* 表格数据源 */
  188. async datasource({ page, limit, where }) {
  189. const res = await getMaterialList({
  190. ...where,
  191. pageNum: page,
  192. size: limit,
  193. categoryLevelId: this.categoryLevelId
  194. });
  195. return res;
  196. },
  197. open(item, title) {
  198. this.processData = item || [];
  199. this.title = title || '选择工具';
  200. this.visible = true;
  201. this.getTreeData();
  202. },
  203. async getTreeData() {
  204. try {
  205. this.treeLoading = true;
  206. const res = await getProduceTreeByPid(5);
  207. this.treeLoading = false;
  208. if (res?.code === '0') {
  209. this.treeList = res.data;
  210. this.$nextTick(() => {
  211. // 默认高亮第一级树节点
  212. if (this.treeList[0]) {
  213. this.rootTreeId = this.treeList[0].id;
  214. this.$nextTick(() => {
  215. this.$refs.treeRef.setCurrentKey(this.treeList[0].id);
  216. });
  217. }
  218. });
  219. return this.treeList;
  220. }
  221. } catch (error) {}
  222. this.treeLoading = false;
  223. },
  224. handleNodeClick(data) {
  225. this.categoryLevelId = data.id;
  226. this.$refs.table.reload({ pageNum: 1, where: {} });
  227. },
  228. /* 刷新表格 */
  229. reload(where) {
  230. this.$refs.table.reload({ page: 1, where: where });
  231. },
  232. handleClose() {
  233. this.$refs.table.setSelectedRows([]);
  234. this.selection = [];
  235. this.current = null;
  236. this.currentId = '';
  237. this.visible = false;
  238. },
  239. selected() {
  240. if (!this.multiple) {
  241. if (!this.current) {
  242. this.$message.warning('请选择数据');
  243. return;
  244. }
  245. this.$emit('chooseModal', this.current);
  246. return this.handleClose();
  247. }
  248. let _arr = [];
  249. if (!this.selection.length) {
  250. this.$message.warning('请至少选择一条数据');
  251. return;
  252. }
  253. _arr = this.selection.map((m) => {
  254. m.categoryId = m.id;
  255. delete m.id;
  256. return {
  257. ...m
  258. };
  259. });
  260. this.$emit('chooseModal', _arr);
  261. this.handleClose();
  262. }
  263. }
  264. };
  265. </script>
  266. <style lang="scss" scoped>
  267. .rx-sc {
  268. display: flex;
  269. align-items: center;
  270. justify-content: center;
  271. }
  272. .ml60 {
  273. margin-left: 60px;
  274. }
  275. :deep(.radio) {
  276. .el-radio__label {
  277. padding: 0;
  278. }
  279. }
  280. </style>