EquipmentDialog.vue 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253
  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="['9', '1']"
  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. },
  86. data () {
  87. return {
  88. equipmentdialog: false,
  89. columns: [
  90. {
  91. width: 45,
  92. type: 'selection',
  93. columnKey: 'selection',
  94. align: 'center',
  95. reserveSelection: true
  96. },
  97. {
  98. columnKey: 'index',
  99. label: '序号',
  100. type: 'index',
  101. width: 55,
  102. align: 'center',
  103. showOverflowTooltip: true
  104. },
  105. {
  106. prop: 'code',
  107. label: '物品编码',
  108. align: 'center',
  109. showOverflowTooltip: true,
  110. minWidth: 110,
  111. slot: 'code'
  112. },
  113. {
  114. prop: 'name',
  115. label: '物品名称',
  116. align: 'center',
  117. showOverflowTooltip: true,
  118. minWidth: 110
  119. },
  120. {
  121. prop: 'brandNum',
  122. label: '牌号',
  123. align: 'center',
  124. showOverflowTooltip: true,
  125. minWidth: 110
  126. },
  127. {
  128. prop: 'specification',
  129. label: '规格',
  130. align: 'center',
  131. showOverflowTooltip: true,
  132. minWidth: 110
  133. },
  134. {
  135. prop: 'modelType',
  136. label: '型号',
  137. align: 'center',
  138. showOverflowTooltip: true,
  139. minWidth: 110
  140. }
  141. ],
  142. tableList: [],
  143. categoryLevelId: null,
  144. searchKey: null,
  145. code: null,
  146. name: null,
  147. selection: []
  148. };
  149. },
  150. watch: {},
  151. methods: {
  152. async datasource ({ page, limit }) {
  153. const params = {
  154. code: this.code,
  155. name: this.name,
  156. searchKey: this.searchKey,
  157. pageNum: page,
  158. size: limit,
  159. categoryLevelId: this.categoryLevelId,
  160. isProduct: true
  161. };
  162. const data = await getList(params);
  163. this.tableList = data.list;
  164. return data;
  165. },
  166. open () {
  167. this.equipmentdialog = true;
  168. this.setSelect();
  169. },
  170. handleNodeClick (data) {
  171. this.categoryLevelId = data.id;
  172. this.reload();
  173. },
  174. reload () {
  175. this.$refs.equiTable.reload();
  176. },
  177. handleClose () {
  178. this.equipmentdialog = false;
  179. this.code = '';
  180. this.$refs.equiTable.clearSelection();
  181. },
  182. reset () {
  183. this.code = null;
  184. this.reload();
  185. },
  186. // 设置选中
  187. setSelect () {
  188. this.$nextTick(() => {
  189. this.tableList.forEach((row) => {
  190. this.selectList.forEach((selected, index) => {
  191. if (selected.productCode === row.code) {
  192. this.$refs.equiTable.toggleRowSelection(row, true);
  193. }
  194. });
  195. });
  196. });
  197. },
  198. // 取消选中
  199. handleSelect (selection, row) {
  200. if (!selection.find((i) => i.id === row.id)) {
  201. const index = this.selectList.findIndex(
  202. (itm) => row.code == itm.productCode
  203. );
  204. console.log(index);
  205. if (index > -1) {
  206. this.selectList.splice(index, 1);
  207. }
  208. }
  209. },
  210. // 选择
  211. selected () {
  212. this.$emit('choose', [
  213. ...this.selection,
  214. ...this.selectList.filter(
  215. (i) => !this.selection.find((p) => p.code === i.productCode)
  216. )
  217. ]);
  218. this.handleClose();
  219. }
  220. }
  221. };
  222. </script>
  223. <style lang="scss" scoped>
  224. .tree_col {
  225. border: 1px solid #eee;
  226. padding: 10px 0;
  227. box-sizing: border-box;
  228. max-height: 530px;
  229. overflow: auto;
  230. }
  231. .table_col {
  232. padding-left: 10px;
  233. ::v-deep .el-table th.el-table__cell {
  234. background: #f2f2f2;
  235. }
  236. }
  237. .pagination {
  238. text-align: right;
  239. padding: 10px 0;
  240. }
  241. .btns {
  242. text-align: center;
  243. padding: 10px 0;
  244. }
  245. .topsearch {
  246. margin-bottom: 15px;
  247. }
  248. </style>