366 lines
10 KiB
Vue
366 lines
10 KiB
Vue
<template>
|
|
<view>
|
|
<view
|
|
v-if="barVisible"
|
|
class="card_payment flex-center ju-between bg16 h_128 p-l-34 p-r-40"
|
|
:style="{ bottom: props.bottomOffset + 'px' }"
|
|
>
|
|
<view class="flex-center ju-flex-start flex1" @click="showPopup">
|
|
<uni-badge :text="num" absolute="rightTop" :offset="[13, 6]">
|
|
<view class="w_80 h_80 m-r-24">
|
|
<image class="w100 h100" :src="$url + 'ai/index/2.svg'" mode="scaleToFill" />
|
|
</view>
|
|
</uni-badge>
|
|
<view class="flex1">总计: <span class="c13 size24 m-r-5">¥</span><span
|
|
class="c13 size34">{{ $fen2yuan(price) }}</span></view>
|
|
</view>
|
|
<view class="ai-button1 h_80 line80 w_200" @click="go"> 去结算 </view>
|
|
</view>
|
|
<uni-popup ref="popupRef" type="bottom" border-radius="10px 10px 0 0" @change="onPopupChange">
|
|
<view class="p-x-32 p-y-40 bg17">
|
|
<view class="flex-center ju-between p-b-44">
|
|
<view>已加购商品</view>
|
|
<view @click="hidePopup">
|
|
<uni-icons type="closeempty" color="#999999" size="20" />
|
|
</view>
|
|
</view>
|
|
<view class="popupCon">
|
|
<view class="flex-row m-b-24" v-for="(v, i) in cartList" :key="i">
|
|
<view class="w_130 h_130 shrink m-r-16">
|
|
<image class="w100 h100 radius8" :src="v.picUrl" mode="scaleToFill" />
|
|
</view>
|
|
<view class="flex-column ju-between flex1">
|
|
<view class="m-b-14">
|
|
<view class="size28 lineTwo">{{ v?.name }}</view>
|
|
</view>
|
|
<view class="w100">
|
|
<view class="flex-center m-b-12" v-for="(item, index) in v.skuArr" :key="index"
|
|
@click="openSelectSku(v, item)">
|
|
<view class="flex1 flex-center ju-between h_52 bg18 radius8 p-l-8 p-r-16">
|
|
<view class="lineOne c19" v-if="item?.properties">
|
|
{{item?.properties.length > 1? item?.propertyText: item?.properties[0].valueName}}
|
|
</view>
|
|
<view class="flex-center">
|
|
<view class="c19">x{{ item?.count }}</view>
|
|
<view class="m-l-12 weight900">¥{{ $fen2yuan(item?.discountedPrice?item?.discountedPrice:item?.price) }}</view>
|
|
<uni-icons class="m-l-10" type="right" color="#999999" size="16" />
|
|
</view>
|
|
</view>
|
|
<view class="m-l-16" @click.stop="deleteCart(v, item)">
|
|
<uni-icons type="closeempty" size="27" color="#999999"></uni-icons>
|
|
</view>
|
|
</view>
|
|
<view class="p-x-8 p-y-10 radius8 bg18 c20" style="display: inline-block">
|
|
<span class="m-r-12" @click="openSelectSku(v)">再选一款</span>
|
|
<uni-icons type="plusempty" color="#D4D8E1" size="13" />
|
|
</view>
|
|
</view>
|
|
<view class="c13 size36 m-t-8 weight900">
|
|
<span class="size28">¥</span>{{ $fen2yuan(v.discountedPrice?v.discountedPrice:v.price) }}
|
|
</view>
|
|
</view>
|
|
</view>
|
|
</view>
|
|
<view class="popupBottom flex-center ju-between h_128">
|
|
<view class="flex-center ju-flex-start flex1">
|
|
<uni-badge :text="num" absolute="rightTop" :offset="[13, 6]">
|
|
<view class="w_80 h_80 m-r-24">
|
|
<image class="w100 h100" :src="$url + 'ai/index/2.svg'" mode="scaleToFill" />
|
|
</view>
|
|
</uni-badge>
|
|
<view class="flex1">
|
|
总计: <span class="c13 size24 m-r-5">¥</span>
|
|
<span class="c13 size34">{{ $fen2yuan(price) }}</span>
|
|
</view>
|
|
</view>
|
|
<view class="ai-button1 h_80 line80 w_200" @click="go"> 去结算 </view>
|
|
</view>
|
|
<view class="popupSpacer" :style="{ height: popupSpacerHeight + 'px' }"></view>
|
|
</view>
|
|
</uni-popup>
|
|
|
|
<s-select-aiSku v-if="showSelectSku" :goodsInfo="goodsInfo" :activeSku="activeSku" :selectSku="selectSku"
|
|
:show="showSelectSku" :activeInfo="activeInfo" @addCart="onAddCart" @change="onSkuChange"
|
|
@close="aiSkuClose" :minSalesCountShow="props.minSalesCountShow"/>
|
|
</view>
|
|
</template>
|
|
|
|
<script setup lang="ts">
|
|
import { ref, computed, getCurrentInstance, onMounted, defineProps, watch } from 'vue';
|
|
import CartApi from '@/sheep/api/trade/cart.js';
|
|
import * as SpuApi from '@/sheep/api/ai/index';
|
|
import { onShow } from '@dcloudio/uni-app';
|
|
|
|
const { proxy } = getCurrentInstance() as any;
|
|
const props = defineProps({
|
|
source: {
|
|
// orderInfo商品详情
|
|
type: String,
|
|
default: 'index',
|
|
},
|
|
actionStatus: {
|
|
// 活动开始状态
|
|
type: String,
|
|
default: 'index',
|
|
},
|
|
addShow: {
|
|
type: Boolean,
|
|
default: false,
|
|
},
|
|
minSalesCountShow: {
|
|
type: Boolean,
|
|
default: false
|
|
},
|
|
bottomOffset: {
|
|
type: Number,
|
|
default: 0
|
|
}
|
|
});
|
|
|
|
const safeAreaBottom = Number(uni.getSystemInfoSync()?.safeAreaInsets?.bottom || 0);
|
|
const popupOpened = ref(false);
|
|
const popupBottomInsetPx = ref(0);
|
|
const popupSpacerHeight = computed(() => Math.max(0, Number(popupBottomInsetPx.value) || 0));
|
|
const cartList = ref([]);
|
|
let price = ref(0);
|
|
let num = ref(0);
|
|
const barVisible = computed(() => Array.isArray(cartList.value) && cartList.value.length > 0);
|
|
|
|
const getCartList = () => {
|
|
num.value = 0;
|
|
price.value = 0;
|
|
SpuApi.getShopCartList({}).then((res) => {
|
|
let list = res.data || [];
|
|
if (list.length) {
|
|
list.forEach((e) => {
|
|
e.skuArr = JSON.parse(e.specification);
|
|
e.skuArr.forEach((item) => {
|
|
num.value += item.count;
|
|
item.propertyText = '';
|
|
if (item.properties) {
|
|
item.properties.forEach((e1) => {
|
|
item.propertyText += e1.valueName + " ";
|
|
});
|
|
}
|
|
});
|
|
price.value += e.discountedPrice;
|
|
});
|
|
}
|
|
cartList.value = list;
|
|
proxy.$emit('updatePrice', list.length > 0);
|
|
});
|
|
|
|
};
|
|
onShow(() => {
|
|
getCartList();
|
|
});
|
|
let popupRef = ref(null);
|
|
const resolvePopupBottomInsetPx = () => {
|
|
return Math.max(0, (Number(props.bottomOffset) || 0) - safeAreaBottom);
|
|
};
|
|
const onPopupChange = (e: any) => {
|
|
popupOpened.value = !!e?.show;
|
|
if (popupOpened.value) {
|
|
popupBottomInsetPx.value = resolvePopupBottomInsetPx();
|
|
} else {
|
|
popupBottomInsetPx.value = 0;
|
|
}
|
|
};
|
|
const showPopup = () => {
|
|
if (!popupRef.value) return;
|
|
|
|
popupOpened.value = true;
|
|
popupBottomInsetPx.value = resolvePopupBottomInsetPx();
|
|
popupRef.value.open('bottom');
|
|
};
|
|
const hidePopup = () => {
|
|
popupOpened.value = false;
|
|
popupBottomInsetPx.value = 0;
|
|
popupRef.value.close();
|
|
};
|
|
onMounted(() => { });
|
|
watch(
|
|
() => cartList.value?.length,
|
|
(len) => {
|
|
if (popupOpened.value && (!len || len <= 0)) {
|
|
hidePopup();
|
|
}
|
|
},
|
|
);
|
|
//#region 选择规格弹窗
|
|
let showSelectSku = ref(false);
|
|
let goodsInfo = ref({});
|
|
// 加入购物车
|
|
const onAddCart = (data) => {
|
|
let obj = {
|
|
spuId: '',
|
|
specification: '',
|
|
shoppingPlazaId: '', //选品广场id
|
|
id: '',
|
|
};
|
|
let url = SpuApi.addShopCart;
|
|
if (addShow.value) {
|
|
// 新增
|
|
delete obj.id;
|
|
obj.spuId = addObj.value.id;
|
|
obj.shoppingPlazaId = addObj.value.shoppingPlazaId;
|
|
let arr = [];
|
|
arr.push(data);
|
|
obj.specification = JSON.stringify(arr);
|
|
url(obj).then((res) => {
|
|
if (res.code === 0) {
|
|
aiSkuClose();
|
|
getCartList();
|
|
}
|
|
});
|
|
} else {
|
|
// 编辑
|
|
let info = activeInfo.value;
|
|
console.log(info)
|
|
console.log(activeSku.value)
|
|
let index = -1;
|
|
if (activeSku.value.id) {
|
|
// index = info.skuArr.findIndex((e) => activeSku.value.id == data.id);
|
|
info.skuArr.forEach((e, i) => {
|
|
if (e.id == activeSku.value.id) {
|
|
index = i
|
|
}
|
|
})
|
|
} else {
|
|
index = info.skuArr.findIndex((e) => e.id == data.id);
|
|
}
|
|
if (index != -1) {
|
|
info.skuArr[index] = data;
|
|
} else {
|
|
info.skuArr.push(data);
|
|
}
|
|
infoChange(info);
|
|
}
|
|
};
|
|
const onSkuChange = (data) => { };
|
|
let activeSku = ref({}); // 选中的sku
|
|
let selectSku = ref([]); // 选中的sku列表
|
|
let activeInfo = ref({}); // 当前商品信息
|
|
// 打开规格选择弹窗
|
|
const openSelectSku = async (v : any = {}, item = {}) => {
|
|
let res = await SpuApi.getSpuDetail(v.spuId, v.shoppingPlazaId);
|
|
if (res.code === 0) {
|
|
goodsInfo.value = res.data;
|
|
activeSku.value = item;
|
|
selectSku.value = v?.skuArr || [];
|
|
activeInfo.value = v;
|
|
showSelectSku.value = true;
|
|
}
|
|
};
|
|
// 关闭规格选择弹窗
|
|
const aiSkuClose = () => {
|
|
showSelectSku.value = false;
|
|
goodsInfo.value = {};
|
|
activeSku.value = {};
|
|
selectSku.value = [];
|
|
activeInfo.value = {};
|
|
addObj.value = {};
|
|
|
|
addShow.value = false;
|
|
};
|
|
//#endregion
|
|
const deleteCart = (v, item) => {
|
|
if (v.skuArr.length == 1) {
|
|
// 删除接口
|
|
SpuApi.deleteShopCart({ id: v.id }).then((res) => {
|
|
if (res.code === 0) {
|
|
getCartList();
|
|
proxy.$emit('updataList');
|
|
}
|
|
});
|
|
} else {
|
|
// 修改接口
|
|
let index = v.skuArr.findIndex((e) => e.id == item.id);
|
|
v.skuArr.splice(index, 1);
|
|
infoChange(v);
|
|
}
|
|
};
|
|
// 修改属性
|
|
const infoChange = (data) => {
|
|
let obj = {
|
|
spuId: data.spuId,
|
|
specification: JSON.stringify(data.skuArr),
|
|
shoppingPlazaId: data.shoppingPlazaId, //选品广场id
|
|
id: data.id,
|
|
};
|
|
let url = SpuApi.updateShopCart;
|
|
url(obj).then((res) => {
|
|
if (res.code === 0) {
|
|
aiSkuClose();
|
|
getCartList();
|
|
}
|
|
});
|
|
};
|
|
let addObj = ref({});
|
|
let addShow = ref(false);
|
|
const addCar = async (data) => {
|
|
addObj.value = data;
|
|
let obj = cartList.value.find(
|
|
(e) => e.shoppingPlazaId == data.shoppingPlazaId && e.spuId == data.id,
|
|
);
|
|
if (obj?.id) {
|
|
openSelectSku(obj);
|
|
return;
|
|
}
|
|
addShow.value = true;
|
|
let res = await SpuApi.getSpuDetail(data.id, data.shoppingPlazaId);
|
|
if (res.code === 0) {
|
|
goodsInfo.value = res.data;
|
|
showSelectSku.value = true;
|
|
}
|
|
};
|
|
defineExpose({
|
|
addCar,
|
|
getCartList,
|
|
});
|
|
const go = () => {
|
|
// if (props.actionStatus === '开始') {
|
|
// uni.showToast({
|
|
// title: '活动未开始',
|
|
// icon: 'none'
|
|
// });
|
|
// return;
|
|
// }
|
|
if (price.value > 0) {
|
|
// proxy.utils.go('/pages/AI/placeOrder');
|
|
uni.redirectTo({
|
|
url: '/pages/AI/placeOrder',
|
|
});
|
|
} else {
|
|
if (props.source == 'orderInfo') {
|
|
proxy.$emit('addCar');
|
|
return;
|
|
}
|
|
proxy.utils.toast('请选择商品');
|
|
}
|
|
};
|
|
</script>
|
|
<style scoped lang="scss">
|
|
.card_payment {
|
|
position: fixed;
|
|
bottom: 0;
|
|
left: 0;
|
|
width: 100%;
|
|
box-shadow: 0px 0px 18px 0px rgba(0, 0, 0, 0.04);
|
|
z-index: 2;
|
|
}
|
|
|
|
.popupCon {
|
|
height: 506rpx;
|
|
overflow-y: auto;
|
|
}
|
|
|
|
.popupBottom {
|
|
box-shadow: 0px 0px 18px 0px rgba(0, 0, 0, 0.04);
|
|
}
|
|
|
|
.popupSpacer {
|
|
width: 100%;
|
|
}
|
|
</style>
|