Browse Source

测试水电支付功能都OK,有待与后台进行对接

程志平 5 years ago
parent
commit
b47453ce8c
5 changed files with 91 additions and 106 deletions
  1. 1 1
      App.vue
  2. 1 1
      pages/index/index.vue
  3. 72 87
      pages/jiaofei/jiaofei.vue
  4. 12 12
      pages/select/select.vue
  5. 5 5
      pages/show/show.vue

+ 1 - 1
App.vue

@@ -11,7 +11,7 @@
 		},
 		},
 		globalData: {
 		globalData: {
 			primaryColor: '#1296db',
 			primaryColor: '#1296db',
-			test: true
+			test: false
 		}
 		}
 	}
 	}
 </script>
 </script>

+ 1 - 1
pages/index/index.vue

@@ -10,7 +10,7 @@
 					<image src="../../static/images/shower2x.png" mode=""></image>
 					<image src="../../static/images/shower2x.png" mode=""></image>
 					<text>洗 浴</text>
 					<text>洗 浴</text>
 				</navigator>
 				</navigator>
-				<navigator :url="'/pages/jiaofei/jiaofei?item=' + encodeURIComponent(JSON.stringify(this.userinfo))"
+				<navigator :url="'/pages/jiaofei/jiaofei?o=index&item=' + encodeURIComponent(JSON.stringify(this.userinfo))"
 					open-type="redirect" class="menu_item">
 					open-type="redirect" class="menu_item">
 					<image src="../../static/images/recharge2x.png" mode=""></image>
 					<image src="../../static/images/recharge2x.png" mode=""></image>
 					<text>电费充值</text>
 					<text>电费充值</text>

+ 72 - 87
pages/jiaofei/jiaofei.vue

@@ -82,51 +82,40 @@
 			}
 			}
 		},
 		},
 		onLoad: function(options) {
 		onLoad: function(options) {
-			// console.log('item:' + options.item);
+			let item_tmp = decodeURIComponent(options.item)
+			//将字符串解密转换成对象
+			let item = JSON.parse(item_tmp);
+			// console.log(options.o, item)
+			// 如果是选择宿舍号返回
+			if (options.o == 'select') {
+				this.roomSelect = item.roomSelect;
+				this.add_class = 1;
+				this.dom = item.dom;
+			}
 			try {
 			try {
 				// 获取存储的用户数据
 				// 获取存储的用户数据
 				const value = uni.getStorageSync('userinfo_storage_key')
 				const value = uni.getStorageSync('userinfo_storage_key')
-				let item_tmp = decodeURIComponent(options.item)
-
-				//将字符串解密转换成对象
-				let item = JSON.parse(item_tmp);
 				// console.log(item)
 				// console.log(item)
 				if (item_tmp == '{}') { // 如果没有用户信息,返回首页
 				if (item_tmp == '{}') { // 如果没有用户信息,返回首页
 					uni.redirectTo({
 					uni.redirectTo({
 						url: '../index/index'
 						url: '../index/index'
-					});
-					return;
+					})
+					return
 				}
 				}
-
-				//判断item是否存在
-				if (item_tmp != '') {
-					//判断是哪个页面传入
-					if (typeof(item.roomSelect) != 'undefined') {
-						// this.item = item;
-						this.roomSelect = item.roomSelect;
-						this.add_class = 1;
-						this.dom = item.dom;
-						// console.log(this.roomSelect)
-					} else {
-						// 处理JSON字符串
-						// this.userinfo = options.item.replace(/"/g, "'");
-						this.userinfo = item;
-						// 更新存储的用户信息
-						uni.setStorageSync('userinfo_storage_key', this.userinfo)
-						// console.log(this.userinfo)
-						this.campus = this.userinfo.campus
-						this.dom = this.userinfo.dorm_number
-						this.sub_appid = this.userinfo.sub_appid
-						this.roomSelect = this.campus + this.dom
-						this.add_class = 1
-					}
+				// 如果是选择宿舍号返回
+				if (options.o == 'index') {
+					this.userinfo = item;
+					// 更新存储的用户信息
+					uni.setStorageSync('userinfo_storage_key', this.userinfo)
+					this.roomSelect = this.campus + this.dom
 				} else if (value != '') {
 				} else if (value != '') {
-					// 处理JSON字符串
-					// this.userinfo = value.replace(/"/g, "'");
 					this.userinfo = value;
 					this.userinfo = value;
 				}
 				}
-				// console.log(this.dom)
-				// console.log(this.campus)
+				this.campus = this.userinfo.campus
+				this.dom = this.userinfo.dorm_number
+				this.sub_appid = this.userinfo.sub_appid
+				
+				this.add_class = 1
 			} catch (e) {
 			} catch (e) {
 				console.log(e)
 				console.log(e)
 			}
 			}
@@ -139,13 +128,6 @@
 		},
 		},
 
 
 		methods: {
 		methods: {
-			//修改房间号
-			// changeSelect1(e) {
-			// 	console.log(e);
-			// this.index = e.detail.value;
-			// this.arr1 = this.array1;
-			// },
-
 			/**
 			/**
 			 * 获取应用有效凭证
 			 * 获取应用有效凭证
 			 */
 			 */
@@ -186,7 +168,7 @@
 				});
 				});
 			},
 			},
 
 
