Browse Source

Merge branch 'deploy' of http://git.chelingzhu.com/chelingzhu-web/qhsxKx-mini-html into deploy

lilei 4 years ago
parent
commit
9a137fb7fa

+ 4 - 11
api/login.js

@@ -1,21 +1,14 @@
-import request from '@/libs/axios.js';
+import axios from '@/libs/axios.js';
 
 
-export const code2Session = params => {
-  return request({
-    url: 'code2Session',
-    data: params,
-    method: 'get'
-  }).then(res => res.data);
-};
 export const login = params => {
 export const login = params => {
-  return request({
+  return axios.request({
     url: `loginVerify`,
     url: `loginVerify`,
     data: params,
     data: params,
     method: 'post',
     method: 'post',
   }).then(res => res.data);
   }).then(res => res.data);
 };
 };
 export const logout = params => {
 export const logout = params => {
-  return request({
+  return axios.request({
     url: `logout`,
     url: `logout`,
     data: params,
     data: params,
     method: 'get'
     method: 'get'
@@ -26,7 +19,7 @@ export const logout = params => {
 export const checkLogin = () => {
 export const checkLogin = () => {
   let token = uni.getStorageSync('token')
   let token = uni.getStorageSync('token')
   if (token&&token!='') {
   if (token&&token!='') {
-    return request({
+    return axios.request({
       url: `checkLogin`,
       url: `checkLogin`,
       method: 'get'
       method: 'get'
     }).then(res => res.data);
     }).then(res => res.data);

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

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

+ 1 - 42
pages/coupon/couponTpl.vue

@@ -30,48 +30,7 @@
 			list:{
 			list:{
 				type: Array,
 				type: Array,
 				default: function(){
 				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>
 				<button class="next-button" @click="nextStep" v-if="stepIndex!=2" type="warn">下一步</button>
 				<view v-else class="pay">
 				<view v-else class="pay">
 					<text>合计:</text>
 					<text>合计:</text>
-					<text class="amount">¥10:00</text>
+					<text class="amount">¥{{finalAmount}}</text>
 					<view class="">
 					<view class="">
 						<button @click="toPay" type="warn">去付款</button>
 						<button @click="toPay" type="warn">去付款</button>
 					</view>
 					</view>
@@ -107,6 +107,52 @@
 					}
 					}
 				],
 				],
 				isRead: '', // 是否同意协议
 				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) {
 		onLoad(option) {
@@ -123,9 +169,15 @@
 			console.log(this.stepIndex)
 			console.log(this.stepIndex)
 		},
 		},
 		methods: {
 		methods: {
+			// 获取服务列表
+			getServerList () {
+				
+			},
 			// 选择服务项目
 			// 选择服务项目
 			chooseItem(index) {
 			chooseItem(index) {
 				this.serverIndex = index
 				this.serverIndex = index
+				this.amount = this.itemList[index].price
+				this.getFinalAmount()
 			},
 			},
 			// 下一步
 			// 下一步
 			nextStep() {
 			nextStep() {
@@ -136,10 +188,50 @@
 			read (e) {
 			read (e) {
 				this.isRead = e.msg
 				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 () {
 			intoChooseCoupon () {
 				uni.navigateTo({
 				uni.navigateTo({
-					url: '/pages/coupon/chooseCoupon/chooseCoupon'
+					url: `/pages/coupon/chooseCoupon/chooseCoupon?list=${encodeURIComponent(JSON.stringify(this.couponList))}`
 				})
 				})
 			},
 			},
 			// 打开服务协议
 			// 打开服务协议

+ 49 - 22
pages/index/index.vue

@@ -47,12 +47,14 @@
 <script>
 <script>
 	import uniNavBar from "@/components/uni-nav-bar/uni-nav-bar.vue"
 	import uniNavBar from "@/components/uni-nav-bar/uni-nav-bar.vue"
 	import uniPopup from '@/components/uni-popup/uni-popup.vue'
 	import uniPopup from '@/components/uni-popup/uni-popup.vue'
+	import {checkLogin} from '@/api/login.js'
 	export default {
 	export default {
 		components: {
 		components: {
 			uniNavBar, uniPopup
 			uniNavBar, uniPopup
 		},
 		},
 		data() {
 		data() {
 			return {
 			return {
+				hasLogin: false, // 用户是否登录
 				mapCtx: null, // 地图对象
 				mapCtx: null, // 地图对象
 				markers: [], // 标注点
 				markers: [], // 标注点
 				centerX: '',
 				centerX: '',
@@ -105,10 +107,32 @@
 		onReady() {
 		onReady() {
 			this.mapCtx = uni.createMapContext('map')
 			this.mapCtx = uni.createMapContext('map')
 		},
 		},
+		onShow() {
+			this.checkLogin()
+		},
 		onLoad() {
 		onLoad() {
 			this.getUserLocation()
 			this.getUserLocation()
 		},
 		},
 		methods: {
 		methods: {
+			// 检验登录token是否过期
+			checkLogin () {
+				uni.checkSession({
+					success:(res) => {
+						console.log('已登录')
+						checkLogin().then(res =>{
+							if (res.status == '200'){
+								this.hasLogin = true
+							} else {
+								this.hasLogin = false
+							}
+						})
+					},
+					fail: (err) => {
+						console.log('登录过期')
+						this.hasLogin = false
+					}
+				})
+			},
 			// 用户位置信息授权
 			// 用户位置信息授权
 			getUserLocation() {
 			getUserLocation() {
 				let _this = this
 				let _this = this
@@ -180,9 +204,16 @@
 			},
 			},
 			// 进入个人中心
 			// 进入个人中心
 			toUserCenter () {
 			toUserCenter () {
-				uni.navigateTo({
-				    url: '/pages/userCenter/index'
-				})
+				if (this.hasLogin) {
+					uni.navigateTo({
+					    url: '/pages/userCenter/index'
+					})
+				} else {
+					uni.navigateTo({
+					  url: `/pages/login/login?lanuch=false&path=` + encodeURIComponent(`/pages/userCenter/index`)
+					});
+				}
+				
 			},
 			},
 			// 打开网点列表
 			// 打开网点列表
 			intoList() {
 			intoList() {
@@ -218,26 +249,22 @@
 			},
 			},
 			// 扫码洗车
 			// 扫码洗车
 			scanCode () {
 			scanCode () {
-				uni.checkSession({
-					success: (res) => {
-						console.log("已经登陆")
-						uni.navigateTo({
-							url: "/pages/getOrder/getOrder"
-						})
-					},
-					fail: (err) => {
-						console.log("需要重新登录")
-						uni.navigateTo({
-							url: "/pages/login/login"
-						})
-					}
+				uni.navigateTo({
+					url: '/pages/getOrder/getOrder'
 				})
 				})
-				// uni.scanCode({
-				//     success: function (res) {
-				//         console.log('条码类型:' + res.scanType);
-				//         console.log('条码内容:' + res.result);
-				//     }
-				// });
+				// if (this.hasLogin) {
+				// 	uni.scanCode({
+				// 	    success: function (res) {
+				// 	        console.log('条码类型:' + res.scanType);
+				// 	        console.log('条码内容:' + res.result);
+				// 	    }
+				// 	});
+				// } else {
+				// 	uni.navigateTo({
+				// 		url: '/pages/login/login'
+				// 	})
+				// }
+				
 			},
 			},
 			// 创建标记点
 			// 创建标记点
 			createMarker(point) {
 			createMarker(point) {

+ 67 - 39
pages/login/login.vue

@@ -1,62 +1,90 @@
 <template>
 <template>
 	<view class="content">
 	<view class="content">
-		<u-button type="success" open-type="getUserInfo" @click="loginIn">微信一键登录</u-button>
+		<u-button type="success" open-type="getPhoneNumber" @getphonenumber="getPhoneNumber">微信一键登录</u-button>
 	</view>
 	</view>
 </template>
 </template>
 
 
 <script>
 <script>
-	import {code2Session} from "@/api/login.js"
+	import {
+		login
+	} from "@/api/login.js"
 	export default {
 	export default {
-		components: {
-		},
+		components: {},
 		data() {
 		data() {
 			return {
 			return {
-				
+				path: '/pages/index/index',
+				lanuch: true
 			}
 			}
 		},
 		},
-		onShow () {
-		 
-		},
+		onShow() {},
+		mounted() {},
 		onLoad(option) {
 		onLoad(option) {
-			
+			console.log(option)
+			const {
+				path,
+				lanuch
+			} = option;
+			this.lanuch = (lanuch + '') === 'true';
+			if (path) {
+				this.path = decodeURIComponent(path);
+			}
 		},
 		},
 		methods: {
 		methods: {
-			loginIn () {
-				let _this = this
-				// uni.login({
-				//   provider: provider,
-				//   success(result) {
-				// 	console.log(result)
-				// 	if (result.code) {
-				// 	  code2Session({
-				// 		code: result.code
-				// 	  }).then(res => {
-				// 		if (res.status === '200') {
-				// 			_this.$u.vuex('vuex_openid',res.data)
-				// 			uni.navigateTo({
-				// 				url: '/pages/index/index'
-				// 			})
-				// 		};
-				// 	  });
-				// 	}
-				//   }
-				// });
-				uni.login({
-				  provider: 'weixin',
-				  success: function (loginRes) {
-				    console.log(loginRes);  // 返回code
-					uni.navigateTo({
-						url: '/pages/index/index'
+			getPhoneNumber(e) {
+				uni.showLoading({
+					mask: true,
+					title: '加载中'
+				});
+				if (e.target.errMsg === 'getPhoneNumber:ok') {
+					uni.login({
+						success(result) {
+							if (result.code) {
+								login({
+									code: result.code,
+									encryptedData: e.target.encryptedData,
+									iv: e.target.iv
+								}).then(res => {
+									uni.hideLoading();
+									if (res.status === '200') {
+										console.log(res.data, 'login data')
+										uni.setStorageSync('token', res.data.token);
+										uni.setStorageSync('phone', res.data.phone);
+										uni.setStorageSync('userId', res.data.userId);
+										if (this.path === '/pages/index/main' || this.lanuch) {
+											uni.reLaunch({
+												url: this.path
+											});
+										} else {
+											uni.redirectTo({
+												url: this.path
+											});
+										}
+									} else {
+										uni.showToast({
+											title: res.message,
+											icon: 'none',
+											duration: 2500
+										});
+									}
+								});
+							}
+						}
 					})
 					})
-				  }
-				})
-			},
+
+				} else {
+					uni.showToast({
+						title: '授权失败',
+						icon: 'none',
+						duration: 2500
+					});
+				}
+			}
 		}
 		}
 	}
 	}
 </script>
 </script>
 
 
 <style>
 <style>
-	.content{
+	.content {
 		padding: 0;
 		padding: 0;
 		display: flex;
 		display: flex;
 		align-items: center;
 		align-items: center;

+ 34 - 29
pages/store/storeList.vue

@@ -25,6 +25,10 @@
 					<u-image width="110rpx" height="110rpx" :border-radius="10" :src="getStoreStatus(item)"></u-image>
 					<u-image width="110rpx" height="110rpx" :border-radius="10" :src="getStoreStatus(item)"></u-image>
 				</view>
 				</view>
 			</view>
 			</view>
+			<u-empty :text="noDataText" img-width="120" v-if="list.length==0 && status!='loading'" mode="list"></u-empty>
+			<view style="padding: 20upx;">
+				<u-loadmore v-if="total>pageSize || status=='loading'" :status="status" />
+			</view>
 		</scroll-view>
 		</scroll-view>
 	</view>
 	</view>
 </template>
 </template>
@@ -37,6 +41,8 @@
 		},
 		},
 		data() {
 		data() {
 			return {
 			return {
+				noDataText: '暂无数据',
+				status: 'loadmore',
 				storeList: [{
 				storeList: [{
 						id: 1,
 						id: 1,
 						icon: '',
 						icon: '',
@@ -70,7 +76,8 @@
 					lng: '0'
 					lng: '0'
 				},
 				},
 				pageNo: 1,
 				pageNo: 1,
-				pageSize: 10
+				pageSize: 10,
+				total: 0
 			}
 			}
 		},
 		},
 		onShow() {
 		onShow() {
@@ -99,9 +106,7 @@
 		computed: {},
 		computed: {},
 		methods: {
 		methods: {
 			getStoresList() {
 			getStoresList() {
-				uni.showLoading({
-					title: '正在加载...'
-				})
+				this.status = "loading"
 				let lat = this.currentPosition.lat
 				let lat = this.currentPosition.lat
 				let lng = this.currentPosition.lng
 				let lng = this.currentPosition.lng
 				getStoresList({
 				getStoresList({
@@ -111,36 +116,31 @@
 					lng: lng
 					lng: lng
 				}).then(res => {
 				}).then(res => {
 					console.log(res)
 					console.log(res)
+					uni.hideLoading()
 					if (res.status == 200) {
 					if (res.status == 200) {
 						let list = res.data.list
 						let list = res.data.list
-						if (list && list.length) {
-							list.map(item => {
-								if (item.addrDetail.indexOf("省") > 0 && item.addrDetail.indexOf("市") > 0 && item.addrDetail.indexOf("区") >
-									0) {
-									item.addrDetail = item.addrDetail
+						list.map(item => {
+							if (item.addrDetail.indexOf("省") > 0 && item.addrDetail.indexOf("市") > 0 && item.addrDetail.indexOf("区") >
+								0) {
+								item.addrDetail = item.addrDetail
+							} else {
+								if (item.addrDetail.indexOf("市") > 0 && item.addrDetail.indexOf("区") > 0) {
+									item.addrDetail = item.addrProvinceName + item.addrDetail
+								} else if (item.addrDetail.indexOf("区") > 0) {
+									item.addrDetail = item.addrProvinceName + item.addrCityName + item.addrDetail
 								} else {
 								} else {
-									if (item.addrDetail.indexOf("市") > 0 && item.addrDetail.indexOf("区") > 0) {
-										item.addrDetail = item.addrProvinceName + item.addrDetail
-									} else if (item.addrDetail.indexOf("区") > 0) {
-										item.addrDetail = item.addrProvinceName + item.addrCityName + item.addrDetail
-									} else {
-										item.addrDetail = item.addrProvinceName + item.addrCityName + item.addrDistrictName + item.addrDetail
-									}
+									item.addrDetail = item.addrProvinceName + item.addrCityName + item.addrDistrictName + item.addrDetail
 								}
 								}
-								item.distance = item.distance ? Math.round(item.distance / 1000) : ''
-								item.star = getStarNum(item.level)
-							})
-							this.storeList = this.storeList.concat(list)
-						} else {
-							if (this.pageNo != 1) {
-								uni.showToast({
-									title: '已经是最后一页'
-								})
-								this.isLastPage = true
 							}
 							}
-						}
+							item.distance = item.distance ? Math.round(item.distance / 1000) : ''
+						})
+						this.storeList = this.storeList.concat(list)
+						this.total = res.data.count || 0
+					} else {
+						this.storeList = []
+						this.total = 0
+						this.noDataText = res.message
 					}
 					}
-					uni.hideLoading()
 				})
 				})
 			},
 			},
 			// 获取网点营业状态
 			// 获取网点营业状态
@@ -167,7 +167,12 @@
 			},
 			},
 			// 到达底部
 			// 到达底部
 			reachBottom() {
 			reachBottom() {
-
+				if(this.storeList.length < this.total){
+					this.pageNo += 1
+					this.getStoresList()
+				}else{
+					this.status = "nomore"
+				}
 			}
 			}
 
 
 		}
 		}