add.html 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  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. @select="handleSelectionChange">
  8. <el-table-column type="selection" width="55">
  9. </el-table-column>
  10. <el-table-column prop="name" label="规格" align="center">
  11. </el-table-column>
  12. <el-table-column prop="packet" label="包装箱" align="center">
  13. <template #default="{row}">
  14. <el-select v-model="row.packet" placeholder="请选择">
  15. <el-option v-for="item in options" :key="item.value" :label="item.label"
  16. :value="item.value">
  17. </el-option>
  18. </el-select>
  19. </template>
  20. </el-table-column>
  21. <el-table-column prop="price" label="发货价" align="center">
  22. <template #default="{row}">
  23. <el-input v-model="row.price"></el-input>
  24. </template>
  25. </el-table-column>
  26. </el-table>
  27. </el-tabs>
  28. </el-card>
  29. <div style="width: 100%;display: flex; align-items: center; justify-content: center; position: fixed; bottom: 6px;">
  30. <el-button type="primary" @click="onSubmit">立即创建</el-button>
  31. <el-button @click="cancelDialog">取消</el-button>
  32. </div>
  33. </template>
  34. <script>
  35. import table from "@components/Table.js";
  36. export default {
  37. components: { 'YunTable': table },
  38. data: {
  39. extend: {
  40. index_url: 'general/category/index',
  41. },
  42. row: Yunqi.data.row,
  43. tabData: Object.entries(Yunqi.data.typeList).map(([value, label]) => ({ label, value })),
  44. tableData: [],
  45. value: "",
  46. form: {
  47. nameValue: null,
  48. },
  49. options: Object.entries(Yunqi.data.packingList).map(([value, label]) => ({ label, value: value.toString() })),//品种
  50. tabValue: Object.entries(Yunqi.data.typeList).map(([value, label]) => ({ label, value }))[0].value, //选中的品种 获取到品种数据后要给他默认赋值第一个
  51. chooseSpec: [], // 当前分类选中的规格
  52. allData: {},
  53. type: 1, // 1编辑 0新增
  54. },
  55. methods: {
  56. cancelDialog: function () {
  57. Yunqi.api.closelayer(Yunqi.app.window.id, true);
  58. },
  59. onSubmit() {
  60. if (this.allData == "") return;
  61. let arr = Object.values(this.allData).flat(Infinity)
  62. console.log(JSON.stringify(arr), "所有数据")
  63. //
  64. Yunqi.ajax.post('shop/customer_spec/add', { ids: Yunqi.data.ids, all_data: arr }, false, false, true).then(res => {
  65. if (res.code == 200) {
  66. this.$message.success(__('设置成功'));
  67. //倒计时刷新窗口
  68. setTimeout(() => {
  69. Yunqi.api.closelayer(Yunqi.app.window.id, true);
  70. }, 1000);
  71. } else {
  72. Yunqi.alert(__('请填写发货价格'), __('温馨提示'), { type: 'error' });
  73. }
  74. });
  75. },
  76. handleSelectionChange(e) {
  77. // if (e.length > 0) {
  78. this.allData[this.tabValue] = e || []
  79. // }
  80. },
  81. handleClick(data, row) {
  82. // 品种切换事件 可以在这里请求规格接口
  83. this.tabValue = data.props.name
  84. // this.chooseSpec = this.allData[this.tabValue]
  85. console.log(this.allData[this.tabValue], "this.allData[this.tabValue]")
  86. this.tabName = data.props.label
  87. this.tableData = [];
  88. this.getSpecData()
  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. console.log("res", res)
  96. for (var key in Object(res)) {
  97. let index = this.tableData.findIndex(item => item.value == res[key]['id']);
  98. if (index != -1) {
  99. this.tableData.splice(index, 1)
  100. } else {
  101. this.tableData.push({ name: res[key]['title'], value: res[key]['id'], price: res[key]['price'], type_id: this.tabValue });
  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.value == item.value
  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.value === selected.value);
  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].price = matched.price
  135. this.tableData[index].packet = matched.box_id != 0 ? matched?.box_id.toString() : ""
  136. } else {
  137. this.tableData[index] = matched
  138. }
  139. }
  140. })
  141. this.allData[Number(this.tabValue)].forEach(selected => {
  142. const matched = this.tableData.find(row => {
  143. if (selected.product_id) {
  144. return selected.product_id == row.value
  145. } else {
  146. return row.value === selected.value
  147. }
  148. });
  149. if (matched) {
  150. this.$refs['multipleTable_' + this.tabValue].toggleRowSelection(matched, true); // 勾选
  151. }
  152. });
  153. // this.type = 0
  154. }
  155. });
  156. }
  157. });
  158. }
  159. },
  160. onLoad: function (query) {
  161. let row = Yunqi.data.row;
  162. if (row.length > 0) {
  163. this.type = 1
  164. } else {
  165. this.type = 0
  166. }
  167. console.log(this.type)
  168. const grouped = row.reduce((acc, item) => {
  169. const key = item.type_id;
  170. if (!acc[key]) {
  171. acc[key] = [];
  172. }
  173. item.value = item.product_id
  174. item.packet = item.box_id
  175. acc[key].push(item);
  176. return acc;
  177. }, {});
  178. this.allData = JSON.parse(JSON.stringify(grouped))
  179. this.getSpecData()
  180. },
  181. }
  182. </script>
  183. <style>
  184. </style>