queue.js 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. // pages/queue/queue.js
  2. const util = require("../../utils/util")
  3. const urlDef = require("../../utils/urls")
  4. Page({
  5. /**
  6. * 页面的初始数据
  7. */
  8. data: {
  9. ShowBtn: false,
  10. planId: undefined,
  11. orgId: undefined,
  12. waitDate: undefined,
  13. list: [
  14. ],
  15. loading: '上拉加载',
  16. flag: 0,
  17. pageNum: 0,
  18. hasNextPage: true,
  19. btnFlag: true
  20. },
  21. /**
  22. * 生命周期函数--监听页面加载
  23. */
  24. onLoad: function (options) {
  25. this.setData({ planId: options.planId, orgId: options.orgId, waitDate: options.visitDate })
  26. this.queryList()
  27. },
  28. /**
  29. * 生命周期函数--监听页面初次渲染完成
  30. */
  31. onReady: function () {
  32. },
  33. /**
  34. * 生命周期函数--监听页面显示
  35. */
  36. onShow: function () {
  37. },
  38. /**
  39. * 生命周期函数--监听页面隐藏
  40. */
  41. onHide: function () {
  42. },
  43. /**
  44. * 生命周期函数--监听页面卸载
  45. */
  46. onUnload: function () {
  47. },
  48. /**
  49. * 页面相关事件处理函数--监听用户下拉动作
  50. */
  51. onPullDownRefresh: function () {
  52. },
  53. /**
  54. * 页面上拉触底事件的处理函数
  55. */
  56. onReachBottom: function () {
  57. if (this.data.hasNextPage) {
  58. let pn = this.data.pageNum
  59. this.setData({ loading: '加载中', 'pageNum': ++pn })
  60. this.queryList()
  61. }
  62. },
  63. /**
  64. * 用户点击右上角分享
  65. */
  66. onShareAppMessage: function () {
  67. },
  68. doQueueUp: function () {
  69. wx.showLoading({
  70. title: '处理中',
  71. mask: true
  72. })
  73. const urls = urlDef.urls;
  74. let stu = wx.getStorageSync('student');
  75. this.setData({studentId: stu.studentId})
  76. util.apiPost(urls.queueUp, this.data).then(rs => {
  77. wx.hideLoading({});
  78. if(rs.message ) {
  79. wx.showToast({
  80. title: rs.message,
  81. icon: 'none'
  82. })
  83. }else{
  84. wx.showToast({
  85. title: '排队成功',
  86. icon: 'success'
  87. })
  88. let pages = getCurrentPages();
  89. let prevPage = pages[pages.length - 2]
  90. prevPage.setData({
  91. refreshFlag: 1
  92. })
  93. this.setData({
  94. list:[]
  95. })
  96. this.queryList()
  97. }
  98. })
  99. },
  100. queryList: function () {
  101. const urls = urlDef.urls;
  102. let params = { 'q.orgId': this.data.orgId, 'q.visitDate': this.data.waitDate, 'q.planId': this.data.planId }
  103. params.pageNum = this.data.pageNum
  104. util.apiPost(urls.queue_list, params).then(rs => {
  105. let list = rs.list
  106. if(list.length > 0){
  107. let stuId = wx.getStorageSync('student').studentId
  108. for(var i in list){
  109. list[i].name = list[i].name.substring(0,1)+ "*"+list[i].name.substring(list[i].name.length -1,list[i].name.length)
  110. if(list[i].studentId == stuId){
  111. this.setData({
  112. btnFlag: false
  113. })
  114. }
  115. }
  116. }
  117. this.setData({
  118. 'hasNextPage': rs.hasNextPage,
  119. 'loading': rs.hasNextPage ? '上拉加载' : '没有更多数据',
  120. 'list': this.data.list.concat(list),
  121. ShowBtn: true
  122. })
  123. })
  124. },
  125. })