const app = getApp(); const util = require("../../../util/util.js") Page({ data: { StatusBar: app.globalData.StatusBar, CustomBar: app.globalData.CustomBar, loadModal:false, userInfo:{}, name:'', from:0, size:6, list:[ ] }, /** * 生命周期函数--监听页面加载 */ onLoad: function ( ) { app.checkLogin( ()=>{ this.loadData() this.getuserInfo() } ) }, search(e){ let {name} = e.detail.value; this.setData({name}) this.getTaskList( 0 ) }, getuserInfo( cb ){ app.getMakerInfo( (userInfo)=>{ this.setData({userInfo}) } ) }, onReachBottom: function () { var that = this let newFrom = that.data.from if (newFrom == -1) { wx.stopPullDownRefresh(); return; } this.getTaskList(newFrom, wx.stopPullDownRefresh); }, bidTask: function( e ){ let index = e.currentTarget.dataset.index; let item = this.data.list[index] util.http("/wx/applyWxB2B", {id:item.id}, (err, res) =>{ if( err != 0) return; item.target_id = this.data.userInfo.ID this.setData({ list: this.data.list}) util.showSuccess("抢单子成功"); }) }, goDetail(e){ let id = e.currentTarget.dataset.id; wx.navigateTo({ url: `/pages/task/info/b2bInfo?id=${id}`, }) }, getTaskList: function( newFrom, cb){ let param = { from: newFrom, size:this.data.size,name: this.data.name } let list = this.data.list let that = this util.http("/wx/getDemandCenter", param, function (err, res) { if( err != 0) return; if (newFrom == 0) list = []; let newlist = res.list.map( item =>{ item.bid_end_at = item.bid_end_at.substr(0,10); return item }); that.setData({ from: res.from || -1, list: list.concat(newlist) }) cb && cb() }); }, loadData :function( ){ this.getTaskList(0) }, })