School_library.js 4.7 KB

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