ProductModal.vue 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  1. <template>
  2. <el-dialog
  3. title="选择产品"
  4. :visible.sync="visible"
  5. :before-close="handleClose"
  6. :close-on-click-modal="false"
  7. :close-on-press-escape="false"
  8. append-to-body
  9. width="80%"
  10. >
  11. <el-card shadow="never">
  12. <seekPage :seekList="seekList" @search="reload" />
  13. <ele-split-layout
  14. width="244px"
  15. allow-collapse
  16. :right-style="{ overflow: 'hidden' }"
  17. >
  18. <div class="ele-border-lighter split-layout-right-content">
  19. <AssetTree
  20. ref="assetTreeRef"
  21. id="9"
  22. @handleNodeClick="handleNodeClick"
  23. />
  24. </div>
  25. <!-- 表格 -->
  26. <template v-slot:content>
  27. <ele-pro-table
  28. ref="table"
  29. :columns="columns"
  30. :datasource="datasource"
  31. height="calc(100vh - 450px)"
  32. class="dict-table"
  33. :selection.sync="selection"
  34. @cell-click="cellClick"
  35. >
  36. </ele-pro-table>
  37. </template>
  38. </ele-split-layout>
  39. </el-card>
  40. <div class="btns">
  41. <el-button type="primary" size="small" @click="selected">选择</el-button>
  42. <el-button size="small" @click="handleClose">关闭</el-button>
  43. </div>
  44. </el-dialog>
  45. </template>
  46. <script>
  47. import AssetTree from '@/components/AssetTree';
  48. import { getListAndInProduceTask } from '@/api/classifyManage/itemInformation';
  49. export default {
  50. components: { AssetTree },
  51. props: {
  52. // 是否 多选
  53. multiple: {
  54. type: Boolean,
  55. default: false
  56. }
  57. },
  58. computed: {
  59. seekList() {
  60. return [
  61. {
  62. label: '产品编码',
  63. value: 'code',
  64. type: 'input',
  65. placeholder: '请输入'
  66. },
  67. {
  68. label: '产品名称',
  69. value: 'name',
  70. type: 'input',
  71. placeholder: '请输入'
  72. },
  73. {
  74. label: '型号',
  75. value: 'modelType',
  76. type: 'input',
  77. placeholder: '请输入'
  78. }
  79. ];
  80. }
  81. },
  82. data() {
  83. return {
  84. visible: false,
  85. // 表格列配置
  86. columns: [
  87. {
  88. width: 45,
  89. type: 'selection',
  90. columnKey: 'selection',
  91. align: 'center'
  92. },
  93. {
  94. columnKey: 'index',
  95. type: 'index',
  96. width: 45,
  97. align: 'center',
  98. reserveSelection: true
  99. },
  100. {
  101. prop: 'code',
  102. label: '产品编码'
  103. },
  104. {
  105. prop: 'name',
  106. label: '产品名称',
  107. showOverflowTooltip: true
  108. },
  109. {
  110. prop: 'brandNum',
  111. label: '牌号'
  112. },
  113. {
  114. prop: 'modelType',
  115. label: '型号'
  116. },
  117. {
  118. prop: 'measuringUnit',
  119. label: '计量单位'
  120. },
  121. {
  122. prop: 'packingUnit',
  123. label: '包装单位'
  124. }
  125. ],
  126. categoryLevelId: '9',
  127. // 表格选中数据
  128. selection: []
  129. };
  130. },
  131. watch: {},
  132. methods: {
  133. /* 表格数据源 */
  134. datasource({ page, where, limit }) {
  135. return getListAndInProduceTask({
  136. ...where,
  137. pageNum: page,
  138. size: limit,
  139. categoryLevelId: this.categoryLevelId
  140. });
  141. },
  142. handleNodeClick(data) {
  143. this.categoryLevelId = data.id;
  144. this.reload();
  145. },
  146. /* 刷新表格 */
  147. reload(where = {}) {
  148. this.$refs.table.reload({ page: 1, where: where });
  149. },
  150. open(rows, produceTaskCode) {
  151. this.produceTaskCode = produceTaskCode;
  152. console.log('rows', rows, this.produceTaskCode);
  153. this.visible = true;
  154. if (rows) {
  155. this.selection = rows;
  156. this.$nextTick(() => {
  157. this.$refs.table.setSelectedRows(rows);
  158. });
  159. } else {
  160. this.selection = [];
  161. this.$nextTick(() => {
  162. this.$refs.table.setSelectedRows([]);
  163. });
  164. }
  165. // 刷新表格
  166. this.reload();
  167. console.log('this.selection', this.selection);
  168. },
  169. handleClose() {
  170. this.visible = false;
  171. this.selection = [];
  172. },
  173. selected() {
  174. console.log('this.selection', this.selection);
  175. if (!this.selection.length) {
  176. return this.$message.warning('请选择产品');
  177. }
  178. if (!this.multiple && this.selection.length > 1) {
  179. return this.$message.warning('只能选择一个产品');
  180. }
  181. this.$emit(
  182. 'changeProduct',
  183. this.multiple ? this.selection : this.selection[0]
  184. );
  185. this.handleClose();
  186. },
  187. cellClick(row) {
  188. console.log('cellClick', row);
  189. this.selection.push(row);
  190. this.$refs.table.setSelectedRows(this.selection);
  191. }
  192. }
  193. };
  194. </script>
  195. <style lang="scss" scoped>
  196. .tree_col {
  197. border: 1px solid #eee;
  198. padding: 10px 0;
  199. box-sizing: border-box;
  200. height: 500px;
  201. overflow: auto;
  202. }
  203. .table_col {
  204. padding-left: 10px;
  205. ::v-deep .el-table th.el-table__cell {
  206. background: #f2f2f2;
  207. }
  208. }
  209. .pagination {
  210. text-align: right;
  211. padding: 10px 0;
  212. }
  213. .btns {
  214. text-align: center;
  215. padding: 10px 0;
  216. }
  217. .topsearch {
  218. margin-bottom: 15px;
  219. }
  220. </style>