specs.html 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  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. let arr = Object.values(this.allData).flat(Infinity)
  56. Yunqi.ajax.post('goods/import_list/specs', { ids: Yunqi.data.row.id, all_data: arr }, false, false, true).then(res => {
  57. // console.log(res)
  58. if (res.code == 200) {
  59. this.$message.success(__('设置成功'));
  60. //倒计时刷新窗口
  61. setTimeout(() => {
  62. Yunqi.api.closelayer(Yunqi.app.window.id, true);
  63. }, 1000);
  64. } else {
  65. Yunqi.alert(__('请选择规格'), __('温馨提示'), { type: 'error' });
  66. }
  67. });
  68. },
  69. handleAllSelect(e) {
  70. this.allData[this.tabValue] = e || []
  71. },
  72. handleCurrentChange(e) {
  73. this.tableData = this.tableData.map((item) => {
  74. if(e.id==item.id){
  75. item.spec_id_selected=true
  76. }else{
  77. item.spec_id_selected=false
  78. }
  79. return item;
  80. })
  81. this.allData[this.tabValue] = e || []
  82. },
  83. handleSelectionChange(e) {
  84. },
  85. handleClick(data, row) {
  86. // 品种切换事件 可以在这里请求规格接口
  87. this.tabValue = data.props.name
  88. this.tabName = data.props.label
  89. this.tableData = [];
  90. this.getSpecData()
  91. },
  92. cancelDialog: function () {
  93. Yunqi.api.closelayer(Yunqi.app.window.id, true);
  94. },
  95. getSpecData() {
  96. //获取规格 ;
  97. Yunqi.ajax.get('shop/customer_spec/get_box', { type_id: this.tabValue }, false, false, true).then(res => {
  98. //编辑数据
  99. if (res.length > 0) {
  100. for (var key in Object(res)) {
  101. let index = this.tableData.findIndex(item => item.id == res[key]['id']);
  102. const isExist = this.shop_allData.includes(res[key]['id'])
  103. let spec_id = this.spec_id == res[key]['id'] ? true : false;
  104. if (index != -1) {
  105. this.tableData.splice(index, 1)
  106. } else {
  107. let item = {
  108. id: res[key]['id'],
  109. name: res[key]['title'],
  110. type_id: this.tabValue,
  111. selected_d: isExist,
  112. spec_id_selected: spec_id
  113. }
  114. this.tableData.push(item);
  115. }
  116. }
  117. }
  118. });
  119. }
  120. },
  121. onLoad: function (query) {
  122. let rows = Yunqi.data.rows;
  123. if (rows) {
  124. const grouped = JSON.parse(rows).reduce((acc, item) => {
  125. const key = item.type_id;
  126. if (!acc[key]) {
  127. acc[key] = [];
  128. }
  129. acc[key].push(item);
  130. return acc;
  131. }, {});
  132. this.shop_allData = JSON.parse(JSON.stringify(grouped))
  133. let arr = Object.values(this.shop_allData).flat(Infinity)
  134. let acc = [];
  135. for (var key in Object(arr)) {
  136. acc[key] = Number(arr[key]['value']);
  137. }
  138. this.shop_allData = acc;
  139. }
  140. // this.tableData = [];
  141. //你只需要保存规格是吧, 是你末尾加了个row
  142. this.getSpecData()
  143. },
  144. }
  145. </script>
  146. <style>
  147. </style>