对接购物车

This commit is contained in:
gyq
2025-02-26 18:06:37 +08:00
parent 44144c5ac7
commit d3ed4ec8e6
27 changed files with 2589 additions and 1629 deletions

View File

@@ -1,7 +1,7 @@
<!-- 称重商品组件 -->
<template>
<el-dialog title="可选套餐" width="70%" :close-on-click-modal="false" v-model="dialogVisible" top="10vh">
<div class="row" v-for="(item, index) in goodsItem.proGroupVo" :key="index">
<div class="row" v-for="(item, index) in goodsItem.groupSnap" :key="index">
<div class="title_wrap">
<div class="item">规格组名{{ item.title }}</div>
<div class="item"
@@ -43,6 +43,9 @@
import { ref } from "vue";
import { ElMessage } from "element-plus";
import { inputFilterFloat, formatDecimal } from '@/utils/index.js'
import { useGoods } from '@/store/goods.js'
const goodsStore = useGoods()
const dialogVisible = ref(false);
const number = ref("");
@@ -52,23 +55,55 @@ const emit = defineEmits(["success"]);
const tabRefs = ref([])
function show(item) {
disabled.value = true
const confirmType = ref('')
const cartItem = ref('')
function show(item, type = 'add') {
confirmType.value = type
dialogVisible.value = true;
goodsItem.value = { ...item }
goodsItem.value.proGroupVo.map(item => {
item.isError = false
})
setTimeout(() => {
tabRefs.value.map(item => {
item.clearSelection()
if (type == 'add') {
disabled.value = true
goodsItem.value = { ...item }
goodsItem.value.groupSnap.map(item => {
item.isError = false
})
}, 100);
setTimeout(() => {
tabRefs.value.map(item => {
item.clearSelection()
})
}, 100);
} else {
cartItem.value = { ...item }
disabled.value = false
goodsItem.value = goodsStore.originGoodsList.find(val => val.id == item.product_id)
// console.log('item===', item)
// console.log('goodsItem.value===', goodsItem.value);
let selectGroup = JSON.parse(item.pro_group_info)
console.log('selectGroup===', selectGroup);
setTimeout(() => {
goodsItem.value.groupSnap.map((item, index) => {
item.goods.map((val, i) => {
selectGroup[index].map(sg => {
if (val.proId == sg.proId) {
tabRefs.value[index].toggleRowSelection(val, true)
}
})
})
})
goodsItem.value.groupSnap.map(item => {
item.isError = false
})
}, 100)
}
}
// 选择表格触发
function selectChange($event, index) {
let item = goodsItem.value.proGroupVo[index]
let item = goodsItem.value.groupSnap[index]
let selectNum = tabRefs.value[index].getSelectionRows()
if (selectNum.length != item.number) {
@@ -79,7 +114,7 @@ function selectChange($event, index) {
let flags = []
goodsItem.value.proGroupVo.map((item, index) => {
goodsItem.value.groupSnap.map((item, index) => {
let selectNum = tabRefs.value[index].getSelectionRows()
if (selectNum.length != item.number) {
flags.push({ flag: false })
@@ -103,7 +138,7 @@ const disabled = ref(true)
function confirmHandle() {
let flags = []
goodsItem.value.proGroupVo.map((item, index) => {
goodsItem.value.groupSnap.map((item, index) => {
let selectNum = tabRefs.value[index].getSelectionRows()
if (selectNum.length != item.number) {
flags.push({ flag: false })
@@ -122,17 +157,25 @@ function confirmHandle() {
disabled.value = false
let goodIds = []
goodsItem.value.proGroupVo.map((item, index) => {
goodsItem.value.groupSnap.map((item, index) => {
let selectNum = tabRefs.value[index].getSelectionRows()
goodIds.push(selectNum)
})
// 将商品数据转为一维数组返回
emit("success", {
...goodsItem.value,
productId: goodsItem.value.id,
groupProductIdList: goodIds.flat().map(item => item.proId)
});
if (confirmType.value == 'add') {
emit("success", {
...goodsItem.value.skuList[0],
goods_type: goodsItem.value.type,
pro_group_info: goodIds
});
} else {
// 编辑
goodsStore.operateCart({
...cartItem.value,
pro_group_info: goodIds
}, 'edit')
}
dialogVisible.value = false;
}