add.html 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237
  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" @select-all="handleAllSelect">
  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="请选择" @change="changePacket($event, row)">
  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="fast_mail" label="快递" align="center">
  22. <template #default="{row}">
  23. <el-select v-model="row.fast_mail" placeholder="请选择" @change="changeLogi($event, row)">
  24. <el-option v-for="item in logiOptions" :key="item" :label="item" :value="item">
  25. </el-option>
  26. </el-select>
  27. </template>
  28. </el-table-column>
  29. <el-table-column prop="price" label="发货价" align="center">
  30. <template #default="{row}">
  31. <el-input v-model="row.price" @input="changePrice($event, row)"></el-input>
  32. </template>
  33. </el-table-column>
  34. </el-table>
  35. </el-tabs>
  36. </el-card>
  37. <div style="width: 100%;display: flex; align-items: center; justify-content: center; position: fixed; bottom: 6px;">
  38. <el-button type="primary" @click="onSubmit">立即创建</el-button>
  39. <el-button>取消</el-button>
  40. </div>
  41. </template>
  42. <script>
  43. import table from "@components/Table.js";
  44. export default {
  45. components: { 'YunTable': table },
  46. data: {
  47. extend: {
  48. index_url: 'general/category/index',
  49. },
  50. row: Yunqi.data.row,
  51. tabData: Object.entries(Yunqi.data.typeList).map(([value, label]) => ({ label, value })),
  52. tableData: [],
  53. value: "",
  54. form: {
  55. nameValue: null,
  56. },
  57. options: Object.entries(Yunqi.data.packingList).map(([value, label]) => ({ label, value: value.toString() })),//品种
  58. tabValue: Object.entries(Yunqi.data.typeList).map(([value, label]) => ({ label, value }))[0].value, //选中的品种 获取到品种数据后要给他默认赋值第一个
  59. logiOptions: Yunqi.data.fastmailList,
  60. chooseSpec: [], // 当前分类选中的规格
  61. allData: {},
  62. type: 1, // 1编辑 0新增
  63. },
  64. methods: {
  65. onSubmit() {
  66. if (this.allData == "") return;
  67. let arr = Object.values(this.allData).flat(Infinity)
  68. console.log(JSON.stringify(arr), "所有数据")
  69. //
  70. Yunqi.ajax.post('shop/customer_spec/add', { ids: Yunqi.data.ids, all_data: arr }, false, false, true).then(res => {
  71. if (res.code == 200) {
  72. this.$message.success(__('设置成功'));
  73. //倒计时刷新窗口
  74. setTimeout(() => {
  75. Yunqi.api.closelayer(Yunqi.app.window.id, true);
  76. }, 1000);
  77. } else {
  78. Yunqi.alert(__('请填写发货价格'), __('温馨提示'), { type: 'error' });
  79. }
  80. });
  81. },
  82. handleSelectionChange(e) {
  83. // if (e.length > 0) {
  84. this.allData[this.tabValue] = e || []
  85. // }
  86. },
  87. handleAllSelect(e){
  88. this.allData[this.tabValue] = e || []
  89. },
  90. handleClick(data, row) {
  91. // 品种切换事件 可以在这里请求规格接口
  92. this.tabValue = data.props.name
  93. // this.chooseSpec = this.allData[this.tabValue]
  94. console.log(this.allData[this.tabValue], "this.allData[this.tabValue]")
  95. this.tabName = data.props.label
  96. this.tableData = [];
  97. this.getSpecData()
  98. },
  99. getSpecData() {
  100. //获取规格
  101. Yunqi.ajax.get('shop/customer_spec/get_box', { type_id: this.tabValue }, false, false, true).then(res => {
  102. //编辑数据
  103. if (res.length > 0) {
  104. console.log("res", res)
  105. for (var key in Object(res)) {
  106. let index = this.tableData.findIndex(item => item.value == res[key]['id']);
  107. if (index != -1) {
  108. this.tableData.splice(index, 1)
  109. } else {
  110. this.tableData.push({ name: res[key]['name'], value: res[key]['id'], price: res[key]['price'], type_id: this.tabValue, fast_mail: res[key]['fast_mail'] });
  111. }
  112. }
  113. this.$nextTick(() => {
  114. const tableRef = this.$refs['multipleTable_' + this.tabValue];
  115. if (this.type == 0 && this.allData[this.tabValue]?.length > 0 && tableRef) {
  116. console.log(this.allData[Number(this.tabValue)], this.tableData, "===")
  117. this.tableData.forEach((item, index) => {
  118. const matched = this.allData[this.tabValue].find(row => {
  119. return row.value == item.value
  120. });
  121. if (matched) {
  122. this.tableData[index] = matched
  123. }
  124. })
  125. this.allData[this.tabValue].forEach(selected => {
  126. const matched = this.tableData.find(row => row.value === selected.value);
  127. if (matched) {
  128. this.$refs['multipleTable_' + this.tabValue].toggleRowSelection(matched, true); // 勾选
  129. }
  130. });
  131. }
  132. else if (this.type == 1 && this.allData[Number(this.tabValue)]) {
  133. console.log(this.allData[Number(this.tabValue)], this.tableData)
  134. this.tableData.forEach((item, index) => {
  135. const matched = this.allData[Number(this.tabValue)].find(row => {
  136. if (row.product_id) {
  137. return row.product_id == item.value
  138. } else {
  139. return row.value == item.value
  140. }
  141. });
  142. if (matched) {
  143. // this.tableData[index] = { name: 'kam', value: 3, price: '111', type_id: '4', packet: '3' }
  144. if (matched.product_id) {
  145. this.tableData[index].price = matched.price
  146. this.tableData[index].packet = matched.box_id != 0 ? matched?.box_id.toString() : ""
  147. this.tableData[index].fast_mail = matched.fast_mail
  148. } else {
  149. this.tableData[index] = matched
  150. }
  151. }
  152. })
  153. this.allData[Number(this.tabValue)].forEach(selected => {
  154. const matched = this.tableData.find(row => {
  155. if (selected.product_id) {
  156. return selected.product_id == row.value
  157. } else {
  158. return row.value === selected.value
  159. }
  160. });
  161. if (matched) {
  162. this.$refs['multipleTable_' + this.tabValue].toggleRowSelection(matched, true); // 勾选
  163. }
  164. });
  165. // this.type = 0
  166. }
  167. });
  168. }
  169. });
  170. },
  171. changeLogi(value, row) {
  172. if (this.allData[this.tabValue].length > 0) {
  173. this.allData[this.tabValue].forEach((item, index) => {
  174. if (item.product_id == row.value) {
  175. this.allData[this.tabValue][index].fast_mail = value
  176. }
  177. })
  178. }
  179. },
  180. changePacket(value, row) {
  181. if (this.allData[this.tabValue].length > 0) {
  182. this.allData[this.tabValue].forEach((item, index) => {
  183. if (item.product_id == row.value) {
  184. this.allData[this.tabValue][index].packet = value
  185. this.allData[this.tabValue][index].box_id = value
  186. }
  187. })
  188. }
  189. },
  190. changePrice(value, row) {
  191. this.allData[this.tabValue].forEach((item, index) => {
  192. if (item.product_id == row.value) {
  193. this.allData[this.tabValue][index].price = value
  194. }
  195. })
  196. },
  197. },
  198. onLoad: function (query) {
  199. let row = Yunqi.data.row;
  200. if (row.length > 0) {
  201. this.type = 1
  202. } else {
  203. this.type = 0
  204. }
  205. // Yunqi.data.fastmailList 快递 1111
  206. console.log(Yunqi.data.fastmailList, "快递")
  207. console.log(row, "-----")
  208. const grouped = row.reduce((acc, item) => {
  209. const key = item.type_id;
  210. if (!acc[key]) {
  211. acc[key] = [];
  212. }
  213. item.value = item.product_id
  214. item.packet = item.box_id
  215. acc[key].push(item);
  216. return acc;
  217. }, {});
  218. this.allData = JSON.parse(JSON.stringify(grouped))
  219. this.getSpecData()
  220. },
  221. }
  222. </script>
  223. <style>
  224. </style>