const _Http = getApp().globalData.http; import { tianditu } from "../../utils/tianditu.js"; const api = new tianditu(); import { formatTime } from "../../utils/getTime"; let timing = null; Page({ data: { loading: false, markers: [], content: {}, time: formatTime(new Date(), '-'), form: null, continue1: null, count: 0 }, onLoad(options) { getApp().globalData.Language.getLanguagePackage(this, '签到'); this.getLocation(); timing = setInterval(() => { this.setData({ time: formatTime(new Date(), '-') }) }, 1000); this.rander(); }, submit() { let data = this.selectComponent("#Form").submit(), content = JSON.parse(JSON.stringify(this.data.content)), that = this; content.remarks = data.remarks; if (data.sys_enterprise) content.sys_enterpriseid = data.sys_enterprise[1][0]; if (data.sa_project) content.sa_projectid = data.sa_project[1][0]; wx.showModal({ title: getApp().globalData.Language.getMapText("提示"), content: getApp().globalData.Language.getMapText("是否确认本次签到") + '?', cancelText: getApp().globalData.Language.getMapText("取消"), confirmText: getApp().globalData.Language.getMapText("确定"), complete: ({ confirm }) => { if (confirm) that.onConfirm(content); } }) }, onConfirm(content) { this.setData({ loading: true }) _Http.basic({ id: 20221229145901, content }).then(res => { console.log("签到", res) this.setData({ loading: false }) wx.showToast({ title: res.code == '1' ? (this.data.language['成功的'] || '签到成功') : res.msg, icon: "none" }) if (res.code != '1') return; let { attachmentids } = this.selectComponent("#Yl_Files").getFiles(); if (attachmentids.length == 0) return setTimeout(() => { getCurrentPages()[getCurrentPages().length - 2].toDate(this.data.time.split(" ")[0]); wx.navigateBack(); }, 500) _Http.basic({ "classname": "system.attachment.Attachment", "method": "createFileLink", "content": { "ownertable": "sys_signin", "ownerid": res.data.sys_signinid, "usetype": "default", attachmentids } }).then(s => { console.log('附件改绑', s) if (s.code != '1') wx.showToast({ title: s.msg, icon: "none", mask: true }); setTimeout(() => { getCurrentPages()[getCurrentPages().length - 2].toDate(this.data.time.split(" ")[0]); wx.navigateBack(); }, 500) }) }) }, rander() { this.setData({ form: [{ label: "客户", error: false, errMsg: "", type: "route", url: "/packageA/select/setclient/select", value: "", params: { id: 20221012164402, content: { pageNumber: 1, pageTotal: 1, nocache: true, type: 8, isExport: 0, where: { condition: "", }, sort: [{ sortname: "默认", sorted: 1, sortid: 67, reversed: 0 }] }, }, query: "&radio=true&idname=sys_enterpriseid", interrupt: true, placeholder: "选择客户", valueName: "sys_enterprise", checking: "base", required: false }, { label: "项目", error: false, errMsg: "", type: "route", url: "/packageA/select/project/select", value: "", params: { id: 20221020143502, content: { nocache: true, type: 8, where: { condition: "", //模糊搜索 }, }, }, query: "&radio=true", interrupt: true, placeholder: "选择项目", valueName: "sa_project", checking: "base", required: false }, { label: "说明", error: false, errMsg: "", type: "textarea", value: "", placeholder: "请填写", valueName: "remarks", required: false, //必填 }] }); }, /* 打断处理form */ interrupt(e) { console.log(e) let { data, form, temporary } = e.detail; if (temporary.item.value[0] == data.value[0]) return wx.navigateBack() temporary.item.value = data.value; if (temporary.item.valueName == "sys_enterprise") { form[0] = temporary.item; form[1].label = '客户关联项目'; form[1].interrupt = false; form[1].params = { id: 20221020143502, content: { nocache: true, type: 0, where: { condition: "", //模糊搜索 sys_enterpriseid: data.value[1][0], }, }, } form[1].value = ""; this.setData({ form, continue1: "sa_project" }) } else if (temporary.item.valueName == "sa_project") { form.splice(0, 1, temporary.item); form.splice(1, 1, { label: "项目关联客户", error: false, errMsg: "", type: "route", url: "/packageA/select/setclient/select", value: "", params: { "id": 20221012164402, content: { nocache: true, type: 0, isExport: 0, where: { condition: "", sa_projectid: data.value[1][0], }, sort: [{ sortname: "默认", sorted: 1, sortid: 67, reversed: 0 }] }, }, query: "&radio=true&idname=sys_enterpriseid", placeholder: "选择客户", valueName: "sys_enterprise", checking: "base", required: false }); this.setData({ form, continue1: "sys_enterprise" }) }; wx.navigateBack() }, /* 获取定位 */ getLocation() { let that = this; wx.showLoading({ title: getApp().globalData.Language.getMapText('定位中...'), }); wx.getLocation({ type: 'gcj02', isHighAccuracy: true, highAccuracyExpireTime: 8000, success({ latitude, longitude }) { console.log('精确', latitude, longitude) that.setData({ 'markers[0]': { id: 1, latitude, longitude, } }); } }) wx.getLocation({ success({ latitude, longitude }) { wx.hideLoading(); api.getPlace(longitude, latitude).then((place) => { console.log("获取逆解析地址", place) let result = place.result; that.setData({ content: { province: result.addressComponent.province || result.addressComponent.city, city: result.addressComponent.city || result.addressComponent.province, county: result.addressComponent.county, address: result.formatted_address, latitude, longitude, remarks: "", sa_projectid: 0, sys_enterpriseid: 0 } }) }) }, fail: function (e) { //这里是获取失败的时候 wx.hideLoading(); wx.getSetting({ success: res => { if (typeof (res.authSetting['scope.userLocation']) != 'undefined' && !res.authSetting['scope.userLocation']) { wx.showModal({ title: getApp().globalData.Language.getMapText('提示'), content: getApp().globalData.Language.getMapText('您拒绝了定位权限,将无法使用签到功能 是否前往开启'), cancelText: getApp().globalData.Language.getMapText('取消'), confirmText: getApp().globalData.Language.getMapText('确定'), success: res => { if (res.confirm) { wx.openSetting({ success: res => { if (res.authSetting['scope.userLocation']) { that.getLocation(); } else { getApp().globalData.Language.showToast('未获取到权限') } } }); } } }); } } }) }, }) }, onUnload() { clearInterval(timing) }, /* 绑定媒体 */ insertImgEdit({ detail }) { _Http.basic({ "classname": "system.attachment.Attachment", "method": "createFileLink", "content": { "ownertable": "sys_signin", "ownerid": 0, "usetype": "default", "attachmentids": detail } }).then(res => { console.log('跟进记录绑定附件', res) if (res.code != '1') return wx.showToast({ title: res.msg, icon: "none" }) this.selectComponent("#Yl_Files").handleFiles(res.data) this.setData({ count: this.data.count + detail.length }) }) }, /* 监听删除附件 */ onDeteleFiles({ detail }) { this.setData({ count: detail.attachmentids.length }) } })