-			//跳转到显示页面
+			//跳转到台账页面
 			navigateToShow(e) {
 			navigateToShow(e) {
 				uni.navigateTo({
 				uni.navigateTo({
 					url: '../show/show?card_number=' + this.card_number,
 					url: '../show/show?card_number=' + this.card_number,
@@ -198,73 +180,74 @@
 				this.add_class1 = 0
 				this.add_class1 = 0
 				this.addMoney = e.currentTarget.dataset.item
 				this.addMoney = e.currentTarget.dataset.item
 
 
-				this.confirm_info()
+				this.confirm_room('add_money')
 			},
 			},
 
 
-			confirm_info(num_money) {
+			confirm_room(op) {
+				// 检查房间号
 				if (this.roomSelect == '') {
 				if (this.roomSelect == '') {
 					uni.showToast({
 					uni.showToast({
 						title: '请选择房间号',
 						title: '请选择房间号',
-						icon:'success'
+						icon: 'success'
 					})
 					})
-					
 					return
 					return
 				}
 				}
-				
+				// 输入金额进行充值
+				if (op == 'input_money') {
+					//判断输入是否为空或不是数字
+					if (this.inputMoney == '' || this.inputMoney == null) {
+						uni.showToast({
+							title: '请输入充值金额',
+							duration: 2000
+						})
+						return
+					}
+
+					if (isNaN(this.inputMoney)) {
+						uni.showToast({
+							title: '请输入数值',
+							duration: 2000
+						})
+						return
+					}
+
+					if (!this.test) {
+						if (this.inputMoney > 200 || this.inputMoney < 10) {
+							uni.showToast({
+								title: '限额10~200元',
+								duration: 2000
+							})
+							return
+						}
+					}
+
+					this.addMoney = this.inputMoney
+				}
+				// 确认充值对话框
+				this.confirm_dialog()
+			},
+			// 确认充值对话框
+			confirm_dialog() {
 				uni.showModal({
 				uni.showModal({
 					// title: '确定充值'+this.inputMoney+'元',
 					// title: '确定充值'+this.inputMoney+'元',
 					title: '确定充值' + this.addMoney + '元',
 					title: '确定充值' + this.addMoney + '元',
 					success: (res) => {
 					success: (res) => {
 						if (res.confirm) {
 						if (res.confirm) {
-							this.pay_money_start()
+							this.jsapi()
 						} else if (res.cancel) {
 						} else if (res.cancel) {
 							console.log('用户点击取消');
 							console.log('用户点击取消');
 						}
 						}
 					}
 					}
 				})
 				})
 			},
 			},
-
 			//增加可变金额
 			//增加可变金额
 			input_money(e) {
 			input_money(e) {
 				// console.log(e)
 				// console.log(e)
-				//判断输入是否为空或不是数字
-				if (this.inputMoney == '' || this.inputMoney == null) {
-					uni.showToast({
-						title: '请输入充值金额',
-						duration: 2000
-					})
-
-					return
-				}
-
-				if (isNaN(this.inputMoney)) {
-					uni.showToast({
-						title: '请输入数值',
-						duration: 2000
-					})
-
-					return
-				}
-				if (this.test) {
-
-				} else {
-					if (this.inputMoney > 200 || this.inputMoney < 10) {
-						uni.showToast({
-							title: '限额10~200元',
-							duration: 2000
-						})
-
-						return
-					}
-				}
-
-				this.addMoney = this.inputMoney
-
-				this.confirm_info()
+				this.confirm_room('input_money')
 			},
 			},
 
 
 			//准备支付
 			//准备支付
-			async pay_money_start() {
+			async jsapi() {
 				const res = await this.$myRequest({
 				const res = await this.$myRequest({
 					host: 'wecard',
 					host: 'wecard',
 					url: "/cgi-bin/pay/app/mppay",
 					url: "/cgi-bin/pay/app/mppay",
@@ -278,13 +261,15 @@
 						'user_id': this.card_number,
 						'user_id': this.card_number,
 						"order_id": this.order_id = get_order_id('dianfei'),
 						"order_id": this.order_id = get_order_id('dianfei'),
 						"amount": this.addMoney * 100,
 						"amount": this.addMoney * 100,
+						'order_type': 1,
+						'callback_url': ''
 					}
 					}
 				})
 				})
 
 
 				if (res.data.code == 0) {
 				if (res.data.code == 0) {
 					this.pay_info = res.data.data.pay_info
 					this.pay_info = res.data.data.pay_info
 					// 发起支付
 					// 发起支付
-					this.add_money_pay()
+					this.pay_amount()
 				} else {
 				} else {
 					uni.showToast({
 					uni.showToast({
 						icon: 'none',
 						icon: 'none',
@@ -294,8 +279,8 @@
 				}
 				}
 			},
 			},
 
 
-			//调起支付
-			add_money_pay() {
+			// 调起支付
+			pay_amount() {
 				var OpenMidas = require("@/static/openMidas.js"); // 引入小程序目录下的SDK文件
 				var OpenMidas = require("@/static/openMidas.js"); // 引入小程序目录下的SDK文件
 
 
 				// 设置支付配置
 				// 设置支付配置

+ 12 - 12
pages/select/select.vue

@@ -49,7 +49,7 @@
 			</view>
 			</view>
 		</picker>
 		</picker>
 		<view class="submit-item">
 		<view class="submit-item">
-			<button @tap="navigateToIndex" class="submit" :data-room='room' :disabled="dis_num5">完成</button>
+			<button @tap="navigateToIndex" class="submit" :data-room='room'>完成</button>
 		</view>
 		</view>
 	</view>
 	</view>
 </template>
 </template>
@@ -83,9 +83,9 @@
 				dis_num2: 1, //选择器disable属性,是否禁用
 				dis_num2: 1, //选择器disable属性,是否禁用
 				dis_num3: 1,
 				dis_num3: 1,
 				dis_num4: 1,
 				dis_num4: 1,
-				dis_num5: 1,
+				// dis_num5: 1,
 				allData: sortdata, //所有数据
 				allData: sortdata, //所有数据
-				storage: {}, //存放选择数据
+				storage: {} //存放选择数据
 			}
 			}
 		},
 		},
 
 
@@ -127,6 +127,11 @@
 					this.arr4 = [arr[2]]
 					this.arr4 = [arr[2]]
 				}
 				}
 
 
+				this.sel1(this.arr1)
+				this.sel2(this.arr2)
+				this.sel3(this.arr3)
+				this.sel4(this.arr4)
+
 				this.add_class1 = 1
 				this.add_class1 = 1
 				this.add_class2 = 1
 				this.add_class2 = 1
 				this.add_class3 = 1
 				this.add_class3 = 1
@@ -135,12 +140,7 @@
 				this.dis_num2 = 0
 				this.dis_num2 = 0
 				this.dis_num3 = 0
 				this.dis_num3 = 0
 				this.dis_num4 = 0
 				this.dis_num4 = 0
-				this.dis_num5 = 0
-
-				this.sel1(this.arr1)
-				this.sel2(this.arr2)
-				this.sel3(this.arr3)
-				this.sel4(this.arr4)
+				// this.dis_num5 = 0
 			}
 			}
 		},
 		},
 
 
