Files
kangyuan-mobile/pages/AI/giftOrder.vue
T

162 lines
4.8 KiB
Vue

<template>
<s-pages title="确认订单" :pink_bg="true">
<view class="p-b-132">
<AddressSelection v-model="addressState" theme="2" @getSettlementInfo="getSettlementInfo" />
<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">
<view class="c25 size28">运费</view>
<view>¥{{ $fen2yuan(settlementInfo?.price?.deliveryPrice || 0) }}</view>
</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" @click="sub">确认订单</view>
</view>
</s-pages>
</template>
<script setup lang="ts">
import { ref, getCurrentInstance } 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';
const addressState = ref({
addressInfo: {},
deliveryType: 1,
isPickUp: false,
pickUpInfo: {},
receiverName: '',
receiverMobile: '',
});
let remark_value = ref();
let spuId = ref();
let spuPrice = ref();
const settlementInfo = ref<any>({});
let addressId = ref('');
const getSettlementInfo = (id = '') => {
addressId.value = id;
SpuApi.getGiftSettlementInfo({
id: id,
spuId: spuId.value,
}).then((res: any) => {
settlementInfo.value = res.data || {};
// 设置收货地址
if (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 (!addressId.value) return proxy.utils.toast('请选择地址');
let res: any = await SpuApi.createOrderOpen({
id: addressId.value,
spuId: spuId.value,
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);
}
};
const getAddress = () => {
api.getAddressList().then((res) => {
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);
if (index !== -1) {
addressState.value.addressInfo = res.data[index];
getSettlementInfo(res.data[index].id);
} else {
getSettlementInfo();
}
} else {
getSettlementInfo();
}
});
};
// onLoad((options: any) => {
// if (options.id) {
// spuId.value = options.id;
// }
// if (options.price) {
// spuPrice.value = options.price;
// }
// getSettlementInfo();
// });
onLoad((e) => {
// getCartList();
spuId.value = e.id;
// console.log(e.id);
});
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;
}
</style>