Explorar o código

1.完成历史咨询上拉分页功能
2.调试获取充值列表接口
3.调试充值接口
4.修改首页异步逻辑
5.优化个人信息页面

306132416@qq.com %!s(int64=6) %!d(string=hai) anos
pai
achega
3b5ceccace
Modificáronse 4 ficheiros con 188 adicións e 53 borrados
  1. 5 5
      App.vue
  2. 75 16
      pages/index/index.vue
  3. 87 18
      pages/selfInfo/payList/payList.vue
  4. 21 14
      pages/selfInfo/selfInfo.vue

+ 5 - 5
App.vue

@@ -20,11 +20,11 @@
 		onLaunch: function() {
 			console.log('App Launch')
 			// 用户登录状态判断
-			uni.login({
-				success: (res) => {
-			        this.getCodeRabot(res)
-				}
-			});
+			// uni.login({
+			// 	success: (res) => {
+			//         this.getCodeRabot(res)
+			// 	}
+			// });
 		},
 		onShow: function() {
 			console.log('App Show')

+ 75 - 16
pages/index/index.vue

@@ -2,7 +2,7 @@
 	<view class="content">
 		<navigation-custom :config="config" :scrollTop="scrollTopNav" @customConduct="customConduct" :scrollMaxHeight="scrollMaxHeight" />
 		<scroll-view id="scrollview" class='chat-box' :style="{height: style.contentViewHeight + 'px'}" scroll-y="true"
-		 :scroll-with-animation="true" :scroll-top="scrollTop">
+		 :scroll-with-animation="false" :scroll-top="scrollTop" @scrolltoupper="lower()">
 			<view class="tips-box">
 				{{nowTime}}
 			</view>
@@ -12,7 +12,7 @@
 
 			<view class="talk-box">
 				<view class="talk-head-box">
-					<image src="../../static/logo.png" mode="" class="talk-head"></image>
+					<image src="../../static/logo.png" mode="" class="talk-head"></image> 
 				</view>
 				<view class="talk-content">您好,智能顾投很高兴为您服务!</view>
 			</view>
@@ -45,6 +45,7 @@
 <script>
 	import navigationCustom from "../../components/struggler-navigationCustom/navigation-custom";
 	var md5 = require("../../common/md5.js");
+	var page = 1;
 	export default {
 		data() {
 			return {
@@ -69,6 +70,8 @@
 				scrollTopNav: 0, // 当linear为true的时候需要通过onpagescroll传递参数
 				scrollMaxHeight: 200 ,//滑动的高度限制,超过这个高度即背景全部显示
 				scrollTop:0,
+				scrollRequestEnable: true, 
+				pageSize:10,
 				style: {
 					pageHeight: 0,
 					contentViewHeight: 0,
@@ -84,15 +87,48 @@
 			this.scrollTopNav = e.scrollTop;
 		},
 		onLoad() {
+			this.userLogin();
 			this.getEquipmentHeight();
-			setTimeout(()=>{
-		     this.getHistory();	
-		    },100)
 		},
 		onShow() {
 			this.getNowTime();
 		},
 		methods: {
+			userLogin(){
+				uni.login({
+					success: (res) => {
+				        this.getCodeRabot(res)
+					}
+				});
+			},
+			getCodeRabot(res){
+				let that = this;
+				uni.request({
+					url:getApp().globalData.shareUrl, //需要设置为全局
+					method: 'POST',
+					header: {
+						'content-type': 'application/x-www-form-urlencoded'
+					},
+					data: {
+						method: 'login',
+						timestamp: getApp().globalData.globalTimestamp, //Date.now()
+						code: res.code,
+						sign: md5('login' + getApp().globalData.globalTimestamp),
+						// invited:'invited'
+					},
+					success: res => {
+						// 通过openid发起会员登录
+						 getApp().globalData.user_id = res.data.msg.id;
+						 getApp().globalData.open_id = res.data.msg.openid;
+						 getApp().globalData.isAuth = res.data.msg.isauth === '0';
+						 getApp().globalData.user_name = res.data.msg.name;
+						 getApp().globalData.user_headUrl = res.data.msg.headimg;
+						 getApp().globalData.times = res.data.msg.times;
+						 getApp().globalData.total_times = res.data.msg.total_times;
+						 that.getHistory();	
+					} 
+				});
+			},
 			getNowTime() {
 				let time = new Date();
 				let y = time.getFullYear();
@@ -109,7 +145,6 @@
 				getApp().globalData.glbalHeight = this.nowHeight;
 				this.style.pageHeight = height;
 				this.style.contentViewHeight = height - uni.getSystemInfoSync().screenWidth / 750 * (100) - 70; //像素   因为给出的是像素高度 然后我们用的是upx  所以换算一下 
-			   
 			},
 			scrollToBottom() {
 				let that = this;
@@ -139,18 +174,29 @@
 							data: {
 								method: 'question_list',
 								timestamp: getApp().globalData.globalTimestamp, //Date.now()
-								uid: getApp().globalData.user_id || '1',
+								uid: getApp().globalData.user_id,
 								sign: md5('question_list' + getApp().globalData.globalTimestamp),
-								page: 1,
+								page: page || 1,
 								pageSize: 10,
 							},
 							success: res => {
-								that.talkList = (res.data.msg).reverse();
 								that.userHeadUrl = getApp().globalData.user_headUrl;
-								setTimeout(()=>{
-									that.scrollToBottom()	
-								},100)
-								
+								if(page === 1){
+									that.scrollRequestEnable = true;
+									that.talkList  = ((res.data.msg).reverse());
+									console.log(1,that.talkList)
+									setTimeout(()=>{
+										that.scrollToBottom()	
+									},100)
+								}else if (page > 1 && res.data.msg.length === that.pageSize) {
+										that.scrollRequestEnable = true;
+										that.talkList.unshift(...((res.data.msg).reverse()));
+								}else if (page > 1 && (res.data.msg.length > 0) && (res.data.msg.length < that.pageSize)){
+										that.scrollRequestEnable = true;
+										that.talkList.unshift(...((res.data.msg).reverse()));
+								}else if (page > 1 && res.data.msg.length == 0){
+									    that.scrollRequestEnable = false;
+								}
 							}
 						});
 					},
@@ -159,7 +205,7 @@
 							url: '../selfInfo/selfInfo'
 						})
 					},
