|
@@ -2,6 +2,7 @@ import { checkOut, calculateDiscount, ordersAndPrepay } from '@/api/parking';
|
|
|
|
|
|
// import checkOutQHResponse from '@/api/mockData/checkout.qh3.response.json'
|
|
|
// import checkOutQHResponse from '@/api/mockData/checkout.hz.response.json';
|
|
|
+import checkOutQHResponse from '@/api/mockData/checkout.qh4.response.json'
|
|
|
|
|
|
// 微服务接口字段
|
|
|
const state = {
|
|
@@ -24,6 +25,7 @@ const state = {
|
|
|
enablePaperCoupons: false, // 启动纸质优惠券
|
|
|
usingTotalDiscount: 0, // 优惠金额
|
|
|
actualPayFee: 0, // 应付金额
|
|
|
+ availableDiscountFee: 0, // 当日剩余可使用优惠金额
|
|
|
// 积分相关
|
|
|
available: 0, // 用户可用积分
|
|
|
maxPointsTime: '', // 积分最大兑换时长
|
|
@@ -87,6 +89,9 @@ const mutations = {
|
|
|
setActualPayFee(state, payload) {
|
|
|
state.actualPayFee = payload;
|
|
|
},
|
|
|
+ setAvailableDiscountFee(state, payload) {
|
|
|
+ state.availableDiscountFee = payload;
|
|
|
+ },
|
|
|
setPointsPerHour(state, payload) {
|
|
|
state.pointsPerHour = payload;
|
|
|
},
|
|
@@ -130,13 +135,13 @@ const actions = {
|
|
|
// }
|
|
|
// const res = await checkOut('浙A616A1');
|
|
|
// const res = await checkOut('闽AAQ5519');
|
|
|
- const res = await checkOut('闽AAQ5518');
|
|
|
+ const res = await checkOut('粤A51113');
|
|
|
// const res = await checkOut('沪DCJ986');
|
|
|
// console.log('浙A616A1', res);
|
|
|
// 所有的优惠时间长转为金额
|
|
|
// console.log(112, '所有的优惠时间长转为金额');
|
|
|
// dispatch('orderInitRule', checkOutQHResponse);
|
|
|
- dispatch('orderInitRule', res);
|
|
|
+ dispatch('orderInitRule', checkOutQHResponse);
|
|
|
} catch (error) {
|
|
|
console.log(error);
|
|
|
}
|
|
@@ -211,6 +216,7 @@ const actions = {
|
|
|
const {
|
|
|
maxPointsTime = 0, // 最大积分
|
|
|
enablePoints,
|
|
|
+ availableDiscountFee,
|
|
|
maxOneDayDiscountFee, // 每日最大优惠金额(深圳车场)
|
|
|
remainConsumeTime, // 当前订单剩余可使用的优惠
|
|
|
} = parkingRule;
|
|
@@ -225,6 +231,7 @@ const actions = {
|
|
|
label,
|
|
|
},
|
|
|
] = points;
|
|
|
+ commit('setAvailableDiscountFee', availableDiscountFee);
|
|
|
dispatch('maxPointsTimeMath', checkOutResponse) // 剩余积分可兑换上限
|
|
|
commit('setEnablePoints', enablePoints);
|
|
|
commit('setAvailable', available);
|
|
@@ -243,19 +250,27 @@ const actions = {
|
|
|
* 1、不能超过积分上限
|
|
|
* 2、
|
|
|
* */
|
|
|
- maxPointsTimeMath({ commit, dispatch, state }, checkOutResponse){
|
|
|
+ maxPointsTimeMath({ commit, dispatch, state }, checkOutResponse) {
|
|
|
const { discountInfo, parkingRule, parkInfo } = checkOutResponse
|
|
|
- const {points:[{
|
|
|
+ const { points: [{
|
|
|
available, // 用户可用的积分(当前车辆在) available是用户选择抵扣N小时后剩余的可用积分
|
|
|
unitAmount, // 兑换值(元)
|
|
|
pointsPerUnit = 0, // 500 积分对应的价值
|
|
|
discountFee,
|
|
|
maxDiscountFee,
|
|
|
- }]} = discountInfo
|
|
|
+ }] } = discountInfo
|
|
|
// 总积分
|
|
|
const max = available / pointsPerUnit * unitAmount;
|
|
|
const timeNum = maxDiscountFee / unitAmount;
|
|
|
console.log(';999988888;', timeNum);
|
|
|
+
|
|
|
+ /**
|
|
|
+ * maxDiscountFee 单次最大可使用金额
|
|
|
+ * availableDiscountFee 当日剩余可使用优惠金额
|
|
|
+ * available 当前用户的剩余积分,也可以说是可以抵扣的积分,如果有积分抵扣自动勾选,那么这个值=这个值-已勾选积分
|
|
|
+ *
|
|
|
+ */
|
|
|
+
|
|
|
// if ( !state.maxPointsTime ) {
|
|
|
// commit('setMaxPointsTime', discountFee || max)
|
|
|
// }
|
|
@@ -270,19 +285,31 @@ const actions = {
|
|
|
|
|
|
// 积分减免
|
|
|
pointsMath({ commit, dispatch, state }, { type }) {
|
|
|
+ /**
|
|
|
+ * maxDiscountFee 单次最大可使用金额
|
|
|
+ * availableDiscountFee 当日剩余可使用优惠金额
|
|
|
+ * available 当前用户的剩余积分,也可以说是可以抵扣的积分,如果有积分抵扣自动勾选,那么这个值=这个值-已勾选积分
|
|
|
+ */
|
|
|
+
|
|
|
// console.log('289289289289289289289289', state.available / (state.pointsPerUnit / state.unitAmount) + state.pointsTime);
|
|
|
+ // 计算用户当前的最大可使用积分的总数(单位:元)
|
|
|
let maxPointsTime = state.available / (state.pointsPerUnit / state.unitAmount) + state.pointsTime;
|
|
|
- if ( maxPointsTime > state.maxDiscountFee) {
|
|
|
+ if (maxPointsTime > state.maxDiscountFee) {
|
|
|
maxPointsTime = state.maxDiscountFee
|
|
|
}
|
|
|
+ // 验证最大积分的总数(单位:元)
|
|
|
+ if (maxPointsTime > state.availableDiscountFee) {
|
|
|
+ maxPointsTime = state.availableDiscountFee
|
|
|
+ }
|
|
|
+ console.log(303, maxPointsTime);
|
|
|
if (type === 'add' && state.pointsTime < maxPointsTime) {
|
|
|
- const pointsTime = state.pointsTime + 1;
|
|
|
+ const pointsTime = state.pointsTime + state.unitAmount;
|
|
|
// 如果是深圳车场
|
|
|
commit('setAvailable', state.available - state.pointsPerUnit / state.unitAmount);
|
|
|
commit('setPointsTime', pointsTime);
|
|
|
}
|
|
|
if (type === 'minus' && state.pointsTime > 0) {
|
|
|
- const pointsTime = state.pointsTime - 1;
|
|
|
+ const pointsTime = state.pointsTime - state.unitAmount;
|
|
|
// 如果是深圳车场
|
|
|
commit('setAvailable', state.available + state.pointsPerUnit / state.unitAmount);
|
|
|
commit('setPointsTime', pointsTime);
|
|
@@ -293,25 +320,38 @@ const actions = {
|
|
|
discountInfo: { points },
|
|
|
parkingRule,
|
|
|
} = state.orderDetail;
|
|
|
- const [{ pointsPerHour, available }] = points;
|
|
|
+ const [{ pointsPerHour, available, discountFee }] = points;
|
|
|
const { maxPointsTime, enablePoints } = parkingRule;
|
|
|
commit('setAvailable', available);
|
|
|
- commit('setPointsTime', maxPointsTime);
|
|
|
+ commit('setPointsTime', discountFee || 0);
|
|
|
callback && callback();
|
|
|
},
|
|
|
async savePointsMath({ commit, dispatch, state }, callback) {
|
|
|
- const orderDetail = { ...state.orderDetail };
|
|
|
- // 计算积分修改之后的金额,返回给后端
|
|
|
- // orderDetail.discountInfo.points[0].discountFee = state.pointsTime * orderDetail.discountInfo.points[0].unitAmount;
|
|
|
- orderDetail.discountInfo.points[0].discountFee = state.pointsTime;
|
|
|
- orderDetail.discountInfo.points[0].available = state.available;
|
|
|
- orderDetail.discountInfo.points[0].selected = true;
|
|
|
try {
|
|
|
+ const orderDetail = { ...state.orderDetail };
|
|
|
+ // 如果是重复提交,则不做重新计算
|
|
|
+ if (orderDetail.discountInfo.points[0].available === state.available) {
|
|
|
+ callback && callback();
|
|
|
+ return
|
|
|
+ }
|
|
|
+ // 计算积分修改之后的金额,返回给后端
|
|
|
+ // orderDetail.discountInfo.points[0].discountFee = state.pointsTime * orderDetail.discountInfo.points[0].unitAmount;
|
|
|
+ orderDetail.discountInfo.points[0].discountFee = state.pointsTime;
|
|
|
+ orderDetail.discountInfo.points[0].available = state.available;
|
|
|
+ orderDetail.discountInfo.points[0].selected = true;
|
|
|
+ /* 其他优惠统计 */
|
|
|
+ // 优惠券: 如果没有添加 selected 字段,则增加 selected; 默认取 defaultSelected;
|
|
|
+ if (orderDetail?.discountInfo?.hasOwnProperty('coupons') && !orderDetail?.discountInfo?.coupons[0]?.hasOwnProperty('selected')) {
|
|
|
+ orderDetail.discountInfo.coupons = orderDetail.discountInfo.coupons.map(elm => {
|
|
|
+ elm.selected = elm.defaultSelected || false;
|
|
|
+ return elm;
|
|
|
+ })
|
|
|
+ }
|
|
|
const res = await calculateDiscount({
|
|
|
...orderDetail,
|
|
|
});
|
|
|
console.log('积分修改失败', { res });
|
|
|
- dispatch('orderInitRule', res);
|
|
|
+ dispatch('orderInitRule', checkOutQHResponse);
|
|
|
callback && callback();
|
|
|
} catch (err) {
|
|
|
console.log('积分修改失败!', err);
|
|
@@ -322,7 +362,9 @@ const actions = {
|
|
|
async saveCouponMath({ commit, dispatch, state }, { couponList, callback }) {
|
|
|
const orderDetail = { ...state.orderDetail };
|
|
|
orderDetail.discountInfo.coupons = couponList;
|
|
|
- orderDetail.discountInfo.points[0].selected = false;
|
|
|
+ if (orderDetail?.discountInfo?.points[0]?.discountFee) {
|
|
|
+ orderDetail.discountInfo.points[0].selected = true;
|
|
|
+ }
|
|
|
try {
|
|
|
const res = await calculateDiscount({
|
|
|
...orderDetail,
|