specs.html 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  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" :row-class-name="tableRowClassName">
  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>
  14. </el-tabs>
  15. </el-card>
  16. <div style="width: 100%;display: flex; align-items: center; justify-content: center; position: fixed; bottom: 6px;">
  17. <el-button type="primary" @click="onSubmit">立即创建</el-button>
  18. <el-button @click="cancelDialog">取消</el-button>
  19. </div>
  20. </template>
  21. <script>
  22. import table from "@components/Table.js";
  23. export default {
  24. components: { 'YunTable': table },
  25. data: {
  26. extend: {
  27. index_url: 'general/category/index',
  28. },
  29. row: Yunqi.data.row,
  30. tabData: Object.entries(Yunqi.data.typeList).map(([value, label]) => ({ label, value })),
  31. tableData: [],
  32. value: "",
  33. form: {
  34. nameValue: null,
  35. },
  36. options: Yunqi.data.packingList,//品种
  37. // tabValue: Object.entries(Yunqi.data.typeList).map(([value, label]) => ({ label, value }))[0].value, //选中的品种 获取到品种数据后要给他默认赋值第一个
  38. tabValue: Yunqi.data.tabValue,
  39. chooseSpec: [], // 当前分类选中的规格
  40. allData: {},
  41. type: 0, // 1编辑 0新增,
  42. shop_allData: [],
  43. spec_id: Yunqi.data.spec_id
  44. },
  45. methods: {
  46. tableRowClassName({ row, rowIndex }) {
  47. // 根据行数据中的selected_d字段判断是否高亮
  48. if (row.spec_id_selected) {
  49. return 'current-row';
  50. }
  51. return '';
  52. },
  53. onSubmit() {
  54. if (this.allData == "") return;
  55. const loading = ElementPlus.ElLoading.service({
  56. lock: true,
  57. text: '请等待...',
  58. background: 'rgba(0, 0, 0, 0.7)',
  59. })
  60. let arr = Object.values(this.allData).flat(Infinity)
  61. Yunqi.ajax.post('goods/import_list/specs', { ids: Yunqi.data.row.id, all_data: arr }, false, false, true).then(res => {
  62. // console.log(res)
  63. if (res.code == 200) {
  64. this.$message.success(__('设置成功'));
  65. //倒计时刷新窗口
  66. setTimeout(() => {
  67. Yunqi.api.closelayer(Yunqi.app.window.id, true);
  68. loading.close()
  69. }, 1000);
  70. } else {
  71. Yunqi.alert(__('请选择规格'), __('温馨提示'), { type: 'error' });
  72. loading.close()
  73. }
  74. });
  75. },
  76. handleAllSelect(e) {
  77. this.allData[this.tabValue] = e || []
  78. },
  79. handleCurrentChange(e) {
  80. this.tableData = this.tableData.map((item) => {
  81. if(e.id==item.id){
  82. item.spec_id_selected=true
  83. }else{
  84. item.spec_id_selected=false
  85. }
  86. return item;
  87. })
  88. this.allData[this.tabValue] = e || []
  89. },
  90. handleSelectionChange(e) {
  91. },
  92. handleClick(data, row) {
  93. // 品种切换事件 可以在这里请求规格接口
  94. this.tabValue = data.props.name
  95. this.tabName = data.props.label
  96. this.tableData = [];
  97. this.getSpecData()
  98. },
  99. cancelDialog: function () {
  100. Yunqi.api.closelayer(Yunqi.app.window.id, true);
  101. },
  102. getSpecData() {
  103. //获取规格 ;
  104. Yunqi.ajax.get('shop/customer_spec/get_box', { type_id: this.tabValue }, false, false, true).then(res => {
  105. //编辑数据
  106. if (res.length > 0) {
  107. for (var key in Object(res)) {
  108. let index = this.tableData.findIndex(item => item.id == res[key]['id']);
  109. const isExist = this.shop_allData.includes(res[key]['id'])
  110. let spec_id = this.spec_id == res[key]['id'] ? true : false;
  111. if (index != -1) {
  112. this.tableData.splice(index, 1)
  113. } else {
  114. let item = {
  115. id: res[key]['id'],
  116. name: res[key]['title'],
  117. type_id: this.tabValue,
  118. selected_d: isExist,
  119. spec_id_selected: spec_id
  120. }
  121. this.tableData.push(item);
  122. }
  123. }
  124. }
  125. });
  126. }
  127. },
  128. onLoad: function (query) {
  129. let rows = Yunqi.data.rows;
  130. if (rows) {
  131. const grouped = JSON.parse(rows).reduce((acc, item) => {
  132. const key = item.type_id;
  133. if (!acc[key]) {
  134. acc[key] = [];
  135. }
  136. acc[key].push(item);
  137. return acc;
  138. }, {});
  139. this.shop_allData = JSON.parse(JSON.stringify(grouped))
  140. let arr = Object.values(this.shop_allData).flat(Infinity)
  141. let acc = [];
  142. for (var key in Object(arr)) {
  143. acc[key] = Number(arr[key]['value']);
  144. }
  145. this.shop_allData = acc;
  146. }
  147. // this.tableData = [];
  148. //你只需要保存规格是吧, 是你末尾加了个row
  149. this.getSpecData()
  150. },
  151. }
  152. </script>
  153. <style>
  154. </style>