| | |
| | | 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, |
| | |
| | | width: 160, |
| | | height: 160, |
| | | }, |
| | | originFiles: [ |
| | | ], |
| | | feedBackList: Array(19).fill({ |
| | | createTime: "2023-05-06 12:36:25", |
| | | responseTime: "2023-05-07 12:36:25" |
| | | }), |
| | | contentValue:''//反馈详情 |
| | | originFiles: [], |
| | | |
| | | contentValue: '', //反馈详情 |
| | | accSavePath: [], //上传的音频文件接口返回的地址 |
| | | photoSavePath: [], //上传的照片文件返回的地址 |
| | | phoneNumber: "", |
| | | lat: "", |
| | | lng: "", |
| | | loading: false, |
| | | hasMore: true, |
| | | pageCurr: 1, |
| | | pageSize: 20, |
| | | listData: [], //已提问题列表 |
| | | }, |
| | | |
| | | onLoad() { |
| | |
| | | time: 3000 |
| | | }) |
| | | } else { |
| | | |
| | | |
| | | that.setData({ |
| | | voiceTime: voiceTime, |
| | | isShowVoiceMask: false, |
| | |
| | | } = res; //这里松开按钮 会返回录音本地路径 |
| | | audio.src = tempFilePath |
| | | console.log(tempFilePath); |
| | | that.upACC(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; |
| | | // } |
| | | // } |
| | | // }) |
| | | }); |
| | | 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 { |
| | |
| | | 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"); |
| | |
| | | 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', // 仅为示例,非真实的接口地址 |
| | | filePath: file.url, |
| | | onUploadPhoto(imgPath) { |
| | | const uploadTask = wx.uploadFile({ |
| | | url: BASEURL + "wx/webFile/upPhoto", // 仅为示例,非真实的接口地址 |
| | | 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('图片上传成功》》updatedFiles', file + "++++++++++" + imgPath); |
| | | if (file.url === imgPath) { |
| | | return { |
| | | ...file, |
| | | status: undefined, // 上传成功状态 |
| | | uploadTask: undefined, // 清理上传任务 |
| | | webPath: jsonData.content.webPath, |
| | | id: jsonData.content.id |
| | | }; |
| | | } |
| | | return file; |
| | | }); |
| | | // 将创建的对象添加到images数组中 |
| | | 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, // 保持或删除uploadTask |
| | | }; |
| | | } |
| | | return file; |
| | | }); |
| | | this.setData({ |
| | | originFiles: updatedFiles, |
| | | }); |
| | | }); |
| | | } |
| | | return uploadTask; |
| | | }, |
| | | //按住按钮 |
| | | startHandel() { |
| | |
| | | }); |
| | | }, |
| | | onPullDownRefresh() { |
| | | this.setData({ |
| | | isRefreshing: false |
| | | }); |
| | | this.getList(true); |
| | | }, |
| | | feelBack(){ |
| | | //上传问题 |
| | | feelBackPost() { |
| | | wx.showLoading({ |
| | | title: '正在提交...', // 加载提示文字 |
| | | 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 = { |
| | | content: this.data.contentValue, //取水口ID |
| | | image: this.data.vcId, //虚拟卡ID |
| | | operator: app.globalData.sessionId, //操作员 |
| | | forceOpen: !!isforce // 使用逻辑非操作符 !! 来确保 isForce 是布尔值 |
| | | 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: "operation/feedback/add", |
| | | url: "wx/issue/addIssueReport", |
| | | data: data |
| | | }).then(response => { |
| | | |
| | | // 处理成功响应 |
| | | console.log('请求成功:', response); |
| | | // 加载完成后隐藏加载动画 |
| | | wx.hideLoading(); |
| | | //完成后回到首页 |
| | | wx.reLaunch({ |
| | | url: '/pages/home/home?param=true' // 首页的路径,根据实际情况填写 |
| | | }); |
| | | wx.showToast({ |
| | | title: '提交成功', |
| | | icon: 'success', |
| | | duration: 2000, |
| | | success() {} |
| | | }) |
| | | setTimeout(() => { |
| | | wx.navigateBack({ |
| | | delta: 1 |
| | | }); |
| | | }, 2000); |
| | | |
| | | }).catch(error => { |
| | | // 加载完成后隐藏加载动画 |
| | | wx.hideLoading(); |
| | | // 处理错误响应 |
| | | console.error('请求失败:', error); |
| | | // if (error.code === "10005") { |
| | | // this.setData({ |
| | | // showDialog: false, |
| | | // showForceConfirm: true |
| | | // }) |
| | | // } else { |
| | | |
| | | this.setData({ |
| | | showErrorDialog: true, |
| | | errorData: error.msg |
| | |
| | | // } |
| | | }); |
| | | }, |
| | | handleDelete(){ |
| | | this.setData({ |
| | | isShowVoiceView:false, |
| | | voiceTime:0, |
| | | }) |
| | | 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, // 将triggered属性设置为false,表示下拉刷新已完成 |
| | | isWXRefreshing: false, // 将triggered属性设置为false,表示下拉刷新已完成 |
| | | loading: false, |
| | | hasMore: this.data.pageCurr < data.content.pageTotal |
| | | }) |
| | | this.updateDisplayText(); |
| | | }).catch(err => { |
| | | // 错误回调 |
| | | this.setData({ |
| | | isRefreshing: false, // 将triggered属性设置为false,表示下拉刷新已完成 |
| | | isWXRefreshing: false, // 将triggered属性设置为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: '正在强制删除请稍候...', // 加载提示文字 |
| | | mask: true // 是否显示透明蒙层,防止触摸穿透,默认为 false |
| | | }); |
| | | that.setData({ |
| | | lastIntakeName: intakeName |
| | | }) |
| | | const data = { |
| | | vcNum: item.vcNum, //取水口ID |
| | | 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); |
| | | }); |
| | | } |
| | | |
| | | }); |