Преглед изворни кода

Signed-off-by: 1004749546@qq.com <1004749546@qq.com>
下单修改

1004749546@qq.com пре 4 година
родитељ
комит
e71c65b413

+ 6 - 2
pages/coupon/chooseCoupon/chooseCoupon.vue

@@ -1,6 +1,6 @@
 <template>
 	<view class="coopon-pages">
-		<couponTpl @checkOk="checkOk" :showCheck="true"></couponTpl>
+		<couponTpl @checkOk="checkOk" :list="couponList" :showCheck="true"></couponTpl>
 		<view class="fix-button" v-if="curCoupon">
 			<view>
 				<view>优惠:¥9.8</view>
@@ -18,9 +18,13 @@
 		},
 		data() {
 			return {
-				curCoupon: null
+				curCoupon: null,
+				couponList:  []
 			};
 		},
+		onLoad(opt) {
+			this.couponList = JSON.parse(decodeURIComponent(opt.list)) 
+		},
 		methods:{
 			checkOk(item){
 				this.curCoupon = item

+ 1 - 42
pages/coupon/couponTpl.vue

@@ -30,48 +30,7 @@
 			list:{
 				type: Array,
 				default: function(){
-					return [
-						{
-							id: 23432445,
-							name: "满100减50",
-							price: 100,
-							yxTime: "2020-05-16",
-							remarks: '优惠卷使用说明优惠卷使用说明优惠卷使用说明',
-							checked: false
-						},
-						{
-							id: 3544355,
-							name: "满100减50",
-							price: 100,
-							yxTime: "2020-05-16",
-							remarks: '优惠卷使用说明优惠卷使用说明优惠卷使用说明',
-							checked: false
-						},
-						{
-							id: 234234234,
-							name: "满100减50",
-							price: 100,
-							yxTime: "2020-05-16",
-							remarks: '优惠卷使用说明优惠卷使用说明优惠卷使用说明',
-							checked: false
-						},
-						{
-							id: 66264646,
-							name: "满100减50",
-							price: 100,
-							yxTime: "2020-05-16",
-							remarks: '优惠卷使用说明优惠卷使用说明优惠卷使用说明',
-							checked: false
-						},
-						{
-							id: 9794694698,
-							name: "满100减50",
-							price: 100,
-							yxTime: "2020-05-16",
-							remarks: '优惠卷使用说明优惠卷使用说明优惠卷使用说明',
-							checked: false
-						}
-					]
+					return []
 				}
 			}
 		},

+ 94 - 2
pages/getOrder/getOrder.vue

@@ -68,7 +68,7 @@
 				<button class="next-button" @click="nextStep" v-if="stepIndex!=2" type="warn">下一步</button>
 				<view v-else class="pay">
 					<text>合计:</text>
-					<text class="amount">¥10:00</text>
+					<text class="amount">¥{{finalAmount}}</text>
 					<view class="">
 						<button @click="toPay" type="warn">去付款</button>
 					</view>
@@ -107,6 +107,52 @@
 					}
 				],
 				isRead: '', // 是否同意协议
