bookmember.js 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. // pages/myinfo/bookmember/bookmember.js
  2. let util = require('../../../utils/util.js');
  3. var that
  4. Page({
  5. /**
  6. * 页面的初始数据
  7. */
  8. data: {
  9. imgurl: util.imgurl,
  10. name: '',
  11. count: 0,
  12. users: [],
  13. selcount: 0,
  14. bookid: 0,
  15. books: []
  16. },
  17. bookChange(e) {
  18. var nobk = this.data.books[e.detail.value]
  19. this.setData({
  20. bookid: nobk.id
  21. })
  22. this.getDetail()
  23. },
  24. /**
  25. * 生命周期函数--监听页面加载
  26. */
  27. onLoad: function(options) {
  28. that = this
  29. var ui = wx.getStorageSync("userinfo")
  30. if (ui) {
  31. this.setData({
  32. nowui: ui
  33. })
  34. }
  35. if (options.id) {
  36. this.setData({
  37. bookid: options.id
  38. })
  39. this.getDetail()
  40. }
  41. this.getBooks()
  42. },
  43. getBooks() {
  44. util.query('accountbook/wxapi/list', {
  45. pageNo: 1,
  46. pageSize: 99999
  47. }, function(res) {
  48. if (res.code === 10000) {
  49. var books = []
  50. res.data.forEach(function(e) {
  51. books.push({
  52. id: e.id,
  53. name: e.name
  54. })
  55. })
  56. that.setData({
  57. books: books
  58. })
  59. } else {
  60. }
  61. })
  62. },
  63. deluser() {
  64. if (this.data.selcount === 0) {
  65. util.showToast('请选择记账人')
  66. return
  67. }
  68. wx.showModal({
  69. title: '确认',
  70. content: '是否确定删除记账人',
  71. success(res) {
  72. if (res.confirm) {
  73. var userIds = []
  74. that.data.users.forEach(function(e) {
  75. if (e.sel) {
  76. userIds.push({
  77. userId: e.id
  78. })
  79. }
  80. })
  81. util.query("accountbook/wxapi/left", {
  82. accountBookId: that.data.bookid,
  83. userIds: userIds
  84. }, function(res) {
  85. if (res.code == 10000) {
  86. util.showToast('删除成功')
  87. that.getDetail()
  88. } else {
  89. util.showToast(res.message)
  90. }
  91. }, "POST")
  92. } else if (res.cancel) {
  93. }
  94. }
  95. })
  96. },
  97. setsel(e) {
  98. var data = this.data.users
  99. data[e.currentTarget.dataset.index].sel = !data[e.currentTarget.dataset.index].sel
  100. var i = 0
  101. data.forEach(function(res) {
  102. if (res.sel) {
  103. i++
  104. }
  105. })
  106. this.setData({
  107. users: data,
  108. selcount: i
  109. })
  110. },
  111. getDetail() {
  112. util.query('accountbook/wxapi/findbyid', {
  113. id: this.data.bookid
  114. }, function(res) {
  115. if (res.code === 10000) {
  116. var ismine = false
  117. if (that.data.nowui.uid === res.data.uid) {
  118. ismine = true
  119. }
  120. res.data.userInfos.forEach(function(e) {
  121. e.sel = false
  122. if (e.uid === res.data.uid) {
  123. that.setData({
  124. ui: e
  125. })
  126. }
  127. })
  128. that.setData({
  129. name: res.data.name,
  130. count: res.data.userInfos.length,
  131. users: res.data.userInfos,
  132. ismine: ismine
  133. })
  134. } else {
  135. util.showToast('未发现该账本')
  136. }
  137. })
  138. },
  139. /**
  140. * 生命周期函数--监听页面初次渲染完成
  141. */
  142. onReady: function() {
  143. },
  144. /**
  145. * 生命周期函数--监听页面显示
  146. */
  147. onShow: function() {
  148. },
  149. /**
  150. * 生命周期函数--监听页面隐藏
  151. */
  152. onHide: function() {
  153. },
  154. /**
  155. * 生命周期函数--监听页面卸载
  156. */
  157. onUnload: function() {
  158. },
  159. /**
  160. * 页面相关事件处理函数--监听用户下拉动作
  161. */
  162. onPullDownRefresh: function() {
  163. },
  164. /**
  165. * 页面上拉触底事件的处理函数
  166. */
  167. onReachBottom: function() {
  168. },
  169. /**
  170. * 用户点击右上角分享
  171. */
  172. onShareAppMessage: function(res) {
  173. if (res.from === 'button') {
  174. return {
  175. title: this.data.ui.wechatName + '邀请你一起记账',
  176. path: 'pages/myinfo/joinbook/joinbook?id=' + this.data.bookid + '&uid=' + this.data.ui.id
  177. }
  178. }
  179. }
  180. })