specs.html 10 KB

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