277 lines
8.5 KiB
Vue
277 lines
8.5 KiB
Vue
<template>
|
|
<s-pages title="确认订单" :pink_bg="true">
|
|
<view class="p-b-132">
|
|
<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">
|
|
<view class="m-b-24 no-click-wrap" v-for="(v, i) in settlementInfo.items" :key="i">
|
|
<aiOrder :data="v" :source="3" />
|
|
<view class="no-click-block" @click.stop.prevent></view>
|
|
</view>
|
|
</view>
|
|
<view class="flex-row ju-between m-b-36">
|
|
<view class="c25 size28">商品金额</view>
|
|
<view>¥{{ $fen2yuan(settlementInfo?.price?.totalPrice || 0) }}</view>
|
|
</view>
|
|
<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"
|
|
>¥{{ $fen2yuan(settlementInfo?.price?.payPrice || 0) }}</span
|
|
>
|
|
</view>
|
|
</view>
|
|
</view>
|
|
</view>
|
|
<view class="p-x-32 btn">
|
|
<view class="ai-button2" :class="{ 'ai-button2--disabled': isSubmitting }" @click="sub"
|
|
>确认订单</view
|
|
>
|
|
</view>
|
|
</s-pages>
|
|
</template>
|
|
<script setup lang="ts">
|
|
import { ref, getCurrentInstance, watch } from 'vue';
|
|
import AddressSelection from '@/pages/order/addressSelection.vue';
|
|
import { onLoad, onShow } from '@dcloudio/uni-app';
|
|
import aiOrder from '@/components/ai_order/ai_order';
|
|
let { proxy } = getCurrentInstance();
|
|
import api from '@/sheep/api/member/address';
|
|
import * as SpuApi from '@/sheep/api/ai/index';
|
|
import { DeliveryTypeEnum } from '@/sheep/helper/const';
|
|
|
|
const addressState = ref({
|
|
addressInfo: {},
|
|
deliveryType: DeliveryTypeEnum.EXPRESS.type,
|
|
isPickUp: true,
|
|
pickUpInfo: {},
|
|
receiverName: '',
|
|
receiverMobile: '',
|
|
});
|
|
let remark_value = ref();
|
|
let spuId = ref();
|
|
const isSubmitting = ref(false);
|
|
|
|
const settlementInfo = ref<any>({});
|
|
const lastSettlementQuery = ref('');
|
|
const getSettlementRequestId = () => String(addressState.value.addressInfo?.id || '');
|
|
const getSettlementInfo = () => {
|
|
const query = {
|
|
id: getSettlementRequestId(),
|
|
spuId: spuId.value,
|
|
deliveryType: addressState.value.deliveryType,
|
|
pickUpStoreId:
|
|
addressState.value.deliveryType === DeliveryTypeEnum.PICK_UP.type
|
|
? String(addressState.value.pickUpInfo?.id || '')
|
|
: undefined,
|
|
};
|
|
const queryKey = JSON.stringify(query);
|
|
if (queryKey === lastSettlementQuery.value) {
|
|
return;
|
|
}
|
|
lastSettlementQuery.value = queryKey;
|
|
SpuApi.getGiftSettlementInfo({
|
|
...query,
|
|
}).then((res: any) => {
|
|
settlementInfo.value = res.data || {};
|
|
// 设置收货地址
|
|
if (!addressState.value.addressInfo?.id && res.data.address) {
|
|
addressState.value.addressInfo = res.data.address;
|
|
}
|
|
// if (settlementInfo.value?.items?.length) {
|
|
// settlementInfo.value.items.forEach((e) => {
|
|
// e.skuArr = e.items;
|
|
// e.skuArr.forEach((item) => {
|
|
// item.propertyText = '';
|
|
// if(item.properties){
|
|
// item.properties.forEach((e1) => {
|
|
// item.propertyText += e1.valueName + ' ';
|
|
// });
|
|
// }
|
|
// });
|
|
// });
|
|
// }
|
|
});
|
|
};
|
|
const sub = async () => {
|
|
if (isSubmitting.value) {
|
|
return;
|
|
}
|
|
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('请填写正确的手机号');
|
|
}
|
|
}
|
|
isSubmitting.value = true;
|
|
try {
|
|
let res: any = await SpuApi.createOrderOpen({
|
|
id: getSettlementRequestId(),
|
|
spuId: spuId.value,
|
|
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,
|
|
userRemark: remark_value.value,
|
|
});
|
|
if (res.code === 0) {
|
|
proxy.utils.toast('下单成功');
|
|
setTimeout(() => {
|
|
proxy.utils.go('/pages/AI/giftCashierDesk', {
|
|
id: res.data.id,
|
|
payOrderId: res.data.payOrderId,
|
|
returnTo: 'aiStore_plaza',
|
|
});
|
|
}, 1000);
|
|
return;
|
|
}
|
|
isSubmitting.value = false;
|
|
} catch (e) {
|
|
isSubmitting.value = false;
|
|
}
|
|
};
|
|
const getAddress = () => {
|
|
api.getAddressList().then((res: any) => {
|
|
if (res.code === 0 && res.data?.length) {
|
|
let index = res.data.findIndex((e: any) => e.defaultStatus);
|
|
if (index !== -1) {
|
|
addressState.value.addressInfo = res.data[index];
|
|
getSettlementInfo();
|
|
} else {
|
|
getSettlementInfo();
|
|
}
|
|
} else {
|
|
getSettlementInfo();
|
|
}
|
|
});
|
|
};
|
|
// onLoad((options: any) => {
|
|
// if (options.id) {
|
|
// spuId.value = options.id;
|
|
// }
|
|
// if (options.price) {
|
|
// }
|
|
// getSettlementInfo();
|
|
// });
|
|
onLoad((e: any) => {
|
|
// getCartList();
|
|
spuId.value = e.id;
|
|
// console.log(e.id);
|
|
});
|
|
|
|
watch(
|
|
() => [
|
|
addressState.value.deliveryType,
|
|
addressState.value.addressInfo?.id,
|
|
addressState.value.pickUpInfo?.id,
|
|
spuId.value,
|
|
],
|
|
() => {
|
|
getSettlementInfo();
|
|
},
|
|
);
|
|
|
|
onShow(() => {
|
|
getAddress();
|
|
});
|
|
</script>
|
|
<style lang="scss" scoped>
|
|
.no-click-wrap {
|
|
position: relative;
|
|
}
|
|
.no-click-block {
|
|
position: absolute;
|
|
top: 0;
|
|
left: 0;
|
|
width: 100%;
|
|
height: 100%;
|
|
}
|
|
.btn {
|
|
position: fixed;
|
|
bottom: 0;
|
|
left: 0;
|
|
width: 100%;
|
|
padding-bottom: calc(env(safe-area-inset-bottom) + 12rpx);
|
|
z-index: 100;
|
|
background: transparent;
|
|
}
|
|
.borderTop {
|
|
border-top: 1rpx solid #dfdfdf;
|
|
padding: 12rpx 0;
|
|
}
|
|
: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;
|
|
}
|
|
.ai-button2--disabled {
|
|
opacity: 0.6;
|
|
pointer-events: none;
|
|
}
|
|
</style>
|