From 69cf2b1ed059b8eed4740ba76d73bf4c195c1775 Mon Sep 17 00:00:00 2001 From: zuoxiao <470321431@qq.com> Date: 星期三, 08 一月 2025 14:10:59 +0800 Subject: [PATCH] 添加虚拟卡时添加二次确认 --- pages/home/home.js | 270 +++++++++++++++++++++++++++++++++++++----------------- 1 files changed, 185 insertions(+), 85 deletions(-) diff --git a/pages/home/home.js b/pages/home/home.js index cbba07e..b20556c 100644 --- a/pages/home/home.js +++ b/pages/home/home.js @@ -31,6 +31,10 @@ showForceConfirm: false, //鏄惁寮哄埗寮�闃� lastIntakeName: "", isLogin: false, //鏄惁宸茬粡鐧诲綍 + showInfoDialog: false, + showTipDialog: false, + options: '', + showUnBind: false }, openValve: function (e) { @@ -44,7 +48,6 @@ icon: 'error' }) } - }, calculateScrollViewHeight: function () { wx.createSelectorQuery().selectAll('.list-item').boundingClientRect((rects) => { @@ -55,7 +58,7 @@ }).exec(); }, startPullDownRefresh() { - if(this.data.isLogin){ + if (this.data.isLogin) { if (!this.data.isWXRefreshing) { var self = this; console.log(this.data.isRefreshing); @@ -64,14 +67,12 @@ }); this.getOpenList(); } - }else{ + } else { wx.showToast({ title: '璇峰厛鐧诲綍', icon: 'error' }) } - - }, //鑾峰彇鐢ㄦ埛鏁版嵁 getUserData() { @@ -89,19 +90,13 @@ * 鐢熷懡鍛ㄦ湡鍑芥暟--鐩戝惉椤甸潰鍔犺浇 */ onLoad(options) { - // 浣跨敤 wx.nextTick 绛夊緟椤甸潰娓叉煋瀹屾垚 - wx.nextTick(() => { - this.calculateScrollViewHeight(); - }); //褰撳紑闃�鎴愬姛鍚庤皟鐢ㄥ埛鏂� console.log("onLoad锛�" + options.param); - if (options.param) { - wx.showToast({ - title: '寮�闃�鎴愬姛', - icon: 'success', - duration: 3000 + if (options.param === "1" || options.param === "2") { + this.setData({ + options: options, + isLogin: true, }) - this.getOpenList(); } }, @@ -115,33 +110,55 @@ const app = getApp(); storage.getItem('sessionId').then((data) => { app.globalData.sessionId = data; + this.setData({ + isLogin: true + }) if (app.globalData.sessionId) { - this.getOpenList(); this.getUserDataBySession(); } }).catch((err) => {}); storage.getItem('clientId').then((data) => { app.globalData.clientId = data; + this.getOpenList(); }).catch((err) => {}); } else { //鏈湴娌℃湁缂撳瓨寰俊鐧诲綍 this.wxLogin(); } + if (this.data.options.param === "1") { + this.setData({ + showTipDialog: true, + tipData: "寮�闃�鍛戒护涓嬪彂鎴愬姛锛屽洜寮�闃�闇�瑕佹椂闂达紝绾�20-60绉掑悗鍙埛鏂板揩閫熷叧闃�鍒楄〃鏌ョ湅鎵ц缁撴灉銆�" + }) + setTimeout(() => { + this.getOpenList(); + }, 20000) + + } else if (this.data.options.param === "2") { + this.setData({ + showTipDialog: true, + tipData: "棰勭害寮�闃�鍛戒护涓嬪彂鎴愬姛锛屽綋鍒拌揪棰勭害鏃堕棿骞朵笖鎴愬姛寮�闃�鍚庡揩閫熷叧闃�鍒楄〃浼氭樉绀烘湭鍏抽榾璁板綍" + }) + this.getOpenList(); + } }, 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); + // if (!this.data.isLogin) { + 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) { @@ -255,13 +272,16 @@ this.setData({ showConfirm: false, showErrorDialog: false, - showForceConfirm: false + showForceConfirm: false, + showTipDialog: false }); }, cancelDialog() { this.setData({ showForceConfirm: false, - showConfirm: false + showConfirm: false, + showTipDialog: false, + showUnBind: false }); }, /** @@ -296,14 +316,17 @@ wx.hideLoading(); this.getOpenList(); if (response.content.data.success) { - wx.showToast({ - title: '鍏抽榾鎴愬姛', - icon: 'success', - duration: 3000 + this.setData({ + isLogin: true, + showTipDialog: true, + tipData: "鍏抽榾鍛戒护涓嬪彂鎴愬姛锛岀害20-60绉掑悗鍙埛鏂板揩閫熷叧闃�鍒楄〃鏌ョ湅鎵ц缁撴灉銆�" }) + setTimeout(() => { + this.getOpenList(); + }, 40000) } else { wx.showToast({ - title: '鍏抽榾澶辫触', + title: '鍛戒护鎵ц澶辫触', icon: 'error', duration: 3000 }) @@ -324,32 +347,44 @@ * 鑾峰彇涓哄叧闃�璁板綍 */ getOpenList() { - const app = getApp(); - const params = { - url: 'wx/valve/get', - data: { - operator: app.globalData.sessionId - } - }; - get(params).then(data => { - this.setData({ - listData: data.content, - isRefreshing: false, // 灏唗riggered灞炴�ц缃负false锛岃〃绀轰笅鎷夊埛鏂板凡瀹屾垚 - isWXRefreshing: false, // 灏唗riggered灞炴�ц缃负false锛岃〃绀轰笅鎷夊埛鏂板凡瀹屾垚 - }) - this.updateDisplayText(); - }).catch(err => { - // 閿欒鍥炶皟 - this.setData({ - isRefreshing: false, // 灏唗riggered灞炴�ц缃负false锛岃〃绀轰笅鎷夊埛鏂板凡瀹屾垚 - isWXRefreshing: false, // 灏唗riggered灞炴�ц缃负false锛岃〃绀轰笅鎷夊埛鏂板凡瀹屾垚 - }) + if (this.data.isLogin) { + const app = getApp(); + const params = { + url: 'wx/valve/get', + data: { + operator: app.globalData.clientId + } + }; + get(params).then(data => { + this.setData({ + listData: data.content, + isRefreshing: false, // 灏唗riggered灞炴�ц缃负false锛岃〃绀轰笅鎷夊埛鏂板凡瀹屾垚 + isWXRefreshing: false, // 灏唗riggered灞炴�ц缃负false锛岃〃绀轰笅鎷夊埛鏂板凡瀹屾垚 + }) + this.updateDisplayText(); + }).catch(err => { + // 閿欒鍥炶皟 + this.setData({ + isRefreshing: false, // 灏唗riggered灞炴�ц缃负false锛岃〃绀轰笅鎷夊埛鏂板凡瀹屾垚 + isWXRefreshing: false, // 灏唗riggered灞炴�ц缃负false锛岃〃绀轰笅鎷夊埛鏂板凡瀹屾垚 + }) + wx.showToast({ + title: err.msg, + icon: 'error', + duration: 3000 + }) + }); + } else { wx.showToast({ - title: err.msg, - icon: 'error', - duration: 3000 + title: '璇峰厛鐧诲綍', + icon: 'error' }) - }); + this.setData({ + isRefreshing: false, // 灏唗riggered灞炴�ц缃负false锛岃〃绀轰笅鎷夊埛鏂板凡瀹屾垚 + isWXRefreshing: false, // 灏唗riggered灞炴�ц缃负false锛岃〃绀轰笅鎷夊埛鏂板凡瀹屾垚 + }) + } + }, /** * 纭鍏抽棴鍥炶皟 @@ -403,25 +438,36 @@ * 鎵爜寮�闃� */ scenCode() { - const that = this; - wx.scanCode({ - success(res) { - console.log(res.result); // 褰撲笖浠呭綋鎵爜涓洪潪寰俊浜岀淮鐮佹椂锛屼細杩斿洖result - if (res.result.startsWith("content://")) { - let jsonStr = res.result.replace("content://", "") - try { - that.saveData(jsonStr) - } catch (error) { - console.error('Error parsing JSON:', error); + if (this.data.isLogin) { + const that = this; + wx.scanCode({ + success(res) { + console.log(res.result); // 褰撲笖浠呭綋鎵爜涓洪潪寰俊浜岀淮鐮佹椂锛屼細杩斿洖result + if (res.result.startsWith("content://")) { + let jsonStr = res.result.replace("content://", "") + try { + that.saveData(jsonStr) + } catch (error) { + console.error('Error parsing JSON:', error); + } + } else { + wx.navigateTo({ + url: '/pages/openCard/openCard?intakeName=' + res.result, + }) + // that.postOppenValva() } - } else { - that.postOppenValva(res.result) + }, + fail(err) { + console.error(err); } - }, - fail(err) { - console.error(err); - } - }) + }) + } else { + wx.showToast({ + title: '璇峰厛鐧诲綍', + icon: 'error' + }) + } + }, confirmForceDialog() { console.log("confirmForceDialog"); @@ -521,9 +567,6 @@ title: '姝e湪寮哄埗鍒犻櫎璇风◢鍊�...', // 鍔犺浇鎻愮ず鏂囧瓧 mask: true // 鏄惁鏄剧ず閫忔槑钂欏眰锛岄槻姝㈣Е鎽哥┛閫忥紝榛樿涓� false }); - that.setData({ - lastIntakeName: intakeName - }) const data = { vcNum: item.vcNum, //鍙栨按鍙D rtuAddr: item.rtuAddr, //闃�鎺у櫒鍦板潃 @@ -555,9 +598,22 @@ } else { displayText = "鍏抽榾" } + let deleteText = "鍒犻櫎" + let time; + if (!item.dt) { + time = "鏆傛棤" + } else { + time = this.extractTime(item.dt) + } + if (item.waterInstant===null) { + item.waterInstant = "鏆傛棤" + } + return { ...item, - displayText + displayText, + deleteText, + time }; // 淇濈暀鎵�鏈夊叾浠栧瓧娈碉紝骞舵坊鍔� displayText 瀛楁 }); // 鏇存柊鍒楄〃鏁版嵁 @@ -567,11 +623,14 @@ }, //瑙g粦 unbind() { - //娓呯┖鏁版嵁 this.setData({ - userPhone: "璇风櫥褰�", - userName: "鏈櫥褰�", - listData: [] + showUnBind: true + }) + }, + //纭瑙g粦 + unBindPost() { + this.setData({ + showUnBind: false }) wx.showLoading({ title: '姝e湪瑙g粦璇风◢鍊�...', // 鍔犺浇鎻愮ず鏂囧瓧 @@ -594,7 +653,7 @@ userPhone: "璇风櫥褰�", userName: "鏈櫥褰�", listData: [], - isLogin:false + isLogin: false }) app.globalData.sessionId = ""; app.globalData.clientId = "" @@ -610,6 +669,47 @@ wx.hideLoading(); // 澶勭悊閿欒鍝嶅簲 console.error('璇锋眰澶辫触:', error); + wx.showToast({ + title: '瑙g粦澶辫触', + icon: 'error', + duration: 3000 + }) }); + }, + //鐐瑰嚮鎻愮ず鎸夐挳 + infoShow() { + this.setData({ + showInfoDialog: true + }) + }, + //鎻愮ず绐楃‘璁ゆ寜閽� + confirmBtnInfoDialog() { + this.setData({ + showInfoDialog: false + }) + }, + //澶勭悊鏃堕棿鍘绘帀骞存湀鏃� + extractTime(datetimeString) { + const formattedDate = datetimeString.replace(" ", "T"); + const date = new Date(formattedDate); + // 鑾峰彇灏忔椂銆佸垎閽熷拰绉� + const hours = date.getHours().toString().padStart(2, '0'); + const minutes = date.getMinutes().toString().padStart(2, '0'); + const seconds = date.getSeconds().toString().padStart(2, '0'); + return `${hours}:${minutes}:${seconds}`; + }, + onShareAppMessage: function (options) { + // 璁剧疆鍒嗕韩鍐呭 + return { + title: '澶х鐏屾簤鍔╂墜', // 鍒嗕韩鏍囬 + path: '/pages/home/home', // 鍒嗕韩璺緞锛岃璺緞闇�瑕佹槸褰撳墠灏忕▼搴忓瓨鍦ㄧ殑椤甸潰璺緞 + imageUrl: '/images/logo2.jpg', // 鍒嗕韩鍥炬爣锛屽彲浠ユ槸缃戠粶鍥剧墖璺緞鎴栨湰鍦板浘鐗囪矾寰� + success: function (res) { + // 鍒嗕韩鎴愬姛鐨勫洖璋冨嚱鏁� + }, + fail: function (res) { + // 鍒嗕韩澶辫触鐨勫洖璋冨嚱鏁� + } + }; } }) \ No newline at end of file -- Gitblit v1.8.0