var Api = require('../../../utils/common.js'); var re = require('../../../utils/request.js'); Page({ /** * 页面的初始数据 */ data: { personList: [{ img: '../../../images/ava.png', name: '李三', rank: '1', score: '2222', ispop: false }, { img: '../../../images/ava.png', name: '李三', rank: '2', score: '2222', ispop: true }, { img: '../../../images/ava.png', name: '李三', rank: '3', score: '2222', ispop: true }, { img: '../../../images/ava.png', name: '李三', rank: '4', score: '2222', ispop: false }, { img: '../../../images/ava.png', name: '李三', rank: '5', score: '2222', ispop: true }, ], teamList: [{ img: '../../../images/logo.jpg', title: '众行天下', time: '2020-11-16', people: '12', user: '2' }, { img: '../../../images/ava.png', title: '众行天下', time: '2020-11-16', people: '12', user: '1' }, { img: '../../../images/ava.png', title: '众行天下', time: '2020-11-16', people: '12', user: '3' }, { img: '../../../images/ava.png', title: '众行天下', time: '2020-11-16', people: '12', user: '3' }, { img: '../../../images/ava.png', title: '众行天下', time: '2020-11-16', people: '12', user: '3' }, { img: '../../../images/ava.png', title: '众行天下', time: '2020-11-16', people: '12', user: '3' }, { img: '../../../images/ava.png', title: '众行天下', time: '2020-11-16', people: '12', user: '3' }, ] }, currentTab: function (e) { var that = this; if (that.data.currentTab == e.currentTarget.dataset.idx) { return; } that.setData({ currentTab: e.currentTarget.dataset.idx, }) if (e.currentTarget.dataset.idx == 0) { that.setData({ person: false, team: true, }) } else { that.setData({ person: true, team: false, }) } }, toteamjoin: function () { wx.navigateTo({ url: '../teamJoin/teamJoin' }) }, /** * 生命周期函数--监听页面加载 */ onLoad: function (options) { var that = this; that.setData({ clubId: options.id }) this.clubMember(options.id) }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady: function () { }, /** * 生命周期函数--监听页面显示 */ onShow: function () { let obj = { age: 123, name: 'pyy' } function deepclone() { // 先判斷是否是空 或者是object if (!obj || typeof obj !== "object") { return obj } else { // 先判断传入进啦的是数组还是对象 let newobj = Array.isArray(obj) ? [] : {} // 拿到数组的下标 或者是拿到数组的key for (let key in obj) { // 拿到key之后在判断key 是否存在 if (obj.hasOwnProperty(key)) { // 由于三元运算符优先级比较高 先进行计算是否进行递归调用 否则就进行赋值 newobj[key] = typeof obj[key] ? deepclone(obj[key]) : obj[key] } } // 最后retrun 出去 return newobj } } }, clubMember: function (id) { var that = this; const imgUrl = wx.getStorageSync('imgUrl') var header = { token: wx.getStorageSync('token'), "Content-Type": "application/x-www-form-urlencoded" }; var postData = { clubId: id, }; re.request(Api.clubMember(), postData, header).then((res) => { let datas = res.data.data; console.log(datas); let obj = {} let newdatas = datas.reduce((x, item) => { obj[item.userId] ? "" : obj[item.userId] = true && x.push(item) return x }, []) console.log(newdatas) that.setData({ personList: newdatas }) }) }, /** * 生命周期函数--监听页面隐藏 */ onHide: function () { }, /** * 生命周期函数--监听页面卸载 */ onUnload: function () { }, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh: function () { }, /** * 页面上拉触底事件的处理函数 */ onReachBottom: function () { }, /** * 用户点击右上角分享 */ onShareAppMessage: function () { } })