Quellcode durchsuchen

说明:改支付方式

程志平 vor 5 Jahren
Ursprung
Commit
3533538f19
7 geänderte Dateien mit 183 neuen und 99 gelöschten Zeilen
  1. 1 1
      App.vue
  2. 0 3
      main.js
  3. 78 25
      pages/jiaofei/jiaofei.vue
  4. 6 3
      pages/reshui/reshui.vue
  5. 87 63
      pages/select/select.vue
  6. 5 4
      static/api.js
  7. 6 0
      store/index.js

+ 1 - 1
App.vue

@@ -11,7 +11,7 @@
 		},
 		globalData: {
 			primaryColor: '#1296db',
-			test: true  // 控制是否是测试环境
+			test: false  // 控制是否是测试环境
 		}
 	}
 </script>

+ 0 - 3
main.js

@@ -14,9 +14,6 @@ Vue.prototype.$getDate = getDate
 Vue.prototype.$getOrderId = getOrderId
 Vue.prototype.$store = store
 
-// import {common} from './static/common.js'
-// Vue.prototype.$request = common.axios
-
 Vue.config.productionTip = false
 
 App.mpType = 'app'

+ 78 - 25
pages/jiaofei/jiaofei.vue

@@ -65,7 +65,7 @@
 			return {
 				index: 0,
 				roomSelect: '', //房间号
-				remainElec: 80.10.toFixed(2), //剩余电量
+				remainElec: 0.00.toFixed(2), //剩余电量
 				add_class: '', //增加class属性
 				add_class1: '',
 				inputMoney: '', //手动输入增加金额
@@ -86,15 +86,9 @@
 			let item_tmp = decodeURIComponent(options.item)
 			//将字符串解密转换成对象
 			let item = JSON.parse(item_tmp);
-			// 如果是选择宿舍号返回
-			if (options.o == 'select') {
-				this.roomSelect = item.roomSelect;
-				this.add_class = 1;
-				this.dom = item.dom;
-				
-				// 请求选定的月份消费记录
-				this.request_consumption_records()
-			}
+
+			// 请求选定的月份消费记录
+			// this.request_consumption_records()
 			try {
 				// 获取存储的用户数据
 				const value = uni.getStorageSync('userinfo_storage_key')
@@ -107,6 +101,10 @@
 				}
 				// 如果是选择宿舍号返回
 				if (options.o == 'index') {
+					this.$store.state.building.roomSelect = '';
+					this.$store.state.building.add_class = 0;
+					this.$store.state.building.dom = '';
+
 					this.userinfo = item;
 					// 更新存储的用户信息
 					uni.setStorageSync('userinfo_storage_key', this.userinfo)
@@ -117,7 +115,7 @@
 				this.campus = this.userinfo.campus
 				this.dom = this.userinfo.dorm_number
 				this.sub_appid = this.userinfo.sub_appid
-				
+
 				this.add_class = 1
 			} catch (e) {
 				console.log(e)
@@ -126,12 +124,67 @@
 			//将缓存中的卡号进行获取
 			this.card_number = this.userinfo.card_number
 
-			// 获取应用有效凭证
-			this.get_valid_credentials()
+			if (this.$store.state.hasUserInfo == false) {
+				// 获取应用有效凭证
+				this.get_valid_credentials()
+			}
 		},
+		onShow() {
+			if (this.$store.state.building.roomSelect != '') {
+				// 如果是选择宿舍号返回
+				this.roomSelect = this.$store.state.building.roomSelect;
+				this.add_class = this.$store.state.building.add_class;
+				this.dom = this.$store.state.building.dom;
 
+				if (this.roomSelect != '') {
+					this.getDianLiang()
+				}
+			}
+		},
 		methods: {
 			/**
+			 * 取得电费额度
+			 */
+			async getDianLiang() {
+				let res;
+				if (this.test) { // 测试环境
+					res = await this.$myRequest({
+						host: 'ceshi',
+						url: 'http://tdqdjt.natappfree.cc/HotWaters/buildoverElec.action',
+						method: 'POST',
+						header: {
+							'content-type': 'application/x-www-form-urlencoded'
+						},
+						data: {
+							'roomSelect': this.roomSelect
+						}
+					})
+				} else {
+					res = await this.$myRequest({
+						host: 'code',
+						url: '/HotWater/buildoverElec.action',
+						method: 'POST',
+						header: {
+							'content-type': 'application/x-www-form-urlencoded'
+						},
+						data: {
+							'roomSelect': this.roomSelect
+						}
+					})
+				}
+				console.log(res.data.amount);
+				if (res.mess != '请选择房间号!') {
+					setTimeout(() => {
+						this.remainElec = res.data.amount.toFixed(2)
+					}, 300);
+				} else {
+					uni.showToast({
+						title: '获取电量失败!',
+						duration: 2000
+					})
+				}
+			},
+			/**
 			 * 获取应用有效凭证
 			 */
 			async get_valid_credentials() {
@@ -162,11 +215,11 @@
 						duration: 2000
 					})
 				}
