123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199 |
- // pages/myinfo/bookmember/bookmember.js
- let util = require('../../../utils/util.js');
- var that
- Page({
- /**
- * 页面的初始数据
- */
- data: {
- imgurl: util.imgurl,
- name: '',
- count: 0,
- users: [],
- selcount: 0,
- bookid: 0,
- books: []
- },
- bookChange(e) {
- var nobk = this.data.books[e.detail.value]
- this.setData({
- bookid: nobk.id
- })
- this.getDetail()
- },
- /**
- * 生命周期函数--监听页面加载
- */
- onLoad: function(options) {
- that = this
- var ui = wx.getStorageSync("userinfo")
- if (ui) {
- this.setData({
- nowui: ui
- })
- }
- if (options.id) {
- this.setData({
- bookid: options.id
- })
- this.getDetail()
- }
- this.getBooks()
- },
- getBooks() {
- util.query('accountbook/wxapi/list', {
- pageNo: 1,
- pageSize: 99999
- }, function(res) {
- if (res.code === 10000) {
- var books = []
- res.data.forEach(function(e) {
- books.push({
- id: e.id,
- name: e.name
- })
- })
- that.setData({
- books: books
- })
- } else {
- }
- })
- },
- deluser() {
- if (this.data.selcount === 0) {
- util.showToast('请选择记账人')
- return
- }
- wx.showModal({
- title: '确认',
- content: '是否确定删除记账人',
- success(res) {
- if (res.confirm) {
- var userIds = []
- that.data.users.forEach(function(e) {
- if (e.sel) {
- userIds.push({
- userId: e.id
- })
- }
- })
- util.query("accountbook/wxapi/left", {
- accountBookId: that.data.bookid,
- userIds: userIds
- }, function(res) {
- if (res.code == 10000) {
- util.showToast('删除成功')
- that.getDetail()
- } else {
- util.showToast(res.message)
- }
- }, "POST")
- } else if (res.cancel) {
- }
- }
- })
- },
- setsel(e) {
- var data = this.data.users
- data[e.currentTarget.dataset.index].sel = !data[e.currentTarget.dataset.index].sel
- var i = 0
- data.forEach(function(res) {
- if (res.sel) {
- i++
- }
- })
- this.setData({
- users: data,
- selcount: i
- })
- },
- getDetail() {
- util.query('accountbook/wxapi/findbyid', {
- id: this.data.bookid
- }, function(res) {
- if (res.code === 10000) {
- var ismine = false
- if (that.data.nowui.uid === res.data.uid) {
- ismine = true
- }
- res.data.userInfos.forEach(function(e) {
- e.sel = false
- if (e.uid === res.data.uid) {
- that.setData({
- ui: e
- })
- }
- })
- that.setData({
- name: res.data.name,
- count: res.data.userInfos.length,
- users: res.data.userInfos,
- ismine: ismine
- })
- } else {
- util.showToast('未发现该账本')
- }
- })
- },
- /**
- * 生命周期函数--监听页面初次渲染完成
- */
- onReady: function() {
- },
- /**
- * 生命周期函数--监听页面显示
- */
- onShow: function() {
- },
- /**
- * 生命周期函数--监听页面隐藏
- */
- onHide: function() {
- },
- /**
- * 生命周期函数--监听页面卸载
- */
- onUnload: function() {
- },
- /**
- * 页面相关事件处理函数--监听用户下拉动作
- */
- onPullDownRefresh: function() {
- },
- /**
- * 页面上拉触底事件的处理函数
- */
- onReachBottom: function() {
- },
- /**
- * 用户点击右上角分享
- */
- onShareAppMessage: function(res) {
- if (res.from === 'button') {
- return {
- title: this.data.ui.wechatName + '邀请你一起记账',
- path: 'pages/myinfo/joinbook/joinbook?id=' + this.data.bookid + '&uid=' + this.data.ui.id
- }
- }
- }
- })
|