bookmanage.js 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. let util = require('../../../utils/util.js');
  2. var that
  3. Page({
  4. /**
  5. * 页面的初始数据
  6. */
  7. data: {
  8. imageurl: util.imgurl,
  9. baseImgUrl: util.baseImgUrl,
  10. isfirst: true
  11. },
  12. /**
  13. * 生命周期函数--监听页面加载
  14. */
  15. onLoad: function(options) {
  16. that = this
  17. util.checklogin(
  18. function() {
  19. that.getDefaultBook()
  20. }
  21. )
  22. // var nb = wx.getStorageSync("nowbookid")
  23. // if (nb) {
  24. // this.setData({
  25. // nowbookid: nb
  26. // })
  27. // }
  28. },
  29. nodo() {},
  30. tomember(e) {
  31. wx.navigateTo({
  32. url: '/pages/myinfo/bookmember/bookmember?id=' + e.currentTarget.dataset.id,
  33. })
  34. },
  35. del(e) {
  36. wx.showModal({
  37. title: '确认',
  38. content: '是否确定删除账本',
  39. success(res) {
  40. if (res.confirm) {
  41. util.query("accountbook/wxapi/delete", {
  42. id: parseInt(e.currentTarget.dataset.id)
  43. }, function(res) {
  44. if (res.code == 10000) {
  45. util.showToast('删除成功')
  46. that.getList()
  47. } else {
  48. util.showToast(res.message)
  49. }
  50. }, "POST")
  51. } else if (res.cancel) {
  52. }
  53. }
  54. })
  55. },
  56. toedite(e) {
  57. wx.navigateTo({
  58. url: '/pages/myinfo/createbook/createbook?id=' + e.currentTarget.dataset.id,
  59. })
  60. },
  61. setuse(e) {
  62. if (e.detail.value) {
  63. this.setdefault(e.currentTarget.dataset.id)
  64. }
  65. },
  66. setdefault(id) {
  67. util.query('accountbook/wxapi/setdefault', {
  68. accountBookId: id
  69. }, function(res) {
  70. if (res.code === 10000) {
  71. that.getList(id)
  72. }
  73. }, 'POST')
  74. },
  75. getDefaultBook() {
  76. util.query('accountbook/wxapi/getdefault', {}, function(res) {
  77. if (res.code === 10000) {
  78. that.getList(res.data.id)
  79. }
  80. })
  81. },
  82. getList(nowid) {
  83. util.query('accountbook/wxapi/list', {
  84. pageNo: 1,
  85. pageSize: 99999
  86. }, function(res) {
  87. if (res.code === 10000) {
  88. res.data.forEach(function(e) {
  89. if (e.userInfos) {
  90. e.count = e.userInfos.length
  91. } else {
  92. e.count = 0
  93. }
  94. if (nowid === e.id) {
  95. e.sel = true
  96. } else {
  97. e.sel = false
  98. }
  99. })
  100. that.setData({
  101. data: res.data
  102. })
  103. } else {
  104. }
  105. })
  106. },
  107. tocreate() {
  108. wx.navigateTo({
  109. url: '/pages/myinfo/createbook/createbook',
  110. })
  111. },
  112. /**
  113. * 生命周期函数--监听页面初次渲染完成
  114. */
  115. onReady: function() {
  116. },
  117. /**
  118. * 生命周期函数--监听页面显示
  119. */
  120. onShow: function() {
  121. if (!this.data.isfirst) {
  122. this.getList()
  123. }
  124. },
  125. /**
  126. * 生命周期函数--监听页面隐藏
  127. */
  128. onHide: function() {
  129. this.setData({
  130. isfirst: false
  131. })
  132. },
  133. /**
  134. * 生命周期函数--监听页面卸载
  135. */
  136. onUnload: function() {
  137. },
  138. /**
  139. * 页面相关事件处理函数--监听用户下拉动作
  140. */
  141. onPullDownRefresh: function() {
  142. },
  143. /**
  144. * 页面上拉触底事件的处理函数
  145. */
  146. onReachBottom: function() {
  147. },
  148. /**
  149. * 用户点击右上角分享
  150. */
  151. onShareAppMessage: function() {
  152. }
  153. })