select_library.js 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. // pages/select_library/select_library.js
  2. import { routers, viewImage, sharePage, isFn, getGlobalVal, formatDateTime, formateNumber } from '../../utils/util.js'
  3. import { LibList} from '../../utils/api.js'
  4. const { navigateTo, redirectTo, navigateBack } = routers()
  5. const { globalData } = getApp()
  6. const { baseImgUrl, thumbnail } = globalData
  7. const app = getApp();
  8. Page({
  9. /**
  10. * 页面的初始数据
  11. */
  12. data: {
  13. areaIndex:0,
  14. cityName:'',
  15. nodata: {
  16. nodataObj: {
  17. text: '没有搜索结果'
  18. }
  19. }
  20. },
  21. /**
  22. * 生命周期函数--监听页面加载
  23. */
  24. onLoad: function (options) {
  25. this.setData(options);
  26. this.getLibList();
  27. },
  28. /**
  29. * 生命周期函数--监听页面初次渲染完成
  30. */
  31. onReady: function () {
  32. const obj = { navigateTo, redirectTo, navigateBack, viewImage }
  33. for (const i in obj) {
  34. this[i] = obj[i]
  35. }
  36. },
  37. /**
  38. * 生命周期函数--监听页面显示
  39. */
  40. onShow: function () {
  41. },
  42. /**
  43. * 生命周期函数--监听页面隐藏
  44. */
  45. onHide: function () {
  46. },
  47. /**
  48. * 生命周期函数--监听页面卸载
  49. */
  50. onUnload: function () {
  51. },
  52. /**
  53. * 页面相关事件处理函数--监听用户下拉动作
  54. */
  55. onPullDownRefresh: function () {
  56. },
  57. /**
  58. * 页面上拉触底事件的处理函数
  59. */
  60. onReachBottom: function () {
  61. },
  62. /**
  63. * 用户点击右上角分享
  64. */
  65. onShareAppMessage: function () {
  66. },
  67. /**
  68. * 跳转
  69. */
  70. navigateCtl: app.navigateCtl,
  71. /**
  72. * 底部导航跳转
  73. */
  74. redirectCtl: app.redirectCtl,
  75. /**
  76. * 保存学生姓名
  77. */
  78. inputCtl: function (e) {
  79. const { value } = e.detail
  80. const { cityName } = this.data
  81. if (cityName == value) {
  82. return
  83. }
  84. this.setData({ cityName: value })
  85. },
  86. /**
  87. * 重新搜索学生列表
  88. */
  89. blurCtl: function () {
  90. const { cityName } = this.data
  91. this.setData({ areaIndex:0})
  92. // if (!cityName) {
  93. // wx.showToast({
  94. // title: '搜索内容不能为空',
  95. // icon: 'none'
  96. // })
  97. // return
  98. // }
  99. this.getLibList()
  100. },
  101. /**
  102. * 点击馆
  103. */
  104. getLibList: function (cb) {
  105. const continuousFn = { fn: this.getLibList, param: { ...arguments } }
  106. const { areaIndex, libIndex, cityName } = this.data;
  107. LibList({ data: { cityName}, continuousFn }).then(res => {
  108. const { cityList } = res.data;
  109. var temp = {};
  110. var listTemp=(res=>{
  111. for (var i in res) {
  112. for (var j in res[i].libList) {
  113. res[i].libList[j].status= ''
  114. }
  115. }
  116. return res
  117. })(cityList)
  118. this.setData({ cityList: listTemp})
  119. if (isFn(cb)) cb()
  120. }).catch(res => {
  121. if (isFn(cb)) cb()
  122. })
  123. },
  124. /**
  125. * 选择城市
  126. */
  127. selectCity: function (e) {
  128. const { index } = e.currentTarget.dataset;
  129. this.setData({ areaIndex: index })
  130. },
  131. /**
  132. * 选择馆名
  133. */
  134. setLibName: function (e) {
  135. const { item, idx } = e.currentTarget.dataset;
  136. const { libId, libName } = item;
  137. const { areaIndex, libIndex, cityList, curatorName='', phone,code=''} = this.data;
  138. var temp = {};
  139. for (var i in cityList) {
  140. for (var j in cityList[i].libList) {
  141. temp[`cityList[${i}].libList[${j}].status`] = ''
  142. }
  143. }
  144. temp[`cityList[${areaIndex}].libList[${idx}].status`] = cityList[areaIndex].libList[idx].status == '' ? 'active' : '';
  145. this.setData(temp)
  146. this.redirectCtl({ url: 'register', method: { libId, libName, curatorName, phone,code,isSlect:1} }, true)
  147. },
  148. })