feat: 选品广场/会员优选添加自提模块
This commit is contained in:
+129
-42
@@ -1,7 +1,7 @@
|
||||
<template>
|
||||
<s-pages title="确认订单" :pink_bg="true">
|
||||
<view class="p-b-132">
|
||||
<AddressSelection v-model="addressState" theme="2" @getSettlementInfo="getSettlementInfo" />
|
||||
<AddressSelection v-model="addressState" theme="2" />
|
||||
<view class="p-x-32 m-t-24">
|
||||
<view class="bg24 p-x-20 p-t-20 radius16">
|
||||
<view v-if="settlementInfo.items && settlementInfo.items.length">
|
||||
@@ -11,12 +11,34 @@
|
||||
</view>
|
||||
<view class="flex-row ju-between m-b-36">
|
||||
<view class="c25 size28">商品金额</view>
|
||||
<view>¥{{ $fen2yuan(settlementInfo?.price?.payPrice || 0) }}</view>
|
||||
<view>¥{{ $fen2yuan(settlementInfo?.price?.totalPrice || 0) }}</view>
|
||||
</view>
|
||||
<view class="flex-row ju-between m-b-36">
|
||||
<view class="flex-row ju-between m-b-36" v-if="addressState.deliveryType === DeliveryTypeEnum.EXPRESS.type">
|
||||
<view class="c25 size28">运费</view>
|
||||
<view>¥{{ $fen2yuan(settlementInfo?.price?.deliveryPrice || 0) }}</view>
|
||||
</view>
|
||||
<view class="flex-row ju-between m-b-36" v-if="addressState.deliveryType === DeliveryTypeEnum.PICK_UP.type">
|
||||
<view class="c25 size28">联系人</view>
|
||||
<uni-easyinput
|
||||
class="order-input"
|
||||
maxlength="20"
|
||||
placeholder="请填写您的联系姓名"
|
||||
v-model="addressState.receiverName"
|
||||
:inputBorder="false"
|
||||
:clearable="false"
|
||||
/>
|
||||
</view>
|
||||
<view class="flex-row ju-between m-b-36" v-if="addressState.deliveryType === DeliveryTypeEnum.PICK_UP.type">
|
||||
<view class="c25 size28">联系电话</view>
|
||||
<uni-easyinput
|
||||
class="order-input"
|
||||
maxlength="20"
|
||||
placeholder="请填写您的联系电话"
|
||||
v-model="addressState.receiverMobile"
|
||||
:inputBorder="false"
|
||||
:clearable="false"
|
||||
/>
|
||||
</view>
|
||||
<view class="flex-center ju-flex-end borderTop">
|
||||
<span class="size26 line96">合计: </span>
|
||||
<span class="c13 size28 m-l-12 line96 weight900"
|
||||
@@ -32,54 +54,69 @@
|
||||
</s-pages>
|
||||
</template>
|
||||
<script setup lang="ts">
|
||||
import { ref, reactive, onMounted, onUnmounted, getCurrentInstance, watch, nextTick } from 'vue';
|
||||
import { ref, getCurrentInstance, watch } from 'vue';
|
||||
import AddressSelection from '@/pages/order/addressSelection.vue';
|
||||
import { onLoad } from '@dcloudio/uni-app';
|
||||
import aiOrder from '@/components/ai_order/ai_order';
|
||||
import api from '@/sheep/api/member/address';
|
||||
let { proxy } = getCurrentInstance();
|
||||
import * as SpuApi from '@/sheep/api/ai/index';
|
||||
import { DeliveryTypeEnum } from '@/sheep/helper/const';
|
||||
|
||||
const addressState = ref({
|
||||
addressInfo: {}, // 选择的收货地址
|
||||
deliveryType: 1, // 收货方式:1-快递配送,2-门店自提
|
||||
isPickUp: false, // 门店自提是否开启
|
||||
deliveryType: DeliveryTypeEnum.EXPRESS.type, // 收货方式:1-快递配送,2-门店自提
|
||||
isPickUp: true, // 门店自提是否开启
|
||||
pickUpInfo: {}, // 选择的自提门店信息
|
||||
receiverName: '', // 收件人名称
|
||||
receiverMobile: '', // 收件人手机
|
||||
});
|
||||
|
||||
const cartList = ref([]);
|
||||
const getCartList = () => {
|
||||
SpuApi.getShopCartList({}).then((res) => {
|
||||
let list = res.data || [];
|
||||
if (list.length) {
|
||||
list.forEach((e) => {
|
||||
e.skuArr = JSON.parse(e.specification);
|
||||
});
|
||||
}
|
||||
cartList.value = list;
|
||||
});
|
||||
};
|
||||
// 获取订单结算信息
|
||||
const settlementInfo = ref({});
|
||||
let addressId = ref('');
|
||||
const getSettlementInfo = (id = '') => {
|
||||
addressId.value = id;
|
||||
SpuApi.getSettlementInfo({
|
||||
id: id,
|
||||
}).then((res) => {
|
||||
const settlementInfo = ref<any>({});
|
||||
const lastSettlementQuery = ref('');
|
||||
const getSettlementRequestId = () => String(addressState.value.addressInfo?.id || '');
|
||||
const getSettlementInfo = () => {
|
||||
const query = {
|
||||
id: getSettlementRequestId(),
|
||||
deliveryType: addressState.value.deliveryType,
|
||||
pickUpStoreId:
|
||||
addressState.value.deliveryType === DeliveryTypeEnum.PICK_UP.type
|
||||
? String(addressState.value.pickUpInfo?.id || '')
|
||||
: undefined,
|
||||
receiverName:
|
||||
addressState.value.deliveryType === DeliveryTypeEnum.PICK_UP.type
|
||||
? addressState.value.receiverName
|
||||
: undefined,
|
||||
receiverPhone:
|
||||
addressState.value.deliveryType === DeliveryTypeEnum.PICK_UP.type
|
||||
? addressState.value.receiverMobile
|
||||
: undefined,
|
||||
};
|
||||
const queryKey = JSON.stringify(query);
|
||||
if (queryKey === lastSettlementQuery.value) {
|
||||
return;
|
||||
}
|
||||
lastSettlementQuery.value = queryKey;
|
||||
SpuApi.getSettlementInfo(query).then((res: any) => {
|
||||
settlementInfo.value = res.data || {};
|
||||
if (
|
||||
!addressState.value.addressInfo?.id &&
|
||||
res.data?.address &&
|
||||
addressState.value.deliveryType === DeliveryTypeEnum.EXPRESS.type
|
||||
) {
|
||||
addressState.value.addressInfo = res.data.address;
|
||||
}
|
||||
|
||||
// if (proxy.$fen2yuan(settlementInfo?.price?.payPrice || 0) >= 5000) {
|
||||
// proxy.utils.toast('订单金额不能超过5000元');
|
||||
// }
|
||||
if (settlementInfo.value?.items?.length) {
|
||||
settlementInfo.value.items.forEach((e) => {
|
||||
settlementInfo.value.items.forEach((e: any) => {
|
||||
e.skuArr = e.items;
|
||||
e.skuArr.forEach((item) => {
|
||||
e.skuArr.forEach((item: any) => {
|
||||
item.propertyText = '';
|
||||
item.properties.forEach((e1) => {
|
||||
item.properties.forEach((e1: any) => {
|
||||
item.propertyText += e1.valueName + ' ';
|
||||
});
|
||||
});
|
||||
@@ -87,13 +124,45 @@
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
const sub = async () => {
|
||||
// if (proxy.$fen2yuan(settlementInfo?.price?.payPrice || 0) >= 5000) {
|
||||
// proxy.utils.toast('订单金额不能超过5000元, 请重新选择商品');
|
||||
// return;
|
||||
// }
|
||||
if (!addressId.value) return proxy.utils.toast('请选择地址');
|
||||
let res: any = await SpuApi.createOrder({ id: addressId.value });
|
||||
if (addressState.value.deliveryType === DeliveryTypeEnum.EXPRESS.type && !addressState.value.addressInfo?.id) {
|
||||
return proxy.utils.toast('请选择收货地址');
|
||||
}
|
||||
if (addressState.value.deliveryType === DeliveryTypeEnum.PICK_UP.type) {
|
||||
if (!addressState.value.pickUpInfo?.id) {
|
||||
return proxy.utils.toast('请选择自提门店');
|
||||
}
|
||||
if (addressState.value.receiverName === '' || addressState.value.receiverMobile === '') {
|
||||
return proxy.utils.toast('请填写联系人或联系人电话');
|
||||
}
|
||||
if (!/^[\u4e00-\u9fa5\w]{2,16}$/.test(addressState.value.receiverName)) {
|
||||
return proxy.utils.toast('请填写您的真实姓名');
|
||||
}
|
||||
if (!/^1(3|4|5|7|8|9|6)\d{9}$/.test(addressState.value.receiverMobile)) {
|
||||
return proxy.utils.toast('请填写正确的手机号');
|
||||
}
|
||||
}
|
||||
let res: any = await SpuApi.createOrder({
|
||||
id: getSettlementRequestId(),
|
||||
deliveryType: addressState.value.deliveryType,
|
||||
pickUpStoreId:
|
||||
addressState.value.deliveryType === DeliveryTypeEnum.PICK_UP.type
|
||||
? addressState.value.pickUpInfo?.id
|
||||
: undefined,
|
||||
receiverName:
|
||||
addressState.value.deliveryType === DeliveryTypeEnum.PICK_UP.type
|
||||
? addressState.value.receiverName
|
||||
: undefined,
|
||||
receiverPhone:
|
||||
addressState.value.deliveryType === DeliveryTypeEnum.PICK_UP.type
|
||||
? addressState.value.receiverMobile
|
||||
: undefined,
|
||||
});
|
||||
if (res.code === 0) {
|
||||
// proxy.utils.toast('下单成功');
|
||||
setTimeout(() => {
|
||||
@@ -114,14 +183,12 @@
|
||||
}
|
||||
};
|
||||
const getAddress = () => {
|
||||
api.getAddressList().then((res) => {
|
||||
api.getAddressList().then((res: any) => {
|
||||
if (res.code === 0 && res.data?.length) {
|
||||
// addressState.value.addressInfo = res.data[0];
|
||||
// getSettlementInfo(res.data[0].id);
|
||||
let index = res.data.findIndex((e) => e.defaultStatus);
|
||||
let index = res.data.findIndex((e: any) => e.defaultStatus);
|
||||
if (index !== -1) {
|
||||
addressState.value.addressInfo = res.data[index];
|
||||
getSettlementInfo(res.data[index].id);
|
||||
getSettlementInfo();
|
||||
} else {
|
||||
getSettlementInfo();
|
||||
}
|
||||
@@ -130,22 +197,42 @@
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
watch(
|
||||
() => [
|
||||
addressState.value.deliveryType,
|
||||
addressState.value.addressInfo?.id,
|
||||
addressState.value.pickUpInfo?.id,
|
||||
],
|
||||
() => {
|
||||
getSettlementInfo();
|
||||
},
|
||||
);
|
||||
|
||||
onLoad(() => {
|
||||
// getCartList();
|
||||
getAddress();
|
||||
});
|
||||
</script>
|
||||
<style lang="scss" scoped>
|
||||
.pages {
|
||||
}
|
||||
|
||||
.bottom {
|
||||
}
|
||||
|
||||
.borderTop {
|
||||
border-top: 1px solid #d4d4d4;
|
||||
}
|
||||
|
||||
:deep(.order-input) {
|
||||
width: 320rpx;
|
||||
}
|
||||
|
||||
:deep(.order-input .uni-easyinput__content) {
|
||||
background: transparent !important;
|
||||
}
|
||||
|
||||
:deep(.order-input .uni-easyinput__content-input) {
|
||||
text-align: right !important;
|
||||
font-size: 26rpx;
|
||||
height: 56rpx;
|
||||
padding-right: 0 !important;
|
||||
}
|
||||
|
||||
.btn {
|
||||
width: 100%;
|
||||
position: fixed;
|
||||
|
||||
Reference in New Issue
Block a user