import { $wuxActionSheet } from '../../../../../components/dist/index' const QQMapWX = require('../../../../../utils/qqmap-wx-jssdk') const config = require('../../../../../utils/config') const app = getApp() var recorderManager = wx.getRecorderManager(); var innerAudioContext = wx.createInnerAudioContext() import api from "../../../../../utils/api" var timer; Page({ /** * 页面的初始数据 */ data: { optionsId: '', defaultMeasureNames: { label: 'categoryName', value: 'categoryCode', children: 'childCateList' }, fmData: { gridId: '', attachmentList: [], //图片 voiceList: [], latitude: "", longitude: "", resiId: "", happenTime: "", content: "", //内容 address: "", //地址 }, minDate: '2018-01-01 00:00:00', tabVal: "0", ruTabVal: "yes", uploadImageList: [], //图片上传的数组 streetList: [], // 街道 imageId: 1, addressContent: '', overDuration: 600000, duration: 0, url: '', hasStop: false, hasStart: false, // 录音开始 暂停 isStart: false, // 是否开启录音 recordingTime: '00:00', recordingLength: 0, setInter: null, showRecord: false, // 是否显示录音sheet uploadRecord: { uploaded: true, url: "" }, totalTime: "00:00", // 录音时长 submitDisabled: false, // 时间组件 visibleTime: false, angencyList: [], //组织下拉数据 angencyId: "", totalMax: 0, stepValue: 0, hasPlay: false, playUrl: "", // defaultFieldNames: { label: 'agencyName', value: 'agencyId', children: 'subAgencyList' }, angencyVisible: false, measureList: [], measureValue: '', measureVisible: false, reportUserName: '', reportUserMobile: '', showWantServiceTimeTime: '', reportTypeList: [], //上报类型 reportTypeVisible: false }, /** * 生命周期函数--监听页面加载 */ onLoad(options) { this.setData({ angencyId: app.globalData.user.agencyId, reportUserName: app.globalData.user.realName, reportUserMobile: app.globalData.user.phone, }) this.getAgencygridtree() this.getDemandoption() this.getDictList() if (options.id) { if (options.type === '0') { this.getIcEventOldDetail(options.id) } else { this.getDemandDetail(options.id) } this.setData({ tabVal: options.type || 0, optionsId: options.id }) return } this.data.qqMapWX = new QQMapWX({ key: 'CMJBZ-4DECI-JXGGN-5B4WU-QLV2H-B5BEJ' }) // this.getLocation().then(() => { // }) this.reverseLocation() }, getDemandDetail(id) { let parm = { demandRecId: id } api.getDemandDetail(parm).then(res => { console.log(res); this.setData({ 'fmData.content': res.data.content, // 'fmData.voiceList':res.data.voiceList, 'fmData.gridId': res.data.gridId, 'fmData.demandUserId': res.data.reportUserId, 'fmData.categoryCode': res.data.categoryCode, 'fmData.reportType': res.data.reportType, 'fmData.happenTime': res.data.reportTime, 'fmData.wantServiceTime': res.data.wantServiceTime, 'fmData.resiId': res.data.icResiUserId, categoryName: res.data.parentCategoryName + res.data.firstCategoryName, agencyName: res.data.gridName, reportTypeName: res.data.reportTypeName, resiName: res.data.demandUserName, resiMobile: res.data.demandUserMobile, showTime: res.data.reportTime, showWantServiceTimeTime: res.data.wantServiceTime, // uploadImageList:res.data.imageList.map(item=>({ossUrl:{url:item},uploaded:true})), // uploadRecord:res.data.voiceList[0], // totalTime:this.format(res.data.voiceList[0].duration) }) this.downLoadAudio() }).catch(err => { console.log(err); }) }, getIcEventOldDetail(id) { let parm = { icEventId: id } api.getIcEventOld(parm).then(res => { console.log(res); this.setData({ 'fmData.content': res.data.eventContent, 'fmData.voiceList': res.data.voiceList || [], 'fmData.gridId': res.data.gridId, 'fmData.happenTime': res.data.happenTime, 'fmData.address': res.data.address, 'fmData.resiId': res.data.reportUserId, 'fmData.longitude': res.data.longitude, 'fmData.latitude': res.data.latitude, 'fmData.demandType': res.data.demandType, 'fmData.responsibleUnit': res.data.responsibleUnit, 'fmData.responsibleName': res.data.responsibleName, 'fmData.responsibleMobile': res.data.responsibleMobile, agencyName: res.data.gridName, showTime: res.data.happenTime, addressContent: res.data.address, resiName: res.data.name, resiMobile: res.data.mobile, responsibleUnit: res.data.responsibleUnit, responsibleName: res.data.responsibleName, responsibleMobile: res.data.responsibleMobile, uploadImageList: res.data.imageList && res.data.imageList.length > 0 ? res.data.imageList.map(item => ({ ossUrl: { url: item }, uploaded: true })) : [], uploadRecord: res.data.voiceList && res.data.voiceList.length > 0 ? res.data.voiceList[0] : null, totalTime: this.format(res.data.voiceList && res.data.voiceList.length > 0 ? res.data.voiceList[0].duration : 0) }) if (this.data.uploadRecord) { this.downLoadAudio() } }).catch(err => { console.log(err); }) }, update() { this.submitPersonalInfo() }, updateMeasure() { this.setData({ submitDisabled: true }) let { categoryCode, content, happenTime, resiId, gridId, attachmentList, voiceList, wantServiceTime, parentCode, reportType } = this.data.fmData const parm = { categoryCode, content, reportUserName: this.data.reportUserName, reportTime: happenTime, reportUserMobile: this.data.reportUserMobile, demandUserId: resiId, gridId, reportType, // attachments:[...attachmentList,...voiceList], wantServiceTime, parentCode: parentCode, demandRecId: this.data.optionsId } api.updateMeasure(parm).then(res => { if (res.code === 0) { wx.showModal({ title: '提示', content: `提交成功`, confirmText: '确认', showCancel: false, success: res => { this.setData({ submitDisabled: false, uploadImageList: [], uploadRecord: { uploaded: true, url: "" }, agencyName: '', showTime: '', resiName: '', resiMobile: '', 'fmData.gridId': '', 'fmData.attachmentList': [], //图片 'fmData.voiceList': [], 'fmData.latitude': "", 'fmData.longitude': "", 'fmData.resiId': "", 'fmData.happenTime': "", 'fmData.content': "", //内容 'fmData.wantServiceTime': "", 'fmData.reportType': '' }) wx.navigateBack({ delta: 1 }) } }) wx.removeStorageSync('resiDetail') } else { console.log('提交失败'); wx.showToast({ title: "提交失败,请重试~", icon: "none", duration: 1500 }) this.setData({ submitDisabled: false }) } }).catch(err => { wx.showToast({ title: "提交失败,请重试~", icon: "none", duration: 1500 }) this.setData({ submitDisabled: false }) }) setTimeout(function () { wx.hideLoading() }, 1000) }, updateEvent() { wx.showLoading({ title: '提交中...', mask: true }) this.setData({ submitDisabled: true }) const parm = this.data.fmData parm.icEventId = this.data.optionsId console.log(parm, '事件更新'); api.updateEvent(parm).then(res => { console.log(res); if (res.code === 0) { wx.showModal({ title: '提示', content: `修改成功`, confirmText: '确认', showCancel: false, success: res => { this.setData({ submitDisabled: false, uploadImageList: [], uploadRecord: { uploaded: true, url: "" }, agencyName: '', showTime: '', resiName: '', resiMobile: '', 'fmData.gridId': '', 'fmData.attachmentList': [], //图片 'fmData.voiceList': [], 'fmData.latitude': "", 'fmData.longitude': "", 'fmData.resiId': "", 'fmData.happenTime': "", 'fmData.content': "", //内容 'fmData.wantServiceTime': "", 'fmData.reportType': '' }) wx.navigateBack({ delta: 1 }) } }) wx.removeStorageSync('resiDetail') } else { console.log('提交失败'); wx.showToast({ title: "提交失败,请重试~", icon: "none", duration: 1500 }) this.setData({ submitDisabled: false }) } }).catch(err => { console.log(err) wx.showToast({ title: "提交失败,请重试~", icon: "none", duration: 1500 }) this.setData({ submitDisabled: false }) }) setTimeout(function () { wx.hideLoading() }, 1000) }, delete() { let that = this wx.showModal({ title: '提示', content: '确定要删除这条数据吗,删除后将无法找回,请谨慎操作', success(res) { if (res.confirm) { console.log(that.data.tabVal); if (that.data.tabVal == 0) { that.icEventOldDelete() } else { that.userDemandCance() } } else if (res.cancel) {} } }) }, icEventOldDelete() { api.icEventOldDelete([this.data.optionsId]).then(res => { if (res.code === 0) { wx.showToast({ title: '删除成功', icon: 'none', success() { setTimeout(() => { wx.navigateBack({ delta: 1 }) }, 3000) } }) } }).catch(err => { console.log(err); }) }, userDemandCance() { let parm = { demandRecId: this.data.optionsId } api.userDemandCance(parm).then(res => { if (res.code === 0) { wx.showToast({ title: '删除成功', icon: 'none' }) } }).catch(err => { console.log(err); }) }, // 组织树 getAgencygridtree() { let parm = { agencyId: this.data.angencyId, purpose: 'query' } api.getGridoptionDict(parm).then(res => { console.log(res); this.setData({ angencyList: res.data }) }).catch(err => { console.log(err); }) }, getDictList() { api.getDictList('user_demand_report_type').then(res => { console.log(res); this.setData({ reportTypeList: res.data }) }).catch(err => { console.log(err); }) }, getDemandoption() { api.getDemandoption().then(res => { console.log(res); this.setData({ measureList: res.data }) }).catch(err => { console.log(err); }) }, // 触底函数 onReachBottom() { if (this.projectlist) { this.projectlist.onReachBottom() } }, //跳转地图选点 toughGetLocation() { // this.getLocation(false); wx.chooseLocation({ success: res => { console.log('resadddres', res) const { fmData } = this.data; this.setData({ fmData: { ...fmData, address: res.address, longitude: res.longitude, latitude: res.latitude }, addressContent: res.address }); console.log(this.data.fmData); } }) }, showRecordSheet() { this.setData({ showRecord: true, recorderData: {}, recordingTime: "0:00", uploadRecord: { uploaded: true, url: "" } }) }, // 获取经纬度 // getLocation() { // return new Promise((resolve, reject) => { // const _this = this // wx.getLocation({ // type: 'gcj02', // success(res) { // if (res.latitude && res.longitude) { // _this.setData({ // 'personalInfo.issueLatitude': res.latitude, // 'personalInfo.issueLongitude': res.longitude // }) // resolve(true) // } // }, // fail(err) { // reject(err) // } // }) // }) // }, // 提交按钮 submitPersonalInfo() { const imagesList = [] if (this.data.uploadImageList.length > 0) { const isUploadDown = this.data.uploadImageList.some(item => !item.uploaded) if (isUploadDown) { wx.showToast({ title: '请等待图片上传完成', icon: 'none', duration: 1000 }) return false } } console.log(this.data.uploadImageList); if (this.data.uploadImageList.length > 0) { this.data.uploadImageList.forEach(item => { imagesList.push({ format: item.format || 'png', originFileName: item.originFileName || '', url: item.ossUrl.url, type: item.type }) }) } this.setData({ 'fmData.attachmentList': imagesList, }) console.log(this.data.tabVal); if (!this.data.fmData.gridId) { this.showToast('所属组织不能为空') return } if (this.data.tabVal === '1') { if (!this.data.fmData.content) { this.showToast('需求描述不能为空') return } if (!this.data.fmData.content) { this.showToast('需求描述不能为空') return } if (!this.data.fmData.categoryCode) { this.showToast('需求类型不能为空') return } if (!this.data.fmData.reportType) { this.showToast('上报类型不能为空') return } if (!this.data.fmData.happenTime) { this.showToast('需求时间不能为空') return } if (!this.data.fmData.wantServiceTime) { this.showToast('服务时间不能为空') return } if (!this.data.fmData.resiId) { this.showToast('需求人不能为空') return } if (!this.data.resiMobile) { this.showToast('需求人电话不能为空') return } } else { if (!this.data.fmData.content) { this.showToast('事件描述不能为空') return } if (!this.data.fmData.happenTime) { this.showToast('发生时间不能为空') return } if (!this.data.fmData.address) { this.showToast('发生地点不能为空') return } if (!this.data.fmData.resiId && (this.data.tabVal==0 || this.data.tabVal==1)) { this.showToast('联系人不能为空') return } if (!this.data.resiMobile && (this.data.tabVal==0 || this.data.tabVal==1)) { this.showToast('联系人电话不能为空') return } if (!this.data.fmData.responsibleName && this.data.tabVal==2 && this.data.ruTabVal=='yes') { this.showToast('责任人不能为空') return } if (!this.data.fmData.responsibleMobile && this.data.tabVal==2 && this.data.ruTabVal=='yes') { this.showToast('责任人电话不能为空') return } } if (this.data.tabVal === '1') { this.data.optionsId ? this.updateMeasure() : this.submitMeasure(); } else { this.data.optionsId ? this.updateEvent() : this.submitEven(); } }, // 事件提交接口 submitEven() { wx.showLoading({ title: '提交中...', mask: true }) this.setData({ submitDisabled: true }) // 事件上报 if(this.data.tabVal==0){ this.setData({ 'fmData.demandType': 'report' }) } // 城管上报 if(this.data.tabVal==2){ this.setData({ 'fmData.demandType': 'chengguan' }) } if(this.data.ruTabVal=='yes'){ this.setData({ 'fmData.responsibleUnit': 'yes' }) }else{ his.setData({ 'fmData.responsibleUnit': 'no' }) } const parm = this.data.fmData parm.reportUserId = this.data.fmData.resiId parm.eventContent = this.data.fmData.content parm.sourceType = "4" console.log(parm, '事件'); api.addEvent(parm).then(res => { console.log(res); if (res.code === 0) { wx.showModal({ title: '提示', content: `提交成功`, confirmText: '确认', showCancel: false, success: res => { this.setData({ submitDisabled: false, uploadImageList: [], uploadRecord: { uploaded: true, url: "" }, agencyName: '', showTime: '', resiName: '', resiMobile: '', 'fmData.gridId': '', 'fmData.attachmentList': [], //图片 'fmData.voiceList': [], 'fmData.latitude': "", 'fmData.longitude': "", 'fmData.resiId': "", 'fmData.happenTime': "", 'fmData.content': "", //内容 'fmData.wantServiceTime': "", // 'fmData.reportType': '', // 'fmData.demandType': '', // 'fmData.responsibleUnit': '', // 'fmData.responsibleName': '', // 'fmData.responsibleMobile': '' }) wx.switchTab({ url: '/pages/work/work', }) } }) wx.removeStorageSync('resiDetail') } else { console.log('提交失败'); wx.showToast({ title: "提交失败,请重试~", icon: "none", duration: 1500 }) this.setData({ submitDisabled: false }) } }).catch(err => { console.log(err) wx.showToast({ title: "提交失败,请重试~", icon: "none", duration: 1500 }) this.setData({ submitDisabled: false }) }) setTimeout(function () { wx.hideLoading() }, 1000) }, // 个性服务提交 submitMeasure() { wx.showLoading({ title: '提交中...', mask: true }) this.setData({ submitDisabled: true }) let { categoryCode, content, happenTime, resiId, gridId, attachmentList, voiceList, wantServiceTime, parentCode, reportType } = this.data.fmData const parm = { categoryCode, content, reportUserName: this.data.reportUserName, reportTime: happenTime, reportUserMobile: this.data.reportUserMobile, demandUserId: resiId, gridId, reportType, // attachments:[...attachmentList], voices: [...voiceList], wantServiceTime, parentCode: parentCode } console.log(parm, '服务'); api.addMeasure(parm).then(res => { console.log(res); if (res.data) { wx.showModal({ title: '提示', content: `提交成功`, confirmText: '确认', showCancel: false, success: res => { this.setData({ submitDisabled: false, uploadImageList: [], uploadRecord: { uploaded: true, url: "" }, agencyName: '', showTime: '', resiName: '', resiMobile: '', categoryName: '', reportTypeName: '', showWantServiceTimeTime: '', 'fmData.gridId': '', 'fmData.attachmentList': [], //图片 'fmData.voiceList': [], 'fmData.latitude': "", 'fmData.longitude': "", 'fmData.resiId': "", 'fmData.happenTime': "", 'fmData.content': "", //内容 'fmData.wantServiceTime': "", 'fmData.reportType': '' }) wx.switchTab({ url: '/pages/work/work', }) } }) wx.removeStorageSync('resiDetail') } else { wx.showToast({ title: "提交失败,请重试~", icon: "none", duration: 1500 }) this.setData({ submitDisabled: false }) } }).catch(err => { console.log(err) wx.showToast({ title: "提交失败,请重试~", icon: "none", duration: 1500 }) this.setData({ submitDisabled: false }) }) setTimeout(function () { wx.hideLoading() }, 1000) }, // 双向绑定 内容输入框 bindTextareaInput(e) { this.setData({ 'fmData.content': e.detail.value }) console.log(this.data.fmData); }, bindResponsibleName(e) { this.setData({ 'fmData.responsibleName': e.detail.value }) console.log(this.data.fmData); }, bindResponsibleMobile(e) { this.setData({ 'fmData.responsibleMobile': e.detail.value }) console.log(this.data.fmData); }, // 点击空白,隐藏sheet onHideSheet() { this.setData({ showRecord: false }) }, // 选择图片 上传弹窗 - 上传图片方式 - 选择图片 - 上传图片 - 回调赋值 chooseImage() { if (this.data.uploadImageList.length > 3) { wx.showToast({ title: "最多上传3张照片", icon: "none" }) return } const _this = this $wuxActionSheet().showSheet({ buttons: [{ text: '拍照' }, { text: '从相册中获取', openType: null, }, ], className: 'dialog-class', buttonClicked(index) { if (index === 0) { wx.chooseMedia({ count: 1, sizeType: ['original', 'compressed'], sourceType: ['camera'], success(res) { console.log(res); let deleteLength = _this.data.uploadImageList.length const uploadImageList = [..._this.data.uploadImageList] if (res.tempFiles[0].size <= 5 * 1024 * 1024) { uploadImageList.push({ uploaded: false, ossUrl: { url: res.tempFiles[0].tempFilePath }, imgUrl: res.tempFiles[0].tempFilePath, imageId: ++_this.data.imageId, type: res.tempFiles[0].tempFilePath.substr(res.tempFiles[0].tempFilePath.length - 3, 3), format: "image", name: 'wximage' }) } else { _this.showToast('图片上限5M,请压缩后重试~') return false } _this.setData({ uploadImageList }) wx.uploadFile({ url: `${config.BASEURL()}oss/file/uploadvariedfile`, filePath: res.tempFiles[0].tempFilePath, name: 'file', header: { 'Content-type': 'application/json;charset=UTF-8', 'Authorization': wx.getStorageSync('token') }, success(fileRes) { if (!JSON.parse(fileRes.data).data) { _this.showToast('图片上传失败,请重试~') // 删除 const index = _this.data.uploadImageList.findIndex(item => item.imageId === _this.data.imageId) if (index > -1) { _this.data.uploadImageList.splice(index, 1) _this.setData({ uploadImageList: _this.data.uploadImageList }) } } else { uploadImageList[uploadImageList.length - 1].uploaded = true uploadImageList[uploadImageList.length - 1].ossUrl = JSON.parse(fileRes.data).data _this.setData({ uploadImageList }) } }, fail(fileRes) { _this.setData({ uploadImageList: [] }) _this.showToast('图片上传失败,请重试~') } }) } }) } else if (index === 1) { wx.chooseMedia({ count: 1, type: 'image', sourceType: ['album'], success(res) { console.log(res, '图片上传的res'); let deleteLength = _this.data.uploadImageList.length const uploadImageList = [] const endIndex = _this.data.uploadImageList.length res.tempFiles.forEach((item, index) => { if (item.size <= 5 * 1024 * 1024) { uploadImageList.push({ uploaded: false, ossUrl: { url: item.tempFilePath }, imgUrl: item.tempFilePath, imageId: ++_this.data.imageId, format: "image", type: item.tempFilePath.substr(item.tempFilePath.length - 3, 3), originFileName: 'image' + index + 1 }) } else { _this.showToast('图片上限5M,请压缩后重试~') } }) _this.setData({ uploadImageList: [..._this.data.uploadImageList, ...uploadImageList] }) uploadImageList.forEach((item, index) => { return (function (index) { wx.uploadFile({ url: `${config.BASEURL()}oss/file/uploadvariedfile`, filePath: res.tempFiles[index].tempFilePath, name: 'file', header: { 'Content-type': 'application/json;charset=UTF-8', 'Authorization': wx.getStorageSync('token') }, success(fileRes) { if (!JSON.parse(fileRes.data).data) { _this.showToast('图片上传失败,请重试~') _this.data.uploadImageList.splice(deleteLength, _this.data.uploadImageList.length - deleteLength) _this.setData({ uploadImageList: _this.data.uploadImageList }) } else { uploadImageList[index].uploaded = true uploadImageList[index].ossUrl = JSON.parse(fileRes.data).data _this.data.uploadImageList = _this.data.uploadImageList.slice(0, endIndex) _this.setData({ uploadImageList: [..._this.data.uploadImageList, ...uploadImageList] }) } }, fail(fileRes) { _this.setData({ uploadImageList: [] }) _this.showToast('图片上传失败,请重试~') } }) })(index) }) } }) } return true }, cancelText: '取消', cancel() {}, destructiveButtonClicked() {}, }) }, // 删除选中的图片 deleteImage(e) { const index = this.data.uploadImageList.findIndex(item => item.imageId === e.currentTarget.dataset.imageid) if (index > -1) { this.data.uploadImageList.splice(index, 1) this.setData({ uploadImageList: this.data.uploadImageList }) } }, // 代码简化,弹窗统一封装 showToast(title) { wx.showToast({ title: title, icon: 'none', duration: 2000 }) }, // 单选点击事件 inputSyncPicker(e) { let { detail: { value }, currentTarget: { dataset: { idKey, nameKey, listName, subname, subindex }, }, } = e; let item = this.data[listName][value]; let { personalInfo } = this.data; if (subname && subindex !== undefined) { personalInfo[subname][subindex][idKey] = item.value; personalInfo[subname][subindex][nameKey] = item.label; } else { personalInfo[idKey] = item.value; personalInfo[nameKey] = item.label; } this.setData({ personalInfo }); this.dataHandle(listName) }, dataHandle(listName) { if (listName == 'streetList') { this.setData({ communityList: [], gridList: [], 'personalInfo.community': '', // 社区 'personalInfo.communityId': '', // 社区 }) } else if (listName == 'communityList') { this.setData({ gridList: [], 'personalInfo.grid': '', // 网格 'personalInfo.gridId': '' // 网格 }) } if (this.data.personalInfo.streetId) { // 选择街道 this.data.streetList.forEach((element, index) => { if (this.data.personalInfo.streetId == element.value) { this.setData({ communityList: element.children }) } }); } if (this.data.personalInfo.communityId) { // 选择社区 this.data.communityList.forEach((element, index) => { if (this.data.personalInfo.communityId == element.value) { this.setData({ gridList: element.children }) } }); } }, // 逆地址解析 reverseLocation() { const _this = this this.data.qqMapWX.reverseGeocoder({ success(res) { console.log(res); _this.setData({ addressContent: res.result.address, 'fmData.address': res.result.address, 'fmData.longitude': res.result.location.lng, 'fmData.latitude': res.result.location.lat, }) }, fail(err) { console.debug(err) } }) }, onConfirmDate(e) { this.setData({ 'fmData.happenTime': e.detail.label + ':00', visibleTime: false, showTime: e.detail.label + ':00' }) }, onConfirmWantServiceTime(e) { this.setData({ 'fmData.wantServiceTime': e.detail.label + ':00', visibleTimeWantServiceTime: false, showWantServiceTimeTime: e.detail.label + ':00' }) }, //时间组件隐藏 onCancel(e) { this.setData({ visibleTime: false, visibleTimeWantServiceTime: false }) }, bindMobile(e) { this.setData({ resiMobile: e.detail.value }) }, getCurrentDateTime() { const date = new Date(); const year = date.getFullYear(); const month = (1 + date.getMonth()).toString().padStart(2, '0'); // Months are zero-based. const day = date.getDate().toString().padStart(2, '0'); 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 year + '-' + month + '-' + day + ' ' + hours + ':' + minutes + ':' + seconds; }, showTimePicker(e) { this.setData({ visibleTime: true, maxDate: this.getCurrentDateTime(), 'fmData.happenTime': this.getCurrentDateTime(), }) }, showTimePickerW(e) { this.setData({ visibleTimeWantServiceTime: true, maxDate: this.getCurrentDateTime(), 'fmData.wantServiceTime': this.getCurrentDateTime(), }) }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady() { }, /** * 生命周期函数--监听页面显示 */ onShow() { let resiDetail = wx.getStorageSync('resiDetail') if (resiDetail) { this.setData({ "fmData.resiId": resiDetail.resiId, resiName: resiDetail.resiName, resiMobile: resiDetail.resiMobile }) } }, /** * 生命周期函数--监听页面隐藏 */ onHide() { wx.removeStorageSync('resiDetail') }, /** * 生命周期函数--监听页面卸载 */ onUnload() { wx.removeStorageSync('resiDetail') }, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh() { }, /** * 用户点击右上角分享 */ // /page/user?id=123 onShareAppMessage() { }, handleRecordDel() { const { hasStop, isStart } = this.data console.log('hasStop---', this.data.hasStop) if (isStart && !hasStop) { recorderManager.stop() } if (!hasStop && isStart) recorderManager.stop(); recorderManager.stop(); clearInterval(timer) timer = null this.setData({ recordingTime: '00:00', recordingLength: 0, hasStart: false, isStart: false, hasStop: false, url: '', duration: 0 }) }, handleRecord() { let { hasStart } = this.data console.log(hasStart); if (hasStart) this.recortPause() else this.recortResume() }, handleOpenRecord() { this.setData({ isStart: true, }); console.log('opppppp') this.recordStart() }, // 录音暂停 recortPause() { recorderManager.pause(); this.setData({ hasStart: false }) clearInterval(timer) timer = null }, // 录音继续 recortResume() { this.recordingTimer() recorderManager.resume(); this.setData({ hasStart: true }) }, // 录音上传 uploadRecord(file, duration) { wx.uploadFile({ url: `${config.BASEURL()}oss/file/uploadvoice`, filePath: file, name: "file", header: { "Content-type": "multipart/form-data", 'Authorization': wx.getStorageSync('token') }, success: (fileRes) => { wx.hideLoading() console.log('ressss', fileRes) if (!JSON.parse(fileRes.data).data) { wx.showToast({ title: "录音上传失败,请重试~", icon: "none", duration: 1500 }) this.setData({ "uploadRecord.uploaded": true, "uploadRecord.url": "", totalTime: "", showRecord: false, hasStart: false, isStart: false, recordingTime: '00:00' }) } else { // let { recordingLength } = this.data // if (duration - (recordingLength * 1000) > 1000 ) duration = recordingLength * 1000 let url = JSON.parse(fileRes.data).data.url let fileName = Date.now() + Math.floor(Math.random() * 1000) this.setData({ "uploadRecord.uploaded": true, "uploadRecord.url": url, 'fmData.voiceList': [{ url: url, format: null, type: 'mp3', duration, originFileName: fileName.toString() }], showRecord: false, hasStart: false, isStart: false, recordingTime: '00:00', }) this.downLoadAudio() console.log(this.data.fmData.voiceList); } }, fail: (fileRes) => { console.log(fileRes); wx.showToast({ title: "录音上传失败,请重试~", icon: "none", duration: 1500 }) this.setData({ "uploadRecord.uploaded": true, "uploadRecord.url": "", totalTime: "", }) } }) }, // 录音开始 recordStart() { this.setData({ hasStart: true, }); const options = { duration: this.data.overDuration, format: 'mp3', type: 'voice' }; this.recordingTimer() recorderManager.start(options); recorderManager.onStart(res => { console.log('recorder start', res); }); recorderManager.onPause(res => { console.log('onPause', res) }) console.log(recorderManager); recorderManager.onResume(res => { console.log('onResume', res) }) recorderManager.onStop((res) => { console.log('recorder stop', res); const { tempFilePath, duration } = res; this.setData({ hasStop: true, url: tempFilePath, duration }) }); recorderManager.onFrameRecorded(res => { console.log('onFrameRecorded', res) }) recorderManager.onError((res) => { console.log('recorder onError', res); wx.showToast({ title: res.errMsg, icon: 'none', duration: 1500 }) }); }, // 录音暂停 recortPause() { recorderManager.pause(); this.setData({ hasStart: false }) clearInterval(timer) timer = null }, // 录音继续 recortResume() { this.recordingTimer() recorderManager.resume(); this.setData({ hasStart: true }) }, // 录音结束 recordStop() { const { url, recordingLength, hasStop } = this.data this.setData({ hasStart: false }) wx.showLoading({ title: '录音上传中...' }) console.log(url, recordingLength, hasStop) if (hasStop) { this.uploadRecord(url, 600000) console.log('hasStop', hasStop) } else { console.log('hasStopeee', hasStop) recorderManager.stop(); clearInterval(timer) timer = null recorderManager.onStop((res) => { console.log('recorder stop1111', res); const { tempFilePath, duration } = res; this.uploadRecord(tempFilePath, duration) // console.log(duration, '上传结束的语音时间'); this.setData({ recordingLength: 0, totalTime: this.format(duration) }) }); } }, recordingTimer() { clearInterval(timer) timer = null timer = setInterval(() => { let { overDuration, recordingLength } = this.data if (recordingLength * 1000 >= overDuration) { wx.showToast({ title: '录音已超时,已停止录音', icon: 'none', duration: 1500 }) console.log('lllllllll超时了') recorderManager.stop(); clearInterval(timer) timer = null this.setData({ hasStart: false }) return } let time = this.data.recordingLength + 1; this.setData({ recordingLength: time, recordingTime: this.formatTime(time) }); console.log('timer,还在执行', this.data.recordingLength) }, 1000); }, formatTime(num) { let min = parseInt(num / 60) let second = num % 60 min = min >= 10 ? min : '0' + min second = second >= 10 ? second : '0' + second return min + ':' + second }, hancleCancle() { this.handleRecordDel() this.setData({ showRecord: false }) }, hidePickerAngency() { this.setData({ angencyVisible: false }) }, showPicker() { this.setData({ angencyVisible: true }) }, onConfirmAngecy(e) { this.setData({ agencyName: e.detail.label, 'fmData.gridId': e.detail.value[e.detail.value.length - 1], angencyVisible: false }) }, onConfirmReportType(e) { console.log(e); this.setData({ reportTypeName: e.detail.label, 'fmData.reportType': e.detail.value[0], reportTypeVisible: false }) }, hidePickerReportType() { this.setData({ reportTypeVisible: false }) }, // 播放逻辑 initDuration() { var _a = this.data, duration = _a.duration; if (duration) { this.setData({ totalMax: duration }); } console.log('totalMax', this.data.totalMax); }, downLoadAudio() { var _this = this; wx.downloadFile({ url: this.data.uploadRecord.url, success(res) { console.log(res); if (res.statusCode === 200) { console.log('res2222222', res); _this.setData({ playUrl: res.tempFilePath }); _this.initAudio(); } else { wx.showToast({ title: '音频加载失败', icon: 'none', duration: 1500 }); } }, fail(err) { console.log(err); wx.showToast({ title: '音频加载失败', icon: 'none', duration: 1500 }); } }); }, initAudio() { var _this = this; innerAudioContext.src = this.data.playUrl; innerAudioContext.autoplay = false; this.initDuration(); console.log('ppppplllaaa', innerAudioContext); innerAudioContext.onCanplay(() => { console.log('初始化播放', innerAudioContext.duration); }); innerAudioContext.onPlay(() => { console.log('开始播放', innerAudioContext.duration); }); innerAudioContext.onTimeUpdate(() => { console.log("duration-onTimeUpdate", innerAudioContext.duration); console.log("currentTime", innerAudioContext.currentTime); if (innerAudioContext.duration) { _this.setData({ totalMax: (innerAudioContext.duration * 1000), }); } _this.setData({ stepValue: (innerAudioContext.currentTime * 1000), }); console.log('stepValue', _this.data.stepValue); console.log('totalTime', _this.data.totalTime); console.log('totalMax', _this.data.totalMax); }); innerAudioContext.onEnded(function () { console.log("end"); _this.setData({ hasPlay: false }); }); innerAudioContext.onError((res) => { console.log("errMsg", res.errMsg); wx.showToast({ title: res.errMsg, icon: 'none', duration: 1500 }); }); }, handlePlay() { var hasPlay = this.data.hasPlay; if (hasPlay) this.audioPause(); else this.audioPlay(); }, audioPause() { innerAudioContext.pause(); this.setData({ hasPlay: false }); }, audioPlay() { innerAudioContext.play(); this.setData({ hasPlay: true }); console.log('innerAudioContext', innerAudioContext); }, // 需求分类 onConfirmMeasure(e) { console.log(e); this.setData({ 'fmData.categoryCode': e.detail.selectedValue[1], 'fmData.parentCode': e.detail.selectedValue[0], categoryName: e.detail.label, measureVisible: false }) }, slideChange(e) { this.audioPause(); var value = e.detail.value; console.log('slidechange', value); innerAudioContext.seek(value / 1000); this.setData({ stepValue: value, }); this.audioPlay(); }, handleSlideMove(e) { this.audioPause(); }, handleAudioDel() { innerAudioContext.stop(); console.log('innerAudioContextdel', innerAudioContext); this.setData({ totalTime: '00:00', 'fmData.voiceList': [] }) }, showMeasurePicker() { this.setData({ measureVisible: true }) }, showReportTypePicker() { this.setData({ reportTypeVisible: true }) }, hidePickerMeasure() { this.setData({ measureVisible: false }) }, handleChangeType(e) { this.setData({ tabVal: e.detail.value }) }, handleChangeResponsibleUnit(e) { this.setData({ ruTabVal: e.detail.value, 'fmData.responsibleUnit': e.detail.value }) }, format(num) { let min = parseInt(num / 1000 / 60) let second = parseInt(num / 1000) % 60 min = min >= 10 ? min : '0' + min second = second >= 10 ? second : '0' + second return min + ':' + second }, process() { wx.navigateTo({ url: `/subpages/myTroubleshootDemand/pages/event/event?id=${this.data.optionsId}`, }) }, })