const pages = require('../../mixin/pages') const { postFollowUser } = require('./api/index') Page({ /** * 页面的初始数据 */ data: { ...pages.data(), listUrl: '/api/user/track/list', searchForm: { 'key_words': '' // 'follow_type': 1 }, nav: [ { name: '推荐', value: '1' }, { name: '关注', value: '2' } ], active: '1', booLock: false }, ...pages.methods, /** * 生命周期函数--监听页面加载 */ onLoad(options) { this.fetchOrderList() }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady() { }, /** * 生命周期函数--监听页面显示 */ onShow() { this.getTabBar().init() }, /** * 生命周期函数--监听页面隐藏 */ onHide() { }, /** * 生命周期函数--监听页面卸载 */ onUnload() { }, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh() { if (this.data.freshing) { return } this.setData({ freshing: true }) this.bindCallBack() }, /** * 页面上拉触底事件的处理函数 */ onReachBottom() { this.fetchOrderList() }, bindCallBack() { this.refreshOrderList() }, handleNav(e) { const { value } = e.detail const searchForm = JSON.parse(JSON.stringify(this.data.searchForm)) if (value === '1' && searchForm.hasOwnProperty('follow_type')) { delete searchForm.follow_type } else if (value === '2') { searchForm.follow_type = 1 } this.setData({ active: value, searchForm: searchForm }, () => { this.refreshOrderList() }) }, // 关注 async followUser(e) { const { item, index } = e.target.dataset this.setData({ booLock: true }) try { const { status, msg } = await postFollowUser(item.shop_id) if (status) { wx.showToast({ title: '已关注', icon: 'none' }) this.setData({ ['listData[' + index + '].follow_status']: 1 }) } else { wx.showToast({ title: msg, icon: 'none' }) } } catch (err) {} this.setData({ booLock: false }) }, jumpAddNews() { wx.navigateTo({ url: '/pages/addNews/addNews' }) } })