specs.html 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  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. now_spec_id: 0
  54. },
  55. methods: {
  56. onSubmit() {
  57. if (this.allData == "") return;
  58. let arr = Object.values(this.allData).flat(Infinity)
  59. Yunqi.ajax.post('goods/import_list/specs', { ids: Yunqi.data.row.id, all_data: arr }, false, false, true).then(res => {
  60. // console.log(res)
  61. if (res.code == 200) {
  62. this.$message.success(__('设置成功'));
  63. //倒计时刷新窗口
  64. setTimeout(() => {
  65. Yunqi.api.closelayer(Yunqi.app.window.id, true);
  66. }, 1000);
  67. } else {
  68. Yunqi.alert(__('请选择规格'), __('温馨提示'), { type: 'error' });
  69. }
  70. });
  71. },
  72. handleAllSelect(e) {
  73. this.allData[this.tabValue] = e || []
  74. },
  75. handleCurrentChange(e) {
  76. this.allData[this.tabValue] = e || []
  77. },
  78. handleSelectionChange(e) {
  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. let now_spec_state = this.now_spec_id == res[key]['id'] ? true : false;
  99. if (index != -1) {
  100. this.tableData.splice(index, 1)
  101. } else {
  102. let item = {
  103. id: res[key]['id'],
  104. name: res[key]['title'],
  105. type_id: this.tabValue,
  106. selected_d: isExist,
  107. now_spec_state: now_spec_state
  108. }
  109. this.tableData.push(item);
  110. // if(now_spec_state){
  111. // this.allData[this.tabValue] = item
  112. // }
  113. }
  114. }
  115. }
  116. });
  117. }
  118. },
  119. onLoad: function (query) {
  120. this.now_spec_id = Yunqi.data.now_spec_id;
  121. let rows = Yunqi.data.rows;
  122. if (rows) {
  123. const grouped = JSON.parse(rows).reduce((acc, item) => {
  124. const key = item.type_id;
  125. if (!acc[key]) {
  126. acc[key] = [];
  127. }
  128. acc[key].push(item);
  129. return acc;
  130. }, {});
  131. this.shop_allData = JSON.parse(JSON.stringify(grouped))
  132. let arr = Object.values(this.shop_allData).flat(Infinity)
  133. let acc = [];
  134. for (var key in Object(arr)) {
  135. acc[key] = Number(arr[key]['value']);
  136. }
  137. this.shop_allData = acc;
  138. }
  139. //你只需要保存规格是吧, 是你末尾加了个row
  140. this.getSpecData()
  141. },
  142. }
  143. </script>
  144. <style>
  145. </style>