specs.html 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  1. <template>
  2. <el-card shadow="never" style="min-height: 450px; max-height: 450px; overflow: auto;">
  3. <el-tabs tab-position="left" style="height: 100%; overflow: auto;" v-model="tabValue" @tab-click="handleClick">
  4. <el-tab-pane v-for="(item,index) in tabData" :label="item.label" :name="item.value">
  5. </el-tab-pane>
  6. <el-table :data="tableData" style="width: 100%" border :ref="'multipleTable_' + tabValue" stripe
  7. highlight-current-row @select="handleSelectionChange" @select-all="handleAllSelect"
  8. @current-change="handleCurrentChange">
  9. <el-table-column type="index" width="55">
  10. </el-table-column>
  11. <el-table-column prop="name" label="规格" align="center">
  12. </el-table-column>
  13. <!-- <el-table-column prop="packet" label="包装箱" align="center">
  14. <template #default="{row}">
  15. <span>{{options[row.box_id]}}</span>
  16. </template>
  17. </el-table-column>
  18. <el-table-column prop="price" label="发货价" align="center" ></el-table-column> -->
  19. </el-table>
  20. </el-tabs>
  21. </el-card>
  22. <div style="width: 100%;display: flex; align-items: center; justify-content: center; position: fixed; bottom: 6px;">
  23. <el-button type="primary" @click="onSubmit">立即创建</el-button>
  24. <el-button @click="cancelDialog">取消</el-button>
  25. </div>
  26. </template>
  27. <script>
  28. import table from "@components/Table.js";
  29. export default {
  30. components: { 'YunTable': table },
  31. data: {
  32. extend: {
  33. index_url: 'general/category/index',
  34. },
  35. row: Yunqi.data.row,
  36. tabData: Object.entries(Yunqi.data.typeList).map(([value, label]) => ({ label, value })),
  37. tableData: [],
  38. value: "",
  39. form: {
  40. nameValue: null,
  41. },
  42. options: Yunqi.data.packingList,//品种
  43. tabValue: Object.entries(Yunqi.data.typeList).map(([value, label]) => ({ label, value }))[0].value, //选中的品种 获取到品种数据后要给他默认赋值第一个
  44. chooseSpec: [], // 当前分类选中的规格
  45. allData: {},
  46. type: 0, // 1编辑 0新增,
  47. shop_allData: []
  48. },
  49. methods: {
  50. onSubmit() {
  51. if (this.allData == "") return;
  52. let arr = Object.values(this.allData).flat(Infinity)
  53. Yunqi.ajax.post('goods/import_list/specs', { ids: Yunqi.data.row.id, all_data: arr }, false, false, true).then(res => {
  54. console.log(res.data)
  55. if (res.code == 200) {
  56. this.$message.success(__('设置成功'));
  57. //倒计时刷新窗口
  58. setTimeout(() => {
  59. Yunqi.api.closelayer(Yunqi.app.window.id, true);
  60. }, 1000);
  61. } else {
  62. Yunqi.alert(__('请选择规格'), __('温馨提示'), { type: 'error' });
  63. }
  64. });
  65. },
  66. handleAllSelect(e) {
  67. this.allData[this.tabValue] = e || []
  68. },
  69. handleCurrentChange(e) {
  70. this.allData[this.tabValue] = e || []
  71. },
  72. handleSelectionChange(e) {
  73. console.log(this.allData, "=====this.allData")
  74. },
  75. handleClick(data, row) {
  76. // 品种切换事件 可以在这里请求规格接口
  77. this.tabValue = data.props.name
  78. this.tabName = data.props.label
  79. this.tableData = [];
  80. this.getSpecData()
  81. },
  82. cancelDialog: function () {
  83. Yunqi.api.closelayer(Yunqi.app.window.id, true);
  84. },
  85. getSpecData() {
  86. //获取规格 ;
  87. Yunqi.ajax.get('shop/customer_spec/get_box', { type_id: this.tabValue }, false, false, true).then(res => {
  88. //编辑数据
  89. if (res.length > 0) {
  90. for (var key in Object(res)) {
  91. let index = this.tableData.findIndex(item => item.id == res[key]['id']);
  92. const isExist = this.shop_allData.includes(res[key]['id'])
  93. if(isExist){
  94. if (index != -1) {
  95. this.tableData.splice(index, 1)
  96. } else {
  97. this.tableData.push({ name: res[key]['title'], id: res[key]['id'], type_id: this.tabValue });
  98. }
  99. }
  100. }
  101. this.$nextTick(() => {
  102. const tableRef = this.$refs['multipleTable_' + this.tabValue];
  103. if (this.type == 0 && this.allData[this.tabValue]?.length > 0 && tableRef) {
  104. this.tableData.forEach((item, index) => {
  105. const matched = this.allData[this.tabValue].find(row => {
  106. return row.id == item.id
  107. });
  108. if (matched) {
  109. this.tableData[index] = matched
  110. }
  111. })
  112. this.allData[this.tabValue].forEach(selected => {
  113. const matched = this.tableData.find(row => row.id === selected.id);
  114. if (matched) {
  115. this.$refs['multipleTable_' + this.tabValue].toggleRowSelection(matched, true); // 勾选
  116. }
  117. });
  118. }
  119. else if (this.type == 1 && this.allData[Number(this.tabValue)]) {
  120. this.tableData.forEach((item, index) => {
  121. const matched = this.allData[Number(this.tabValue)].find(row => {
  122. if (row.product_id) {
  123. return row.product_id == item.value
  124. } else {
  125. return row.value == item.value
  126. }
  127. });
  128. if (matched) {
  129. // this.tableData[index] = { name: 'kam', value: 3, price: '111', type_id: '4', packet: '3' }
  130. if (matched.product_id) {
  131. this.tableData[index].name = matched.name
  132. this.tableData[index].box_name = matched.box_name
  133. this.tableData[index].type_name = matched.type_name
  134. this.tableData[index].price = matched.price
  135. this.tableData[index].packet = matched.box_id != 0 ? matched?.box_id.toString() : ""
  136. } else {
  137. this.tableData[index] = matched
  138. }
  139. }
  140. })
  141. this.allData[Number(this.tabValue)].forEach(selected => {
  142. const matched = this.tableData.find(row => {
  143. if (selected.product_id) {
  144. return selected.product_id == row.value
  145. } else {
  146. return row.value === selected.value
  147. }
  148. });
  149. if (matched) {
  150. this.$refs['multipleTable_' + this.tabValue].toggleRowSelection(matched, true); // 勾选
  151. }
  152. });
  153. console.log(this.allData)
  154. }
  155. });
  156. }
  157. });
  158. }
  159. },
  160. onLoad: function (query) {
  161. let rows = Yunqi.data.rows;
  162. if (rows) {
  163. const grouped = JSON.parse(rows).reduce((acc, item) => {
  164. const key = item.type_id;
  165. if (!acc[key]) {
  166. acc[key] = [];
  167. }
  168. acc[key].push(item);
  169. return acc;
  170. }, {});
  171. this.shop_allData = JSON.parse(JSON.stringify(grouped))
  172. let arr = Object.values(this.shop_allData).flat(Infinity)
  173. let acc = [];
  174. for (var key in Object(arr)) {
  175. acc[key] = Number(arr[key]['value']);
  176. }
  177. this.shop_allData=acc;
  178. }
  179. //你只需要保存规格是吧, 是你末尾加了个row
  180. this.getSpecData()
  181. },
  182. }
  183. </script>
  184. <style>
  185. </style>