From 19804e37592d2250c551fcf5df1d87cdf551f1d1 Mon Sep 17 00:00:00 2001 From: zuoxiao <470321431@qq.com> Date: 星期一, 12 八月 2024 09:06:39 +0800 Subject: [PATCH] 添加识别二维码切换地址的功能 --- pages/waterIntake/waterIntake.js | 230 +++++++++++++++++++++++++++++++++++++++++++++++---------- 1 files changed, 190 insertions(+), 40 deletions(-) diff --git a/pages/waterIntake/waterIntake.js b/pages/waterIntake/waterIntake.js index 869e711..de10bb5 100644 --- a/pages/waterIntake/waterIntake.js +++ b/pages/waterIntake/waterIntake.js @@ -6,9 +6,27 @@ Page({ data: { currentTab: 0, // 褰撳墠鏄剧ず鐨勮〃鏍硷紝榛樿涓虹涓�涓〃鏍� - searchQuery:"", + searchQuery: "", commonWaterPoints: [], // 甯哥敤鍙栨按鍙f暟鎹� allWaterPoints: [], // 鎵�鏈夊彇姘村彛鏁版嵁 + searchData: [{ + intakeNum: "1111111" + }, { + intakeNum: "2222222" + }], + isRefreshing_all: false, + isRefreshing_common: false, + showConfirm: false, + waterIntakeName: "", + choseItem: null, + errorData: '', //閿欒鍐呭 + showErrorDialog: false, + confirmBtn: { + content: '纭' + }, + showForceConfirm: false, + forceIntakeId: "", //寮哄埗寮�闃�鐨勫彇姘村彛id + inputValue:"" }, // 鍒囨崲 Tabs @@ -18,7 +36,7 @@ currentTab: tab }); }, - onInput(e){ + onInput(e) { this.setData({ searchQuery: e.detail.value // 灏嗚緭鍏ユ鐨勫�煎瓨鍌ㄥ埌 inputValue }); @@ -26,10 +44,12 @@ onSearch: function () { const query = this.data.searchQuery; if (query) { - this.getallWaterPoints(query) + this.getallWaterPoints(query) // 鍦ㄨ繖閲岃繘琛屾悳绱㈡搷浣滐紝鏇存柊 allWaterPoints 鏁版嵁 } else { - this.getallWaterPoints(query) + this.setData({ + allWaterPoints: [] + }) } }, @@ -38,13 +58,73 @@ * @param {} event */ choseCard(event) { - const intakeId= event.currentTarget.dataset.item.intakeId; - console.log(intakeId); - wx.navigateTo({ - url: '/pages/openCard/openCard?intakeId='+intakeId, + //鏄剧ず浜屾纭寮圭獥 + this.setData({ + showConfirm: true, + choseItem: event.currentTarget.dataset.item, + allWaterPoints: [] }) - }, + // console.log(intakeId); + // wx.navigateTo({ + // url: '/pages/openCard/openCard?intakeId='+intakeId, + // }) + }, + //寮�娉甸�氫俊 + /** + * + * @param {*} intakeId 鍙栨按鍙d + * @param {*} isforce 鏄惁寮哄埗寮�闃� + */ + postOpenValva(intakeId, isforce) { + this.setData({ + inputValue:"" + }) + console.log("intakeId:" + intakeId + " isforce:" + isforce) + wx.showLoading({ + title: '姝e湪寮�闃�璇风◢鍊�...', // 鍔犺浇鎻愮ず鏂囧瓧 + mask: true // 鏄惁鏄剧ず閫忔槑钂欏眰锛岄槻姝㈣Е鎽哥┛閫忥紝榛樿涓� false + }); + const app = getApp(); + const data = { + intakeId: intakeId, //鍙栨按鍙D + // vcId: vcId, //铏氭嫙鍗D + operator: app.globalData.sessionId, //鎿嶄綔鍛� + forceOpen: !!isforce // 浣跨敤閫昏緫闈炴搷浣滅 !! 鏉ョ‘淇� isForce 鏄竷灏斿�� + }; + post({ + url: "wx/valve/open_wx", + data: data, + timeout: 180000 + }).then(response => { + + // 澶勭悊鎴愬姛鍝嶅簲 + console.log('璇锋眰鎴愬姛:', response); + // 鍔犺浇瀹屾垚鍚庨殣钘忓姞杞藉姩鐢� + wx.hideLoading(); + //瀹屾垚鍚庡洖鍒伴椤� + wx.reLaunch({ + url: '/pages/home/home?param=true' // 棣栭〉鐨勮矾寰勶紝鏍规嵁瀹為檯鎯呭喌濉啓 + }); + + }).catch(error => { + // 鍔犺浇瀹屾垚鍚庨殣钘忓姞杞藉姩鐢� + wx.hideLoading(); + // 澶勭悊閿欒鍝嶅簲 + console.error('璇锋眰澶辫触:', error); + if (error.code === "10005") { + this.setData({ + forceIntakeId: intakeId, + showForceConfirm: true + }) + } else { + this.setData({ + showErrorDialog: true, + errorData: error.msg + }) + } + }); + }, /** * 鐢熷懡鍛ㄦ湡鍑芥暟--鐩戝惉椤甸潰鍔犺浇 @@ -57,7 +137,6 @@ * 鐢熷懡鍛ㄦ湡鍑芥暟--鐩戝惉椤甸潰鍒濇娓叉煋瀹屾垚 */ onReady() { - this.getallWaterPoints(); this.getcommonWaterPoints(); }, @@ -82,12 +161,8 @@ }, - /** - * 椤甸潰鐩稿叧浜嬩欢澶勭悊鍑芥暟--鐩戝惉鐢ㄦ埛涓嬫媺鍔ㄤ綔 - */ - onPullDownRefresh() { - }, + /** * 椤甸潰涓婃媺瑙﹀簳浜嬩欢鐨勫鐞嗗嚱鏁� @@ -101,24 +176,37 @@ */ onShareAppMessage() { - } - , + }, /** - * 鑾峰彇鎵�鏈夊彇姘村彛 + *鍦ㄦ墍鏈夊彇姘村彛鎼滅储 */ getallWaterPoints: function (intakeNum) { - let params = { url: 'rtu/get_online_intakes' }; + let params = { + url: 'wx/intake/all_intakes' + }; if (intakeNum) { - params.data = { intakeNum: intakeNum }; + params.data = { + intakeNum: intakeNum + }; } - get(params) .then((data) => { - if(data.success&&data.code==="0001"){ - this.setData({ - allWaterPoints: data.content.obj - }); - }else{ + this.setData({ + isRefreshing_all: false + }); + if (data.success && data.code === "0001") { + if (!data.content) { + wx.showToast({ + title: '娌℃湁鎼滅储鍒板彇姘村彛', + icon: 'error', + }) + }else{ + this.setData({ + allWaterPoints:[data.content] + }); + } + + } else { wx.showToast({ title: data.msg, }) @@ -126,28 +214,90 @@ console.log('Failed to add item:'); }) .catch((error) => { + this.setData({ + isRefreshing_all: false + }); + wx.showToast({ + title: error.msg, + icon: 'error', + duration: 3000 // 鎻愮ず鐨勬寔缁椂闂达紝鍗曚綅姣 + }) console.error('Failed to add item:', error); }); }, - getcommonWaterPoints(){ - - get({url:'rtu/used_intakes', data: { - operator: getApp().globalData.sessionId - }}) - .then((data) => { - if(data.success&&data.code==="0001"){ + //鑾峰彇甯哥敤鍙栨按鍙� + getcommonWaterPoints() { + get({ + url: 'wx/intake/used_intakes', + data: { + operator: getApp().globalData.sessionId + } + }) + .then((data) => { this.setData({ - commonWaterPoints: data.content + isRefreshing_common: false }); - }else{ + if (data.success && data.code === "0001") { + this.setData({ + commonWaterPoints: data.content + }); + } else { + wx.showToast({ + title: data.msg, + }) + } + console.log('Failed to add item:'); + }) + .catch((error) => { + this.setData({ + isRefreshing_common: false + }); wx.showToast({ - title: data.msg, + title: error.msg, + icon: 'error', + duration: 3000 // 鎻愮ず鐨勬寔缁椂闂达紝鍗曚綅姣 }) - } - console.log('Failed to add item:'); + console.error('Failed to add item:', error); + }); + }, + /** + * 椤甸潰鐩稿叧浜嬩欢澶勭悊鍑芥暟--鐩戝惉鐢ㄦ埛涓嬫媺鍔ㄤ綔 + */ + onPullDownRefresh_all() { + this.getallWaterPoints(); + }, + onPullDownRefresh_common() { + this.getcommonWaterPoints(); + }, + confirmDialog() { + this.setData({ + showConfirm: false }) - .catch((error) => { - console.error('Failed to add item:', error); + this.postOpenValva(this.data.choseItem.intakeId); + }, + closeDialog() { + this.setData({ + showConfirm: false + }) + }, + closeErrorDialog() { + this.setData({ + showErrorDialog: false + }) + }, + cancelDialog() { + this.setData({ + showForceConfirm: false }); + }, + //寮哄埗寮�闃� + confirmForceDialog() { + this.postOpenValva(this.data.forceIntakeId, true); + }, + closeSearch(){ + this.setData({ + allWaterPoints:[], + inputValue:"" + }) } }) \ No newline at end of file -- Gitblit v1.8.0