This commit is contained in:
zmj 2024-06-12 13:55:17 +08:00
parent 35fc21e14e
commit f66abb2002
3 changed files with 415 additions and 413 deletions

2
.gitignore vendored
View File

@ -37,3 +37,5 @@ components.d.ts
.env.development .env.development
.env.production .env.production
/unpackage/ /unpackage/
helper.json

View File

@ -1,8 +1,8 @@
let BASE_URL let BASE_URL
import store from "@/store/user.js" import store from "@/store/user.js"
// 环境 // 环境
// let env = "dev" let env = "dev"
let env = "prod" // let env = "prod"
// let env = "liu"; // let env = "liu";
switch (env) { switch (env) {

View File

@ -1,73 +1,73 @@
<template> <template>
<view class=""> <view class="">
<view class="m-card m-address"> <view class="m-card m-address">
<view class="address-info" @click="showAddress = true" v-if='orderInfo.shipping_type==1'> <view class="address-info" @click="showAddress = true" v-if='orderInfo.shipping_type == 1'>
<view class="top"> <view class="top">
<up-icon name="account"></up-icon> <up-icon name="account"></up-icon>
<view class="t-name">{{addressInfo.real_name}}</view> <view class="t-name">{{ addressInfo.real_name }}</view>
<view>{{addressInfo.phone}}</view> <view>{{ addressInfo.phone }}</view>
</view> </view>
<view class="bottom u-line-2"> <view class="bottom u-line-2">
{{addressInfo.detail}} {{ addressInfo.detail }}
</view> </view>
</view> </view>
<view class="address-info" v-else> <view class="address-info" v-else>
<view class="top"> <view class="top">
{{STORE_INFO.name}} {{ STORE_INFO.name }}
</view> </view>
<view class="bottom u-line-2"> <view class="bottom u-line-2">
{{STORE_INFO.detailed_address}} {{ STORE_INFO.detailed_address }}
</view> </view>
</view> </view>
<view class="address-btn item-center"> <view class="address-btn item-center">
<view class='ship-type' style=""> <view class='ship-type' style="">
<view class="ship-type-item" :class='{actShipItem:orderInfo.shipping_type==2 }' <view class="ship-type-item" :class='{ actShipItem: orderInfo.shipping_type == 2 }'
@click='orderInfo.shipping_type=2'> @click='orderInfo.shipping_type = 2'>
自提 自提
</view> </view>
<view class="ship-type-item" @click='orderInfo.shipping_type=1' <view class="ship-type-item" @click='orderInfo.shipping_type = 1'
:class='{actShipItem:orderInfo.shipping_type==1 }' v-if='orderInfo.default_delivery==1'> :class='{ actShipItem: orderInfo.shipping_type == 1 }' v-if='orderInfo.default_delivery == 1'>
配送 配送
</view> </view>
</view> </view>
</view> </view>
</view> </view>
<view class="m-card m-good" v-for="(item,index) in cartList" :key="index"> <view class="m-card m-good" v-for="(item, index) in cartList" :key="index">
<view class="image"> <view class="image">
<up-image width="160rpx" height="160rpx" :src="item.imgs"></up-image> <up-image width="160rpx" height="160rpx" :src="item.imgs"></up-image>
</view> </view>
<view class="body-content"> <view class="body-content">
<view> <view>
<view class="title"> <view class="title">
<view>{{item.name}}</view> <view>{{ item.name }}</view>
<view>¥{{item.price}}</view> <view>¥{{ item.price }}</view>
</view> </view>
<view class="tips"> <view class="tips">
<view>{{item.unit_name}}</view> <view>{{ item.unit_name }}</view>
<view>x{{item.cart_num}}</view> <view>x{{ item.cart_num }}</view>
</view> </view>
</view> </view>
<view class="time"> <view class="time">
{{orderInfo.delivery_msg}} {{ orderInfo.delivery_msg }}
</view> </view>
</view> </view>
</view> </view>
<view class="m-card good-info"> <view class="m-card good-info">
<view class="head-title">价格明细</view> <view class="head-title">价格明细</view>
<view class="row"> <view class="row">
<view>商品总价 <text>共计{{cartList.length}}款商品</text></view> <view>商品总价 <text>共计{{ cartList.length }}款商品</text></view>
<view> <view>
<text>¥</text>{{c_price(orderInfo.total_price, 0)}}<text>.{{c_price(orderInfo.total_price, 1)}}</text> <text>¥</text>{{ c_price(orderInfo.total_price, 0) }}<text>.{{ c_price(orderInfo.total_price, 1) }}</text>
</view> </view>
</view> </view>
<view class="row"> <view class="row">
<view>运费</view> <view>运费</view>
<view><text>¥</text>0<text>.00</text></view> <view><text>¥</text>0<text>.00</text></view>
</view> </view>
<view class="row" v-if="orderInfo.activities==1" style="color: red;"> <view class="row" v-if="orderInfo.activities == 1" style="color: red;">
<view>活动折扣 <text>{{orderInfo.activity}}</text></view> <view>活动折扣 <text>{{ orderInfo.activity }}</text></view>
<view> <view>
-¥<text>{{orderInfo.activity_price}}</text> -¥<text>{{ orderInfo.activity_price }}</text>
</view> </view>
</view> </view>
</view> </view>
@ -119,8 +119,8 @@
<text style="color: #000;">合计: </text> <text style="color: #000;">合计: </text>
<text></text> <text></text>
<block v-if="orderInfo.total_price"> <block v-if="orderInfo.total_price">
<text style="font-size: 32rpx;font-weight: bold;">{{c_price(orderInfo.pay_price, 0)}}</text> <text style="font-size: 32rpx;font-weight: bold;">{{ c_price(orderInfo.pay_price, 0) }}</text>
<text>.{{c_price(orderInfo.pay_price, 1)}}</text> <text>.{{ c_price(orderInfo.pay_price, 1) }}</text>
</block> </block>
</view> </view>
</view> </view>
@ -129,9 +129,9 @@
</view> </view>
</view> </view>
<addressPopup ref="addressRef" :show="showAddress" :list="addressList" @close="showAddress=false" <addressPopup ref="addressRef" :show="showAddress" :list="addressList" @close="showAddress = false"
@change="changeAddress" /> @change="changeAddress" />
<shopListPopupVue ref="shopRef" :show="shopListShow" :list="merchantList" @close="shopListShow=false" <shopListPopupVue ref="shopRef" :show="shopListShow" :list="merchantList" @close="shopListShow = false"
@change="changeShop" @search="searchShop" /> @change="changeShop" @search="searchShop" />
<modal title="尚未设置收货地址" content="您还没有添加收货地址,请点击添加" cancleText="添加地址" confirmText="继续支付" :show="toastAddressShow" <modal title="尚未设置收货地址" content="您还没有添加收货地址,请点击添加" cancleText="添加地址" confirmText="继续支付" :show="toastAddressShow"
@close="addAddress" @change="goPay" /> @close="addAddress" @change="goPay" />
@ -141,449 +141,449 @@
</template> </template>
<script setup> <script setup>
import { import {
onLoad, onLoad,
onShow onShow
} from "@dcloudio/uni-app" } from "@dcloudio/uni-app"
import { import {
nextTick, nextTick,
ref ref
} from "vue" } from "vue"
import addressPopup from "@/components/addressPopup.vue"; import addressPopup from "@/components/addressPopup.vue";
import shopListPopupVue from "@/components/shopListPopup.vue"; import shopListPopupVue from "@/components/shopListPopup.vue";
import useCartStore from "@/store/cart.js"; import useCartStore from "@/store/cart.js";
import modal from "@/components/modal.vue"; import modal from "@/components/modal.vue";
import { import {
checkOrderApi checkOrderApi
} from "@/api/cart.js"; } from "@/api/cart.js";
import { import {
addressListsApi, addressListsApi,
merchantListApi merchantListApi
} from "@/api/user.js"; } from "@/api/user.js";
import { import {
createOrderApi createOrderApi
} from "@/api/order.js"; } from "@/api/order.js";
// //
let STORE_INFO = uni.getStorageSync('STORE_INFO'); let STORE_INFO = uni.getStorageSync('STORE_INFO');
if (STORE_INFO) if (STORE_INFO)
STORE_INFO = JSON.parse(STORE_INFO) STORE_INFO = JSON.parse(STORE_INFO)
const cartStore = useCartStore(); const cartStore = useCartStore();
const reservation_time = ref('') const reservation_time = ref('')
const formData = ref({ const formData = ref({
remark: "" remark: ""
})
const isAddress = ref(false);
const toastAddressShow = ref(false);
const onChoosePaytype = (e) => {
pay_type.value = e;
}
//
const addressRef = ref(null);
const showAddress = ref(false);
const addressInfo = ref({});
const changeAddress = (e) => {
addressInfo.value = e;
showAddress.value = false;
isAddress.value = true;
}
const openAddress = () => {
if (addressList.length > 0) showAddress.value = true;
else uni.navigateTo({
url: '/pagesOrder/addressEdit/addressEdit'
}) })
}
const isAddress = ref(false); //
const toastAddressShow = ref(false); const addressList = ref([]);
const getAddressList = () => {
const onChoosePaytype = (e) => { addressListsApi().then(res => {
pay_type.value = e; addressList.value = res.data.lists;
} addressList.value.forEach(item => {
if (item.is_default) {
// addressInfo.value = item;
const addressRef = ref(null);
const showAddress = ref(false);
const addressInfo = ref({});
const changeAddress = (e) => {
addressInfo.value = e;
showAddress.value = false;
isAddress.value = true;
}
const openAddress = () => {
if (addressList.length > 0) showAddress.value = true;
else uni.navigateTo({
url: '/pagesOrder/addressEdit/addressEdit'
})
}
//
const addressList = ref([]);
const getAddressList = () => {
addressListsApi().then(res => {
addressList.value = res.data.lists;
addressList.value.forEach(item => {
if (item.is_default) {
addressInfo.value = item;
isAddress.value = true;
}
})
if (!isAddress.value && addressList.value.length > 0) {
addressInfo.value = addressList.value[0];
isAddress.value = true; isAddress.value = true;
} }
if (addressInfo.value.address_id) {
nextTick(() => {
addressRef.value.setCheck(addressInfo.value.address_id);
})
}
}) })
} if (!isAddress.value && addressList.value.length > 0) {
addressInfo.value = addressList.value[0];
// isAddress.value = true;
const shopRef = ref(null); }
const shopListShow = ref(false); if (addressInfo.value.address_id) {
const merchantList = ref([]); nextTick(() => {
const myAddressInfo = ref({ addressRef.value.setCheck(addressInfo.value.address_id);
long: "", })
lat: "" }
}) })
const shopInfo = ref({ }
mer_id: ''
});
const getMerchantList = (mer_name = null) => { //
merchantListApi({ const shopRef = ref(null);
...myAddressInfo.value, const shopListShow = ref(false);
mer_name: mer_name ? mer_name : '' const merchantList = ref([]);
}).then(res => { const myAddressInfo = ref({
merchantList.value = res.data.lists; long: "",
if (mer_name === null && myAddressInfo.value.long && merchantList.value.length > 0 && !shopInfo lat: ""
.value.mer_id) { })
shopInfo.value = merchantList.value[0]; const shopInfo = ref({
shopInfo.value.recommend = 1; mer_id: ''
nextTick(() => { });
shopRef.value.setCheck(shopInfo.value.mer_id);
})
}
})
}
// getMerchantList(); const getMerchantList = (mer_name = null) => {
// merchantListApi({
const LoadAddress = () => { ...myAddressInfo.value,
uni.getLocation({ mer_name: mer_name ? mer_name : ''
success: (res) => {}, }).then(res => {
fail: (err) => { merchantList.value = res.data.lists;
uni.$u.toast('定位失败, 请手动选择提货点!') if (mer_name === null && myAddressInfo.value.long && merchantList.value.length > 0 && !shopInfo
}, .value.mer_id) {
complete: (res) => { shopInfo.value = merchantList.value[0];
myAddressInfo.value.long = res.longitude || ""; shopInfo.value.recommend = 1;
myAddressInfo.value.lat = res.latitude || ""; nextTick(() => {
getMerchantList(); shopRef.value.setCheck(shopInfo.value.mer_id);
} })
}) }
} })
// LoadAddress(); }
const changeShop = (e) => { // getMerchantList();
shopInfo.value = e; //
shopListShow.value = false; const LoadAddress = () => {
} uni.getLocation({
const searchShop = (e) => { success: (res) => { },
getMerchantList(e) fail: (err) => {
} uni.$u.toast('定位失败, 请手动选择提货点!')
},
complete: (res) => {
myAddressInfo.value.long = res.longitude || "";
myAddressInfo.value.lat = res.latitude || "";
getMerchantList();
}
})
}
// LoadAddress();
// const changeShop = (e) => {
// const callShow = ref(false) shopInfo.value = e;
// const phone = ref(''); shopListShow.value = false;
// const callphone = (e) => { }
// callShow.value = true; const searchShop = (e) => {
// phone.value = e; getMerchantList(e)
}
//
// const callShow = ref(false)
// const phone = ref('');
// const callphone = (e) => {
// callShow.value = true;
// phone.value = e;
// }
const onCall = (e) => {
uni.makePhoneCall({
phoneNumber: e,
success() {
callShow.value = false
}
})
}
//
const addAddress = () => {
toastAddressShow.value = false;
nextTick(() => {
showAddress.value = true;
})
}
//
const goPay = () => {
toastAddressShow.value = false;
isAddress.value = true;
submitOrder();
}
//
const submitOrder = () => {
// if (!shopInfo.value.mer_id) {
// uni.$u.toast('');
// return shopListShow.value = true;
// } // }
const onCall = (e) => { if (!isAddress.value && orderInfo.value.shipping_type == 1) return toastAddressShow.value = true;
uni.makePhoneCall({ createOrder();
phoneNumber: e, }
success() { //
callShow.value = false const cartList = ref([]);
} const orderInfo = ref({});
}) const checkOrder = () => {
} checkOrderApi({
cart_id: cartStore.cartList,
store_id: STORE_INFO.id || 0
}).then(res => {
cartList.value = res.data.cart_list;
orderInfo.value = res.data.order;
if (orderInfo.value.default_delivery == 0) {
orderInfo.value.shipping_type = 2
}
})
}
// const pay_type = ref('');
const addAddress = () => {
toastAddressShow.value = false;
nextTick(() => {
showAddress.value = true;
})
}
//
const goPay = () => {
toastAddressShow.value = false;
isAddress.value = true;
submitOrder();
}
// const createOrder = () => {
const submitOrder = () => { if (!pay_type.value) return uni.$u.toast('请选择支付方式');
// if (!shopInfo.value.mer_id) {
// uni.$u.toast('');
// return shopListShow.value = true;
// }
if (!isAddress.value && orderInfo.value.shipping_type == 1) return toastAddressShow.value = true;
createOrder();
}
//
const cartList = ref([]);
const orderInfo = ref({});
const checkOrder = () => {
checkOrderApi({
cart_id: cartStore.cartList,
store_id: STORE_INFO.id || 0
}).then(res => {
cartList.value = res.data.cart_list;
orderInfo.value = res.data.order;
if (orderInfo.value.default_delivery == 0) {
orderInfo.value.shipping_type = 2
}
})
}
const pay_type = ref(''); createOrderApi({
cart_id: cartStore.cartList,
address_id: addressInfo.value.address_id,
pay_type: pay_type.value,
store_id: STORE_INFO.id || 0,
reservation_time: reservation_time.value,
shipping_type: orderInfo.value.shipping_type,
mark: formData.value.remark
const createOrder = () => { }).then(res => {
if (!pay_type.value) return uni.$u.toast('请选择支付方式'); console.log(res);
if (pay_type.value == 3) {
createOrderApi({ if (res.code == 1) {
cart_id: cartStore.cartList, uni.showToast({
address_id: addressInfo.value.address_id, title: res.msg,
pay_type: pay_type.value, icon: "none",
store_id: STORE_INFO.id || 0, success() {
reservation_time: reservation_time.value, setTimeout(() => {
shipping_type: orderInfo.value.shipping_type, uni.redirectTo({
mark: formData.value.remark url: '/pagesOrder/order/order?back=-1&type=2'
}).then(res => {
console.log(res);
if (pay_type.value == 3) {
if (res.code == 1) {
uni.showToast({
title: res.msg,
icon: "none",
success() {
setTimeout(() => {
uni.redirectTo({
url: '/pagesOrder/order/order?back=-1&type=2'
})
}, 1500)
}
})
} else {
uni.$u.toast(res.msg);
}
} else {
if (!res.data?.nonceStr) return uni.$u.toast('支付失败!');
uni.requestPayment({
provider: 'wxpay',
timeStamp: res.data.timeStamp,
nonceStr: res.data.nonceStr,
package: res.data.package,
signType: res.data.signType,
paySign: res.data.paySign,
success: (e) => {
if (e.errMsg == 'requestPayment:ok') {
uni.showModal({
title: '订单支付成功',
confirmText: '查看订单',
cancelText: '继续购买',
success: (e) => {
if (e.confirm) uni.redirectTo({
url: '/pagesOrder/order/order?back=-1&type=2'
})
else uni.navigateBack();
}
}) })
} else uni.$u.toast('支付失败') }, 1500)
},
fail: (e) => {
uni.$u.toast('用户取消支付');
uni.redirectTo({
url: '/pagesOrder/order/order?back=-1&type=1'
})
} }
}) })
} else {
uni.$u.toast(res.msg);
} }
}).catch(err => { } else {
uni.$u.toast(err.msg || '网络错误') if (!res.data?.nonceStr) return uni.$u.toast('支付失败!');
}) uni.requestPayment({
} provider: 'wxpay',
timeStamp: res.data.timeStamp,
const c_price = (price, index = 0) => { nonceStr: res.data.nonceStr,
price = price + ''; package: res.data.package,
return price.split('.')[index] || (index ? '00' : '0'); signType: res.data.signType,
} paySign: res.data.paySign,
success: (e) => {
onLoad(options => { if (e.errMsg == 'requestPayment:ok') {
checkOrder(); uni.showModal({
}) title: '订单支付成功',
onShow(() => { confirmText: '查看订单',
getAddressList(); cancelText: '继续购买',
success: (e) => {
if (e.confirm) uni.redirectTo({
url: '/pagesOrder/order/order?back=-1&type=2'
})
else uni.navigateBack();
}
})
} else uni.$u.toast('支付失败')
},
fail: (e) => {
uni.$u.toast('用户取消支付');
uni.redirectTo({
url: '/pagesOrder/order/order?back=-1&type=1'
})
}
})
}
}).catch(err => {
uni.$u.toast(err.msg || '网络错误')
}) })
}
const c_price = (price, index = 0) => {
price = price + '';
return price.split('.')[index] || (index ? '00' : '0');
}
onLoad(options => {
checkOrder();
})
onShow(() => {
getAddressList();
})
</script> </script>
<style lang="scss"> <style lang="scss">
.m-card { .m-card {
margin: 20rpx; margin: 20rpx;
border-radius: 14rpx; border-radius: 14rpx;
background-color: #fff; background-color: #fff;
padding: 20rpx; padding: 20rpx;
} }
.row { .row {
padding: 0; padding: 0;
overflow: hidden;
}
.m-address {
margin-bottom: 20rpx;
display: flex;
justify-content: space-between;
color: #999999;
.address-info {
width: 450rpx;
.top {
display: flex;
font-size: 28rpx;
.t-name {
color: #444;
margin: 0 10rpx;
}
}
.bottom {
font-size: 24rpx;
}
}
}
.m-good {
display: flex;
justify-content: space-between;
margin-bottom: 20rpx;
.image {
width: 160rpx;
height: 160rpx;
margin-right: 20rpx;
border-radius: 14rpx;
overflow: hidden; overflow: hidden;
} }
.m-address { .body-content {
margin-bottom: 20rpx; width: 490rpx;
display: flex; display: flex;
flex-direction: column;
justify-content: space-between; justify-content: space-between;
color: #999999; color: #989898;
.address-info { .title {
width: 450rpx;
.top {
display: flex;
font-size: 28rpx;
.t-name {
color: #444;
margin: 0 10rpx;
}
}
.bottom {
font-size: 24rpx;
}
}
}
.m-good {
display: flex;
justify-content: space-between;
margin-bottom: 20rpx;
.image {
width: 160rpx;
height: 160rpx;
margin-right: 20rpx;
border-radius: 14rpx;
overflow: hidden;
}
.body-content {
width: 490rpx;
display: flex; display: flex;
flex-direction: column;
justify-content: space-between; justify-content: space-between;
color: #989898; font-size: 28rpx;
color: #444;
}
.title { .tips {
display: flex; display: flex;
justify-content: space-between; justify-content: space-between;
font-size: 28rpx; font-size: 24rpx;
color: #444; margin-top: 10rpx;
} }
.tips { .time {
display: flex; background-color: #F6F6F6;
justify-content: space-between; padding: 5rpx 10rpx;
font-size: 24rpx; font-size: 26rpx;
margin-top: 10rpx; color: #444;
} border-radius: 10rpx;
.time {
background-color: #F6F6F6;
padding: 5rpx 10rpx;
font-size: 26rpx;
color: #444;
border-radius: 10rpx;
}
} }
} }
}
.good-info { .good-info {
margin-bottom: 20rpx; margin-bottom: 20rpx;
.head-title { .head-title {
margin-bottom: 18rpx; margin-bottom: 18rpx;
color: #000; color: #000;
font-weight: bold; font-weight: bold;
}
.row {
display: flex;
align-items: center;
justify-content: space-between;
margin-bottom: 18rpx;
.red {
color: #F55726;
} }
.row { .icon-text {
display: flex; display: flex;
align-items: center; align-items: center;
justify-content: space-between;
margin-bottom: 18rpx;
.red {
color: #F55726;
}
.icon-text {
display: flex;
align-items: center;
}
.icon {
image {
width: 40rpx;
height: 40rpx;
}
}
} }
.row-need { .icon {
display: flex; image {
justify-content: flex-end; width: 40rpx;
color: #F55726; height: 40rpx;
} }
text {
font-size: 22rpx;
} }
} }
.order-remark { .row-need {
.head-title {
margin-bottom: 18rpx;
display: flex;
justify-content: space-between;
}
}
.tips {
font-size: 28rpx;
color: #999;
display: flex; display: flex;
justify-content: flex-end; justify-content: flex-end;
align-items: center; color: #F55726;
flex: 1;
margin-right: 20rpx;
.all {
color: #F55726;
}
} }
.item-center { text {
display: flex; font-size: 22rpx;
align-items: center;
position: relative;
} }
}
.ship-type { .order-remark {
.head-title {
margin-bottom: 18rpx;
display: flex; display: flex;
z-index: 9; justify-content: space-between;
background-color: #F6F6F6; }
}
.tips {
font-size: 28rpx;
color: #999;
display: flex;
justify-content: flex-end;
align-items: center;
flex: 1;
margin-right: 20rpx;
.all {
color: #F55726;
}
}
.item-center {
display: flex;
align-items: center;
position: relative;
}
.ship-type {
display: flex;
z-index: 9;
background-color: #F6F6F6;
border-radius: 30rpx;
.ship-type-item {
width: 82rpx;
height: 54rpx;
line-height: 54rpx;
text-align: center;
transition: background-color 0.3s ease;
border-radius: 30rpx; border-radius: 30rpx;
.ship-type-item {
width: 82rpx;
height: 54rpx;
line-height: 54rpx;
text-align: center;
transition: background-color 0.3s ease;
border-radius: 30rpx;
}
.actShipItem {
background-color: #27B52F;
color: white;
}
} }
.actShipItem {
background-color: #27B52F;
color: white;
}
}
</style> </style>