Browse Source

优化体验:子页面传值给父页面,进行了优化,,提升了用户体验

程志平 5 years ago
parent
commit
80b4a80997
8 changed files with 159 additions and 117 deletions
  1. 2 0
      main.js
  2. 2 1
      pages/jiaofei/jiaofei.css
  3. 3 1
      pages/jiaofei/jiaofei.vue
  4. 46 35
      pages/recharge/recharge.vue
  5. 10 9
      pages/reshui/reshui.vue
  6. 76 68
      pages/select/select.vue
  7. 3 3
      static/api.js
  8. 17 0
      store/index.js

+ 2 - 0
main.js

@@ -1,5 +1,6 @@
 import Vue from 'vue'
 import Vue from 'vue'
 import App from './App'
 import App from './App'
+import store from 'store/index.js'
 import {
 import {
 	CODE_BASE_URL,
 	CODE_BASE_URL,
 	myRequest,
 	myRequest,
@@ -11,6 +12,7 @@ Vue.prototype.$myRequest = myRequest
 Vue.prototype.$code_base_url = CODE_BASE_URL
 Vue.prototype.$code_base_url = CODE_BASE_URL
 Vue.prototype.$getDate = getDate
 Vue.prototype.$getDate = getDate
 Vue.prototype.$getOrderId = getOrderId
 Vue.prototype.$getOrderId = getOrderId
+Vue.prototype.$store = store
 
 
 // import {common} from './static/common.js'
 // import {common} from './static/common.js'
 // Vue.prototype.$request = common.axios
 // Vue.prototype.$request = common.axios

+ 2 - 1
pages/jiaofei/jiaofei.css

@@ -129,7 +129,8 @@ page {
 
 
 .input-money{
 .input-money{
 	height: 139upx;
 	height: 139upx;
-	font-size: 30upx;
+	font-size: 48upx;
+	font-weight: bold;
 	color: #333333;
 	color: #333333;
 	margin-left: 29upx;
 	margin-left: 29upx;
 }
 }

+ 3 - 1
pages/jiaofei/jiaofei.vue

@@ -86,7 +86,6 @@
 			let item_tmp = decodeURIComponent(options.item)
 			let item_tmp = decodeURIComponent(options.item)
 			//将字符串解密转换成对象
 			//将字符串解密转换成对象
 			let item = JSON.parse(item_tmp);
 			let item = JSON.parse(item_tmp);
-			// console.log(options.o, item)
 			// 如果是选择宿舍号返回
 			// 如果是选择宿舍号返回
 			if (options.o == 'select') {
 			if (options.o == 'select') {
 				this.roomSelect = item.roomSelect;
 				this.roomSelect = item.roomSelect;
@@ -204,6 +203,9 @@
 			 * 请求选定的月份消费记录
 			 * 请求选定的月份消费记录
 			 */
 			 */
 			async request_consumption_records() {
 			async request_consumption_records() {
+				const userinfo = uni.getStorageInfoSync('userinfo_storage_key')
+				this.card_number = userinfo.card_number
+				
 				if (this.card_number != '') {
 				if (this.card_number != '') {
 					this.xiaofei_items = []
 					this.xiaofei_items = []
 					const res = await this.$myRequest({
 					const res = await this.$myRequest({

+ 46 - 35
pages/recharge/recharge.vue

@@ -119,24 +119,43 @@
 			 * 组合地址,发起支付
 			 * 组合地址,发起支付
 			 */
 			 */
 			async jsapi() {
 			async jsapi() {
-				const res = await this.$myRequest({
-					host: 'wecard',
-					url: '/cgi-bin/pay/app/mppay',
-					method: 'POST',
-					header: {
-						'content-type': 'application/json'
-					},
-					data: {
-						'access_token': this.access_token,
-						'sub_appid': this.sub_appid,
-						'user_id': this.card_number,
-						'order_id': this.order_id = this.$getOrderId('shuifei'),
-						'amount': this.amount * 100,
-						'order_type': 1,
-						// 'callback_url': 'http://wvwviw.natappfree.cc/HotWaters/wxpayrecharge.action'
-						'callback_url': this.$code_base_url + '/HotWater/wxpayrecharge.action'
-					}
-				})
+				if (this.test) { // 测试环境
+					const res = await this.$myRequest({
+						host: 'wecard',
+						url: '/cgi-bin/pay/app/mppay',
+						method: 'POST',
+						header: {
+							'content-type': 'application/json'
+						},
+						data: {
+							'access_token': this.access_token,
+							'sub_appid': this.sub_appid,
+							'user_id': this.card_number,
+							'order_id': this.order_id = this.$getOrderId('shuifei'),
+							'amount': this.amount * 100,
+							'order_type': 1,
+							'callback_url': 'http://wvwviw.natappfree.cc/HotWaters/wxpayrecharge.action'
+						}
+					})
+				} else {
+					const res = await this.$myRequest({
+						host: 'wecard',
+						url: '/cgi-bin/pay/app/mppay',
+						method: 'POST',
+						header: {
+							'content-type': 'application/json'
+						},
+						data: {
+							'access_token': this.access_token,
+							'sub_appid': this.sub_appid,
+							'user_id': this.card_number,
+							'order_id': this.order_id = this.$getOrderId('shuifei'),
+							'amount': this.amount * 100,
+							'order_type': 1,
+							'callback_url': this.$code_base_url + '/HotWater/wxpayrecharge.action'
+						}
+					})
+				}
 
 
 				this.pay_info = res.data.data.pay_info
 				this.pay_info = res.data.data.pay_info
 				// 发起支付
 				// 发起支付
@@ -145,7 +164,7 @@
 			// 调起支付
 			// 调起支付
 			pay_amount() {
 			pay_amount() {
 				var OpenMidas = require("@/static/openMidas.js") // 引入小程序目录下的SDK文件
 				var OpenMidas = require("@/static/openMidas.js") // 引入小程序目录下的SDK文件
-				if (this.test) { // 是否是测试环境
+				if (this.test) { // 测试环境
 					// 设置支付配置
 					// 设置支付配置
 					wx['OpenMidasConfig'] = {
 					wx['OpenMidasConfig'] = {
 						apiCommonConf: {
 						apiCommonConf: {
@@ -188,22 +207,13 @@
 						// console.log(innerCode); // 支付响应内部错误码
 						// console.log(innerCode); // 支付响应内部错误码
 						// console.log(resultMsg); // 支付响应说明
 						// console.log(resultMsg); // 支付响应说明
 						// console.log(appMetaData); // 自定义回调数据
 						// console.log(appMetaData); // 自定义回调数据
-
-						if (resultCode == 0) {
-							let pay_info_storage_key = {}
-							pay_info_storage_key.resultCode = resultCode
-							pay_info_storage_key.resultMsg = resultMsg
-							// 保存用户充值成功
-							uni.setStorageSync('pay_info_storage_key', pay_info_storage_key)
-							uni.navigateBack({
-								delta: 1
-							})
-						} else {
-							uni.showToast({
-								title: '支付异常',
-								icon: 'success'
-							})
-						}
+						
+						this.$store.state.payInfo.from = 'reshui_pay'
+						this.$store.state.payInfo.resultCode = resultCode
+						this.$store.state.payInfo.resultMsg = resultMsg
+						uni.navigateBack({
+							delta: 1
+						})
 					}
 					}
 					// },
 					// },
 					// appMetaData
 					// appMetaData
@@ -280,6 +290,7 @@
 
 
 					return
 					return
 				}
 				}
+				// 生产环境
 				if (this.amount < 10 || this.amount > 100) {
 				if (this.amount < 10 || this.amount > 100) {
 					uni.showToast({
 					uni.showToast({
 						icon: 'none',
 						icon: 'none',

+ 10 - 9
pages/reshui/reshui.vue

@@ -155,24 +155,25 @@
 				console.log(e)
 				console.log(e)
 			}
 			}
 
 
-			this.card_number = this.userinfo.card_number;  // 卡号
+			this.card_number = this.userinfo.card_number; // 卡号
 
 
 			// 查询用户信息
 			// 查询用户信息
 			this.select_user_info()
 			this.select_user_info()
 		},
 		},
 		onShow() {
 		onShow() {
-			try {
-				const pay_info = uni.getStorageSync('pay_info_storage_key')
-				if (pay_info && pay_info.resultCode == 0) {
+			if (this.$store.state.payInfo.from == 'reshui_pay') {
+				if (this.$store.state.payInfo.resultCode == 0) {
 					uni.showToast({
 					uni.showToast({
-						title: pay_info.resultMsg,
+						title: this.$store.state.payInfo.resultMsg,
+						icon: 'success'
+					})
+				} else {
+					uni.showToast({
+						title: this.$store.state.payInfo.resultMsg,
 						icon: 'success'
 						icon: 'success'
 					})
 					})
-					
-					uni.removeStorageSync('pay_info_storage_key')
 				}
 				}
-			} catch (e) {
-				console.log(e)
+				this.$store.state.payInfo.from = ''
 			}
 			}
 		},
 		},
 		methods: {
 		methods: {

+ 76 - 68
pages/select/select.vue

@@ -71,7 +71,7 @@
 				arr2: ['请选择楼栋'],
 				arr2: ['请选择楼栋'],
 				arr3: ['请选择楼层'],
 				arr3: ['请选择楼层'],
 				arr4: ['请选择房间'],
 				arr4: ['请选择房间'],
-				array1: ["黄家湖校区", "墨轩湖校区"], //选择器的值
+				array1: [], //选择器的值
 				array2: [],
 				array2: [],
 				array3: [],
 				array3: [],
 				array4: [],
 				array4: [],
@@ -83,92 +83,99 @@
 				dis_num2: 1, //选择器disable属性,是否禁用
 				dis_num2: 1, //选择器disable属性,是否禁用
 				dis_num3: 1,
 				dis_num3: 1,
 				dis_num4: 1,
 				dis_num4: 1,
+				options: '',
 				// dis_num5: 1,
 				// dis_num5: 1,
 				allData: [], //所有数据
 				allData: [], //所有数据
 				storage: {} //存放选择数据
 				storage: {} //存放选择数据
 			}
 			}
 		},
 		},
-
 		onLoad(options) {
 		onLoad(options) {
 			// console.log(options)
 			// console.log(options)
-			// 拆分楼栋和宿舍号
-			var str = 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);
-			}
-			// for (i = 0; i < arr.length; i++) {
-			// 	console.log(arr[i], i);
-			// }
+			this.options = options
+			// 请求校区、楼栋、层好、宿舍号等数据
 			this.requestAllData()
 			this.requestAllData()
-
-			// this.nschool = this.allData.data.length
-			
-			// 自动填充
-			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
-			}
 		},
 		},
 
 
 		methods: {
 		methods: {
+			/**
+			 * 请求楼栋、楼层、宿舍等信息
+			 */
 			async requestAllData() {
 			async requestAllData() {
 				const res = await this.$myRequest({
 				const res = await this.$myRequest({
-					host: 'code',
-					url: '',
+					host: 'ceshi',
+					url: 'http://5a69iw.natappfree.cc',
 					// method: 'POST',
 					// method: 'POST',
 					header: {
 					header: {
 						'content-type': 'application/json'
 						'content-type': 'application/json'
-					},
-					data: {
-						// 'access_token': this.access_token
 					}
 					}
 				})
 				})
 				
 				
-				console.log(res)
+				this.allData = res
+				this.nschool = res.data.length
+				this.array1 = []
 				
 				
-				// this.allData = res.data.data
+				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++;
+						}
+						arr.push(s);
+						s = "";
+						while (str.charCodeAt(i) > 256) {
+							s = s + str.charAt(i);
+							i++;
+						}
+						arr.push(s);
+					}
+
+					// 自动填充
+					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
+					}
+				}
 			},
 			},
+			/**
+			 * 选择校区
+			 */
 			changeSelect1(e) {
 			changeSelect1(e) {
 				this.sel1(e.detail.value)
 				this.sel1(e.detail.value)
 			},
 			},
 			// 根据参数的值选中
 			// 根据参数的值选中
 			sel1(index) {
 			sel1(index) {
 				// console.log(index)
 				// console.log(index)
+				// console.log(typeof(index))
 				this.arr1 = this.array1;
 				this.arr1 = this.array1;
 
 
 				//获取选择器1的值
 				//获取选择器1的值
@@ -203,7 +210,7 @@
 						this.index2 = 0
 						this.index2 = 0
 						this.index3 = 0
 						this.index3 = 0
 						this.index4 = 0
 						this.index4 = 0
-						
+
 						this.room = ''
 						this.room = ''
 					}
 					}
 				}
 				}
@@ -247,7 +254,7 @@
 						this.arr4 = ['请选择房间']
 						this.arr4 = ['请选择房间']
 						this.index3 = 0
 						this.index3 = 0
 						this.index4 = 0
 						this.index4 = 0
-						
+
 						this.room = ''
 						this.room = ''
 					}
 					}
 				}
 				}
@@ -261,6 +268,7 @@
 				this.sel3(e.detail.value)
 				this.sel3(e.detail.value)
 			},
 			},
 			sel3(index) {
 			sel3(index) {
+				// console.log(index)
 				this.arr3 = this.array3;
 				this.arr3 = this.array3;
 
 
 				for (var i = 0; i < this.floors; i++) {
 				for (var i = 0; i < this.floors; i++) {
@@ -288,7 +296,7 @@
 					if (typeof(index) == 'string') {
 					if (typeof(index) == 'string') {
 						this.arr4 = ['请选择房间']
 						this.arr4 = ['请选择房间']
 						this.index4 = 0
 						this.index4 = 0
-						
+
 						this.room = ''
 						this.room = ''
 					}
 					}
 				}
 				}
@@ -327,21 +335,21 @@
 				// console.log(this.array4[this.index4])
 				// console.log(this.array4[this.index4])
 				// console.log(this.room)
 				// console.log(this.room)
 			},
 			},
-			//跳转页面
+			//跳转缴费页面
 			navigateToIndex(e) {
 			navigateToIndex(e) {
 				// console.log(e)
 				// console.log(e)
 				var roomSelect = e.currentTarget.dataset.room;
 				var roomSelect = e.currentTarget.dataset.room;
 				this.storage.roomSelect = roomSelect;
 				this.storage.roomSelect = roomSelect;
 				this.storage.dom = this.array4[this.index4];
 				this.storage.dom = this.array4[this.index4];
-				// console.log(roomSelect)
 				if (this.room != '') {
 				if (this.room != '') {
 					uni.redirectTo({
 					uni.redirectTo({
-						url: '../jiaofei/jiaofei?o=select&item=' + encodeURIComponent(JSON.stringify(this.storage)),
+						url: '../jiaofei/jiaofei?o=select&item=' + encodeURIComponent(JSON.stringify(this
+							.storage)),
 					})
 					})
 				} else {
 				} else {
 					uni.showToast({
 					uni.showToast({
-						icon:'success',
-						title:'请选择'
+						icon: 'success',
+						title: '宿舍号不完整'
 					})
 					})
 				}
 				}
 			},
 			},

+ 3 - 3
static/api.js

@@ -14,6 +14,8 @@ const myRequest = (options) => {
 			BASE_URL = WECARD_BASE_URL;
 			BASE_URL = WECARD_BASE_URL;
 		else if (options.host == 'code')
 		else if (options.host == 'code')
 			BASE_URL = CODE_BASE_URL;
 			BASE_URL = CODE_BASE_URL;
+		else if (options.host == 'ceshi')
+			BASE_URL = '';
 		else
 		else
 			return;
 			return;
 
 
@@ -28,11 +30,9 @@ const myRequest = (options) => {
 					resolve(res)
 					resolve(res)
 				} else {
 				} else {
 					uni.showToast({
 					uni.showToast({
-						title: '非正常返回:' + res.statusCode,
+						title: '请求数据失败,状态码:' + res.statusCode,
 						icon: 'none'
 						icon: 'none'
 					})
 					})
-
-					resolve(res)
 				}
 				}
 			},
 			},
 			fail: (err) => {
 			fail: (err) => {

+ 17 - 0
store/index.js

@@ -0,0 +1,17 @@
+import Vue from "vue"
+import Vuex from "vuex"
+
+Vue.use(Vuex)
+const store = new Vuex.Store({
+	state: {
+		payInfo: {
+			from: '',
+			resultCode: 666,
+			resultMsg: ''
+		}
+	},
+	mutations: {},
+	actions: {}
+})
+
+export default store