-					sendMsgRequest(msg) {
+			sendMsgRequest(msg) {
 						let that = this;
 						uni.request({
 							url: getApp().globalData.shareUrl, //需要设置为全局
@@ -176,7 +222,7 @@
 							},
 							success: res => {
 								this.inputInfo = '';
-								that.getHistory()
+								that.getHistory();
 							}
 						});
 					},
@@ -187,9 +233,22 @@
 								icon: 'none'
 							});
 						} else {
+							page = 1;
 							this.sendMsgRequest(this.inputInfo)
 						}
-					}
+					},
+			// 滚动至底部触发的事件
+			lower() {
+				if (this.scrollRequestEnable) {
+					// 允许滚动时,触底page加一,重新请求数据
+					page++;
+					this.getHistory();
+				} else {
+					// 不允许滚动时,只显示"到底了"提示
+					// this.showBottem = true
+					console.log('noData')
+				}
+			},		
 			},
 		}
 </script>

+ 87 - 18
pages/selfInfo/payList/payList.vue

@@ -7,10 +7,10 @@
 				<text>购买查询次数</text>
 			</view>
 			
-			<view class="pay-content" :class="{'border-select':selectId === search.searchId}"
-			 v-for="search in searchList" :key='search.searchId' @click="selectPackage(search)">
-				 <view style="margin-left: 3%;">可查询次数 {{search.searchCount}}</view>
-				 <view style="margin-right: 5%;">¥ {{search.searchMoney}}</view>
+			<view class="pay-content" :class="{'border-select':selectId === search.id}"
+			 v-for="search in searchList" :key='search.id' @click="selectPackage(search)">
+				 <view style="margin-left: 3%;">可查询次数 {{search.times}}</view>
+				 <view style="margin-right: 5%;">¥ {{search.money}}</view>
 			</view>						
 		</view>
 		
@@ -22,7 +22,8 @@
 	</view>
 </template>
 
