import { inputSync, nextTick, doAfterLogin } from "@utils/tools"; import { formatTimestamp } from "@utils/common"; import { wxShowModal, wxRequestPost, wxNavigateTo, } from "@utils/promise-wx-api"; import getLocation from "../../../../utils/location"; import validate from "@utils/validate/index.js"; const app = getApp(); Page({ data: { iniLoaded: false, gridId: "", customerId: "", blurType:'',//是否添加焦点到输入框或语音 showedHint: false, viewHeight: '100%', fmData: { gridId:"",//用户所在网格id content:"",//事件内容,最多1000 latitude:"",//纬度 longitude:"",//经度 address:"",//地址 attachmentList: [],//附件列表 voiceList: [], // 语音文件 }, attachmentList:[], // 最大上传图片数量 maxLimitImg: 3, submitBtnIsAllowed: true, dateStart:formatTimestamp(), tabRecord: false, dialogVisible: false, haveRegistered: false, }, // 更新data数据后需主动触发 $afterUpdateData() { // this.computeSubmitBtnIsAllowed(); }, computeSubmitBtnIsAllowed(isQuiet = true) { const { fmData } = this.data, if(fmData.content||fmData.attachmentList.length>0){ this.setData({ submitBtnIsAllowed: true }); }else{ this.setData({ submitBtnIsAllowed: false }); } }, async onLoad(query) { let { blurType } = query; if(!blurType || blurType===''){ blurType='voice' } this.setData( { blurType }); console.log(1111111) console.log(this.data.blurType) if(blurType==='voice'){ this.setData({ tabRecord: true, }); // this.computedViewHeight(); } await doAfterLogin(); this.setData( { gridId:app.globalData.gridId, customerId:app.globalData.customerId }); this.getLocation(); this.setData({ iniLoaded: true }); }, onShow() { this.syncRoleInfo(); }, // 用户是否注册过居民 async syncRoleInfo() { const haveRegistered =app.globalData.userRoleList.indexOf("registered_resi") !== -1; this.setData({ haveRegistered, }); if(!this.data.haveRegistered){ await this.selectComponent("#modalReg").show(); return false; } }, onReady() { this.computedViewHeight() }, inputSync, // 强行获取地址信息,或打扰用户给予授权 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 } }); } }) }, // 获取地理位置信息 async getLocation(isQuiet = true) { const { msg, data } = await getLocation(isQuiet); console.log(msg, data); if (msg === "success") { const { fmData } = this.data; this.setData({ fmData: { ...fmData, address: data.address, longitude: data.longitude, latitude: data.latitude, } }); } }, async addImg() { await this.selectComponent("#uploadImg").selectImage() console.log(this.selectComponent("#uploadImg").data.attachmentList) }, // 提交通知 async submit(e) { if(!this.data.haveRegistered){ await this.selectComponent("#modalReg").show(); return false; } let { fmData, gridId } = this.data; let attachmentListTemp=this.selectComponent("#uploadImg").data.attachmentList fmData.content = fmData.content.trim(); if (fmData.content === "" && fmData.voiceList.length === 0) { return wx.showToast({ title: "报事内容或报事语音不能为空", icon: "none", duration: 1500, }); } const retConfirm = await wxShowModal({ title: "确认提交?", }); if (retConfirm.msg !== "success" || !retConfirm.data.confirm) { return; } if ( attachmentListTemp.length> 0) { let paramsFile={ customerId:app.globalData.customerId } const { msg: uploadMsg, data: imageList, error: uploadError, } = await this.selectComponent("#uploadImg").upload("oss/file/upload-resi-event-file",paramsFile); if (uploadMsg === "invalid") { const { msg: contiueSubmit } = await wxShowModal({ content: uploadError, cancelText: "继续提交", confirmText: "去修改", }); if (contiueSubmit === "success") { return; } } else if (uploadMsg === "error") { return wx.showToast({ title: uploadError, icon: "none", duration: 2000, }); } } // fmData.content = fmData.content.trim() fmData.attachmentList = imageList fmData.gridId = gridId; let url ="gov/project/icEvent/add-event-resi" let params=fmData this.setData({ fmData }); wx.showLoading({ title: "正在提交中", mask: true }); const { data: { data }, msg } = await wxRequestPost(url, params, { // isMock: true }); wx.hideLoading(); if (msg === "success" && data.code === 0) { wx.showToast({ title: '您的信息已收到,社区会尽快处理', icon: 'none', duration: 1500 }) await nextTick(1500) wx.redirectTo({ url: "/subpages/index/pages/suishijiang/create" }) } }, //重置列表 resetData(){ let {fmData} = this.data fmData= { gridId:"",//用户所在网格id content:"",//事件内容,最多1000 latitude:"",//纬度 longitude:"",//经度 address:"",//地址 attachmentList: [],//附件列表 } this.getLocation(); this.setData( { fmData } ) }, // 动态计算轮播高度 computedViewHeight1() { const ress = wx.getSystemInfoSync() let _height = 230 let _h = 0 _h = (ress.windowHeight - _height) this.setData({ viewHeight: _h + 'px' }) }, // 动态计算轮播高度 computedViewHeight(height = 0) { let that = this; let query = wx.createSelectorQuery().in(this); const ress = wx.getSystemInfoSync(); let _height = height || 120; query .selectAll(".row_myreport,.position-hints,.btn, .topic-record") .boundingClientRect(function (res) { console.log(res) console.log(ress.windowHeight, res[0].height, res[1].height, res[2].height); let _h = 0; if(res[2].height===0){ _h = ress.windowHeight - res[0].height - res[1].height - res[2].height - _height; }else{ _h = ress.windowHeight - res[0].height - res[1].height - res[2].height + 110 - _height; } if (res[3]&&res[3].height) _h = ress.windowHeight - res[3].height - _height; console.log("++++++", _h); that.setData({ viewHeight: _h + "px", }); }) .exec(); }, //跳转到我的报事 handleTapRecord('tab') { this.setData({ tabRecord: !this.data.tabRecord, }); this.computedViewHeight(); }, handleRecordFinish(e) { let { fmData: { voiceList }, } = this.data; const { url, duration } = e.detail; voiceList.push({ url, duration, format:'mp3' , type:'voice'}); console.log("eeeeee", e.detail); this.setData({ "fmData.voiceList": voiceList, tabRecord: false, submitBtnIsAllowed: true, }); this.computedViewHeight(); }, handleAudioDel() { let { fmData: { voiceList }, } = this.data; voiceList.shift(); this.setData({ "fmData.voiceList": voiceList, }); this.computeSubmitBtnIsAllowed(); console.log("dddddddddel"); }, });