specs.html 7.0 KB

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