School_library.js 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  1. // parents/pages/library/library.js
  2. import { routers, viewImage, sharePage, isFn, getGlobalVal, getWxLocationSetting } from '../../../utils/util.js'
  3. import { GetpositionArea,GetMineInfo } from '../../../utils/api.js'
  4. const { navigateTo, redirectTo, navigateBack } = routers()
  5. const { globalData } = getApp()
  6. const { baseImgUrl } = globalData
  7. Page({
  8. /**
  9. * 页面的初始数据
  10. */
  11. data: {
  12. isLoaded: 0,
  13. latitude: '',
  14. longitude: '',
  15. pageNo: 1,
  16. pageSize: 10,
  17. libraryList: [],
  18. isAll: 0,
  19. schoolName:'',
  20. isResult: false,
  21. content:'',
  22. nodataArray: {
  23. text: "搜索无结果"
  24. }
  25. },
  26. /**
  27. * 生命周期函数--监听页面加载
  28. */
  29. onLoad: function (options) {
  30. options.libId = getGlobalVal('library').id || ''
  31. if (options.zindex != 3) {
  32. options.vipId = getGlobalVal('vipId', `vipId_${getGlobalVal('userId')}`) || ''
  33. }
  34. console.log(options)
  35. this.setData({ options })
  36. // if (options.isAdd){
  37. this.getLocation(res => {
  38. this.setData({ isLoaded: 1 })
  39. })
  40. // }else{
  41. // }
  42. // this.getLocation(res => {
  43. // this.setData({ isLoaded: 1 })
  44. // })
  45. },
  46. /**
  47. * 生命周期函数--监听页面初次渲染完成
  48. */
  49. onReady: function () {
  50. const obj = { navigateTo, redirectTo, navigateBack, viewImage }
  51. for (const i in obj) {
  52. this[i] = obj[i]
  53. }
  54. },
  55. /**
  56. * 生命周期函数--监听页面显示
  57. */
  58. onShow: function () {
  59. },
  60. returnBack: function () {
  61. wx.navigateBack({
  62. })
  63. },
  64. /**
  65. * 输入搜索值
  66. */
  67. inputSearchCtl: function (e) {
  68. const { value } = e.detail
  69. const { content } = this.data
  70. if (content == value) {
  71. return
  72. }
  73. this.setData({ content: value, pageNo: 1 })
  74. this.setData({ isResult: true })
  75. this.getLibrary()
  76. },
  77. /**
  78. * 清除搜索值
  79. */
  80. clearSearchCtl: function () {
  81. this.setData({ content: '' })
  82. },
  83. /**
  84. * 生命周期函数--监听页面隐藏
  85. */
  86. onHide: function () {
  87. },
  88. /**
  89. * 生命周期函数--监听页面卸载
  90. */
  91. onUnload: function () {
  92. },
  93. /**
  94. * 页面相关事件处理函数--监听用户下拉动作
  95. */
  96. onPullDownRefresh: function () {
  97. const { libraryList}=this.data
  98. if (libraryList.length<11) return
  99. this.setData({ pageNo: 1 })
  100. this.getLibrary(res => {
  101. wx.stopPullDownRefresh()
  102. })
  103. },
  104. /**
  105. * 页面上拉触底事件的处理函数
  106. */
  107. onReachBottom: function () {
  108. const { isAll } = this.data
  109. if (isAll) return
  110. this.getLibrary()
  111. },
  112. /**
  113. * 用户点击右上角分享
  114. */
  115. onShareAppMessage: function () {
  116. if (isFn(sharePage)) return sharePage()
  117. },
  118. /**
  119. * 获取定位
  120. */
  121. getLocation: function (cb) {
  122. getWxLocationSetting(res => {
  123. this.setData({
  124. isShowPosition: false
  125. })
  126. wx.showLoading({
  127. title: '定位中'
  128. })
  129. wx.getLocation({
  130. type: 'wgs84',
  131. success: res => {
  132. const { latitude, longitude } = res
  133. this.setData({
  134. latitude,
  135. longitude
  136. })
  137. this.getLibrary(cb)
  138. },
  139. fail: res => {
  140. wx.showToast({
  141. title: '定位失败',
  142. icon: 'none'
  143. })
  144. },
  145. complete: res => {
  146. wx.hideLoading()
  147. }
  148. })
  149. })
  150. },
  151. /**
  152. * 获取图书馆
  153. */
  154. getLibrary: function (cb) {
  155. const continuousFn = { fn: this.getLibrary, param: { ...arguments } }
  156. const { options, latitude, longitude, pageNo, pageSize, libraryList, schoolName, content } = this.data
  157. GetpositionArea({ data: { schoolName: content, pageNo, pageSize, leagueLat: latitude, leagueLng: longitude }, continuousFn }).then(res => {
  158. const { list } = res.data
  159. let listTemp = []
  160. if (pageNo == 1) {
  161. listTemp = [].concat(list)
  162. } else {
  163. listTemp = [].concat(libraryList, list)
  164. }
  165. this.setData({
  166. libraryList: listTemp,
  167. pageNo: list.length == pageSize ? pageNo + 1 : pageNo,
  168. isAll: list.length < pageSize
  169. })
  170. console.log(libraryList)
  171. cb && cb(res)
  172. }).catch(res => {
  173. cb && cb(res)
  174. })
  175. },
  176. /**
  177. * 获取图书馆
  178. */
  179. selectLibraryCtl: function (e) {
  180. const { index } = e.currentTarget.dataset
  181. const { libraryList,options } = this.data
  182. const { id, name } = libraryList[index]
  183. const { sex = '', phone = '', parentName = '', parentRole = '', libId = '', vipId = '', grade = '', imgUrl = '', childName = '', zindex,isAdd,league_name=''} = options
  184. if (id) {
  185. redirectTo({ url: 'parents/pages/information/information', paras: { zindex, vipId, libId, imgUrl, sex, phone, parentName, parentRole, grade, childName, isSchool:1,isAdd,league_name,school:name} })
  186. } else {
  187. wx.showToast({
  188. title: '该学校地址无效',
  189. icon: 'none'
  190. })
  191. }
  192. }
  193. })