-				
+
 				// 查询用户信息
 				this.select_user_info()
 			},
-			
+
 			/**
 			 * 查询用户信息
 			 */
@@ -182,11 +235,11 @@
 						card_number: this.userinfo.card_number
 					}
 				});
-			
+
 				// console.log(res, 'select_user_info');
 				if (res.data.info) {
 					let cnumber = this.userinfo.card_number
-			
+
 					if (cnumber == null || cnumber == undefined || cnumber == '') {
 						// 之前未绑定用户信息,现在去绑定用户信息
 						this.send_save_user_info()
@@ -198,14 +251,14 @@
 					})
 				}
 			},
-			
+
 			/**
 			 * 请求选定的月份消费记录
 			 */
 			async request_consumption_records() {
 				const userinfo = uni.getStorageInfoSync('userinfo_storage_key')
 				this.card_number = userinfo.card_number
-				
+
 				if (this.card_number != '') {
 					this.xiaofei_items = []
 					const res = await this.$myRequest({
@@ -220,7 +273,7 @@
 							begin_time: this.date
 						}
 					});
-			
+
 					// console.log(res.data.mess, 'request_consumption_records');
 					if (typeof(res.data.mess) != 'undefined') {
 						let items = res.data.mess
@@ -247,7 +300,7 @@
 					})
 				}
 			},
-			
+
 			/**
 			 * 绑定用户信息
 			 */
@@ -263,7 +316,7 @@
 						user: JSON.stringify(this.userinfo)
 					}
 				});
-			
+
 				// console.log('send_save_user_info:', res)
 				let error = res.data.erro;
 				if (error == '未获取到数据!') {
@@ -330,7 +383,7 @@
 						return
 					}
 
