EquipmentDialog.vue 5.7 KB

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