This commit is contained in:
2025-01-08 09:44:25 +08:00
parent 06f6e29972
commit 4d21314fc6
60 changed files with 5477 additions and 4495 deletions
+278 -179
View File
@@ -25,15 +25,8 @@
<uv-cell
:title="`${item.fieldName}`"
:label="`${item.dateTime} ${getWeek(this.week)} ${item.timePeriod}`"
:value="form.sid === 37 ? '' : `¥${item.type === 1 ? item.price :item.halfPrice}`"
:cellStyle="{ padding: '10px 5px' }"
v-if="childrenPrice > 0"
></uv-cell>
<uv-cell
:title="`${item.fieldName}`"
:label="`${item.dateTime} ${getWeek(this.week)} ${item.timePeriod}`"
:value="`¥${item.price}`"
:cellStyle="{ padding: '10px 5px' }"
v-else
/>
<!-- <uv-cell iconStyle="checkbox-mark" :cellStyle="{ padding: '10px 0' }" :border="false" v-if="childrenPrice > 0">
<template v-slot:title>
@@ -48,34 +41,26 @@
</uv-radio-group>
</template>
</uv-cell> -->
<block v-for="(item,index) in radiolist" :key="index">
<uv-cell iconStyle="checkbox-mark" :cellStyle="{ padding: '10px 5px' }" :border="false"
v-if="childrenPrice > 0">
<template v-slot:title>
<view class="flex">
<span style="margin-right: 40rpx;">{{ item.name }}</span>
<block v-if="item.name === '成人票'">
<span>¥{{ item.price }}</span>
<!-- <span style="padding-left:16rpx;"> x {{ carNum }}张</span> -->
</block>
<block v-if="item.name === '儿童票'">
<span>¥{{ item.price }}</span>
<!-- <span style="padding-left:16rpx;"> x {{ carNum2 }}张</span> -->
</block>
</view>
</template>
<template v-slot:value>
<view v-if="item.name === '成人票'">
<uv-number-box :min="0" :max="1000" v-model="carNum" :disabled="orderId > 0"
@change="onAdultNum"></uv-number-box>
</view>
<view v-if="item.name === '儿童票'">
<uv-number-box :min="0" :max="1000" v-model="carNum2" :disabled="orderId > 0"
@change="onAdultNum2"></uv-number-box>
</view>
<template v-if="form.sid === 37">
<uv-cell @click="changeIsChildren(2)" iconStyle="checkbox-mark" :title="`成人票 ¥${item.price}`"
:cellStyle="{ padding: '10px 5px' }">
<template v-slot:right-icon>
<uv-icon v-if="parseInt(isChildren) === 2" size="30rpx" name="checkbox-mark"></uv-icon>
</template>
</uv-cell>
</block>
<uv-cell @click="changeIsChildren(1)" iconStyle="checkbox-mark" :title="`儿童票 ¥${item.childrenPrice}`"
:cellStyle="{ padding: '10px 5px' }" :border="false">
<template v-slot:right-icon>
<uv-icon v-if="parseInt(isChildren) === 1" size="30rpx" name="checkbox-mark"></uv-icon>
</template>
</uv-cell>
<uv-cell iconStyle="checkbox-mark" title="人数"
:cellStyle="{ padding: '10px 5px' }" :border="false">
<template v-slot:value>
<uv-number-box v-model="peopleNum" @change="reCalSwimAmount"/>
</template>
</uv-cell>
</template>
</block>
</block>
</uv-cell-group>
@@ -103,7 +88,38 @@
</view>
</view>
</uni-card>
<uni-card :title="`选择会员卡`" :border="false" :is-shadow="false" v-if="form.payType === 2">
<template v-if="vipCard.length > 0">
<uv-cell v-for="(v, vIndex) in vipCard" :key="vIndex"
:title="`${v.name}`"
:label="v.desc"
:cellStyle="{ padding: '20rpx 10rpx', borderRadius: '8rpx', backgroundColor: form.vid === v.id ? '#f6fff1' : '' }"
:border="false"
@click="selectVipCard(v)"
>
<template v-slot:right-icon>
<uv-icon v-if="form.vid === v.id" size="30rpx" name="checkbox-mark"></uv-icon>
</template>
</uv-cell>
</template>
<uv-empty v-else text="暂无可用会员卡"/>
</uni-card>
<uni-card :title="`选择IC卡`" :border="false" :is-shadow="false" v-if="form.payType === 5">
<template v-if="userCard.length > 0">
<uv-cell v-for="(v, vIndex) in userCard" :key="vIndex"
:title="`${v.name}`"
:label="v.desc"
:cellStyle="{ padding: '20rpx 10rpx', borderRadius: '8rpx', backgroundColor: form.code === v.code ? '#f6fff1' : '' }"
:border="false"
@click="selectUserCard(v)"
>
<template v-slot:right-icon>
<uv-icon v-if="form.code === v.code" size="30rpx" name="checkbox-mark"></uv-icon>
</template>
</uv-cell>
</template>
<uv-empty v-else text="暂无可用IC卡"/>
</uni-card>
<view class="xieyi web-cell web-text-secondary web-cell-align-top">
<view class="web-cell web-cell-content web-cell-align-top">
<uni-icons type="circle" size="20" color="#a4a5a7" v-if="!disabled" @click="onDisabled"></uni-icons>
@@ -161,23 +177,26 @@
<script>
import * as Api from '@/api/shop/order';
import * as UserApi from '@/api/booking/users';
import * as UserCardApi from '@/api/booking/userCard';
import * as PaymentApi from '@/api/system/payment';
import {checkPayPassword} from '@/api/passport/login';
import {storeToRefs} from 'pinia';
import {cal} from '@/utils/decimal';
import {getWeek, getKey} from '@/utils/common';
import {useCarStore} from '@/store/modules/car';
import {useUserStore} from '@/store/modules/user';
import dayjs from "dayjs";
import {addThinkOrder} from "@/api/think/thinkOrder";
import {listUserThinkCard} from "@/api/think/thinkCard";
import {listThinkUsersVip} from "@/api/think/thinkUsersVip";
import {number} from "@/uni_modules/uv-ui-tools/libs/function/test";
const userStore = useUserStore();
// const carStore = useCarStore();
// const { merchantId, merchantCode, orderInfo, period, totalPrice, reducePrice, payPrice, childrenPrice, carNum, carNum2, merchant, type, dateTime } = storeToRefs(carStore);
export default {
computed: {
dayjs() {
return dayjs
}
},
data() {
return {
orderId: 0,
@@ -212,9 +231,12 @@ export default {
cardId: 0,
getWeek,
isLogin: false,
disabled: false,
disabled: true,
cardList: [],
userCard: {},
userCard: [],
allUserCard: [],
vipCard: [],
allVipCard: [],
// isRefresh: true,
// 支付密码是否正确
isPayPasswordCorrect: false,
@@ -222,23 +244,10 @@ export default {
payPassword: '',
// 折扣率
discount: 1,
// 票类型
radiolist: [
{
name: '成人票',
price: 50,
totalPrice: 50,
disabled: false
},
{
name: '儿童票',
price: 35,
totalPrice: 35,
disabled: false
}
],
radiovalue: '成人票',
userCardList: []
originPrice: 0,
isChildren: null,
peopleNum: 1,
};
},
async onLoad() {
@@ -251,9 +260,12 @@ export default {
const eventChannel = this.getOpenerEventChannel();
const _this = this
this.userInfo = await userStore.fetchUserInfo();
eventChannel.on('data', function (data) {
eventChannel.on('data', async (data) => {
_this.list = data
_this.payPrice = data.reduce((a, b) => a + b.price, 0)
if (data[0].isHalf === 1) _this.payPrice = data.reduce((a, b) => a + b.halfPrice, 0)
else _this.payPrice = data.reduce((a, b) => a + b.price, 0)
_this.originPrice = JSON.parse(JSON.stringify(_this.payPrice))
const thinkOrderInfos = []
data.forEach(item => {
const [startTime, endTime] = item.timePeriod.split(' - ')
@@ -276,6 +288,7 @@ export default {
name: _this.userInfo.realName,
phone: _this.userInfo.phone,
sid: data[0].sid,
fid: data[0].fieldId,
cid: null,
vid: null,
code: null,
@@ -284,9 +297,14 @@ export default {
startTime: thinkOrderInfos.map(item => item.startTime).join()
}
})
_this.isChildren = data[0].isChildren
// console.log(data)
// console.log(this.isChildren)
await this.getPayment()
await this.getUserCard()
await this.getUserVipCard()
console.log(this.form)
})
await this.getPayment()
await this.getUserCard()
},
async onShow() {
this.userInfo = await userStore.fetchUserInfo();
@@ -365,12 +383,19 @@ export default {
}
// 请求数据
app.userCard = []
Promise.all([app.getUserCard(), app.getPayment()]).then((res) => {
const userCard = res[0];
const payment = res[1];
// 当前可用会员卡
app.userCard = userCard;
if (userCard.length > 0) {
app.userCard = userCard.filter(card => {
const sid = card.sid.split(',');
return sid.includes(res[0].sid)
});
if (app.userCard.length > 0) app.form.vid = app.userCard[0].id;
}
// 支付方式列表
app.payment = payment.map((d) => {
if (d.type == 0) {
@@ -390,48 +415,131 @@ export default {
const res = await listUserThinkCard()
if (res.length) {
this.userCard = res
// if (this.userCard) {
// // 整理表单字段
// form.cardId = userCard.id;
// form.payType = 2;
// app.payType = 2;
//
// // 1年卡
// if (userCard.type == 1) {
// }
//
// // 2次卡
// if (userCard.type == 2) {
// }
//
// // 3月卡
// if (userCard.type == 3) {
// }
//
// // 4会员IC卡
// if (userCard.type == 2) {
// }
// // 5充值卡
// if (userCard.type == 5) {
// // 折扣率
// app.discount = cal.cheng(userCard.discount, 0.1);
//
// // 订单金额
// const orderPrice = totalPrice || form.totalPrice;
// if (orderPrice) {
// console.log('orderPrice: ', orderPrice);
// // 折后金额
// const lastTotalPrice = cal.cheng(orderPrice, app.discount);
// console.log('折后金额: ', lastTotalPrice);
// // 减少的金额
// app.reducePrice = cal.jian(orderPrice, lastTotalPrice);
// console.log('减少的金额: ', app.reducePrice);
// // 实付额
// app.payPrice = orderPrice * app.discount;
// console.log('实付额: ', app.payPrice);
// }
// }
// }
if (this.userCard.length > 0) {
this.userCard = this.userCard.filter(card => {
const sid = card.sid.split(',').map(Number);
return sid.includes(parseInt(this.form.sid))
});
this.allUserCard = JSON.parse(JSON.stringify(this.userCard))
this.allUserCard = this.allUserCard.map(item => {
item.desc += `${dayjs(item.expireTime * 1000).format('YYYY-MM-DD HH:mm:ss')}过期`
if (item.type === 2) item.desc += `,剩余${item.num}次`
else if (item.type === 5) item.desc += `,剩余${item.remainingMoney}元`
return item
})
const newList = []
for (let i = 0; i < this.allUserCard.length; i++) {
const item = this.allUserCard[i]
if (item.type === 2) {
if (item.num > 0) newList.push(item)
} else if (item.type === 5) {
if (item.remainingMoney > 0) newList.push(item)
} else newList.push(item)
}
this.allUserCard = JSON.parse(JSON.stringify(newList))
this.makeUserCardList()
}
}
},
makeUserCardList() {
this.userCard = this.allUserCard.filter(item => dayjs(item.expireTime * 1000).isAfter(dayjs()))
if (this.isChildren === 2) {
this.userCard = this.userCard.filter(item => item.cardType !== 2)
} else {
this.userCard = this.userCard.filter(item => item.cardType === 2)
}
if (this.userCard.length) {
this.userCard.sort((a, b) => a.type - b.type)
this.form.payType = 5
this.form.vid = null
let card = null
for (let i = 0; i < this.userCard.length; i++) {
const item = this.userCard[i]
if (item.type === 1) {
this.form.code = item.code
card = item
break
}
if (item.type === 3) {
this.form.code = item.code
card = item
break
}
if (item.type === 2) {
this.form.code = item.code
card = item
break
}
this.form.code = item.code
card = item
break
}
if (card) this.selectUserCard(card)
}
},
async getUserVipCard() {
const res = await listThinkUsersVip()
if (res.length) {
// this.vipCard = res
this.vipCard = res.filter(card => {
const sid = card.sid.split(',').map(Number);
return sid.includes(parseInt(this.form.sid))
});
this.allVipCard = JSON.parse(JSON.stringify(this.vipCard))
this.allVipCard = this.allVipCard.map(item => {
item.desc += `,${dayjs(item.expireTime * 1000).format('YYYY-MM-DD HH:mm:ss')}过期`
if (item.type === 2) item.desc += `,剩余${item.num}次`
else if (item.type === 5) item.desc += `,剩余${item.remainingMoney}元`
return item
})
const newList = []
for (let i = 0; i < this.allVipCard.length; i++) {
const item = this.allVipCard[i]
if (item.type === 2) {
if (item.num > 0) newList.push(item)
} else if (item.type === 5) {
if (item.remainingMoney > 0) newList.push(item)
} else newList.push(item)
}
this.allVipCard = JSON.parse(JSON.stringify(newList))
this.makeUserVipCardList()
}
},
makeUserVipCardList() {
this.vipCard = this.allVipCard.filter(item => dayjs(item.expireTime * 1000).isAfter(dayjs()))
if (this.isChildren === 2) {
this.vipCard = this.vipCard.filter(item => item.cardType !== 2)
} else {
this.vipCard = this.vipCard.filter(item => item.cardType === 2)
}
if (this.vipCard.length) {
this.vipCard.sort((a, b) => a.type - b.type)
this.form.payType = 2
this.form.code = null
let card = null
for (let i = 0; i < this.vipCard.length; i++) {
const item = this.vipCard[i]
if (item.type === 1) {
card = item
this.form.vid = item.id
break
}
if (item.type === 3) {
card = item
this.form.vid = item.id
break
}
if (item.type === 2) {
card = item
this.form.vid = item.id
break
}
card = item
this.form.vid = item.id
break
}
if (card) this.selectVipCard(card)
}
},
// 读取支付方式列表
@@ -448,21 +556,14 @@ export default {
},
// 切换支付方式
async onPayType(index) {
const app = this;
const {form, totalPrice, carNum, childrenPrice, radiovalue} = this;
// app.payType = index;
app.form.payType = index;
app.form.cardId = 0;
console.log('childrenPrice: ', childrenPrice);
// 重新总金额
app.payPrice = 0;
app.reducePrice = 0;
await app.countTotalPrice()
if (index === 2) {
await app.reload();
}
this.form.payType = index;
this.form.vid = null
this.form.code = null
this.reducePrice = 0
if (this.form.sid !== 37) this.payPrice = this.originPrice
if (this.form.payType === 2) this.makeUserVipCardList()
if (this.form.payType === 5) this.makeUserCardList()
},
openUrl(url) {
if (!this.isLogin) {
@@ -506,38 +607,6 @@ export default {
this.disabledPayPayPassword = false;
});
},
onAdultNum(e) {
const app = this;
const index = e.value;
app.carNum = index;
app.orderInfo[0].adultNum = index;
// 重新总金额
app.countTotalPrice()
},
onAdultNum2(e) {
const app = this;
const index = e.value;
app.carNum2 = index;
app.orderInfo[0].childrenNum = index;
// 重新总金额
app.countTotalPrice()
},
// 重新计算金额
countTotalPrice() {
// const app = this
// // 计算总金额
// let total;
// const prices = [];
// app.orderInfo.map(d => {
// prices.push(d.price * d.adultNum + d.childrenPrice * d.childrenNum);
// })
// // 使用reduce方法进行累加
// const sum = prices.reduce((accumulator, currentValue) => accumulator + currentValue, 0);
// console.log(sum);
// app.totalPrice = sum
// app.payPrice = sum
},
save() {
const app = this;
const {form} = this;
@@ -555,9 +624,16 @@ export default {
});
return false;
}
if (form.payType === 2 && !app.userCard) {
if (form.payType === 2 && !app.form.vid) {
uni.showToast({
title: '没有找到可用的会员卡',
title: '请选择会员卡',
icon: 'none'
});
return false;
}
if (form.payType === 5 && !app.form.code) {
uni.showToast({
title: '请选择IC卡',
icon: 'none'
});
return false;
@@ -570,8 +646,19 @@ export default {
uni.showLoading({
title: '订单提交中.'
});
form.thinkOrderInfos = form.thinkOrderInfos.map(item => {
item.isChildren = app.isChildren
if (form.sid === 37) {
if (app.isChildren === 1) {
item.adultNum = 0
item.childrenNum = this.peopleNum
} else if (app.isChildren === 2) {
item.adultNum = this.peopleNum
item.childrenNum = 0
}
}
return item
})
addThinkOrder(form)
.then((data) => {
const orderInfo = data;
@@ -608,13 +695,8 @@ export default {
fail: function (err) {
console.log('支付失败', err);
app.disabled = false;
uni.reLaunch({
url: '/pages/order/order',
success: function (e) {
var page = getCurrentPages()[0];
if (page == undefined || page == null) return;
page.onLoad();
}
uni.switchTab({
url: '/pages/order'
});
// uni.switchTab({
// url: '/pages/order/order'
@@ -639,20 +721,13 @@ export default {
setTimeout(function () {
app.disabled = false;
app.$refs.payPasswordForm.close();
uni.reLaunch({
url: '/pages/order/order',
success: function (e) {
var page = getCurrentPages()[0];
if (page == undefined || page == null) return;
page.onLoad();
}
});
uni.switchTab({url: '/pages/order'})
}, 1500);
}
}
// 使用会员卡支付
if (form.payType === 2) {
if (form.payType === 2 || form.payType === 5) {
if (!orderInfo) {
return uni.showToast({
title: '支付失败',
@@ -666,18 +741,10 @@ export default {
});
setTimeout(function () {
app.disabled = false;
uni.reLaunch({
url: '/pages/order/order',
success: function (e) {
var page = getCurrentPages()[0];
if (page == undefined || page == null) return;
page.onLoad();
}
});
uni.switchTab({url: '/pages/order'})
}, 1500);
}
}
uni.hideLoading();
})
.catch((res) => {
@@ -687,6 +754,38 @@ export default {
});
uni.hideLoading();
});
},
selectVipCard(card) {
this.form.vid = card.id;
this.reCalAmount(card)
},
selectUserCard(card) {
this.form.code = card.code;
this.reCalAmount(card)
},
reCalAmount(card) {
// 余额折扣卡
if (card.type === 5) {
this.reducePrice = this.originPrice * (1 - (card.discount / 10))
this.reducePrice = parseFloat(this.reducePrice.toFixed(2))
this.payPrice = this.originPrice - this.reducePrice
this.payPrice = parseFloat(this.payPrice.toFixed(2))
} else {
this.reducePrice = this.originPrice
this.payPrice = 0
}
},
changeIsChildren(val) {
this.isChildren = val
this.reCalSwimAmount({value: this.peopleNum})
this.makeUserCardList()
this.makeUserVipCardList()
},
reCalSwimAmount({value}) {
this.peopleNum = value
if (this.isChildren === 2) this.payPrice = this.list.reduce((a, b) => a + b.price, 0)
else this.payPrice = this.list.reduce((a, b) => a + b.childrenPrice, 0)
this.payPrice = this.payPrice * this.peopleNum
}
}
};