123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213 |
- // parents/pages/library/library.js
- import { routers, viewImage, sharePage, isFn, getGlobalVal, getWxLocationSetting } from '../../../utils/util.js'
- import { GetpositionArea,GetMineInfo } from '../../../utils/api.js'
- const { navigateTo, redirectTo, navigateBack } = routers()
- const { globalData } = getApp()
- const { baseImgUrl } = globalData
- Page({
- /**
- * 页面的初始数据
- */
- data: {
- isLoaded: 0,
- latitude: '',
- longitude: '',
- pageNo: 1,
- pageSize: 10,
- libraryList: [],
- isAll: 0,
- schoolName:'',
- isResult: false,
- content:'',
- nodataArray: {
- text: "搜索无结果"
- }
- },
- /**
- * 生命周期函数--监听页面加载
- */
- onLoad: function (options) {
- options.libId = getGlobalVal('library').id || ''
- if (options.zindex != 3) {
- options.vipId = getGlobalVal('vipId', `vipId_${getGlobalVal('userId')}`) || ''
- }
- console.log(options)
- this.setData({ options })
- // if (options.isAdd){
- this.getLocation(res => {
- this.setData({ isLoaded: 1 })
- })
- // }else{
- // }
-
- // this.getLocation(res => {
- // this.setData({ isLoaded: 1 })
- // })
- },
- /**
- * 生命周期函数--监听页面初次渲染完成
- */
- onReady: function () {
- const obj = { navigateTo, redirectTo, navigateBack, viewImage }
- for (const i in obj) {
- this[i] = obj[i]
- }
- },
- /**
- * 生命周期函数--监听页面显示
- */
- onShow: function () {
- },
- returnBack: function () {
- wx.navigateBack({
- })
- },
- /**
- * 输入搜索值
- */
- inputSearchCtl: function (e) {
- const { value } = e.detail
- const { content } = this.data
- if (content == value) {
- return
- }
- this.setData({ content: value, pageNo: 1 })
- this.setData({ isResult: true })
- this.getLibrary()
- },
- /**
- * 清除搜索值
- */
- clearSearchCtl: function () {
- this.setData({ content: '' })
- },
- /**
- * 生命周期函数--监听页面隐藏
- */
- onHide: function () {
- },
- /**
- * 生命周期函数--监听页面卸载
- */
- onUnload: function () {
- },
- /**
- * 页面相关事件处理函数--监听用户下拉动作
- */
- onPullDownRefresh: function () {
- const { libraryList}=this.data
- if (libraryList.length<11) return
- this.setData({ pageNo: 1 })
- this.getLibrary(res => {
- wx.stopPullDownRefresh()
- })
- },
- /**
- * 页面上拉触底事件的处理函数
- */
- onReachBottom: function () {
- const { isAll } = this.data
- if (isAll) return
- this.getLibrary()
- },
- /**
- * 用户点击右上角分享
- */
- onShareAppMessage: function () {
- if (isFn(sharePage)) return sharePage()
- },
- /**
- * 获取定位
- */
- getLocation: function (cb) {
- getWxLocationSetting(res => {
- this.setData({
- isShowPosition: false
- })
- wx.showLoading({
- title: '定位中'
- })
- wx.getLocation({
- type: 'wgs84',
- success: res => {
- const { latitude, longitude } = res
- this.setData({
- latitude,
- longitude
- })
- this.getLibrary(cb)
- },
- fail: res => {
- wx.showToast({
- title: '定位失败',
- icon: 'none'
- })
- },
- complete: res => {
- wx.hideLoading()
- }
- })
- })
- },
- /**
- * 获取图书馆
- */
- getLibrary: function (cb) {
- const continuousFn = { fn: this.getLibrary, param: { ...arguments } }
- const { options, latitude, longitude, pageNo, pageSize, libraryList, schoolName, content } = this.data
- GetpositionArea({ data: { schoolName: content, pageNo, pageSize, leagueLat: latitude, leagueLng: longitude }, continuousFn }).then(res => {
- const { list } = res.data
- let listTemp = []
- if (pageNo == 1) {
- listTemp = [].concat(list)
- } else {
- listTemp = [].concat(libraryList, list)
- }
- this.setData({
- libraryList: listTemp,
- pageNo: list.length == pageSize ? pageNo + 1 : pageNo,
- isAll: list.length < pageSize
- })
- console.log(libraryList)
- cb && cb(res)
- }).catch(res => {
- cb && cb(res)
- })
- },
- /**
- * 获取图书馆
- */
- selectLibraryCtl: function (e) {
- const { index } = e.currentTarget.dataset
- const { libraryList,options } = this.data
- const { id, name } = libraryList[index]
- const { sex = '', phone = '', parentName = '', parentRole = '', libId = '', vipId = '', grade = '', imgUrl = '', childName = '', zindex,isAdd,league_name=''} = options
- if (id) {
- redirectTo({ url: 'parents/pages/information/information', paras: { zindex, vipId, libId, imgUrl, sex, phone, parentName, parentRole, grade, childName, isSchool:1,isAdd,league_name,school:name} })
- } else {
- wx.showToast({
- title: '该学校地址无效',
- icon: 'none'
- })
- }
- }
- })
|