|
@@ -2,9 +2,13 @@ import { checkOut, calculateDiscount, ordersAndPrepay, currentUnlicensedPlate, u
|
|
|
|
|
|
// import checkOutQHResponse from '@/api/mockData/checkout.qh3.response.json'
|
|
|
// import checkOutQHResponse from '@/api/mockData/checkout.hz.response.json';
|
|
|
-// import checkOutQHResponse from '@/api/mockData/checkout.qh5 .response.json'
|
|
|
+// import checkOutQHResponse from '@/api/mockData/checkout.qh6.response.json'
|
|
|
// import unlicensedCarCheckInResponse from '@/api/mockData/unlicensedCarCheckIn.qh.response.json';
|
|
|
|
|
|
+/*
|
|
|
+([a-z]*):(.*),
|
|
|
+state.$1 =$2;
|
|
|
+ */
|
|
|
// 大于等于停车费
|
|
|
// 微服务接口字段
|
|
|
const state = {
|
|
@@ -130,6 +134,40 @@ const mutations = {
|
|
|
setUnlicensedCar(state, payload) {
|
|
|
state.unlicensedCar = payload;
|
|
|
},
|
|
|
+ // 订单初始化
|
|
|
+ clearOrderInfo(state) {
|
|
|
+ state.orderDetail = {}; // 订单原始数据
|
|
|
+ state.isShowDiscounts = false; // 是否展示会员登记优惠
|
|
|
+ state.discountDesc = ''; // 停车优惠(首停、会员减免、消费减免)
|
|
|
+ state.checkedTotal = 0; // 选中count数
|
|
|
+ state.enableNewMemberPoints = false; // 是否开启新会员积分
|
|
|
+ state.enablePoints = false; // 是否开启积分减免
|
|
|
+ state.usePoints = 0; // 用户已选择的积分
|
|
|
+ state.isFirst = 0; // 判断用户是否首次进入
|
|
|
+ state.integralDesc = ''; // 积分减免说明文案
|
|
|
+ state.pointsPerHour = 0; // 每小时兑换积分
|
|
|
+ state.enableCoupon = false; // 电子优惠券是否启用
|
|
|
+ state.maxOneDayCoupons = 0; // 单日可选优惠券上限
|
|
|
+ state.coupons = []; // 可选优惠券数量
|
|
|
+ state.couponCount = 0; // 已选择优惠券
|
|
|
+ state.couponDesc = ''; // 优惠券说明文案
|
|
|
+ state.enablePaperCoupons = false; // 启动纸质优惠券
|
|
|
+ state.usingTotalDiscount = 0; // 优惠金额
|
|
|
+ state.actualPayFee = 0; // 应付金额
|
|
|
+ state.availableDiscountFee = 0; // 当日剩余可使用优惠金额
|
|
|
+ // 积分相关
|
|
|
+ state.available = 0; // 用户可用积分
|
|
|
+ state.maxPointsTime = ''; // 积分最大兑换时长
|
|
|
+ state.pointsTime = ''; // 已兑换的积分时间
|
|
|
+ state.unitAmount = 0;
|
|
|
+ // 停车优惠:会员等级和消费减免
|
|
|
+ state.memberLevelDiscount = false; // 是否开启会员等级
|
|
|
+ state.enableConsume = false; // 是否开启消费减免
|
|
|
+ state.pointsPerUnit = 0; //
|
|
|
+ // unlicensed: false // true: 临时车牌;false:普通车牌
|
|
|
+ // 无牌车逻辑
|
|
|
+ state.unlicensedCar = '';
|
|
|
+ }
|
|
|
};
|
|
|
|
|
|
const actions = {
|
|
@@ -141,24 +179,34 @@ const actions = {
|
|
|
* @param {*} param1.callback 回调函数,用于接口报错时,展示对应的信息
|
|
|
* @param {*} param1.endlessLoop 用于判断当前用户是否扫码进入
|
|
|
*/
|
|
|
- async orderInit({ commit, dispatch, state }, { gateId='124p3LK1', vehicleNo = '浙A616A1', callback, endlessLoop }) {
|
|
|
+ async orderInit({ commit, dispatch, state }, { gateId = '124p3LK1', vehicleNo = '浙A616A1', callback, endlessLoop }) {
|
|
|
try {
|
|
|
- const unlicensed = vehicleNo.indexOf('临') > -1; // true: 临时车牌;false:普通车牌
|
|
|
+ commit('clearOrderInfo');
|
|
|
+ const unlicensed = vehicleNo.indexOf('临') > -1 || !vehicleNo; // true: 临时车牌;false:普通车牌
|
|
|
// const res = await checkOut('浙A616A1');
|
|
|
// const res = await checkOut('闽AAQ5519', unlicensed);
|
|
|
// const res = await checkOut('粤A51113');
|
|
|
// const res = await checkOut('沪DCJ986');
|
|
|
// console.log('无牌车扫码出场', endlessLoop);
|
|
|
// 场内缴费,调 check-out 接口,
|
|
|
- const method = unlicensed && endlessLoop ? unlicensedCarCheckout : checkOut
|
|
|
+ const method = unlicensed && endlessLoop || !vehicleNo ? unlicensedCarCheckout : checkOut
|
|
|
const res = await method(vehicleNo, false, gateId);
|
|
|
+ if (res?.parkingRecord?.totalFee <= 0) {
|
|
|
+ callback && callback({
|
|
|
+ unlicensed,
|
|
|
+ endlessLoop,
|
|
|
+ code: endlessLoop,
|
|
|
+ orderDetail: res,
|
|
|
+ }); // 统一处理错误原因
|
|
|
+ return
|
|
|
+ }
|
|
|
// console.log(vehicleNo, res);
|
|
|
// 所有的优惠时间长转为金额
|
|
|
- // console.log(112, '所有的优惠时间长转为金额');
|
|
|
+ console.log(112, '所有的优惠时间长转为金额');
|
|
|
// dispatch('orderInitRule', checkOutQHResponse);
|
|
|
dispatch('orderInitRule', res);
|
|
|
} catch (error) {
|
|
|
- // console.log('151151151151151', error);
|
|
|
+ console.log('151151151151151', error);
|
|
|
/* if (/NOT_FOUND|PARKING_RECORD_NOT_FOUND/.test(error.code)) {
|
|
|
callback && callback(error)
|
|
|
} */
|
|
@@ -168,12 +216,14 @@ const actions = {
|
|
|
orderInitRule({ commit, dispatch, state }, checkOutResponse) {
|
|
|
console.log(119, checkOutResponse);
|
|
|
// 记录buildingId
|
|
|
- window.localStorage.setItem('buildingId', checkOutResponse.parkInfo.buildingId);
|
|
|
+ if (checkOutResponse?.parkInfo?.buildingId) {
|
|
|
+ window.localStorage.setItem('buildingId', checkOutResponse.parkInfo.buildingId);
|
|
|
+ }
|
|
|
commit('setOrderDetail', checkOutResponse);
|
|
|
const isShowDiscounts = checkOutResponse?.parkingRule?.enableCoupon || false;
|
|
|
// 是否展示优惠
|
|
|
commit('setIsShowDiscounts', isShowDiscounts);
|
|
|
- if(isShowDiscounts) {
|
|
|
+ if (checkOutResponse.parkingRule) {
|
|
|
// 会员等级减免
|
|
|
// 停车优惠(首停、会员减免、消费减免)
|
|
|
dispatch('getCheckedTotal', checkOutResponse);
|
|
@@ -186,12 +236,16 @@ const actions = {
|
|
|
// 处理电子优惠券相关逻辑
|
|
|
dispatch('couponRule', checkOutResponse);
|
|
|
// 纸质优惠券(hold)
|
|
|
- commit('setEnablePaperCoupons', checkOutResponse?.parkingRule?.enablePaperCoupons || []);
|
|
|
+ commit('setEnablePaperCoupons', checkOutResponse?.parkingRule?.enablePaperCoupons || false);
|
|
|
// 其他数据收集
|
|
|
commit('setUsingTotalDiscount', checkOutResponse?.discountInfo?.usingTotalDiscount || 0);
|
|
|
+ // console.log(191, checkOutResponse?.parkingRecord.hasOwnProperty(actualPayFee));
|
|
|
+ }
|
|
|
+ if (checkOutResponse?.parkingRecord?.hasOwnProperty('actualPayFee')) {
|
|
|
+ commit('setActualPayFee', checkOutResponse.parkingRecord?.actualPayFee);
|
|
|
+ } else {
|
|
|
+ commit('setActualPayFee', checkOutResponse.parkingRecord?.totalFeeInYuan);
|
|
|
}
|
|
|
- console.log('190190190190', checkOutResponse);
|
|
|
- commit('setActualPayFee', checkOutResponse.parkingRecord?.actualPayFee || checkOutResponse.parkingRecord?.totalFeeInYuan || 0.00);
|
|
|
},
|
|
|
// 停车优惠(首停、会员减免、消费减免)
|
|
|
getCheckedTotal({ commit, dispatch }, orderDetail) {
|
|
@@ -265,7 +319,7 @@ const actions = {
|
|
|
commit('setMaxOneDayDiscountFee', maxOneDayDiscountFee);
|
|
|
commit('setPointsPerHour', pointsPerUnit);
|
|
|
commit('setUnitAmount', unitAmount);
|
|
|
- commit('setIntegralDesc', label);
|
|
|
+ commit('setIntegralDesc', discountFee ? `已选择兑换${discountFee}元` : available > pointsPerUnit ? `${available}积分可减免` : `${pointsPerUnit}积分可停车1小时`); // 积分优惠处的描述
|
|
|
},
|
|
|
// 当前最大可选优惠时间
|
|
|
/*
|
|
@@ -307,29 +361,47 @@ const actions = {
|
|
|
},
|
|
|
|
|
|
// 积分减免
|
|
|
- pointsMath({ commit, dispatch, state }, { type }) {
|
|
|
+ pointsMath({ commit, dispatch, state }, { type, callback }) {
|
|
|
/**
|
|
|
* 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) {
|
|
|
maxPointsTime = state.maxDiscountFee
|
|
|
}
|
|
|
+ let msg = ''
|
|
|
// 验证最大积分的总数(单位:元)
|
|
|
if (maxPointsTime > state.availableDiscountFee) {
|
|
|
maxPointsTime = state.availableDiscountFee
|
|
|
}
|
|
|
- console.log(303, maxPointsTime);
|
|
|
+ if (type === 'add' && state.pointsTime >= maxPointsTime) {
|
|
|
+ // 以下是深圳积分上限规则
|
|
|
+ // 超出抵扣上限,每日最高可抵扣${this.parkFee.parkInfoEntity.maxOneDayHour}元 '优惠金额' >= '每日最高可抵扣'
|
|
|
+ if (state.usingTotalDiscount >= state.maxOneDayDiscountFee) {
|
|
|
+ msg = `超出抵扣上限,每日最高可抵扣${state.maxDiscountFee}元`
|
|
|
+ }
|
|
|
+ // 超出抵扣上限,每次最高可抵扣${this.integralMaxMoney}元 '积分兑换时长' >= '深圳前海停车积分上限'
|
|
|
+ if (state.pointsTime >= state.maxPointsTime) {
|
|
|
+ msg = `超出抵扣上限,每次最高可抵扣${state.maxDiscountFee}元`
|
|
|
+ }
|
|
|
+ callback({
|
|
|
+ message: msg
|
|
|
+ });
|
|
|
+ return
|
|
|
+ }
|
|
|
if (type === 'add' && state.pointsTime < maxPointsTime) {
|
|
|
const pointsTime = state.pointsTime + state.unitAmount;
|
|
|
- // 如果是深圳车场
|
|
|
- commit('setAvailable', state.available - state.pointsPerUnit);
|
|
|
- commit('setPointsTime', pointsTime);
|
|
|
+ const available = state.available - state.pointsPerUnit;
|
|
|
+ const usingTotalDiscount = state.usingTotalDiscount + state.unitAmount; // 重新计算已经使用的优惠逻辑
|
|
|
+ if (available > -1) {
|
|
|
+ // 如果是深圳车场
|
|
|
+ commit('setAvailable', available);
|
|
|
+ commit('setPointsTime', pointsTime);
|
|
|
+ commit('setUsingTotalDiscount', usingTotalDiscount);
|
|
|
+ }
|
|
|
}
|
|
|
if (type === 'minus' && state.pointsTime > 0) {
|
|
|
const pointsTime = state.pointsTime - state.unitAmount;
|
|
@@ -470,6 +542,7 @@ const actions = {
|
|
|
}
|
|
|
});
|
|
|
commit('setCouponCount', couponCount);
|
|
|
+ console.log(479, couponCount);
|
|
|
if (couponCount > 0) {
|
|
|
return commit('setCouponDesc', `已选择${couponCount}张优惠劵`);
|
|
|
} else {
|
|
@@ -478,6 +551,8 @@ const actions = {
|
|
|
}
|
|
|
return commit('setCouponDesc', `暂无可用优惠券`);
|
|
|
}
|
|
|
+ } else {
|
|
|
+ commit('setCouponDesc', `暂无可用优惠券`);
|
|
|
}
|
|
|
},
|
|
|
|
|
@@ -495,13 +570,15 @@ const actions = {
|
|
|
console.log('无牌车的查询记录', res);
|
|
|
commit('setUnlicensedCar', res.vehicleNo);
|
|
|
// 如果是扫码进入的用户,在出场时需要重新扫码,这时会在此处传入的一个回调函数,在获取到临牌时,返回给 qrCodesRule 函数
|
|
|
- if(res.vehicleNo && callback) {
|
|
|
+ if (res.vehicleNo && callback) {
|
|
|
callback(res.vehicleNo);
|
|
|
+ } else {
|
|
|
+ callback('error');
|
|
|
}
|
|
|
} catch (err) {
|
|
|
console.log(err);
|
|
|
}
|
|
|
- }
|
|
|
+ },
|
|
|
|
|
|
// 是否展示优惠
|
|
|
// getIsShowDiscounts({commit, dispatch}, orderDetail) {
|
|
@@ -512,12 +589,13 @@ const actions = {
|
|
|
/*
|
|
|
如果积分发生变化
|
|
|
*/
|
|
|
+
|
|
|
};
|
|
|
|
|
|
export default {
|
|
|
//开启命名模块
|
|
|
namespaced: true,
|
|
|
- state,
|
|
|
+ state: state,
|
|
|
mutations,
|
|
|
actions,
|
|
|
};
|