From 917252ef3ea2b63c74d162cc67a6fbe103cb9b4d Mon Sep 17 00:00:00 2001
From: zuoxiao <470321431@qq.com>
Date: 星期五, 25 十月 2024 14:06:09 +0800
Subject: [PATCH] 1.开关阀记录界面。2.虚拟卡充值相关。3.问题反馈相关
---
pages/home/home.js | 332 ++++++++++++++++++++++++++++++++++++++++--------------
1 files changed, 243 insertions(+), 89 deletions(-)
diff --git a/pages/home/home.js b/pages/home/home.js
index c9b92e3..cbba07e 100644
--- a/pages/home/home.js
+++ b/pages/home/home.js
@@ -4,6 +4,7 @@
get,
post
} = require('../../api/request.js');
+const app = getApp();
Page({
/**
@@ -15,8 +16,8 @@
myItem: {},
waterIntakeName: "",
image: "/images/ic_head_bg.jpg",
- userPhone: "000****0000",
- userName: "鏈煡",
+ userPhone: "鏈櫥褰�",
+ userName: "鐐瑰嚮鐧诲綍",
scrollViewHeight: 0,
listData: [],
isRefreshing: false,
@@ -28,13 +29,22 @@
},
errorDialogTitle: "鍏抽榾閿欒",
showForceConfirm: false, //鏄惁寮哄埗寮�闃�
- lastIntakeName: ""
+ lastIntakeName: "",
+ isLogin: false, //鏄惁宸茬粡鐧诲綍
},
openValve: function (e) {
- wx.navigateTo({
- url: '/pages/waterIntake/waterIntake',
- })
+ if (this.data.isLogin) {
+ wx.navigateTo({
+ url: '/pages/waterIntake/waterIntake',
+ })
+ } else {
+ wx.showToast({
+ title: '璇峰厛鐧诲綍',
+ icon: 'error'
+ })
+ }
+
},
calculateScrollViewHeight: function () {
wx.createSelectorQuery().selectAll('.list-item').boundingClientRect((rects) => {
@@ -45,15 +55,22 @@
}).exec();
},
startPullDownRefresh() {
- if (!this.data.isWXRefreshing) {
- var self = this;
- console.log(this.data.isRefreshing);
- this.setData({
- isRefreshing: true
- });
- this.getOpenList();
-
+ if(this.data.isLogin){
+ if (!this.data.isWXRefreshing) {
+ var self = this;
+ console.log(this.data.isRefreshing);
+ this.setData({
+ isRefreshing: true
+ });
+ this.getOpenList();
+ }
+ }else{
+ wx.showToast({
+ title: '璇峰厛鐧诲綍',
+ icon: 'error'
+ })
}
+
},
//鑾峰彇鐢ㄦ埛鏁版嵁
@@ -68,16 +85,10 @@
console.error('Failed to fetch data:', error);
});
},
-
-
-
/**
* 鐢熷懡鍛ㄦ湡鍑芥暟--鐩戝惉椤甸潰鍔犺浇
*/
onLoad(options) {
- //鍒ゆ柇鏈湴鏄惁淇濆瓨sessionId
-
-
// 浣跨敤 wx.nextTick 绛夊緟椤甸潰娓叉煋瀹屾垚
wx.nextTick(() => {
this.calculateScrollViewHeight();
@@ -92,37 +103,90 @@
})
this.getOpenList();
}
- this.initData();
+
},
/**
* 鐢熷懡鍛ㄦ湡鍑芥暟--鐩戝惉椤甸潰鍒濇娓叉煋瀹屾垚
*/
onReady() {
-
+ //鍒ゆ柇鏈湴鏄惁淇濆瓨sessionId
+ if (storage.isHasKeySync("sessionId")) {
+ const app = getApp();
+ storage.getItem('sessionId').then((data) => {
+ app.globalData.sessionId = data;
+ if (app.globalData.sessionId) {
+ this.getOpenList();
+ this.getUserDataBySession();
+ }
+ }).catch((err) => {});
+ storage.getItem('clientId').then((data) => {
+ app.globalData.clientId = data;
+ }).catch((err) => {});
+ } else {
+ //鏈湴娌℃湁缂撳瓨寰俊鐧诲綍
+ this.wxLogin();
+ }
},
-
- /**
- * 鐢熷懡鍛ㄦ湡鍑芥暟--鐩戝惉椤甸潰鏄剧ず
- */
- onShow() {
-
+ wxLogin() {
+ const that = this;
+ wx.login({
+ success: function (res) {
+ if (res.code) {
+ var code = res.code;
+ console.log(code);
+ // 灏哻ode鍙戦�佸埌鏈嶅姟鍣ㄨ幏鍙杘penid
+ that.codeLogin(code);
+ } else {
+ console.log('鐧诲綍澶辫触锛�' + res.errMsg);
+ }
+ }
+ });
},
+ //寰俊code鐧诲綍
+ codeLogin(codeData) {
+ wx.showLoading({
+ title: '姝e湪鐧诲綍璇风◢鍊�...', // 鍔犺浇鎻愮ず鏂囧瓧
+ mask: true // 鏄惁鏄剧ず閫忔槑钂欏眰锛岄槻姝㈣Е鎽哥┛閫忥紝榛樿涓� false
+ });
+ const data = {
+ code: codeData, //涓存椂鐧诲綍鍑瘉
+ };
+ post({
+ url: "wx/client/code_login",
+ data: data,
+ }).then(response => {
+ // 澶勭悊鎴愬姛鍝嶅簲
+ console.log('璇锋眰鎴愬姛:', response);
+ // 鍔犺浇瀹屾垚鍚庨殣钘忓姞杞藉姩鐢�
+ wx.hideLoading();
+ if (response.code === "0001") {
+ //鍋囧涓虹┖鍒欒烦杞埌缁戝畾鐣岄潰
+ if (response.content.client.clientId === "") {
+ wx.navigateTo({
+ url: '/pages/wxbind/wxbind'
+ })
+ } else {
+ //缂撳瓨鍦ㄦ湰鍦�
+ this.setData({
+ isLogin: true
+ })
+ getApp().globalData.sessionId = response.content.client.sessionId
+ storage.setItem("sessionId", response.content.client.sessionId)
+ getApp().globalData.clientId = response.content.client.clientId
+ storage.setItem("clientId", response.content.client.clientId)
+ this.initData();
+ }
+ } else {
- /**
- * 鐢熷懡鍛ㄦ湡鍑芥暟--鐩戝惉椤甸潰闅愯棌
- */
- onHide() {
-
+ }
+ }).catch(error => {
+ // 鍔犺浇瀹屾垚鍚庨殣钘忓姞杞藉姩鐢�
+ wx.hideLoading();
+ // 澶勭悊閿欒鍝嶅簲
+ console.error('璇锋眰澶辫触:', error);
+ });
},
-
- /**
- * 鐢熷懡鍛ㄦ湡鍑芥暟--鐩戝惉椤甸潰鍗歌浇
- */
- onUnload() {
-
- },
-
/**
* 椤甸潰鐩稿叧浜嬩欢澶勭悊鍑芥暟--鐩戝惉鐢ㄦ埛涓嬫媺鍔ㄤ綔
*/
@@ -137,49 +201,45 @@
// 鏁版嵁璇锋眰瀹屾垚鍚庯紝鍋滄涓嬫媺鍒锋柊鐨勫姩鐢�
this.getOpenList();
},
-
- /**
- * 椤甸潰涓婃媺瑙﹀簳浜嬩欢鐨勫鐞嗗嚱鏁�
- */
- onReachBottom() {
-
- },
-
- /**
- * 鐢ㄦ埛鐐瑰嚮鍙充笂瑙掑垎浜�
- */
- onShareAppMessage() {
-
- },
// 鍏呭��
recharge() {
- wx.navigateTo({
- url: '/pages/rechargeCard/rechargeCard',
- })
- // wx.showToast({
- // title: '鏆傛湭寮�鏀�',
- // icon: 'none'
- // })
+ if (this.data.isLogin) {
+ wx.navigateTo({
+ url: '/pages/rechargeCard/rechargeCard',
+ })
+ } else {
+ wx.showToast({
+ title: '璇峰厛鐧诲綍',
+ icon: 'error'
+ })
+ }
},
//寮�鍏抽榾璁板綍
openValveList() {
- wx.navigateTo({
- url: '/pages/valveList/valveList',
- })
- // wx.showToast({
- // title: '鏆傛湭寮�鏀�',
- // icon: 'none'
- // })
+ if (this.data.isLogin) {
+ wx.navigateTo({
+ url: '/pages/valveList/valveList',
+ })
+ } else {
+ wx.showToast({
+ title: '璇峰厛鐧诲綍',
+ icon: 'error'
+ })
+ }
+
},
//闂鍙嶉
feedBack() {
- // wx.showToast({
- // title: '鏆傛湭寮�鏀�',
- // icon: 'none'
- // })
- wx.navigateTo({
- url: '/pages/feedback/feedback',
- })
+ if (this.data.isLogin) {
+ wx.navigateTo({
+ url: '/pages/feedback/feedback',
+ })
+ } else {
+ wx.showToast({
+ title: '璇峰厛鐧诲綍',
+ icon: 'error'
+ })
+ }
},
handleChange(e) {
const item = e.currentTarget.dataset.item;
@@ -235,20 +295,20 @@
// 鍔犺浇瀹屾垚鍚庨殣钘忓姞杞藉姩鐢�
wx.hideLoading();
this.getOpenList();
- if(response.content.data.success){
+ if (response.content.data.success) {
wx.showToast({
title: '鍏抽榾鎴愬姛',
icon: 'success',
duration: 3000
})
- }else{
+ } else {
wx.showToast({
title: '鍏抽榾澶辫触',
icon: 'error',
duration: 3000
})
}
-
+
}).catch(error => {
wx.hideLoading();
this.setData({
@@ -277,6 +337,7 @@
isRefreshing: false, // 灏唗riggered灞炴�ц缃负false锛岃〃绀轰笅鎷夊埛鏂板凡瀹屾垚
isWXRefreshing: false, // 灏唗riggered灞炴�ц缃负false锛岃〃绀轰笅鎷夊埛鏂板凡瀹屾垚
})
+ this.updateDisplayText();
}).catch(err => {
// 閿欒鍥炶皟
this.setData({
@@ -312,7 +373,8 @@
get(params).then(data => {
this.setData({
userName: data.content.clientName,
- userPhone: this.maskPhoneNumber(data.content.phone)
+ userPhone: this.maskPhoneNumber(data.content.phone),
+ isLogin: true
})
}).catch(err => {
// 閿欒鍥炶皟
@@ -348,16 +410,13 @@
if (res.result.startsWith("content://")) {
let jsonStr = res.result.replace("content://", "")
try {
-
that.saveData(jsonStr)
} catch (error) {
console.error('Error parsing JSON:', error);
}
-
} else {
that.postOppenValva(res.result)
}
-
},
fail(err) {
console.error(err);
@@ -372,7 +431,7 @@
this.postOppenValva(this.data.lastIntakeName, true)
},
/**
- *
+ * 鎵爜寮�闃�璋冪敤寮�闃�鎺ュ彛
* @param {*} intakeName
*/
postOppenValva(intakeName, isforce) {
@@ -435,8 +494,7 @@
//杩涘叆鐣岄潰鑾峰彇鐣岄潰鏁版嵁
initData() {
const app = getApp();
- console.log("tag>>>>:" +app.globalData.tag)
-
+ console.log("tag>>>>:" + app.globalData.tag)
if (storage.isHasKeySync("userData")) {
storage.getItem('userData').then((data) => {
let jsonObj = JSON.parse(data);
@@ -453,9 +511,105 @@
this.getOpenList();
console.log('Failed to load parameter:false');
}
-
+
},
- onDelete(){
-
+ //寮哄埗鍒犻櫎
+ onDelete(e) {
+ const item = e.currentTarget.dataset.item;
+ const that = this;
+ wx.showLoading({
+ title: '姝e湪寮哄埗鍒犻櫎璇风◢鍊�...', // 鍔犺浇鎻愮ず鏂囧瓧
+ mask: true // 鏄惁鏄剧ず閫忔槑钂欏眰锛岄槻姝㈣Е鎽哥┛閫忥紝榛樿涓� false
+ });
+ that.setData({
+ lastIntakeName: intakeName
+ })
+ const data = {
+ vcNum: item.vcNum, //鍙栨按鍙D
+ rtuAddr: item.rtuAddr, //闃�鎺у櫒鍦板潃
+ };
+ post({
+ url: "wx/valve/deleteUnclosed",
+ data: data,
+ timeout: 180000
+ }).then(response => {
+ // 澶勭悊鎴愬姛鍝嶅簲
+ console.log('璇锋眰鎴愬姛:', response);
+ // 鍔犺浇瀹屾垚鍚庨殣钘忓姞杞藉姩鐢�
+ wx.hideLoading();
+ //閲嶆柊鑾峰彇鍒楄〃鍒锋柊鏁版嵁
+ this.getOpenList();
+ }).catch(error => {
+ // 鍔犺浇瀹屾垚鍚庨殣钘忓姞杞藉姩鐢�
+ wx.hideLoading();
+ // 澶勭悊閿欒鍝嶅簲
+ console.error('璇锋眰澶辫触:', error);
+ });
+ },
+ //淇敼鎸夐挳鏂囧瓧
+ updateDisplayText() {
+ const updatedList = this.data.listData.map(item => {
+ let displayText = '';
+ if (item.planned) {
+ displayText = '鍙栨秷';
+ } else {
+ displayText = "鍏抽榾"
+ }
+ return {
+ ...item,
+ displayText
+ }; // 淇濈暀鎵�鏈夊叾浠栧瓧娈碉紝骞舵坊鍔� displayText 瀛楁
+ });
+ // 鏇存柊鍒楄〃鏁版嵁
+ this.setData({
+ listData: updatedList
+ });
+ },
+ //瑙g粦
+ unbind() {
+ //娓呯┖鏁版嵁
+ this.setData({
+ userPhone: "璇风櫥褰�",
+ userName: "鏈櫥褰�",
+ listData: []
+ })
+ wx.showLoading({
+ title: '姝e湪瑙g粦璇风◢鍊�...', // 鍔犺浇鎻愮ず鏂囧瓧
+ mask: true // 鏄惁鏄剧ず閫忔槑钂欏眰锛岄槻姝㈣Е鎽哥┛閫忥紝榛樿涓� false
+ });
+ const data = {
+ sessionId: getApp().globalData.sessionId //鍙栨按鍙D
+ };
+ post({
+ url: 'wx/client/unbind',
+ data: data,
+ useParams: true
+ }).then(response => {
+ // 澶勭悊鎴愬姛鍝嶅簲
+ console.log('璇锋眰鎴愬姛:', response);
+ // 鍔犺浇瀹屾垚鍚庨殣钘忓姞杞藉姩鐢�
+ wx.hideLoading();
+ //娓呯┖鏁版嵁
+ this.setData({
+ userPhone: "璇风櫥褰�",
+ userName: "鏈櫥褰�",
+ listData: [],
+ isLogin:false
+ })
+ app.globalData.sessionId = "";
+ app.globalData.clientId = ""
+ storage.removeItem("sessionId")
+ storage.removeItem("clientId")
+ wx.showToast({
+ title: '瑙g粦鎴愬姛',
+ icon: 'success',
+ duration: 3000
+ })
+ }).catch(error => {
+ // 鍔犺浇瀹屾垚鍚庨殣钘忓姞杞藉姩鐢�
+ wx.hideLoading();
+ // 澶勭悊閿欒鍝嶅簲
+ console.error('璇锋眰澶辫触:', error);
+ });
}
})
\ No newline at end of file
--
Gitblit v1.8.0