// pages/index/index.js import { xcxsfsm, hqdw, xcxGetCompanyList, xcxGetCompanySwjg, xcxsmbd, xcxsy } from "../../apis/index.js" // 屏幕信息 let screenInfo = null let movableInfo = null Page({ /** * 页面的初始数据 */ data: { navigation: {}, addressInfo: {}, userInfo: {}, enterPriceList: [], enterpriceTypeShow: false, hall: {}, markers: [], myYy: {}, showVoice: false, searchValue: "", lbList: [{ url: 'https://smzc-1253299035.cos.ap-nanjing.myqcloud.com/pdjh/miniProgrameYyQh/indexLb1.png', name: "税费争议", path: "../taxDisputes/index/index" }, // { // url: 'https://smzc-1253299035.cos.ap-nanjing.myqcloud.com/pdjh/miniProgrameYyQh/indexLb2.png' // } ], lbIndex: 0, znzxX: 0, znzxY: '500rpx' }, /** * 生命周期函数--监听页面加载 */ onLoad(options) { let that = this that.init() that.getNavigationBar() that.getIndexInfos() }, init() { let that = this let device = wx.getSystemInfoSync() screenInfo = device.screenWidth - 50 that.setData({ znzxX: screenInfo }) }, getNavigationBar() { let that = this const res = wx.getMenuButtonBoundingClientRect() let navigation = { width: res.left + 'px', height: res.height + 6 + 'px', paddingTop: res.top - 3 + 'px' } that.setData({ navigation: navigation }) }, getIndexInfos() { let that = this that.sfsm() }, hqdw() { let that = this wx.getLocation({ type: 'wgs84', isHighAccuracy: true, success(result) { hqdw().then(res => { if (res.code == 200) { let data = JSON.parse(res.message) that.setData({ addressInfo: { lat: result.latitude, lng: result.longitude, address: data.result.ad_info.district || data.result.ad_info.city || data.result.ad_info.province || data.result.ad_info.nation } }) wx.setStorageSync('ADDRESS', data.result.ad_info.district || data.result.ad_info.city || data.result.ad_info.province || data.result.ad_info.nation) } else { that.setData({ addressInfo: { lat: result.latitude, lng: result.longitude, address: "未知" } }) wx.setStorageSync('ADDRESS', "未知") } }) }, fail: (err) => { hqdw().then(res => { if (res.code == 200) { let data = JSON.parse(res.message) that.setData({ addressInfo: { lat: data.result.location.lat, lng: data.result.location.lng, address: data.result.ad_info.district || data.result.ad_info.city || data.result.ad_info.province || data.result.ad_info.nation } }) wx.setStorageSync('ADDRESS', data.result.ad_info.district || data.result.ad_info.city || data.result.ad_info.province || data.result.ad_info.nation) } else { that.setData({ addressInfo: { lat: "", lng: "", address: "未知" } }) wx.setStorageSync('ADDRESS', "未知") } }) } }) }, authorizeSuccess() { let that = this that.getIndexInfos() }, sfsm() { let that = this let publicId = wx.getStorageSync('PUBLIC_ID') if (publicId.unionid) { xcxsfsm({ xcxId: publicId.openid, unionid: publicId.unionid }).then((res) => { switch (res.code) { default: return; case 200: wx.setStorageSync('REAL_NAME', true) wx.setStorageSync('LOCK', false) var userInfos = { name: res.smxx.xm, idcard: res.smxx.sfzhm, phone: res.smxx.sjh, swjgdm: res.smxx.swjgdm || "", nsrsbh: res.smxx.nsrsbh || "", nsrmc: res.smxx.nsrmc || "" } wx.setStorageSync('USERINFO', userInfos) that.setData({ userInfo: userInfos }) break; case 501: wx.setStorageSync('REAL_NAME', false) wx.setStorageSync('LOCK', false) wx.removeStorageSync('USERINFO') wx.removeStorageSync('MY_HALL') break; case 502: wx.setStorageSync('REAL_NAME', true) wx.setStorageSync('LOCK', true) var userInfos = { name: res.smxx.xm, idcard: res.smxx.sfzhm, phone: res.smxx.sjh, swjgdm: res.smxx.swjgdm || "", nsrsbh: res.smxx.nsrsbh || "", nsrmc: res.smxx.nsrmc || "" } wx.setStorageSync('USERINFO', userInfos) that.setData({ userInfo: userInfos }) break; case 500: wx.removeStorageSync('USERINFO') wx.removeStorageSync('MY_HALL') break } }) } else { setTimeout(() => { that.sfsm() }, 500); } }, getHall() { let that = this let publicId = wx.getStorageSync('PUBLIC_ID') if (that.data.addressInfo.lat && that.data.addressInfo.lng) { let form = { xcxId: publicId.openid, unionid: publicId.unionid, longitude: String(that.data.addressInfo.lng), latitude: String(that.data.addressInfo.lat), nsrsbh: that.data.userInfo.nsrsbh || "", swjgdm: that.data.userInfo.swjgdm || "" } xcxsy(form).then(res => { if (res.code == 200) { let halls = res.list.sort((a, b) => { return a.zxjl - b.zxjl }) wx.setStorageSync('HALL_LIST', halls) that.setMyHall(halls) that.setData({ myYy: res.yyjl }) } else { wx.showToast({ title: res.msg || res.message, icon: "none", duration: 5000 }) } }) } else { setTimeout(() => { that.getHall() }, 500); } }, setMyHall(e) { let that = this let userinfo = wx.getStorageSync('USERINFO') let myhall = wx.getStorageSync('MY_HALL') if (myhall) { let update = false for (let i = 0; i < e.length; i++) { if (e[i].bsfwtDm == myhall.bsfwtDm) { update = true that.setData({ hall: e[i] }) that.setMarker(e[i]) wx.setStorageSync('MY_HALL', e[i]) break; } } if (!update) { that.setData({ hall: myhall }) that.setMarker(myhall) } } else { if (userinfo.swjgdm) { let hall = {} let uswjgdm = userinfo.swjgdm.substring(0, 7) for (let i = 0; i < e.length; i++) { let hswjgdm = e[i].ssswjgDm.substring(0, 7) if (uswjgdm == hswjgdm) { hall = e[i] break; } } if (!hall.bsfwtmc) hall = e[0] that.setData({ hall: hall }) wx.setStorageSync('MY_HALL', hall) that.setMarker(hall) } else { let hall = e[0] that.setData({ hall: hall }) wx.setStorageSync('MY_HALL', hall) that.setMarker(hall) } } }, setMarker(e) { let that = this let lat = e.latitude || e.lat let lng = e.longitude || e.lng let marker = { id: 9527, latitude: lat, longitude: lng, title: "", zIndex: 9, alpha: 0.9, iconPath: "../../icon/address.png", width: "30rpx", height: "30rpx", callout: { content: "大厅地址", color: "#313131", textAlign: "center", fontSize: 10, borderRadius: 5, bgColor: "#ffffff", padding: 5, display: "ALWAYS" } } that.setData({ markers: [marker] }) }, changeType() { let that = this let authorize = getApp().globalData.authorize() if (authorize == 0) { let nsrmc = that.data.userInfo.nsrmc if (nsrmc.length > 2) { wx.showLoading({ title: '正在切换身份...', }) let publicId = wx.getStorageSync('PUBLIC_ID') let form = { xcxId: publicId.openid, unionid: publicId.unionid, xm: that.data.userInfo.name, sfzjhm: that.data.userInfo.idcard, sjh: that.data.userInfo.phone, nsrmc: "", nsrsbh: "", swjgdm: "" } xcxsmbd(form).then(res => { wx.hideLoading() if (res.code == 200) { that.getIndexInfos() that.close() } else { wx.showToast({ title: res.msg || res.message, icon: "none", duration: 5000 }) } }) } else { that.changeEnterprice() } } else { let authorizeBox = this.selectComponent("#authorizeBox") authorizeBox.show() } }, changeEnterprice() { let that = this that.setData({ enterPriceList: [] }) let authorize = getApp().globalData.authorize() if (authorize == 0) { wx.showLoading({ title: '正在获取企业信息', }) that.setData({ enterpriceTypeShow: true }) xcxGetCompanyList({ xm: that.data.userInfo.name, sfzjhm: that.data.userInfo.idcard }).then(res => { wx.hideLoading() if (res.code == 200) { that.setData({ enterPriceList: res.list }) } else { wx.showToast({ title: res.msg || res.message, icon: "none", duration: 5000 }) } }) } }, async selectEnterprice(e) { let that = this wx.showLoading({ title: '正在切换...', }) let publicId = wx.getStorageSync('PUBLIC_ID') let item = e.currentTarget.dataset.item let form = { xcxId: publicId.openid, unionid: publicId.unionid, xm: that.data.userInfo.name, sfzjhm: that.data.userInfo.idcard, sjh: that.data.userInfo.phone, nsrmc: item.nsrmc, nsrsbh: item.nsrsbh, swjgdm: await that.getEnterpriceSwjgdm(item) || "" } xcxsmbd(form).then(res => { wx.hideLoading() if (res.code == 200) { that.close() let userinfo = { idcard: form.sfzjhm, name: form.xm, nsrmc: form.nsrmc, nsrsbh: form.nsrsbh, phone: form.sjh, swjgdm: form.swjgdm, } wx.setStorageSync('USERINFO', userinfo) that.setData({ userInfo: userinfo }) wx.removeStorageSync('MY_HALL') that.setMyHall(wx.getStorageSync('HALL_LIST')) } else { wx.showToast({ title: res.msg || res.message, icon: "none", duration: 5000 }) } }) }, getEnterpriceSwjgdm(e) { return new Promise((resolve, rejects) => { let form = { djxh: e.djxh, nsrsbh: e.nsrsbh } xcxGetCompanySwjg(form).then(res => { if (res.code == 200) { resolve(res.swjgdm) } else { resolve(null) } }) }) }, close() { let that = this that.setData({ enterpriceTypeShow: false }) }, selectHall(e) { let that = this let type = e.currentTarget.dataset.type let authorize = getApp().globalData.authorize() if (authorize == 0) { wx.navigateTo({ url: '../indexPages/selectHall/selectHall?type=' + type, }) } else { let authorizeBox = this.selectComponent("#authorizeBox") authorizeBox.show() } }, start(e) { let type = e.currentTarget.dataset.type let authorize = getApp().globalData.authorize() if (authorize == 0) { wx.navigateTo({ url: '../indexPages/selectBusiness/selectBusiness?type=' + type, }) } else { let authorizeBox = this.selectComponent("#authorizeBox") authorizeBox.show() } }, toYyDetail(e) { let item = e.currentTarget.dataset.item wx.navigateTo({ url: '../recordPages/yyjl/yyjl?infos=' + JSON.stringify(item), }) }, toLookSsqh() { wx.switchTab({ url: '../record/record', }) }, startSmrz() { let authorizeBox = this.selectComponent("#authorizeBox") authorizeBox.show() }, toSearch() { console.log('search') }, indexSearchInput(e) { let that = this let value = e.detail.value that.setData({ searchValue: value }) }, startVoice() { let that = this that.setData({ showVoice: true }) }, closeVoice() { let that = this that.setData({ showVoice: false }) }, resVoice(e) { let that = this let searchValue = that.data.searchValue searchValue = searchValue + e.detail that.setData({ searchValue: searchValue }) that.closeVoice() }, movableEnd() { let that = this if (movableInfo) { that.setData({ znzxX: movableInfo.x, znzxY: movableInfo.y }) movableInfo = null } }, movable(e) { let that = this let now = e.detail let x = 0 if (now.x > screenInfo / 2) { x = screenInfo } else { x = 0 } movableInfo = { x: x, y: now.y } }, toZnzx() { wx.navigateTo({ url: '../other/znzx/znzx', }) }, lbChage(e) { let that = this that.setData({ lbIndex: e.detail.current }) }, swiperTap(e) { let item = e.currentTarget.dataset.item if (item.path) { wx.navigateTo({ url: item.path, }) } }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady() { }, /** * 生命周期函数--监听页面显示 */ onShow() { let that = this that.hqdw() that.getHall() that.getIndexInfos() let userInfo = wx.getStorageSync('USERINFO') that.setData({ userInfo: userInfo }) }, /** * 生命周期函数--监听页面隐藏 */ onHide() { }, /** * 生命周期函数--监听页面卸载 */ onUnload() { }, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh() { }, /** * 页面上拉触底事件的处理函数 */ onReachBottom() { }, /** * 用户点击右上角分享 */ onShareAppMessage() { } })