// pages/school/school.js import { routers, viewImage, sharePage, isFn, getGlobalVal, formatDateTime, formateNumber } from '../../utils/util.js' import { SchoolList } from '../../utils/api.js' const { navigateTo, redirectTo, navigateBack } = routers() const { globalData, saveUserInfo, getWxloginCode, checkStatus } = getApp() const { baseImgUrl, thumbnail } = globalData const app = getApp() Page({ /** * 页面的初始数据 */ data: { search: '', isWechat:0, list: [], statusBar: app.globalData.statusBar, isDetail:0, nodata: [ { text: '暂无学校' } ], }, /** * 生命周期函数--监听页面加载 */ onLoad: function (options) { this.setData(options) const {status}=options; this.getLocation() setTimeout(() => { wx.getSetting({ success: res => { if (!res.authSetting['scope.userLocation']) { this.openLocationConfirm() } } }) }, 1000) }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady: function () { const obj = { navigateTo, redirectTo, navigateBack, viewImage } for (const i in obj) { this[i] = obj[i] } }, /** * 生命周期函数--监听页面显示 */ onShow: function () { }, /** * 生命周期函数--监听页面隐藏 */ onHide: function () { }, /** * 生命周期函数--监听页面卸载 */ onUnload: function () { }, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh: function () { }, /** * 页面上拉触底事件的处理函数 */ onReachBottom: function () { }, /** * 用户点击右上角分享 */ onShareAppMessage: function () { }, /** * 路由跳转 */ redirectCtl: app.redirectCtl, navigateCtl: app.navigateCtl, /** * 输入学校 */ inputCtl: function (e) { const { value } = e.detail this.setData({ search: value }) this.getSchoolList() }, /** * 获取定位经纬度 */ getLocation: function () { wx.showLoading({ title: '定位中' }) wx.getLocation({ type: 'wgs84', success: res => { console.log(res) this.setData({ location: { longitude: res.longitude, // '113.36403' || latitude: res.latitude // '23.14203' || } }) this.getSchoolList({ longitude: res.longitude, latitude: res.latitude }) }, fail: res => { wx.showToast({ title: '定位失败', icon: 'none' }) }, complete: res => { wx.hideLoading() } }) }, /** * 再次弹起弹出框要求重新获取地位 */ openLocationConfirm: function () { wx.showModal({ content: '检测到您没打开定位权限,是否去设置打开?', confirmText: "确认", cancelText: "取消", success: res => { if (res.confirm) { wx.openSetting({ success: res => { if (res.authSetting['scope.userLocation']) { this.getLocation() } else { wx.navigateBack({ delta: 1 }) } } }) } else { wx.navigateBack({ delta: 1 }) } } }) }, /** * 获取学校列表 */ getSchoolList: function (e) { const continuousFn = { fn: this.getSchoolList, param: { ...arguments } } const { location, search } = this.data const { longitude, latitude } = location || e const libId = wx.getStorageSync('libId')||''; wx.showLoading({ title: '加载中', }) SchoolList({ data: { longitude, latitude, search, libId }, continuousFn }).then(res => { const { list } = res.data; wx.hideLoading() this.setData({ list }) // if (isFn(cb)) cb() }).catch(res => { // if (isFn(cb)) cb() }) }, /** * 保存学校接口 */ saveSchool:function(){ const postData = { fn: this.saveSchool, param: { ...arguments } } const {search } = this.data; app.post('/api/parents/parents/V2/saveSchoolCopy', { name:search }, 0, postData).then(res => { }) } })