-<script>
+<script>
+	var md5 = require("../../../common/md5.js");
 	export default {
 		data() {
 			return { 
@@ -31,26 +32,94 @@
 				packageMoney:'',
 				searchList:[
 					{
-						searchCount:'100',
-						searchMoney:'10',
-						searchId:'A1',	
+						times:'100',
+						money:'10',
+						id:'1',	
 					},
 					{
-						searchCount:'200',
-						searchMoney:'20',
-						searchId:'A2',	
+						times:'200',
+						money:'20',
+						id:'2',	
 					},{
-						searchCount:'300',
-						searchMoney:'30',
-						searchId:'A3',	
+						times:'300',
+						money:'30',
+						id:'3',	
 					},
 				],
 			}
+		},
+		onLoad() {
+			this.getPayListRequest()
 		},
-		methods: {
+		methods: {
+			getPayListRequest(){
+				let that = this;
+				uni.request({
+					url: getApp().globalData.shareUrl, //需要设置为全局
+					method: 'POST',
+					header: {
+						'content-type': 'application/x-www-form-urlencoded'
+					},
+					data: {
+						method: 'charge_rule_list',
+						timestamp: getApp().globalData.globalTimestamp, //Date.now()
+						uid: getApp().globalData.user_id,
+						sign: md5('charge_rule_list' + getApp().globalData.globalTimestamp),
+					},
+					success: res => {
+						that.searchList = res.data.msg
+					}
+				});
+			},
 			selectPackage(param){
-				this.selectId  = param.searchId;
-				this.packageMoney = param.searchMoney + '元';
+				this.selectId  = param.id;
+				this.packageMoney = param.money + '元';
+			},
+			rechargeNext(obj){
+				let that = this;
+				uni.requestPayment({
+				    // provider: 'wxpay',
+				    timeStamp: obj.timeStamp,
+				    nonceStr: obj.nonceStr,
+				    package: obj.package,
+				    signType:obj.signType,
+				    paySign:obj.paySign,
+				    success: function (res) {
+						console.log(res)
+						uni.showToast({
+							title: '支付成功',
+							icon:'none'
+						});
+				    },
+				    fail: function (err) {
+				        console.log('支付失败:' + JSON.stringify(err));
+				    }
+				});
+			},
+			payPackage(){
+				let that = this;
+				uni.request({
+					url:getApp().globalData.shareUrl, //需要设置为全局
+					method: 'POST',
+					header:{'content-type': 'application/x-www-form-urlencoded'},
+					data: {
+						method:'charge',
+						timestamp:getApp().globalData.globalTimestamp,   //Date.now()
+						sign:md5('charge'+getApp().globalData.globalTimestamp),
+						rule_id:that.selectId,//充值对应的id
+						uid:getApp().globalData.user_id
+					},
+					success: res => {
+						if(res.data.code === 200){
+							console.log(res.data)
+							that.rechargeNext(res.data.msg)
+						}
+					},
+					fail: err => {
+						console.log(err)
+					},
+					complete: () => {}
+				});
 			}
 		}
 	}
@@ -68,7 +137,7 @@
 	 
 	 .pay-list-box {
 		 width: 95%;
-		 min-height:400upx;
+		/* min-height:400upx; */
 		 background: #fff;
 		 margin-top: 3%;
 		 border-radius: 10rpx;

+ 21 - 14
pages/selfInfo/selfInfo.vue

@@ -8,12 +8,12 @@
 		<button class="login-button-pos" v-if="isShowAuthBtn" open-type="getUserInfo" @getuserinfo="getUserInfo">未登录,请点击授权</button>
 		<view class="self-search-box">
 			<view class="search-content">
-				<view class="search-content-value">160</view>
+				<view class="search-content-value">{{userTime}}</view>
 				<view class="search-content-text">剩余查询次数(次)</view>
 			</view>
 			<view class="line"></view>
 			<view class="search-content">
-				<view class="search-content-value">300</view>
+				<view class="search-content-value">{{userTotalTime}}</view>
 				<view class="search-content-text">总查询次数(次)</view>
 			</view>
 		</view>
@@ -63,24 +63,32 @@
 				isShowAuthBtn:getApp().globalData.isAuth,
 				userName:getApp().globalData.user_name || '芝麻开发',
 				userHeadUrl:getApp().globalData.user_headUrl || '../../static/logo.png',
+				userTime:getApp().globalData.times,
+				userTotalTime:getApp().globalData.total_times
 			}
 		},
 		onLoad() {
 		},
+		onShow(){
+			this.loginUserInfo();
+		},
 		methods: {
 			// 获取用户信息
 			getUserInfo(e) {
 				if (e.detail.errMsg == "getUserInfo:ok") {
 					this.userHeadUrl = e.detail.userInfo.avatarUrl;
 					this.userName = e.detail.userInfo.nickName;
+					getApp().globalData.user_name =e.detail.userInfo.nickName;
+					getApp().globalData.user_headUrl = e.detail.userInfo.avatarUrl;
 					this.isShowAuthBtn = false;
-					this.loginUserInfo(e.detail.userInfo)
+					this.loginUserInfo()
 				} else {
 					console.log("用户信息授权失败");
 					this.isShowAuthBtn = true;
 				}
 			},
-			loginUserInfo(info){
+			loginUserInfo(){
+				let that = this;
 				uni.request({
 					url:getApp().globalData.shareUrl, //需要设置为全局
 					method: 'POST',
@@ -92,22 +100,21 @@
 						timestamp: getApp().globalData.globalTimestamp, //Date.now()
 						uid:getApp().globalData.user_id,
 						sign: md5('auth' + getApp().globalData.globalTimestamp),
-						nickname:info.nickName,
-						headimg:info.avatarUrl
+						nickname:getApp().globalData.user_name,
+						headimg:getApp().globalData.user_headUrl
 					},
 					success: res => {
-						 getApp().globalData.user_name = res.data.msg.name;
-						 getApp().globalData.user_headUrl = res.data.msg.headimg;
+						 that.userTime = res.data.msg.times;
+						 that.userTotalTime = res.data.msg.total_times;
+						 getApp().globalData.times = res.data.msg.times;
+						 getApp().globalData.total_times = res.data.msg.total_times;
 					} 
 				});
 			},
 			goMyAskPage(){
-				uni.navigateTo({
-					url: '../index/index',
-					success: res => {},
-					fail: () => {},
-					complete: () => {}
-				});
+				uni.navigateBack({
+					delta:0
+				})
 			},
 			goRechargePage(){
 				uni.navigateTo({