school.js 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  1. // pages/school/school.js
  2. import { routers, viewImage, sharePage, isFn, getGlobalVal, formatDateTime, formateNumber } from '../../utils/util.js'
  3. import { SchoolList } from '../../utils/api.js'
  4. const { navigateTo, redirectTo, navigateBack } = routers()
  5. const { globalData, saveUserInfo, getWxloginCode, checkStatus } = getApp()
  6. const { baseImgUrl, thumbnail } = globalData
  7. const app = getApp()
  8. Page({
  9. /**
  10. * 页面的初始数据
  11. */
  12. data: {
  13. search: '',
  14. isWechat:0,
  15. list: [],
  16. statusBar: app.globalData.statusBar,
  17. isDetail:0,
  18. nodata: [
  19. {
  20. text: '暂无学校'
  21. }
  22. ],
  23. },
  24. /**
  25. * 生命周期函数--监听页面加载
  26. */
  27. onLoad: function (options) {
  28. this.setData(options)
  29. const {status}=options;
  30. this.getLocation()
  31. setTimeout(() => {
  32. wx.getSetting({
  33. success: res => {
  34. if (!res.authSetting['scope.userLocation']) {
  35. this.openLocationConfirm()
  36. }
  37. }
  38. })
  39. }, 1000)
  40. },
  41. /**
  42. * 生命周期函数--监听页面初次渲染完成
  43. */
  44. onReady: function () {
  45. const obj = { navigateTo, redirectTo, navigateBack, viewImage }
  46. for (const i in obj) {
  47. this[i] = obj[i]
  48. }
  49. },
  50. /**
  51. * 生命周期函数--监听页面显示
  52. */
  53. onShow: function () {
  54. },
  55. /**
  56. * 生命周期函数--监听页面隐藏
  57. */
  58. onHide: function () {
  59. },
  60. /**
  61. * 生命周期函数--监听页面卸载
  62. */
  63. onUnload: function () {
  64. },
  65. /**
  66. * 页面相关事件处理函数--监听用户下拉动作
  67. */
  68. onPullDownRefresh: function () {
  69. },
  70. /**
  71. * 页面上拉触底事件的处理函数
  72. */
  73. onReachBottom: function () {
  74. },
  75. /**
  76. * 用户点击右上角分享
  77. */
  78. onShareAppMessage: function () {
  79. },
  80. /**
  81. * 路由跳转
  82. */
  83. redirectCtl: app.redirectCtl,
  84. navigateCtl: app.navigateCtl,
  85. /**
  86. * 输入学校
  87. */
  88. inputCtl: function (e) {
  89. const { value } = e.detail
  90. this.setData({
  91. search: value
  92. })
  93. this.getSchoolList()
  94. },
  95. /**
  96. * 获取定位经纬度
  97. */
  98. getLocation: function () {
  99. wx.showLoading({
  100. title: '定位中'
  101. })
  102. wx.getLocation({
  103. type: 'wgs84',
  104. success: res => {
  105. console.log(res)
  106. this.setData({
  107. location: {
  108. longitude: res.longitude, // '113.36403' ||
  109. latitude: res.latitude // '23.14203' ||
  110. }
  111. })
  112. this.getSchoolList({
  113. longitude: res.longitude,
  114. latitude: res.latitude
  115. })
  116. },
  117. fail: res => {
  118. wx.showToast({
  119. title: '定位失败',
  120. icon: 'none'
  121. })
  122. },
  123. complete: res => {
  124. wx.hideLoading()
  125. }
  126. })
  127. },
  128. /**
  129. * 再次弹起弹出框要求重新获取地位
  130. */
  131. openLocationConfirm: function () {
  132. wx.showModal({
  133. content: '检测到您没打开定位权限,是否去设置打开?',
  134. confirmText: "确认",
  135. cancelText: "取消",
  136. success: res => {
  137. if (res.confirm) {
  138. wx.openSetting({
  139. success: res => {
  140. if (res.authSetting['scope.userLocation']) {
  141. this.getLocation()
  142. } else {
  143. wx.navigateBack({
  144. delta: 1
  145. })
  146. }
  147. }
  148. })
  149. } else {
  150. wx.navigateBack({
  151. delta: 1
  152. })
  153. }
  154. }
  155. })
  156. },
  157. /**
  158. * 获取学校列表
  159. */
  160. getSchoolList: function (e) {
  161. const continuousFn = { fn: this.getSchoolList, param: { ...arguments } }
  162. const { location, search } = this.data
  163. const { longitude, latitude } = location || e
  164. const libId = wx.getStorageSync('libId')||'';
  165. wx.showLoading({
  166. title: '加载中',
  167. })
  168. SchoolList({ data: { longitude, latitude, search, libId }, continuousFn }).then(res => {
  169. const { list } = res.data;
  170. wx.hideLoading()
  171. this.setData({ list })
  172. // if (isFn(cb)) cb()
  173. }).catch(res => {
  174. // if (isFn(cb)) cb()
  175. })
  176. },
  177. /**
  178. * 保存学校接口
  179. */
  180. saveSchool:function(){
  181. const postData = { fn: this.saveSchool, param: { ...arguments } }
  182. const {search } = this.data;
  183. app.post('/api/parents/parents/V2/saveSchoolCopy', { name:search }, 0, postData).then(res => {
  184. })
  185. }
  186. })