specs.html 8.9 KB

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