ProductModal.vue 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  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. isProduct: true,
  141. produceTaskCode: this.produceTaskCode,
  142. bomTypes: [1, 2, 3]
  143. });
  144. },
  145. handleNodeClick(data) {
  146. this.categoryLevelId = data.id;
  147. this.reload();
  148. },
  149. /* 刷新表格 */
  150. reload(where = {}) {
  151. this.$refs.table.reload({ page: 1, where: where });
  152. },
  153. open(rows, produceTaskCode) {
  154. this.produceTaskCode = produceTaskCode;
  155. console.log('rows', rows, this.produceTaskCode);
  156. this.visible = true;
  157. if (rows) {
  158. this.selection = rows;
  159. this.$nextTick(() => {
  160. this.$refs.table.setSelectedRows(rows);
  161. });
  162. } else {
  163. this.selection = [];
  164. this.$nextTick(() => {
  165. this.$refs.table.setSelectedRows([]);
  166. });
  167. }
  168. // 刷新表格
  169. this.reload();
  170. console.log('this.selection', this.selection);
  171. },
  172. handleClose() {
  173. this.visible = false;
  174. this.selection = [];
  175. },
  176. selected() {
  177. console.log('this.selection', this.selection);
  178. if (!this.selection.length) {
  179. return this.$message.warning('请选择产品');
  180. }
  181. if (!this.multiple && this.selection.length > 1) {
  182. return this.$message.warning('只能选择一个产品');
  183. }
  184. this.$emit(
  185. 'changeProduct',
  186. this.multiple ? this.selection : this.selection[0]
  187. );
  188. this.handleClose();
  189. },
  190. cellClick(row) {
  191. console.log('cellClick', row);
  192. this.selection.push(row);
  193. this.$refs.table.setSelectedRows(this.selection);
  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. height: 500px;
  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>