+				couponList: [
+						{
+							id: 23432445,
+							name: "满100减50",
+							price: 100,
+							yxTime: "2020-05-16",
+							remarks: '优惠卷使用说明优惠卷使用说明优惠卷使用说明',
+							checked: false
+						},
+						{
+							id: 3544355,
+							name: "满100减50",
+							price: 100,
+							yxTime: "2020-05-16",
+							remarks: '优惠卷使用说明优惠卷使用说明优惠卷使用说明',
+							checked: false
+						},
+						{
+							id: 234234234,
+							name: "满100减50",
+							price: 100,
+							yxTime: "2020-05-16",
+							remarks: '优惠卷使用说明优惠卷使用说明优惠卷使用说明',
+							checked: false
+						},
+						{
+							id: 66264646,
+							name: "满100减50",
+							price: 100,
+							yxTime: "2020-05-16",
+							remarks: '优惠卷使用说明优惠卷使用说明优惠卷使用说明',
+							checked: false
+						},
+						{
+							id: 9794694698,
+							name: "满100减50",
+							price: 100,
+							yxTime: "2020-05-16",
+							remarks: '优惠卷使用说明优惠卷使用说明优惠卷使用说明',
+							checked: false
+						}
+					], // 用户可用优惠券
+				checkedCoupon: null, // 用户当前所选优惠券
+				amount: 0, // 所选服务项目总金额
+				couponAmount: 0, // 优惠券优惠金额
+				finalAmount: 0, // 用户最终所需支付金额
 			}
 		},
 		onLoad(option) {
@@ -123,9 +169,15 @@
 			console.log(this.stepIndex)
 		},
 		methods: {
+			// 获取服务列表
+			getServerList () {
+				
+			},
 			// 选择服务项目
 			chooseItem(index) {
 				this.serverIndex = index
+				this.amount = this.itemList[index].price
+				this.getFinalAmount()
 			},
 			// 下一步
 			nextStep() {
@@ -136,10 +188,50 @@
 			read (e) {
 				this.isRead = e.msg
 			},
+			// 获取用户可用优惠券
+			getCouponList () {
+				
+			},
+			// 格式化优惠券数据 获取优惠金额最大的优惠券 couponType 优惠券类型:FULLSUB满减/DISCOUNT折扣券/VOUCHER代金券
+			formatCouponData (){
+			  let arr = []
+			  let _this = this
+			  this.couponList.map(item => {
+			    let data = {}
+			    data.id = item.couponReceivesId
+			    if (item.couponType == 'DISCOUNT') {
+			      console.log(_this.amount, '_this.amount')
+			      data.subAmount = Number((_this.amount * (1 - item.subAmount)).toFixed(2))
+			    } else {
+			      data.subAmount = item.couponType == 'FULLSUB' ? item.subAmount : item.price
+			    }
+			    arr.push(data)
+			  })
+			  console.log(arr, 'arr')
+			  // 比较数据中优惠金额最大的值 并返回该对象
+			  let obj = arr.reduce((p, v) => p.subAmount < v.subAmount ? v : p)
+			  console.log(obj)
+			  let p = this.couponList.find(item => item.couponReceivesId == obj.id)
+			  // 订单金额为0时,默认不使用优惠卷
+			  if (this.amount != 0){
+			   this.checkedCoupon = p
+			   this.couponAmount = obj.subAmount > this.amount ? this.amount : obj.subAmount
+			  } else {
+			    this.checkedCoupon = null
+			    this.couponAmount = 0
+			  }
+			  // 计算合计
+			  this.getFinalAmount()
+			},
+			// 计算合计
+			getFinalAmount () {
+			  let ret = this.amount - this.couponAmount 
+			  this.finalAmount = ret.toFixed(2)
+			},
 			// 选择优惠券
 			intoChooseCoupon () {
 				uni.navigateTo({
-					url: '/pages/coupon/chooseCoupon/chooseCoupon'
+					url: `/pages/coupon/chooseCoupon/chooseCoupon?list=${encodeURIComponent(JSON.stringify(this.couponList))}`
 				})
 			},
 			// 打开服务协议

+ 15 - 12
pages/index/index.vue

@@ -249,18 +249,21 @@
 			},
 			// 扫码洗车
 			scanCode () {
-				if (this.hasLogin) {
-					uni.scanCode({
-					    success: function (res) {
-					        console.log('条码类型:' + res.scanType);
-					        console.log('条码内容:' + res.result);
-					    }
-					});
-				} else {
-					uni.navigateTo({
-						url: '/pages/login/login'
-					})
-				}
+				uni.navigateTo({
+					url: '/pages/getOrder/getOrder'
+				})
+				// if (this.hasLogin) {
+				// 	uni.scanCode({
+				// 	    success: function (res) {
+				// 	        console.log('条码类型:' + res.scanType);
+				// 	        console.log('条码内容:' + res.result);
+				// 	    }
+				// 	});
+				// } else {
+				// 	uni.navigateTo({
+				// 		url: '/pages/login/login'
+				// 	})
+				// }
 				
 			},
 			// 创建标记点