|
|
@@ -11,7 +11,10 @@ definePage({
|
|
|
})
|
|
|
const { selectedAddress, userInfo } = storeToRefs(useUserStore())
|
|
|
const { SelectShopInfo } = storeToRefs(useSysXsbStore())
|
|
|
-const orderInfo = ref<Api.shoppingCartOrderConfirm>()
|
|
|
+const { Location } = storeToRefs(useAddressStore())
|
|
|
+type ConfirmOrderInfo = Api.shoppingCartOrderConfirm & Partial<Api.AppletOrderSkuVo>
|
|
|
+
|
|
|
+const orderInfo = ref<ConfirmOrderInfo>()
|
|
|
const { totalProduct } = storeToRefs(useSmqjhCartStore())
|
|
|
const isPay = ref(false)
|
|
|
const remarks = ref('')
|
|
|
@@ -27,8 +30,19 @@ const model = reactive<{
|
|
|
value1: '',
|
|
|
value2: '',
|
|
|
})
|
|
|
+const mobilePattern = /^1[3-9]\d{9}$/
|
|
|
+const mobileRules = [{ required: true, pattern: mobilePattern, message: '请输入正确的手机号' }]
|
|
|
const deliveryType = ref(1)
|
|
|
const isMemberGiftOrder = computed(() => !!orderInfo.value?.memberGiftItems?.length)
|
|
|
+const isSelfPickup = computed(() => current.value === '自提')
|
|
|
+const shopAddressInfo = computed(() => orderInfo.value?.shopAddressDTO)
|
|
|
+const shopDistanceText = computed(() => {
|
|
|
+ const distance = shopAddressInfo.value?.distance
|
|
|
+ if (distance === undefined || distance === null) {
|
|
|
+ return ''
|
|
|
+ }
|
|
|
+ return `距你${Number(distance).toFixed(2)}km`
|
|
|
+})
|
|
|
|
|
|
// 优惠券选择
|
|
|
const couponPopup = ref(false)
|
|
|
@@ -77,15 +91,22 @@ const displayDiscountTotal = computed(() => Number((currentCouponDiscount.value
|
|
|
|
|
|
onLoad((options: any) => {
|
|
|
orderInfo.value = JSON.parse(options.data)
|
|
|
- couponList.value = orderInfo.value?.orderCouponItemDTOS || []
|
|
|
- initialCouponId.value = orderInfo.value?.allowanceId
|
|
|
- confirmedCouponId.value = initialCouponId.value
|
|
|
- draftCouponId.value = initialCouponId.value
|
|
|
+ syncCouponState()
|
|
|
+ deliveryType.value = current.value === '自提' ? 2 : 3
|
|
|
+ // model.value1 = userInfo.value?.nickName || ''
|
|
|
+ model.value2 = userInfo.value?.mobile || ''
|
|
|
})
|
|
|
onShow(() => {
|
|
|
useUserStore().getuserAddresslist()
|
|
|
- if (selectedAddress.value) {
|
|
|
- getDevryList()
|
|
|
+ if (orderInfo.value && current.value === '即时配送') {
|
|
|
+ getConfirmOrder()
|
|
|
+ }
|
|
|
+})
|
|
|
+
|
|
|
+watch(current, async (value) => {
|
|
|
+ deliveryType.value = value === '自提' ? 2 : 3
|
|
|
+ if (orderInfo.value) {
|
|
|
+ await getConfirmOrder()
|
|
|
}
|
|
|
})
|
|
|
|
|
|
@@ -93,16 +114,59 @@ function getCouponDisplayName(coupon?: Partial<Api.AppMemberCouponVO> & Record<s
|
|
|
return coupon?.activityName || coupon?.couponName || ''
|
|
|
}
|
|
|
|
|
|
-async function getDevryList() {
|
|
|
- const res = await Apis.xsb.delivery({
|
|
|
- data: {
|
|
|
- memberId: userInfo.value.id,
|
|
|
- shopId: Number(orderInfo.value?.skuList[0].shopId || SelectShopInfo.value?.shopId || 2),
|
|
|
- addressId: selectedAddress.value?.id,
|
|
|
- },
|
|
|
+function syncCouponState() {
|
|
|
+ couponList.value = orderInfo.value?.orderCouponItemDTOS || []
|
|
|
+ initialCouponId.value = orderInfo.value?.allowanceId
|
|
|
+ confirmedCouponId.value = initialCouponId.value
|
|
|
+ draftCouponId.value = initialCouponId.value
|
|
|
+}
|
|
|
+
|
|
|
+function getOrderConfirmParams() {
|
|
|
+ const firstSku = orderInfo.value?.skuList?.[0]
|
|
|
+ return {
|
|
|
+ skuId: firstSku?.skuId,
|
|
|
+ num: Number(firstSku?.num || 1),
|
|
|
+ channelId: userInfo.value?.channelId,
|
|
|
+ shopId: Number(firstSku?.shopId || SelectShopInfo.value?.shopId || 2),
|
|
|
+ dvyType: deliveryType.value,
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+async function getConfirmOrder() {
|
|
|
+ const params: Record<string, any> = getOrderConfirmParams()
|
|
|
+ if (!params.skuId) {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if (isSelfPickup.value) {
|
|
|
+ if (!Location.value.latitude || !Location.value.longitude) {
|
|
|
+ useGlobalToast().show('暂无定位缓存,无法计算自提点距离')
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ params.latitude = Location.value.latitude
|
|
|
+ params.longitude = Location.value.longitude
|
|
|
+ }
|
|
|
+ }
|
|
|
+ const res = await Apis.xsb.skuOrderConfirm({
|
|
|
+ data: params,
|
|
|
+ })
|
|
|
+ const skuList = res.data.sku
|
|
|
+ ? [{ ...res.data.sku, num: params.num, shopId: params.shopId }]
|
|
|
+ : (orderInfo.value?.skuList || [])
|
|
|
+ orderInfo.value = {
|
|
|
+ ...orderInfo.value,
|
|
|
+ ...res.data,
|
|
|
+ skuList,
|
|
|
+ } as ConfirmOrderInfo
|
|
|
+ syncCouponState()
|
|
|
+}
|
|
|
+
|
|
|
+function openShopLocation() {
|
|
|
+ uni.openLocation({
|
|
|
+ latitude: Number(shopAddressInfo.value?.shopLat) || 0,
|
|
|
+ longitude: Number(shopAddressInfo.value?.shopLng) || 0,
|
|
|
+ name: shopAddressInfo.value?.shopName,
|
|
|
+ address: shopAddressInfo.value?.shopAddress,
|
|
|
})
|
|
|
- deliveryType.value = res.data.deliveryType
|
|
|
- console.log(res)
|
|
|
}
|
|
|
|
|
|
async function openCouponPopup() {
|
|
|
@@ -123,7 +187,7 @@ function confirmCoupon() {
|
|
|
}
|
|
|
|
|
|
async function handlePay() {
|
|
|
- if (!selectedAddress.value) {
|
|
|
+ if (!isSelfPickup.value && !selectedAddress.value) {
|
|
|
useGlobalToast().show({ msg: '请选择收货地址' })
|
|
|
return
|
|
|
}
|
|
|
@@ -131,9 +195,23 @@ async function handlePay() {
|
|
|
useGlobalToast().show({ msg: '网络异常!请联系客服' })
|
|
|
return
|
|
|
}
|
|
|
+ if (isSelfPickup.value) {
|
|
|
+ if (!model.value1) {
|
|
|
+ useGlobalToast().show({ msg: '请填写联系人' })
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if (!mobilePattern.test(model.value2)) {
|
|
|
+ useGlobalToast().show({ msg: '请输入正确的手机号' })
|
|
|
+ return
|
|
|
+ }
|
|
|
+ }
|
|
|
isPay.value = true
|
|
|
try {
|
|
|
if (isMemberGiftOrder.value) {
|
|
|
+ if (!selectedAddress.value) {
|
|
|
+ useGlobalToast().show({ msg: '请选择收货地址' })
|
|
|
+ return
|
|
|
+ }
|
|
|
await Apis.sys.giftsReceive({
|
|
|
data: {
|
|
|
addressId: selectedAddress.value.id,
|
|
|
@@ -158,6 +236,12 @@ async function handlePay() {
|
|
|
orderItemList,
|
|
|
unref(remarks),
|
|
|
confirmedCouponId.value,
|
|
|
+ isSelfPickup.value
|
|
|
+ ? {
|
|
|
+ consigneeName: model.value1,
|
|
|
+ consigneeMobile: model.value2,
|
|
|
+ }
|
|
|
+ : undefined,
|
|
|
)
|
|
|
const res = await useUserStore().handleCommonPayMent(orderNumber)
|
|
|
await useUserStore().clearCart(orderInfo.value.skuList)
|
|
|
@@ -220,40 +304,46 @@ async function handlePay() {
|
|
|
|
|
|
<view v-else class="my20rpx rounded-16rpx bg-white p24rpx">
|
|
|
<view class="flex items-center gap-50rpx">
|
|
|
- <view>
|
|
|
+ <view class="flex-1">
|
|
|
<view class="text-28rpx font-semibold">
|
|
|
- 自提点:星闪豹(贵阳店)
|
|
|
+ 自提点:{{ shopAddressInfo?.shopName || orderInfo?.shopName || '暂无门店信息' }}
|
|
|
</view>
|
|
|
<view class="mt-20rpx text-24rpx text-#AAAAAA">
|
|
|
- 贵州省贵阳市贵阳市观山湖区金麦安置小区12组团26号-28号门面
|
|
|
+ {{ shopAddressInfo?.shopAddress || '暂无门店地址' }}
|
|
|
</view>
|
|
|
</view>
|
|
|
- <view>
|
|
|
- <view class="mb-20rpx text-24rpx text-#AAAAAA">
|
|
|
- 距你XXkm
|
|
|
+ <view class="flex-shrink-0" @click="openShopLocation">
|
|
|
+ <view v-if="shopDistanceText" class="mb-20rpx text-24rpx text-#AAAAAA">
|
|
|
+ {{ shopDistanceText }}
|
|
|
</view>
|
|
|
<wd-icon name="location" size="22px" color="#9ED605" />
|
|
|
</view>
|
|
|
</view>
|
|
|
<view>
|
|
|
- <wd-input
|
|
|
- v-model="model.value1"
|
|
|
- label="联系人"
|
|
|
- label-width="80px"
|
|
|
- prop="value1"
|
|
|
- clearable
|
|
|
- placeholder="请输入联系人"
|
|
|
- :rules="[{ required: true, message: '请填写联系人' }]"
|
|
|
- />
|
|
|
- <wd-input
|
|
|
- v-model="model.value2"
|
|
|
- label="预留电话"
|
|
|
- label-width="80px"
|
|
|
- prop="value1"
|
|
|
- clearable
|
|
|
- placeholder="请输入预留电话"
|
|
|
- :rules="[{ required: true, pattern: /^(13[0-9]|14[01456879]|15[0-35-9]|16[2567]|17[0-8]|18[0-9]|19[0-35-9])\d{8}$/, message: '请输入正确的手机号' }]"
|
|
|
- />
|
|
|
+ <view class="mt-20rpx flex items-center">
|
|
|
+ <view class="w100rpx text-28rpx">
|
|
|
+ 联系人:
|
|
|
+ </view>
|
|
|
+ <wd-input
|
|
|
+ v-model="model.value1"
|
|
|
+ prop="value1"
|
|
|
+ clearable
|
|
|
+ placeholder="请输入联系人"
|
|
|
+ :rules="[{ required: true, message: '请填写联系人' }]"
|
|
|
+ />
|
|
|
+ </view>
|
|
|
+ <view class="mt-20rpx flex items-center">
|
|
|
+ <view class="w140rpx text-28rpx">
|
|
|
+ 预留电话:
|
|
|
+ </view>
|
|
|
+ <wd-input
|
|
|
+ v-model="model.value2"
|
|
|
+ prop="value2"
|
|
|
+ clearable
|
|
|
+ placeholder="请输入预留电话"
|
|
|
+ :rules="mobileRules"
|
|
|
+ />
|
|
|
+ </view>
|
|
|
</view>
|
|
|
</view>
|
|
|
|
|
|
@@ -300,6 +390,9 @@ async function handlePay() {
|
|
|
<view v-if="deliveryType == 1">
|
|
|
快递
|
|
|
</view>
|
|
|
+ <view v-if="deliveryType == 2">
|
|
|
+ 自提
|
|
|
+ </view>
|
|
|
<view class="text-#FF4D3A font-semibold">
|
|
|
¥{{ orderInfo?.transfee }}
|
|
|
</view>
|