@@ -302,7 +302,7 @@
 					// 	this.array4[this.index4]);
 					// 	this.array4[this.index4]);
 				}
 				}
 				this.room = this.room.concat(this.array1[this.index1], this.array4[this.index4]);
 				this.room = this.room.concat(this.array1[this.index1], this.array4[this.index4]);
-				this.dis_num5 = 0;
+				// this.dis_num5 = 0;
 				// console.log(this.array1[this.index1])
 				// console.log(this.array1[this.index1])
 				// console.log(this.array2[this.index2])
 				// console.log(this.array2[this.index2])
 				// console.log(this.array3[this.index3])
 				// console.log(this.array3[this.index3])
@@ -317,8 +317,8 @@
 				this.storage.dom = this.array4[this.index4];
 				this.storage.dom = this.array4[this.index4];
 				// console.log(roomSelect)
 				// console.log(roomSelect)
 				if (this.room != '') {
 				if (this.room != '') {
-					uni.navigateTo({
-						url: '../jiaofei/jiaofei?item=' + encodeURIComponent(JSON.stringify(this.storage)),
+					uni.redirectTo({
+						url: '../jiaofei/jiaofei?o=select&item=' + encodeURIComponent(JSON.stringify(this.storage)),
 					})
 					})
 				} else {
 				} else {
 					uni.showToast({
 					uni.showToast({

+ 5 - 5
pages/show/show.vue

@@ -99,11 +99,11 @@
 		let month = date.getMonth() + 1;
 		let month = date.getMonth() + 1;
 		// let day = date.getDate();
 		// let day = date.getDate();
 	
 	
-		// if (type === 'start_date') {
-		// 	year = year - 4;
-		// } else if (type === 'end_date') {
-		// 	year = year;
-		// }
+		if (type === 'start_date') {
+			year = year - 4;
+		} else if (type === 'end_date') {
+			year = year;
+		}
 	
 	
 		month = month > 9 ? month : '0' + month;
 		month = month > 9 ? month : '0' + month;
 		// day = day > 9 ? day : '0' + day;
 		// day = day > 9 ? day : '0' + day;