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:'',//是否添加焦点到输入框或语音 orgList:[], selectOrgIndex:0, selectOrgList:[], selectedNpc:{}, npcList:[], selectNpcIndex:-1, showedHint: false, viewHeight: '100%', submitStatus: "not-started", fmData: { gridId:"",//用户所在网格id eventContent:"",//事件内容,最多1000 latitude:"",//纬度 longitude:"",//经度 address:"",//地址 attachmentList: [],//附件列表 npcUserList: [],//被@的人大代表 orgList: [],//报给谁? voiceList: [], // 语音文件 }, // 最大上传图片数量 maxLimitImg: 3, submitBtnIsAllowed: false, dateStart:formatTimestamp(), tabRecord: false, dialogVisible: false, }, // 更新data数据后需主动触发 $afterUpdateData() { this.computeSubmitBtnIsAllowed(); }, computeSubmitBtnIsAllowed(isQuiet = true) { const { fmData, submitStatus } = this.data, vlt = validate(fmData, { eventContent: [ { rule: "required", message: "请填写内容" } ], }); if (!vlt.valid) { if (!isQuiet) { wx.showToast({ title: vlt.error, icon: "none", duration: 1500 }); } this.setData({ submitBtnIsAllowed: false }); return false; } else { this.setData({ submitBtnIsAllowed: submitStatus !== "success" }); return true; } }, async onLoad(query) { const { blurType } = query; 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 }); await this.getOrgList() await this.getNpcList() this.getLocation(); this.setData({ iniLoaded: true }); }, onShow() {}, onReady() { this.computedViewHeight() }, inputSync, // 获取组织列表 async getOrgList() { const { gridId } = this.data; const { data: { data: { code, data }, }, msg, } = await wxRequestPost( 'resi/home/resi-event/report-target-level-list', { gridId, }, { // isMock: true } ); if (msg === 'success' && code === 0) { let { orgList,selectOrgIndex,selectOrgList} = this.data; orgList = data.reportTargets selectOrgList = [] if(orgList.length>0){ selectOrgIndex=0 selectOrgList.push(orgList[0]) }else{ selectOrgIndex=-1 } this.setData({ orgList,selectOrgIndex,selectOrgList }); } }, //选择网格列表 handleSelectOrg(e){ let {selectOrgIndex,orgList,selectOrgList}=this.data const { currentTarget: { dataset: { index }, }, } = e; selectOrgIndex = index selectOrgList=[] selectOrgList.push(orgList[index]) this.setData( {selectOrgIndex,selectOrgList} ) }, // 强行获取地址信息,或打扰用户给予授权 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() }, // 获取人大代表列表 async getNpcList() { const { customerId } = this.data; this.setData({ initLoading: true, }); const url = "resi/home/resi-event/npc-list"; const { data: { data: { code, data }, }, msg, } = await wxRequestPost( url, { customerId, }, { // isMock: true, // isQuiet: true } ); this.setData({ initLoading: false, }); if (msg === "success" && code === 0) { let { npcList,selectNpc,selectNpcIndex } =this.data npcList = data.reportTargets // if(npcList.length>0){ // selectNpcIndex=0 // selectNpc=npcList[0] // }else{ // selectNpcIndex=-1 // selectNpc={} // } this.setData({ npcList,selectNpc,selectNpcIndex }); } }, //选择人大代表弹出框 async atNpc() { const $selectNpc = this.selectComponent("#selectNpc"); let {selectNpcIndex,npcList,selectedNpc}= this.data let result=await $selectNpc.show(); if(result!=='cancal'){ selectNpcIndex = result selectedNpc=npcList[selectNpcIndex] } this.setData({ selectedNpc,selectNpcIndex }); }, //删除人大代表 delNpc(){ this.setData({ selectNpcIndex:-1, selectedNpc:{} }); }, // 提交通知 async submit(e) { let { fmData, gridId,selectOrgList,selectNpcIndex,selectedNpc } = this.data; // if (!this.computeSubmitBtnIsAllowed(false)) { // return; // } fmData.eventContent = fmData.eventContent.trim(); if (fmData.eventContent === "" && fmData.voiceList.length === 0) { console.log("fmData.voiceList.length", fmData.voiceList.length); return wx.showToast({ title: "报事内容或报事语音不能为空", icon: "none", duration: 1500, }); } const retConfirm = await wxShowModal({ title: "确认提交?", }); if (retConfirm.msg !== "success" || !retConfirm.data.confirm) { return; } 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); // } = await this.selectComponent("#uploadImg").upload(); 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, }); } if(selectOrgList.length==0){ return wx.showToast({ title: "请选择上报组织", icon: "none", duration: 1500 }); } // fmData.eventContent = fmData.eventContent.trim() fmData.attachmentList = imageList fmData.gridId = gridId; fmData.orgList=selectOrgList fmData.npcUserList=[] if(!(selectNpcIndex<0)){ fmData.npcUserList.push(selectedNpc) } console.log(fmData.npcUserList) let url ="gov/project/resievent/report" 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) { this.setData({ submitStatus: "success" }); // this.setData({ // dialogVisible: true, // }); // await nextTick(1000); // this.resetData() wx.redirectTo({ url: "/subpages/index/pages/report/create" }) // wx.navigateBack({ // delta: 1 // }); } }, // async submitComfire() { // this.setData({ // dialogVisible: false, // }); // if (this.data.templateList && this.data.templateList.length > 0) { // await this.handleRequestMsg(); // } else { // this.setData({ // submitStatus: "success", // }); // if (this.data.topicId) { // wx.reLaunch({ // url: "/subpages/mine/pages/works/topic-part/start-topic/index", // }); // return; // } // // this.computeSubmitBtnIsAllowed(); // await nextTick(1000); // wx.navigateBack({ // delta: 1, // }); // } // }, //重置列表 resetData(){ let {fmData,orgList,selectOrgIndex,selectOrgList,selectedNpc} = this.data fmData= { gridId:"",//用户所在网格id eventContent:"",//事件内容,最多1000 latitude:"",//纬度 longitude:"",//经度 address:"",//地址 attachmentList: [],//附件列表 npcUserList: [],//被@的人大代表 orgList: [],//报给谁? } if(orgList.length>0){ selectOrgIndex=0 selectOrgList.push(orgList[0]) }else{ selectOrgIndex=-1 selectOrgList=[] } selectedNpc={} this.getLocation(); this.setData( { fmData,selectOrgIndex,selectOrgList,selectedNpc } ) }, // 动态计算轮播高度 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(ress.windowHeight, res[0].height, res[1].height, res[2].height, res[3].height); let _h = 0; _h = ress.windowHeight - res[0].height - res[1].height - res[2].height - _height; if (res[3].height) _h = ress.windowHeight - res[3].height - _height; console.log("++++++", _h); that.setData({ viewHeight: _h + "px", }); }) .exec(); }, //跳转到我的报事 toMyReport(){ wxNavigateTo("/subpages/index/pages/report/myReport/index", { groupId: "b596a7cf119ebd812a2d9e16dcb315de" }); }, 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' }); 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"); }, });