EquipmentDialog.vue 5.6 KB

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