EquipmentDialog.vue 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270
  1. <template>
  2. <ele-modal
  3. title="选择产品"
  4. :visible.sync="equipmentdialog"
  5. :before-close="handleClose"
  6. :close-on-click-modal="true"
  7. :close-on-press-escape="false"
  8. append-to-body
  9. width="60%"
  10. :maxable="true"
  11. >
  12. <div>
  13. <el-row>
  14. <el-col :span="24" class="topsearch">
  15. <el-form>
  16. <el-row>
  17. <el-col :span="6">
  18. <el-input
  19. v-model="code"
  20. placeholder="请输入物料编码"
  21. size="small"
  22. ></el-input>
  23. </el-col>
  24. <el-col :span="6" style="margin-left: 10px">
  25. <el-input
  26. v-model="name"
  27. placeholder="请输入物料名称"
  28. size="small"
  29. ></el-input>
  30. </el-col>
  31. <el-col :span="6" style="margin-left: 10px">
  32. <el-input
  33. v-model="searchKey"
  34. placeholder="请输入关键字"
  35. size="small"
  36. ></el-input>
  37. </el-col>
  38. <el-col :span="4" style="margin-left: 10px">
  39. <el-button type="primary" size="small" @click="reload"
  40. >搜索</el-button
  41. >
  42. <el-button size="small" @click="reset">重置</el-button>
  43. </el-col>
  44. </el-row>
  45. </el-form>
  46. </el-col>
  47. <el-col :span="6" class="tree_col">
  48. <AssetTree
  49. @handleNodeClick="handleNodeClick"
  50. :treeIds="treeType"
  51. ref="treeList"
  52. />
  53. </el-col>
  54. <el-col :span="18" class="table_col" v-if="equipmentdialog">
  55. <ele-pro-table
  56. ref="equiTable"
  57. :columns="columns"
  58. :datasource="datasource"
  59. :selection.sync="selection"
  60. @select="handleSelect"
  61. cache-key="systemRoleTable3"
  62. row-key="id"
  63. height="50vh"
  64. @done="setSelect"
  65. >
  66. </ele-pro-table>
  67. </el-col>
  68. </el-row>
  69. </div>
  70. <div class="btns">
  71. <el-button type="primary" size="small" @click="selected">选择</el-button>
  72. <el-button size="small" @click="handleClose">关闭</el-button>
  73. </div>
  74. </ele-modal>
  75. </template>
  76. <script>
  77. import AssetTree from '@/components/AssetTree/treeIndex.vue';
  78. import { getList } from '@/api/classifyManage/itemInformation';
  79. export default {
  80. components: {
  81. AssetTree
  82. },
  83. props: {
  84. selectList: Array,
  85. // 是否多选 1:是 0:否
  86. isMultiple: {
  87. type: String,
  88. default: '1'
  89. },
  90. treeType: {
  91. type: Array,
  92. default: () => ['9', '1']
  93. }
  94. },
  95. data() {
  96. return {
  97. equipmentdialog: false,
  98. columns: [
  99. {
  100. width: 45,
  101. type: 'selection',
  102. columnKey: 'selection',
  103. align: 'center',
  104. reserveSelection: true
  105. },
  106. {
  107. columnKey: 'index',
  108. label: '序号',
  109. type: 'index',
  110. width: 55,
  111. align: 'center',
  112. showOverflowTooltip: true
  113. },
  114. {
  115. prop: 'code',
  116. label: '编码',
  117. align: 'center',
  118. showOverflowTooltip: true,
  119. minWidth: 110,
  120. slot: 'code'
  121. },
  122. {
  123. prop: 'name',
  124. label: '名称',
  125. align: 'center',
  126. showOverflowTooltip: true,
  127. minWidth: 110
  128. },
  129. {
  130. prop: 'brandNum',
  131. label: '牌号',
  132. align: 'center',
  133. showOverflowTooltip: true,
  134. minWidth: 110
  135. },
  136. {
  137. prop: 'specification',
  138. label: '规格',
  139. align: 'center',
  140. showOverflowTooltip: true,
  141. minWidth: 110
  142. },
  143. {
  144. prop: 'modelType',
  145. label: '型号',
  146. align: 'center',
  147. showOverflowTooltip: true,
  148. minWidth: 110
  149. }
  150. ],
  151. tableList: [],
  152. categoryLevelId: null,
  153. searchKey: null,
  154. code: null,
  155. name: null,
  156. selection: []
  157. };
  158. },
  159. watch: {},
  160. methods: {
  161. async datasource({ page, limit }) {
  162. const params = {
  163. code: this.code,
  164. name: this.name,
  165. searchKey: this.searchKey,
  166. pageNum: page,
  167. size: limit,
  168. categoryLevelId: this.categoryLevelId,
  169. isProduct: true,
  170. isEnable: true
  171. };
  172. const data = await getList(params);
  173. this.tableList = data.list;
  174. return data;
  175. },
  176. open(type) {
  177. console.log('type', type);
  178. this.equipmentdialog = true;
  179. this.setSelect();
  180. },
  181. handleNodeClick(data) {
  182. this.categoryLevelId = data.id;
  183. this.reload();
  184. },
  185. reload() {
  186. this.$refs.equiTable.reload();
  187. },
  188. handleClose() {
  189. this.equipmentdialog = false;
  190. this.code = '';
  191. this.$refs.equiTable.clearSelection();
  192. },
  193. reset() {
  194. this.code = null;
  195. this.searchKey = null;
  196. this.name = null;
  197. this.reload();
  198. },
  199. // 设置选中
  200. setSelect() {
  201. this.$nextTick(() => {
  202. this.tableList.forEach((row) => {
  203. this.selectList.forEach((selected, index) => {
  204. if (selected.productCode === row.code) {
  205. this.$refs.equiTable.toggleRowSelection(row, true);
  206. }
  207. });
  208. });
  209. });
  210. },
  211. // 取消选中
  212. handleSelect(selection, row) {
  213. if (!selection.find((i) => i.id === row.id)) {
  214. const index = this.selectList.findIndex(
  215. (itm) => row.code == itm.productCode
  216. );
  217. console.log(index);
  218. if (index > -1) {
  219. this.selectList.splice(index, 1);
  220. }
  221. }
  222. },
  223. // 选择
  224. selected() {
  225. if (this.isMultiple == '0' && this.selection.length > 1) {
  226. return this.$message.warning('生产计划只能选择一条产品');
  227. }
  228. this.$emit('choose', [
  229. ...this.selection,
  230. ...this.selectList.filter(
  231. (i) => !this.selection.find((p) => p.code === i.productCode)
  232. )
  233. ]);
  234. this.handleClose();
  235. }
  236. }
  237. };
  238. </script>
  239. <style lang="scss" scoped>
  240. .tree_col {
  241. border: 1px solid #eee;
  242. padding: 10px 0;
  243. box-sizing: border-box;
  244. max-height: 530px;
  245. overflow: auto;
  246. }
  247. .table_col {
  248. padding-left: 10px;
  249. ::v-deep .el-table th.el-table__cell {
  250. background: #f2f2f2;
  251. }
  252. }
  253. .pagination {
  254. text-align: right;
  255. padding: 10px 0;
  256. }
  257. .btns {
  258. text-align: center;
  259. padding: 10px 0;
  260. }
  261. .topsearch {
  262. margin-bottom: 15px;
  263. }
  264. </style>