// pages/indexPages/selectHall/selectHall.js import { hqdw } from "../../../apis/index.js" Page({ /** * 页面的初始数据 */ data: { navigation: {}, type: "", selectTab: [{ label: "企业匹配的税务机关", value: "0" }, { label: "距离排序", value: "0" }, { label: "我的收藏", value: "1" }], selectTabIndex: 1, barStart: null, containerStyle: '', addressInfo: {}, myHall: {}, hall: [], nowHall: [], markers: [], searchText: "", searchTime: false }, /** * 生命周期函数--监听页面加载 */ onLoad(options) { let that = this that.init(options) that.getNavigationBar() that.hqdw() }, none() { return }, init(e) { let that = this if (e) { if (e.type) { that.setData({ type: e.type }) } } }, 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 }) }, hqdw() { let that = this wx.getLocation({ type: 'wgs84', isHighAccuracy: true, success(result) { that.setMarker(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.setMarker(data.result) 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', "未知") } }) } }) that.getHall() }, getHall() { let that = this let myHall = wx.getStorageSync('MY_HALL') let index = that.data.selectTabIndex let hallList = wx.getStorageSync('HALL_LIST') if (index === 0) { let userinfo = wx.getStorageSync('USERINFO') if (userinfo.swjgdm) { let hall = [] let uswjgdm = userinfo.swjgdm.substring(0, 7) for (let i = 0; i < hallList.length; i++) { let hswjgdm = hallList[i].ssswjgDm.substring(0, 7) if (uswjgdm == hswjgdm) { hall = hall.push(hallList[i]) } } that.setData({ hall: hall, myHall: myHall, nowHall: hall }) } else { that.setData({ hall: [], nowHall: [], myHall: myHall }) } } else if (index === 1) { that.setData({ hall: hallList, nowHall: hallList, myHall: myHall }) } else { that.setData({ hall: [], nowHall: [], myHall: myHall }) } }, selectHall(e) { let that = this let item = e.currentTarget.dataset.item wx.setStorageSync('MY_HALL', item) wx.navigateBack() }, call(e) { let that = this let item = e.currentTarget.dataset.item wx.makePhoneCall({ phoneNumber: item.kfdh, }) }, daohang(e) { let item = e.currentTarget.dataset.item wx.openLocation({ latitude: Number(item.latitude), longitude: Number(item.longitude), scale: 18, name: item.bsfwtmc, address: item.bsfwtdz, complete: (res) => { console.log(res) } }) }, bardown(e) { let that = this that.setData({ barStart: e.changedTouches[0].pageY }) }, barmove(e) { let that = this let barStart = that.data.barStart if (barStart) { let now = e.changedTouches[0].pageY let differ = now - barStart if (differ > 60) { that.setData({ containerStyle: 'down' }) } else if (differ < -60) { that.setData({ containerStyle: '' }) } } }, 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: "50rpx", height: "50rpx", callout: { content: "我的位置", color: "#313131", fontSize: 12, borderRadius: 5, bgColor: "#ffffff", padding: 5, display: "ALWAYS" } } that.setData({ markers: [marker] }) }, back() { wx.navigateBack() }, selectTab(e) { let that = this let index = e.currentTarget.dataset.index that.setData({ selectTabIndex: index }) let hallList = wx.getStorageSync('HALL_LIST') if (index === 0) { let userinfo = wx.getStorageSync('USERINFO') if (userinfo.swjgdm) { let hall = [] let uswjgdm = userinfo.swjgdm.substring(0, 7) for (let i = 0; i < hallList.length; i++) { let hswjgdm = hallList[i].ssswjgDm.substring(0, 7) if (uswjgdm == hswjgdm) { hall = hall.push(hallList[i]) } } that.setData({ hall: hall, nowHall: hall }) } else { that.setData({ hall: [], nowHall: [] }) } } else if (index === 1) { that.setData({ hall: hallList, nowHall: hallList }) } else { that.setData({ hall: [], nowHall: [] }) } }, search(e) { let that = this let value = e.detail.value that.setData({ searchText: value }) that.startSearch(value) }, startSearch(e) { let that = this let searchTime = that.data.searchTime if (e.length != 0) { if (!searchTime) { that.setData({ searchTime: true }) setTimeout(() => { /* */ let hall = that.data.nowHall let newHall = hall.filter((item) => { return item.bsfwtmc.indexOf(e) != -1 }) that.setData({ hall: newHall }) /* */ setTimeout(() => { that.setData({ searchTime: false }) }, 500); }, 0); } } else { that.getHall() } }, // start(e) { // let type = e.currentTarget.dataset.type // wx.navigateTo({ // url: '../selectBusiness/selectBusiness?type=' + type, // }) // }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady() { }, /** * 生命周期函数--监听页面显示 */ onShow() { }, /** * 生命周期函数--监听页面隐藏 */ onHide() { }, /** * 生命周期函数--监听页面卸载 */ onUnload() { }, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh() { }, /** * 页面上拉触底事件的处理函数 */ onReachBottom() { }, /** * 用户点击右上角分享 */ onShareAppMessage() { } })