school.js 4.1 KB

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