EquipmentDialog.vue 6.6 KB

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