-					if (!this.test) {
+					if (!this.test) { // 非测试环境
 						if (this.inputMoney > 200 || this.inputMoney < 10) {
 							uni.showToast({
 								title: '限额10~200元',
@@ -436,7 +489,7 @@
 			 * 输入充值金额
 			 */
 			onInput(e) {
-				if (this.test) {
+				if (this.test) { // 测试环境
 					return
 				}
 
@@ -468,7 +521,7 @@
 			 * 失去焦点时
 			 */
 			onBlur() {
-				if (this.test) {
+				if (this.test) { // 测试环境
 					return
 				}
 

+ 6 - 3
pages/reshui/reshui.vue

@@ -157,8 +157,10 @@
 
 			this.card_number = this.userinfo.card_number; // 卡号
 
-			// 查询用户信息
-			this.select_user_info()
+			if (this.$store.state.hasUserInfo == '') {
+				// 查询用户信息
+				this.select_user_info()
+			}
 		},
 		onShow() {
 			if (this.$store.state.payInfo.from == 'reshui_pay') {
@@ -271,7 +273,8 @@
 						// 之前未绑定用户信息,现在去绑定用户信息
 						this.send_save_user_info()
 					}
-
+					
+					this.$store.state.hasUserInfo == true
 					// 请求选定的月份消费记录
 					this.request_consumption_records()
 				} else {

+ 87 - 63
pages/select/select.vue

@@ -1,6 +1,6 @@
 <template>
 	<view class="container">
-		<picker class="picker-item1" @change="changeSelect1" :range="array1" :value="index1">
+		<picker class="picker-item1" @change="changeSelect1" :range="array1" :value="index1" :disabled="dis_num1">
 			<view class="select-item">
 				<view class="picker-item-logol">
 					<image class="picker-item-logo-left" src="/static/image/school.png"></image>
@@ -80,13 +80,15 @@
 				add_class2: '',
 				add_class3: '',
 				add_class4: '',
-				dis_num2: 1, //选择器disable属性,是否禁用
+				dis_num1: 1, //选择器disable属性,是否禁用
+				dis_num2: 1,
 				dis_num3: 1,
 				dis_num4: 1,
 				options: '',
 				// dis_num5: 1,
 				allData: [], //所有数据
-				storage: {} //存放选择数据
+				storage: {}, //存放选择数据
+				test: getApp().globalData.test
 			}
 		},
 		onLoad(options) {
@@ -101,68 +103,88 @@
 			 * 请求楼栋、楼层、宿舍等信息
 			 */
 			async requestAllData() {
-				const res = await this.$myRequest({
-					host: 'ceshi',
-					url: 'http://5a69iw.natappfree.cc',
-					// method: 'POST',
-					header: {
-						'content-type': 'application/json'
-					}
-				})
-				
-				this.allData = res
-				this.nschool = res.data.length
-				this.array1 = []
-				
-				for (var i = 0; i < this.nschool; i++) {
-					this.array1.push(res.data[i].school)
-				}
-				// 拆分之前选好的楼栋和宿舍号
-				if (this.options.roomSelect != '') {
-					var str = this.options.roomSelect;
-					var arr = new Array();
-					var i = 0;
-					while (i < str.length) {
-						var tmp = str.charCodeAt(i)
-						var s = "";
-						while (str.charCodeAt(i) < 256) {
-							s = s + str.charAt(i);
-							i++;
+				uni.showLoading({
+					title: '数据加载中……',
+					mask: true
+				});
+				let res;
+				if (this.test) {
+					res = await this.$myRequest({
+						host: 'ceshi',
+						url: 'http://3ft7hs.natappfree.cc',
+						method: 'POST',
+						header: {
+							'content-type': 'application/json'
 						}
-						arr.push(s);
-						s = "";
-						while (str.charCodeAt(i) > 256) {
-							s = s + str.charAt(i);
-							i++;
+					})
+				} else {
+					res = await this.$myRequest({
+						host: 'code',
+						url: '/HotWater/buildelec.action',
+						method: 'POST',
+						header: {
+							'content-type': 'application/json'
 						}
-						arr.push(s);
+					})
+				}
+				if (typeof(res.data) != 'undefined') {
+					this.allData = res
+					this.nschool = res.data.length
+					this.array1 = []
+					
+					for (var i = 0; i < this.nschool; i++) {
+						this.array1.push(res.data[i].school)
 					}
-
-					// 自动填充
-					if (arr.length > 0) {
-						if (arr[1] != null && arr[1].length > 0) {
-							this.arr1 = [arr[1]]
+					
+					this.dis_num1 = 0
+					uni.hideLoading()
+					// 拆分之前选好的楼栋和宿舍号
+					if (this.options.roomSelect != '') {
+						var str = this.options.roomSelect;
+						var arr = new Array();
+						var i = 0;
+						while (i < str.length) {
+							var tmp = str.charCodeAt(i)
+							var s = "";
+							while (str.charCodeAt(i) < 256) {
+								s = s + str.charAt(i);
+								i++;
+							}
+							arr.push(s);
+							s = "";
+							while (str.charCodeAt(i) > 256) {
+								s = s + str.charAt(i);
+								i++;
+							}
+							arr.push(s);
 						}
-						let len = arr[2].length
-						if (arr[2] != null && len > 0) {
-							this.arr2 = [arr[2].substring(0, len - 3) + '栋']
-							this.arr3 = [arr[2].substring(len - 3, len - 2) + '层']
-							this.arr4 = [arr[2]]
+					
+						// 自动填充
+						if (arr.length > 0) {
+							if (arr[1] != null && arr[1].length > 0) {
+								this.arr1 = [arr[1]]
+							}
+							let len = arr[2].length
+							if (arr[2] != null && len > 0) {
+								this.arr2 = [arr[2].substring(0, len - 3) + '栋']
+								this.arr3 = [arr[2].substring(len - 3, len - 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_class2 = 1
+							this.add_class3 = 1
+							this.add_class4 = 1
+					
+							this.dis_num2 = 0
+							this.dis_num3 = 0
+							this.dis_num4 = 0
 						}
-
-						this.sel1(this.arr1)
-						this.sel2(this.arr2)
-						this.sel3(this.arr3)
-						this.sel4(this.arr4)
-
-						this.add_class1 = 1
-						this.add_class2 = 1
-						this.add_class3 = 1
-						this.add_class4 = 1
-
-						this.dis_num2 = 0
-						this.dis_num3 = 0
-						this.dis_num4 = 0
 					}
 				}
 			},
@@ -342,9 +364,11 @@
 				this.storage.roomSelect = roomSelect;
 				this.storage.dom = this.array4[this.index4];
 				if (this.room != '') {
-					uni.redirectTo({
-						url: '../jiaofei/jiaofei?o=select&item=' + encodeURIComponent(JSON.stringify(this
-							.storage)),
+					this.$store.state.building.roomSelect = this.storage.roomSelect;
+					this.$store.state.building.add_class = 1;
+					this.$store.state.building.dom = this.storage.dom;
+					uni.navigateBack({
+						delta: 1
 					})
 				} else {
 					uni.showToast({

+ 5 - 4
static/api.js

@@ -10,14 +10,15 @@ const myRequest = (options) => {
 	return new Promise((resolve, reject) => {
 		let BASE_URL = '';
 
-		if (options.host == 'wecard')
+		if (options.host == 'wecard') {
 			BASE_URL = WECARD_BASE_URL;
-		else if (options.host == 'code')
+		} else if (options.host == 'code') {
 			BASE_URL = CODE_BASE_URL;
-		else if (options.host == 'ceshi')
+		} else if (options.host == 'ceshi') {
 			BASE_URL = '';
-		else
+		} else {
 			return;
+		}
 
 		uni.request({
 			url: BASE_URL + options.url,

+ 6 - 0
store/index.js

@@ -8,6 +8,12 @@ const store = new Vuex.Store({
 			from: '',
 			resultCode: 666,
 			resultMsg: ''
+		},
+		hasUserInfo: false,
+		building: {
+			roomSelect: '',
+			add_class: 0,
+			dom: ''
 		}
 	},
 	mutations: {},