代客下单重构
This commit is contained in:
1406
pages/product/components/confirmorder - 副本.vue
Normal file
1406
pages/product/components/confirmorder - 副本.vue
Normal file
File diff suppressed because it is too large
Load Diff
@@ -3,13 +3,6 @@
|
||||
<up-popup :show="showCart" :round="20" :safeAreaInsetBottom="false" :zIndex="98" :overlayStyle="{ zIndex: 98 }"
|
||||
@close="close">
|
||||
<view class="cart-list-wrap">
|
||||
<!-- <view class="cart-header flex-between">
|
||||
<view class="num">已点 {{ cartLists_count }} 份</view>
|
||||
<view class="clear" @click="cartclear">
|
||||
<up-icon name="trash" color="#999"></up-icon>
|
||||
<text class="t">清空</text>
|
||||
</view>
|
||||
</view> -->
|
||||
<scroll-view scroll-y class="scroll-view">
|
||||
<view class="list-wrap">
|
||||
<view v-if="cartList.length>0">
|
||||
@@ -29,15 +22,15 @@
|
||||
<up-image :src="item.coverImg" width="80" radius="10" height="80"></up-image>
|
||||
</view>
|
||||
<view class="info">
|
||||
<view class="name"> {{item.cartListinfo.is_temporary == 1?'临时菜' :item.name }}
|
||||
<view class="name"> {{item.is_temporary == 1?'临时菜' :item.name }}
|
||||
</view>
|
||||
<view class="select-sku-wrap" v-if="item.type == 'sku'">
|
||||
<text v-for="i in item.skuList" :key="i.id">
|
||||
{{item.cartListinfo.sku_id == i.id? i.name:"" }}
|
||||
<text >
|
||||
{{item.skuData.name||''}}
|
||||
</text>
|
||||
</view>
|
||||
<view class="select-sku-wrap" v-if="item.type == 'package'">
|
||||
<view v-for="(a,b) in dataprocessing(item.cartListinfo)" :key="b">
|
||||
<view v-for="(a,b) in dataprocessing(item)" :key="b">
|
||||
<!-- <view>{{a.title}}</view> -->
|
||||
<text v-for="i in a.goods" :key="i.proId" style="margin-left: 4rpx;">
|
||||
{{i.proName }}
|
||||
@@ -47,15 +40,14 @@
|
||||
<view class="price-wrap" style="padding-top: 0;">
|
||||
<view class="price">
|
||||
<text class="i">¥</text>
|
||||
<!-- 会员价与价格 -->
|
||||
<text class="price" v-if="item.type == 'sku'">
|
||||
<text v-for="i in item.skuList" :key="i.id">
|
||||
<!-- -->
|
||||
{{item.cartListinfo.sku_id == i.id?(shopInfo.isVip ==1 && shopInfo.isMemberPrice==1?(i.memberPrice || i.salePrice):i.salePrice):''}}
|
||||
<!-- 会员价 -->
|
||||
<text class="price" v-if="shopInfo.isVip ==1 && shopInfo.isMemberPrice==1">
|
||||
<text >
|
||||
{{item.memberPrice || item.salePrice}}
|
||||
</text>
|
||||
</text>
|
||||
<text class="price" v-else>
|
||||
{{shopInfo.isVip ==1 && shopInfo.isMemberPrice==1?(item.memberPrice || item.salePrice):item.salePrice}}
|
||||
{{item.salePrice}}
|
||||
</text>
|
||||
<!-- <text class="originalprice"
|
||||
v-if="item.originPrice">¥{{item.originPrice}}</text>
|
||||
@@ -66,16 +58,16 @@
|
||||
<view class="operation-wrap">
|
||||
<view class="btn">
|
||||
<up-icon color="#E8AD7B" name="minus-circle" size="25"></up-icon>
|
||||
<view class="btnClick" @click="cartListadd(item,'-')"></view>
|
||||
<view class="btnClick" @click="changeNumber(-1,item)"></view>
|
||||
</view>
|
||||
<text class="num">{{ ifcartNumber(item) }}</text>
|
||||
<text class="num">{{ item.number*1 }}</text>
|
||||
<view class="btn" v-if="item.type !='package'">
|
||||
<!-- <up-icon name="plus-circle-fill"
|
||||
:color="{shopInfo.isVip ==1 && shopInfo.isMemberPrice==1? '#CECECE' : '#E9AB7A'"
|
||||
size="25"></up-icon> -->
|
||||
<up-icon name="plus-circle-fill" color="#E8AD7B"
|
||||
size="25"></up-icon>
|
||||
<view class="btnClick" @click="cartListadd(item,'+')"></view>
|
||||
<view class="btnClick" @click="changeNumber(1,item)"></view>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
@@ -104,7 +96,7 @@
|
||||
} from '@/stores/user.js';
|
||||
|
||||
// 定义自定义事件
|
||||
const emits = defineEmits(['customevent', 'close', 'clickcancelOrder']);
|
||||
const emits = defineEmits(['changeNumber', 'close', 'clearCarts']);
|
||||
|
||||
const props = defineProps({
|
||||
cartList: {
|
||||
@@ -127,54 +119,16 @@
|
||||
});
|
||||
const shopInfo = uni.cache.get('shopInfo')
|
||||
|
||||
// 定义 ifcartNumber 计算属性方法
|
||||
const ifcartNumber = computed(() => {
|
||||
return (item) => {
|
||||
// 如果 item 为空或者 cartNumber 不是字符串类型,返回 0
|
||||
if (!item || typeof item.cartNumber !== 'string') {
|
||||
return 0;
|
||||
}
|
||||
let numValue = parseFloat(item.cartNumber);
|
||||
if (isNaN(numValue)) {
|
||||
// 如果转换结果是 NaN,说明 cartNumber 不是有效的数字字符串,返回 0
|
||||
return 0;
|
||||
}
|
||||
// type string 商品类型 single-单规格商品 sku-多规格商品 package-套餐商品 weight-称重商品 coupon-团购券
|
||||
if (item.type === 'weight') {
|
||||
// 如果类型是称重重量,将值保留两位小数
|
||||
return parseFloat(numValue.toFixed(2));
|
||||
} else {
|
||||
// 如果类型是整数,将值转换为整数
|
||||
return Math.round(numValue);
|
||||
}
|
||||
// 如果类型不匹配,返回原始值
|
||||
return item.cartNumber;
|
||||
};
|
||||
})
|
||||
|
||||
|
||||
const close = () => {
|
||||
emits("close", false)
|
||||
}
|
||||
// 购物车加减
|
||||
const cartListadd = async (item, i) => {
|
||||
// 是否起售 如果小于或者大于都是1
|
||||
const cartNumberFloat = parseFloat(item.cartNumber);
|
||||
const suitNum = item.suitNum >= cartNumberFloat && i == '-' ? item.cartNumber : 1;
|
||||
function changeNumber(step,item){
|
||||
emits("changeNumber", step, item);
|
||||
|
||||
emits('customevent', {
|
||||
id: item.cartListId ? item.cartListId : '',
|
||||
type: 'shopping',
|
||||
table_code: uni.cache.get('tableCode'),
|
||||
shop_id: uni.cache.get('shopId'),
|
||||
operate_type: calculateValue(item.cartNumber, i, suitNum) == 'del' ? 'del' : item.cartListId &&
|
||||
item.cartNumber > 0 ? 'edit' : 'add',
|
||||
product_id: item.id,
|
||||
sku_id: item.skuId,
|
||||
number: await calculateValue(item.cartNumber, i, suitNum),
|
||||
is_print: 1,
|
||||
suitNum: item.suitNum,
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
const dataprocessing = computed(() => {
|
||||
return (item) => {
|
||||
@@ -188,18 +142,6 @@
|
||||
};
|
||||
})
|
||||
|
||||
const clickcancelOrder = (i, key) => {
|
||||
emits('clickcancelOrder', {
|
||||
i,
|
||||
key
|
||||
})
|
||||
emits('customevent', {
|
||||
type: 'shopping',
|
||||
table_code: uni.cache.get('tableCode'),
|
||||
shop_id: uni.cache.get('shopId'),
|
||||
operate_type: 'clearOrder',
|
||||
})
|
||||
}
|
||||
|
||||
const calculateValue = (cartNumber, i, step = 1) => {
|
||||
if (i == '+') {
|
||||
@@ -212,30 +154,10 @@
|
||||
}
|
||||
}
|
||||
|
||||
// 菜品备注修改
|
||||
const productBlur = (item) => {
|
||||
let params = {
|
||||
"skuId": item.skuId,
|
||||
"num": item.number, //数量
|
||||
"type": item.type,
|
||||
"isVip": item.isVip,
|
||||
"productId": item.productId, //商品id
|
||||
"note": item.note,
|
||||
"shopId": this.shopId,
|
||||
"userId": uni.cache.get('userInfo').id,
|
||||
"tableId": this.tableCode,
|
||||
}
|
||||
this.$emit("addCart", params)
|
||||
}
|
||||
|
||||
// 清空购物车
|
||||
const cartclear = () => {
|
||||
emits('customevent', {
|
||||
type: 'shopping',
|
||||
table_code: uni.cache.get('tableCode'),
|
||||
shop_id: uni.cache.get('shopId'),
|
||||
operate_type: 'cleanup',
|
||||
})
|
||||
emits('clearCarts')
|
||||
}
|
||||
</script>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user