list.js 5.0 KB

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