123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200 |
- // pages/school/school.js
- const app = getApp()
- Page({
- /**
- * 页面的初始数据
- */
- data: {
- search: '',
- isWechat:0,
- list: []
- },
- /**
- * 生命周期函数--监听页面加载
- */
- onLoad: function (options) {
- this.setData(options)
- console.log(options)
- const {status}=options;
- const parentVipList = app.globalData.parentVipList || wx.getStorageSync('parentVipList');
- const parentVipLiIdx = app.globalData.parentVipLiIdx || wx.getStorageSync('parentVipLiIdx');
- this.setData({parentVipList, parentVipLiIdx});
- this.getLocation()
- setTimeout(() => {
- wx.getSetting({
- success: res => {
- if (!res.authSetting['scope.userLocation']) {
- this.openLocationConfirm()
- }
- }
- })
- }, 1000)
- },
- /**
- * 生命周期函数--监听页面初次渲染完成
- */
- onReady: function () {
-
- },
- /**
- * 生命周期函数--监听页面显示
- */
- 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 postData = { fn: this.getSchoolList, param: { ...arguments } }
- const { location, search, libId, schoolState, schoolList, isAddChild} = this.data
- const { longitude, latitude } = location || e
- if (isAddChild==1){
- var data = { longitude, latitude, search, libId: !schoolList ? '' : libId }
- }else{
- var data = { longitude, latitude, search, libId: schoolState == 1 ? '' : libId }
- }
- wx.showLoading({
- title: '加载中...',
- })
- app.post('/api/parents/parents/V2/getSchoolList', data, 0, postData).then(res => {
- wx.hideLoading()
- const {list}=res.data;
- // if(list.length==0){
- // this.saveSchool();
- // }
- this.setData({ list})
- })
- },
- /**
- * 保存学校接口
- */
- 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 => {
- })
- }
- })
|