productTable.vue 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. <template>
  2. <div>
  3. <headerTitle title="关联产品" ></headerTitle>
  4. <ele-pro-table ref="table" :needPage="false" :columns="columns" :datasource="datasource" class="time-form"
  5. :toolkit="[]">
  6. <!-- 表头工具栏 -->
  7. <template v-slot:toolbar>
  8. <el-button
  9. v-if="!isView"
  10. size="small"
  11. type="primary"
  12. icon="el-icon-plus"
  13. class="ele-btn-icon"
  14. @click="handParent('', -1)"
  15. >
  16. 新增
  17. </el-button>
  18. </template>
  19. <!-- 操作列 -->
  20. <template v-slot:action="scope">
  21. <el-popconfirm class="ele-action" title="确定要删除吗?" @confirm="remove(scope.$index)">
  22. <template v-slot:reference>
  23. <el-link v-if="!isView" type="danger" :underline="false" icon="el-icon-delete">
  24. 删除
  25. </el-link>
  26. </template>
  27. </el-popconfirm>
  28. </template>
  29. </ele-pro-table>
  30. <product-list
  31. ref="productListRef"
  32. classType="1"
  33. :is-get-inventory-total="true"
  34. @changeParent="changeParent"
  35. :data="datasource"
  36. ></product-list>
  37. </div>
  38. </template>
  39. <script>
  40. import productList from './product-list.vue';
  41. export default {
  42. props: {
  43. isView: {
  44. type: Boolean,
  45. default: false
  46. }
  47. },
  48. components:{
  49. productList
  50. },
  51. data() {
  52. return {
  53. datasource: [],
  54. columns: [
  55. {
  56. width: 50,
  57. label: '序号',
  58. type: 'index',
  59. columnKey: 'index',
  60. align: 'center',
  61. fixed: 'left'
  62. },
  63. {
  64. prop: 'productCategoryName',
  65. label: '类型',
  66. slot: 'productCategoryName',
  67. align: 'center'
  68. },
  69. {
  70. prop: 'productCode',
  71. label: '编码',
  72. slot: 'productCode',
  73. align: 'center'
  74. },
  75. {
  76. prop: 'productName',
  77. label: '名称',
  78. slot: 'productName',
  79. headerSlot: 'headerProductName',
  80. align: 'center',
  81. fixed: 'left'
  82. },
  83. {
  84. prop: 'specification',
  85. label: '规格',
  86. slot: 'specification',
  87. align: 'center'
  88. },
  89. {
  90. prop: 'productBrand',
  91. label: '牌号',
  92. slot: 'productBrand',
  93. align: 'center'
  94. },
  95. {
  96. prop: 'modelType',
  97. label: '型号',
  98. slot: 'modelType',
  99. align: 'center'
  100. },
  101. {
  102. columnKey: 'action',
  103. label: '操作',
  104. width: 80,
  105. align: 'left',
  106. resizable: false,
  107. slot: 'action',
  108. showOverflowTooltip: true
  109. }]
  110. }
  111. },
  112. methods:{
  113. //选择产品回调
  114. changeParent(obj, idx) {
  115. obj.forEach((item, index) => {
  116. let i = idx == -1 ? index : idx;
  117. let row = {};
  118. row.key = this.datasource.length + 1;
  119. let parasm = idx == -1 ? row : this.datasource[i];
  120. this.$set(parasm, 'productId', item.id);
  121. this.$set(parasm, 'productCategoryId', item.categoryLevelId);
  122. this.$set(parasm, 'productCategoryName', item.categoryLevelPath);
  123. this.$set(parasm, 'productCode', item.code);
  124. this.$set(parasm, 'productName', item.name);
  125. this.$set(parasm, 'specification', item.specification);
  126. this.$set(parasm, 'productBrand', item.brandNum);
  127. this.$set(parasm, 'modelType', item.modelType);
  128. if (idx == -1) {
  129. this.datasource.push(row);
  130. }
  131. });
  132. },
  133. //选择产品
  134. handParent() {
  135. this.$refs.productListRef.open(-1);
  136. },
  137. //删除选中产品
  138. remove(index) {
  139. this.datasource.splice(index, 1);
  140. this.setSort();
  141. },
  142. // 重新排序
  143. setSort() {
  144. this.datasource.forEach((n, index) => {
  145. n.key = index + 1;
  146. });
  147. },
  148. // 初始化数据
  149. initData() {
  150. this.datasource = [];
  151. },
  152. // 返回列表数据
  153. getTableValue() {
  154. let comitDatasource = this.datasource;
  155. if (comitDatasource.length === 0) return [];
  156. return comitDatasource;
  157. },
  158. //修改回显
  159. putTableValue(data) {
  160. this.datasource = data;
  161. }
  162. }
  163. }
  164. </script>