EquipmentDialog.vue 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  1. <template>
  2. <el-dialog
  3. title="选择产品"
  4. :visible.sync="equipmentdialog"
  5. :before-close="handleClose"
  6. :close-on-click-modal="false"
  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. 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';
  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: 'modelType',
  114. label: '型号',
  115. align: 'center',
  116. showOverflowTooltip: true,
  117. minWidth: 110
  118. }
  119. ],
  120. tableList: [],
  121. categoryLevelId: null,
  122. code: null,
  123. selection: []
  124. };
  125. },
  126. watch: {},
  127. methods: {
  128. async datasource ({ page, limit }) {
  129. const params = {
  130. code: this.code,
  131. pageNum: page,
  132. size: limit,
  133. categoryLevelId: this.categoryLevelId,
  134. isProduct: true
  135. };
  136. const data = await getList(params);
  137. this.tableList = data.list;
  138. return data;
  139. },
  140. open () {
  141. this.equipmentdialog = true;
  142. this.setSelect();
  143. },
  144. handleNodeClick (data) {
  145. this.categoryLevelId = data.id;
  146. this.reload();
  147. },
  148. reload () {
  149. this.$refs.equiTable.reload();
  150. },
  151. handleClose () {
  152. this.equipmentdialog = false;
  153. this.code = '';
  154. this.$refs.equiTable.clearSelection();
  155. },
  156. reset () {
  157. this.code = null;
  158. this.reload();
  159. },
  160. // 设置选中
  161. setSelect () {
  162. this.$nextTick(() => {
  163. this.tableList.forEach((row) => {
  164. this.selectList.forEach((selected, index) => {
  165. if (selected.productCode === row.code) {
  166. this.$refs.equiTable.toggleRowSelection(row, true);
  167. }
  168. });
  169. });
  170. });
  171. },
  172. // 取消选中
  173. handleSelect (selection, row) {
  174. if (!selection.find((i) => i.id === row.id)) {
  175. const index = this.selectList.findIndex(
  176. (itm) => row.code == itm.productCode
  177. );
  178. console.log(index);
  179. if (index > -1) {
  180. this.selectList.splice(index, 1);
  181. }
  182. }
  183. },
  184. // 选择
  185. selected () {
  186. this.$emit('choose', [
  187. ...this.selection,
  188. ...this.selectList.filter(
  189. (i) => !this.selection.find((p) => p.code === i.productCode)
  190. )
  191. ]);
  192. this.handleClose();
  193. }
  194. }
  195. };
  196. </script>
  197. <style lang="scss" scoped>
  198. .tree_col {
  199. border: 1px solid #eee;
  200. padding: 10px 0;
  201. box-sizing: border-box;
  202. max-height: 530px;
  203. overflow: auto;
  204. }
  205. .table_col {
  206. padding-left: 10px;
  207. ::v-deep .el-table th.el-table__cell {
  208. background: #f2f2f2;
  209. }
  210. }
  211. .pagination {
  212. text-align: right;
  213. padding: 10px 0;
  214. }
  215. .btns {
  216. text-align: center;
  217. padding: 10px 0;
  218. }
  219. .topsearch {
  220. margin-bottom: 15px;
  221. }
  222. </style>