list.js 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. const app = getApp()
  2. import QRCode from '../../../utils/weapp-qrcode.js';
  3. Page({
  4. data: {
  5. frameStyle: { useTop: true, name: '学员信息', leftArrow: true, useBar: false },
  6. list: [],
  7. total: 0,
  8. page: 0,
  9. skip: 0,
  10. limit: 5,
  11. // 等级列表
  12. levelList: [],
  13. // dialog弹框
  14. dialog: { title: '账号绑定', show: false, type: '1' },
  15. form: {},
  16. },
  17. // 返回
  18. back: function () {
  19. wx.navigateBack({ delta: 1 })
  20. },
  21. // 添加
  22. toAdd() {
  23. const that = this;
  24. that.setData({ skip: 0, page: 0, list: [] })
  25. wx.navigateTo({ url: '/pages/schAdmin/student/add' })
  26. },
  27. // 修改
  28. toEdit: function (e) {
  29. const that = this;
  30. let { item } = e.currentTarget.dataset;
  31. that.setData({ skip: 0, page: 0, list: [] })
  32. wx.navigateTo({ url: `/pages/schAdmin/student/add?id=${item.student_id}` })
  33. },
  34. // 删除
  35. toDel: async function (e) {
  36. const that = this;
  37. const { item } = e.currentTarget.dataset;
  38. wx.showModal({
  39. title: '提示',
  40. content: '是否确认删除该条数据?',
  41. async success(res) {
  42. if (res.confirm) {
  43. const arr = await app.$delete(`/rss/${item.id}`);
  44. if (arr.errcode == '0') {
  45. wx.showToast({ title: `删除信息成功`, icon: 'success', duration: 2000 })
  46. that.setData({ skip: 0, page: 0, list: [] })
  47. that.watchLogin()
  48. } else {
  49. wx.showToast({ title: `${arr.errmsg}`, icon: 'error', duration: 2000 })
  50. }
  51. }
  52. }
  53. })
  54. },
  55. // 绑定账号
  56. toBind: async function (e) {
  57. const that = this;
  58. let { item } = e.currentTarget.dataset;
  59. const arr = await app.$get(`/student/${item.student_id}`);
  60. if (arr.errcode == '0') {
  61. that.setData({ form: arr.data })
  62. // 生成二维码
  63. that.makeQRCode();
  64. that.setData({ dialog: { title: '账号绑定', show: true, type: '1' } })
  65. } else { wx.showToast({ title: `${arr.errmsg}`, icon: 'error', duration: 2000 }) }
  66. },
  67. makeQRCode(template = 0) {
  68. const that = this;
  69. const url = `${app.globalData.publicUrl}/courtappbind?id=${that.data.form.id}&type='2'`;
  70. var qrcode = new QRCode(`myQrcode`, {
  71. text: url,
  72. width: 110,
  73. height: 110,
  74. padding: 3,
  75. colorDark: "#000000",
  76. colorLight: "#ffffff",
  77. correctLevel: QRCode.CorrectLevel.L,
  78. });
  79. },
  80. // 关闭弹框
  81. toClose: function () {
  82. const that = this;
  83. that.setData({ form: {} })
  84. that.setData({ dialog: { title: '账号绑定', show: false, type: '1' } })
  85. },
  86. // 分页
  87. toPage: function () {
  88. const that = this;
  89. let list = that.data.list;
  90. let limit = that.data.limit;
  91. if (that.data.total > list.length) {
  92. wx.showLoading({ title: '加载中', mask: true })
  93. let page = that.data.page + 1;
  94. that.setData({ page: page })
  95. let skip = page * limit;
  96. that.setData({ skip: skip })
  97. that.watchLogin();
  98. wx.hideLoading()
  99. } else { wx.showToast({ title: '没有更多数据了', icon: 'none', duration: 2000 }) }
  100. },
  101. // 返回
  102. back(e) {
  103. wx.navigateBack({ delta: 1 })
  104. },
  105. /**
  106. * 生命周期函数--监听页面加载
  107. */
  108. onLoad: function (options) { },
  109. // 监听用户是否登录
  110. watchLogin: async function () {
  111. const that = this;
  112. wx.getStorage({
  113. key: 'user',
  114. success: async res => {
  115. // 学员等级
  116. let aee = await app.$get(`/dict`, { code: 'student_grade' });
  117. if (aee.errcode == '0' && aee.total > 0) that.setData({ levelList: aee.data[0].list })
  118. let info = { skip: that.data.skip, limit: that.data.limit, school_id: res.data.info.id };
  119. const arr = await app.$get(`/rss`, { ...info });
  120. if (arr.errcode == '0') {
  121. for (const val of arr.data) {
  122. let level = that.data.levelList.find(i => i.value == val.student_id_level)
  123. if (level) val.zhLevel = level.label;
  124. }
  125. that.setData({ list: [...that.data.list, ...arr.data] });
  126. that.setData({ total: arr.total });
  127. }
  128. else { wx.showToast({ title: `${arr.errmsg}`, icon: 'error', duration: 2000 }) }
  129. },
  130. fail: async res => {
  131. wx.redirectTo({ url: '/pages/index/index' })
  132. }
  133. })
  134. },
  135. /**
  136. * 生命周期函数--监听页面初次渲染完成
  137. */
  138. onReady: function () { },
  139. /**
  140. * 生命周期函数--监听页面显示
  141. */
  142. onShow: function () {
  143. const that = this;
  144. // 监听用户是否登录
  145. that.watchLogin();
  146. },
  147. /**
  148. * 页面上拉触底事件的处理函数
  149. */
  150. /**
  151. * 生命周期函数--监听页面隐藏
  152. */
  153. onHide: function () {
  154. },
  155. /**
  156. * 生命周期函数--监听页面卸载
  157. */
  158. onUnload: function () {
  159. },
  160. /**
  161. * 页面相关事件处理函数--监听用户下拉动作
  162. */
  163. onPullDownRefresh: function () {
  164. },
  165. /**
  166. * 用户点击右上角分享
  167. */
  168. onShareAppMessage: function () {
  169. }
  170. })