From 578e51b21621b2f2426721ee91e8be33eff41cac Mon Sep 17 00:00:00 2001 From: zuoxiao <470321431@qq.com> Date: 星期一, 04 十一月 2024 10:28:25 +0800 Subject: [PATCH] 将返回的充值金额转换成元 --- pages/feedback/feedback.js | 687 +++++++++++++++++++++++++++++++++++++++++++------------- 1 files changed, 520 insertions(+), 167 deletions(-) diff --git a/pages/feedback/feedback.js b/pages/feedback/feedback.js index 7887046..3e08801 100644 --- a/pages/feedback/feedback.js +++ b/pages/feedback/feedback.js @@ -1,57 +1,153 @@ +const audio = wx.createInnerAudioContext() +const recorderManager = wx.getRecorderManager() +const { + get, + post +} = require('../../api/request.js'); +const { + BASEURL +} = require('../../api/config') +const app = getApp() Page({ data: { + isRefreshing: false, + currentTab: 0, recordingSrc: '', isRecording: false, - isshowVoiceMask: true, //鏄惁鏄剧ず褰曢煶涓� - voiceTime: 2, //褰曢煶鏃堕暱 + isshowVoiceMask: false, //鏄惁鏄剧ず褰曢煶涓� + isShowVoiceView: false, + voiceTime: 0, //褰曢煶鏃堕暱 + maxVoiceTime: 60, //鏈�闀垮綍闊虫椂闂� + contDownTime: 0, + line2Opcity: 1, + line3Opcity: 1, gridConfig: { column: 3, width: 160, height: 160, }, - originFiles: [{ - url: 'https://tdesign.gtimg.com/mobile/demos/example4.png', - name: 'uploaded1.png', - type: 'image', - }, - { - url: 'https://tdesign.gtimg.com/mobile/demos/example6.png', - name: 'uploaded2.png', - type: 'image', - } - ] + originFiles: [], + + contentValue: '', //鍙嶉璇︽儏 + accSavePath: [], //涓婁紶鐨勯煶棰戞枃浠舵帴鍙h繑鍥炵殑鍦板潃 + photoSavePath: [], //涓婁紶鐨勭収鐗囨枃浠惰繑鍥炵殑鍦板潃 + phoneNumber: "", + lat: "", + lng: "", + loading: false, + hasMore: true, + pageCurr: 1, + pageSize: 20, + listData: [], //宸叉彁闂鍒楄〃 }, onLoad() { - this.recorderManager = wx.getRecorderManager(); - this.recorderManager.onStart(() => { - console.log('recorder start'); - this.setData({ - isRecording: true - }); - this.startWaveformDrawing(); + wx.getSetting({ + success: (res) => { + if (!res.authSetting['scope.record']) { + // 濡傛灉鐢ㄦ埛娌℃湁鎺堟潈褰曢煶鏉冮檺锛屽彂璧锋巿鏉冪獥鍙� + wx.authorize({ + scope: 'scope.record', + success() { + // 鐢ㄦ埛宸茬粡鍚屾剰灏忕▼搴忎娇鐢ㄥ綍闊冲姛鑳斤紝鍙互缁х画鎿嶄綔 + console.log('鐢ㄦ埛宸叉巿鏉冨綍闊�'); + }, + fail() { + // 鐢ㄦ埛鎷掔粷鎺堟潈锛屽彲浠ョ粰鍑烘彁绀烘垨鍐嶆鍙戣捣鎺堟潈绐楀彛 + console.log('鐢ㄦ埛鎷掔粷浜嗘巿鏉冨綍闊�'); + } + }); + } else { + // 鐢ㄦ埛宸茬粡鎺堟潈褰曢煶锛屽彲浠ョ洿鎺ヨ繘琛屽綍闊虫搷浣� + console.log('鐢ㄦ埛宸叉巿鏉冨綍闊�'); + } + } }); + var that = this; + recorderManager.onStop((res) => { + console.log('褰曢煶鍋滄', voiceTime); + const voiceTime = Math.floor(res.duration / 1000) + if (voiceTime < 2) { + this.setData({ + isShowVoiceMask: false, + contDownTime: this.data.maxVoiceTime, + isShowVoiceView: false + }) + wx.showToast({ + title: '褰曢煶鏃堕棿杩囩煭', + icon: 'error', + time: 3000 + }) + } else { - this.recorderManager.onStop((res) => { - console.log('recorder stop', res); - const { - tempFilePath - } = res; - this.setData({ - recordingSrc: tempFilePath, - isRecording: false - }); - this.stopWaveformDrawing(); + that.setData({ + voiceTime: voiceTime, + isShowVoiceMask: false, + contDownTime: this.data.maxVoiceTime, + isShowVoiceView: true + }) + console.log('res', res); + const { + tempFilePath + } = res; //杩欓噷鏉惧紑鎸夐挳 浼氳繑鍥炲綍闊虫湰鍦拌矾寰� + audio.src = tempFilePath + console.log(tempFilePath); + that.upACC(tempFilePath); + } + }); - - this.recorderManager.onError((res) => { - console.error(res); - this.setData({ - isRecording: false - }); - this.stopWaveformDrawing(); + recorderManager.onStart(() => { + console.log('褰曢煶寮�濮�'); + }); + recorderManager.onError((err) => { + console.log('褰曢煶閿欒', err); + }); + wx.getLocation({ + type: 'wgs84', // 杩斿洖鍙互鐢ㄤ簬 `wx.openLocation` 鐨勭粡绾害 + success: (res) => { + console.log('鑾峰彇浣嶇疆鎴愬姛', res); + this.setData({ + lat: res.latitude, + lng: res.longitude, + }); + }, + fail: function (err) { + console.error('鑾峰彇浣嶇疆澶辫触', err); + } }); }, + onReady() { + this.getList(); + }, + //涓婁紶闊抽鏂囦欢 + upACC(tempFilePath) { + //涓婁紶褰曞埗鐨勯煶棰戝埌鏈嶅姟鍣� + wx.uploadFile({ + url: BASEURL + "wx/webFile/upPhone", //鎺ュ彛鍦板潃 + name: 'file', //涓婁紶鏂囦欢鍚� + filePath: tempFilePath, + header: { + 'tag': app.globalData.tag, + 'appId': app.globalData.AppID, + }, + success: (res) => { //鍚庡彴杩斿洖缁欏墠绔瘑鍒悗鐨勬枃瀛� + console.log('褰曢煶涓婁紶鎴愬姛', res); + let jsonData = JSON.parse(res.data) + let audioObj = { + webPath: jsonData.content.webPath, + id: jsonData.content.id + }; + this.setData({ + accSavePath: [audioObj] + }) + }, + fail: (err) => { + // 澶勭悊涓婁紶澶辫触鐨勯�昏緫 + console.log('褰曢煶涓婁紶澶辫触', err); + } + }) + }, + //鍒犻櫎鍥剧墖 handleRemove(e) { console.log("handleRemove"); const { @@ -60,13 +156,28 @@ const { originFiles } = this.data; + let imgPath = e.detail.file.url; + const updatedFiles = this.data.originFiles.map((file) => { + //褰撲笂浼犲け璐ョ偣鍑绘椂閲嶆柊涓婁紶 + if (file.url === imgPath && file.uploadTask) { + file.uploadTask.abort(); + } + }); originFiles.splice(index, 1); this.setData({ - originFiles, + originFiles: originFiles, }); + }, - handleClick() { + handleClick(e) { console.log("handleClick"); + let imgPath = e.detail.file.url; + const updatedFiles = this.data.originFiles.map((file) => { + //褰撲笂浼犲け璐ョ偣鍑绘椂閲嶆柊涓婁紶 + if (file.url === imgPath && file.status === "reload") { + this.onUploadPhoto(imgPath); + } + }); }, handleAdd(e) { console.log("handleAdd"); @@ -76,159 +187,401 @@ const { originFiles } = this.data; - this.setData({ - originFiles: [...originFiles, ...files], // 姝ゆ椂璁剧疆浜� fileList 涔嬪悗鎵嶄細灞曠ず閫夋嫨鐨勫浘鐗� + const updatedList = files.map(item => { + return { + ...item, + status: 'loading', + uploadTask: this.onUploadPhoto(item.url) + }; // 淇濈暀鎵�鏈夊叾浠栧瓧娈碉紝骞舵坊鍔� displayText 瀛楁 }); + // 鏇存柊鍒楄〃鏁版嵁 + this.setData({ + originFiles: [...originFiles, ...updatedList], // 姝ゆ椂璁剧疆浜� fileList 涔嬪悗鎵嶄細灞曠ず閫夋嫨鐨勫浘鐗� + }); + }, + handleSuccess(e) { + }, /** * 涓婁紶鍥剧墖 */ - onUpload() { - wx.uploadFile({ - url: 'https://example.weixin.qq.com/upload', // 浠呬负绀轰緥锛岄潪鐪熷疄鐨勬帴鍙e湴鍧� - filePath: file.url, + onUploadPhoto(imgPath) { + const uploadTask = wx.uploadFile({ + url: BASEURL + "wx/webFile/upPhoto", // 浠呬负绀轰緥锛岄潪鐪熷疄鐨勬帴鍙e湴鍧� + filePath: imgPath, name: 'file', - formData: { - user: 'test' + header: { + 'tag': app.globalData.tag, + 'appId': app.globalData.AppID, }, - success: () => { - this.setData({ - [`fileList[${length}].status`]: 'done', + success: (res) => { + console.log('鍥剧墖涓婁紶鎴愬姛', res); + let jsonData = JSON.parse(res.data) + // 鏇存柊鍥剧墖涓婁紶鎴愬姛鐘舵�� + const updatedFiles = this.data.originFiles.map((file) => { + console.log('鍥剧墖涓婁紶鎴愬姛銆嬨�媢pdatedFiles', file + "++++++++++" + imgPath); + if (file.url === imgPath) { + return { + ...file, + status: undefined, // 涓婁紶鎴愬姛鐘舵�� + uploadTask: undefined, // 娓呯悊涓婁紶浠诲姟 + webPath: jsonData.content.webPath, + id: jsonData.content.id + }; + } + return file; }); + // 灏嗗垱寤虹殑瀵硅薄娣诲姞鍒癷mages鏁扮粍涓� + this.setData({ + originFiles: updatedFiles, + }) + }, + fail: (err) => { + // 澶勭悊涓婁紶澶辫触鐨勯�昏緫 + const updatedFiles = this.data.originFiles.map((file) => { + if (file.url === imgPath) { + return { + ...file, + percent: progress, + status: "reload", // 涓婁紶澶辫触鐘舵�� + }; + } + return file; + }); + this.setData({ + originFiles: updatedFiles, + }); + } }); + if (uploadTask) { + uploadTask.onProgressUpdate((res) => { + //澶勭悊 + const progress = Math.round((res.progress / 100) * 100) + const updatedFiles = this.data.originFiles.map((file) => { + if (file.url === imgPath) { + return { + ...file, + percent: progress, + status: progress < 100 ? 'loading' : undefined, // 鏇存柊鐘舵�� + uploadTask: progress < 100 ? file.uploadTask : undefined, // 淇濇寔鎴栧垹闄ploadTask + }; + } + return file; + }); + this.setData({ + originFiles: updatedFiles, + }); + }); + } + return uploadTask; }, //鎸変綇鎸夐挳 - startHandel () { + startHandel() { this.setData({ - isShowVoiceMask:true + isShowVoiceMask: true, + contDownTime: this.data.maxVoiceTime, + voiceTime: 0, + isShowVoiceView: false }) console.log("寮�濮嬪綍闊�") - wx.getRecorderManager().start({ - duration: 0 + recorderManager.start({ + duration: 0 }) - }, - //鏉惧紑鎸夐挳 - endHandle () { - this.setData({ - isShowVoiceMask:false - }) + this.startRecordingCountdown(); + }, + //鏉惧紑鎸夐挳 + endHandle() { + this.stopRecordingCountdown(); console.log("缁撴潫") - const recorderManager = wx.getRecorderManager() - //褰曢煶鍋滄鍑芥暟 - var that = this; - wx.getRecorderManager().onStop((res) => { - const voiceTime = Math.floor(res.duration/1000) - console.log('voiceTime',voiceTime); - that.setData({ - voiceTime - }) - console.log('res',res); - const { tempFilePath } = res; //杩欓噷鏉惧紑鎸夐挳 浼氳繑鍥炲綍闊虫湰鍦拌矾寰� - audio.src = tempFilePath - console.log(tempFilePath); - //涓婁紶褰曞埗鐨勯煶棰戝埌鏈嶅姟鍣� - // wx.uploadFile({ - // url: '鎺ュ彛鍦板潃' + api.voice, //鎺ュ彛鍦板潃 - // name: 'file', //涓婁紶鏂囦欢鍚� - // filePath: tempFilePath, - // success: function (res) { //鍚庡彴杩斿洖缁欏墠绔瘑鍒悗鐨勬枃瀛� - // var model = res.data - // var modeljson = JSON.parse(model) - // if (modeljson.status_code == 500) { - // wx.showToast({ - // title: '璇煶杞崲澶辫触', - // image: '/assets/image/icon/fail@2x.png' - // }) - // return false; - // } - // if (modeljson.meta.status_code === 200 && !modeljson.data.err_msg) { - // var saymessage = modeljson.data.message; - // wx.setStorageSync('sayinfo', saymessage) - // that.setData({ - // inpvalue: saymessage - // }) - // setTimeout(() =>{ - // wx.navigateTo({ - // url: '../loding/loding' - // }) - - // },2000) - // setTimeout(() => { - // wx.hideLoading(); - // }, 100) - // } else if (modeljson.data.err_msg) { - // wx.showToast({ - // title: '璇峰ぇ澹拌璇�', - // image: '/assets/image/icon/fail@2x.png' - // }) - // return false; - // } - // } - // }) - }) //瑙﹀彂褰曢煶鍋滄 - wx.getRecorderManager().stop() - }, -// 鎾斁 -handlePlay(e){ - // 鍊掕鏃� - let time = this.data.voiceTime - audio.play() - let timer1 = -1,timer2 = -1,timer3 = -1,timer4 = -1,timer5 = -1,timer6 = -1; - // 绗竴娆℃挱鏀句负0 绗簩娆℃挱鏀�2绉掗挓 - timer6 = setInterval(()=>{ - console.log('鏃堕棿',time); - if(time <= 0){ - this.setData({ - line2Opcity: 1, - line3Opcity: 1 - }) - clearInterval(timer6) - clearTimeout(timer2) - clearTimeout(timer3) - clearTimeout(timer4) - clearTimeout(timer5) - return - } - timer2 = setTimeout(()=>{ - console.log('timer2'); - this.setData({ - line2Opcity: 0, - line3Opcity: 0 - }) - },300) - timer3 = setTimeout(()=>{ - console.log('timer3'); - this.setData({ - line2Opcity: 1, - line3Opcity:0 - }) - },600) - timer4 = setTimeout(()=>{ - console.log('timer4'); + recorderManager.stop() + }, + // 鎾斁 + handlePlay(e) { + // 鍊掕鏃� + let time = this.data.voiceTime + audio.play() + let timer1 = -1, + timer2 = -1, + timer3 = -1, + timer4 = -1, + timer5 = -1, + timer6 = -1; + // 绗竴娆℃挱鏀句负0 绗簩娆℃挱鏀�2绉掗挓 + timer6 = setInterval(() => { + console.log('鏃堕棿', time); + if (time <= 0) { this.setData({ line2Opcity: 1, line3Opcity: 1 - }) - },900) - timer5 = setTimeout(()=>{ - console.log('timer5'); + }) + clearInterval(timer6) + clearTimeout(timer2) + clearTimeout(timer3) + clearTimeout(timer4) + clearTimeout(timer5) + return + } + timer2 = setTimeout(() => { + console.log('timer2'); this.setData({ line2Opcity: 0, line3Opcity: 0 }) - },1200) - },1200) - // 鍊掕鏃� - timer1 = setInterval(()=>{ - time--; - if(time <= 0){ - clearInterval(timer1) - return - } -},1000) + }, 200) + timer3 = setTimeout(() => { + console.log('timer3'); + this.setData({ + line2Opcity: 1, + line3Opcity: 0 + }) + }, 400) + timer4 = setTimeout(() => { + console.log('timer4'); + this.setData({ + line2Opcity: 1, + line3Opcity: 1 + }) + }, 600) + timer5 = setTimeout(() => { + console.log('timer5'); + this.setData({ + line2Opcity: 0, + line3Opcity: 0 + }) + }, 800) + }, 800) + // 鍊掕鏃� + timer1 = setInterval(() => { + time--; + if (time <= 0) { + clearInterval(timer1) + return + } + }, 1000) -} + }, + //寮�鍚畾鏃跺櫒 + startRecordingCountdown() { + console.log("startRecordingCountdown"); + const that = this; + this.recordingInterval = setInterval(() => { + const newVoiceTime = that.data.voiceTime + 1; + const newContDownTime = that.data.contDownTime - 1; + that.setData({ + voiceTime: newVoiceTime, + contDownTime: newContDownTime + }); + if (this.data.voiceTime >= this.data.maxVoiceTime) { + that.stopRecordingCountdown(); + that.endHandle(); + } + }, 1000); + }, + + stopRecordingCountdown() { + console.log("stopRecordingCountdown"); + if (this.recordingInterval) { + clearInterval(this.recordingInterval); + this.recordingInterval = null; + console.log("Recording countdown stopped"); + } + }, // 鍒囨崲 Tabs + switchTab: function (e) { + const tab = parseInt(e.currentTarget.dataset.tab); + this.setData({ + currentTab: tab + }); + }, + onPullDownRefresh() { + this.getList(true); + }, + //涓婁紶闂 + feelBackPost() { + wx.showLoading({ + title: '姝e湪鎻愪氦...', // 鍔犺浇鎻愮ず鏂囧瓧 + mask: true // 鏄惁鏄剧ず閫忔槑钂欏眰锛岄槻姝㈣Е鎽哥┛閫忥紝榛樿涓� false + }); + this.data.originFiles.map((file) => { + let imageObj = { + webPath: file.webPath, + id: file.id + }; + this.setData({ + photoSavePath: [...this.data.photoSavePath, imageObj] + }) + }) + const app = getApp(); + const data = { + images: this.data.photoSavePath, + audios: this.data.accSavePath, + content: this.data.contentValue, + lng: this.data.lng, + lat: this.data.lat, + clientId: app.globalData.clientId, + phone: this.data.phoneNumber + }; + post({ + url: "wx/issue/addIssueReport", + data: data + }).then(response => { + // 澶勭悊鎴愬姛鍝嶅簲 + console.log('璇锋眰鎴愬姛:', response); + // 鍔犺浇瀹屾垚鍚庨殣钘忓姞杞藉姩鐢� + wx.hideLoading(); + //瀹屾垚鍚庡洖鍒伴椤� + wx.showToast({ + title: '鎻愪氦鎴愬姛', + icon: 'success', + duration: 2000, + success() {} + }) + setTimeout(() => { + wx.navigateBack({ + delta: 1 + }); + }, 2000); + + }).catch(error => { + // 鍔犺浇瀹屾垚鍚庨殣钘忓姞杞藉姩鐢� + wx.hideLoading(); + // 澶勭悊閿欒鍝嶅簲 + console.error('璇锋眰澶辫触:', error); + + this.setData({ + showErrorDialog: true, + errorData: error.msg + }) + // } + }); + }, + handleDelete() { + this.setData({ + isShowVoiceView: false, + voiceTime: 0, + }) + }, + //鎻愪氦 + submit() { + if (this.data.contentValue !== "" || this.data.photoSavePath.length > 0 || this.data.accSavePath !== "") { + if (this.data.phoneNumber !== "" && this.data.phoneNumber.length !== 11) { + wx.showToast({ + title: '鑱旂郴鐢佃瘽閿欒', + icon: 'error', + duration: 2000, + success() {} + }) + } else { + this.feelBackPost(); + } + } else { + wx.showToast({ + title: '璇疯緭鍏ヤ竴椤瑰弽棣堝唴瀹�', + icon: 'error', + duration: 2000, + success() {} + }) + } + + }, + //鐩戝惉鎵嬫満鍙风殑杈撳叆 + phoneInput(e) { + this.setData({ + phoneNumber: e.detail.value + }); + }, + //鐩戝惉 + contentInput(e) { + this.setData({ + contentValue: e.detail.value + }); + }, + //鑾峰彇宸叉彁闂鍒楄〃 + getList(isRefresh) { + if (isRefresh) { + this.setData({ + isRefreshing: false, + pageCurr: 1, + }); + } + const app = getApp(); + const params = { + url: 'wx/issue/getIssueReports', + data: { + clientId: app.globalData.clientId + } + }; + get(params).then(data => { + const updatedList = data.content.obj.map(item => { + if (item.replyTime === "" || item.replyTime === null) { + item.replyTime = "鏈洖澶�" + } + return item; + }); + this.setData({ + listData: [...this.data.listData, ...updatedList], + isRefreshing: false, // 灏唗riggered灞炴�ц缃负false锛岃〃绀轰笅鎷夊埛鏂板凡瀹屾垚 + isWXRefreshing: false, // 灏唗riggered灞炴�ц缃负false锛岃〃绀轰笅鎷夊埛鏂板凡瀹屾垚 + loading: false, + hasMore: this.data.pageCurr < data.content.pageTotal + }) + this.updateDisplayText(); + }).catch(err => { + // 閿欒鍥炶皟 + this.setData({ + isRefreshing: false, // 灏唗riggered灞炴�ц缃负false锛岃〃绀轰笅鎷夊埛鏂板凡瀹屾垚 + isWXRefreshing: false, // 灏唗riggered灞炴�ц缃负false锛岃〃绀轰笅鎷夊埛鏂板凡瀹屾垚 + loading: false + }) + wx.showToast({ + title: err.msg, + icon: 'error', + duration: 3000 + }) + }); + }, + //鍔犺浇鏇村 + loadMore() { + if (this.data.hasMore && !this.data.loading) { + this.setData({ + loading: true, + pageCurr: this.data.pageCurr + 1 + }) + this.getList(); + } + }, + 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/issue/deleteIssueReport", + data: data, + timeout: 180000 + }).then(response => { + // 澶勭悊鎴愬姛鍝嶅簲 + console.log('璇锋眰鎴愬姛:', response); + // 鍔犺浇瀹屾垚鍚庨殣钘忓姞杞藉姩鐢� + wx.hideLoading(); + //閲嶆柊鑾峰彇鍒楄〃鍒锋柊鏁版嵁 + this.getList(); + }).catch(error => { + // 鍔犺浇瀹屾垚鍚庨殣钘忓姞杞藉姩鐢� + wx.hideLoading(); + // 澶勭悊閿欒鍝嶅簲 + console.error('璇锋眰澶辫触:', error); + }); + } }); \ No newline at end of file -- Gitblit v1.8.0