index.js 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. const app = getApp();
  2. const util = require("../../../util/util.js")
  3. Page({
  4. data: {
  5. StatusBar: app.globalData.StatusBar,
  6. CustomBar: app.globalData.CustomBar,
  7. loadModal:false,
  8. userInfo:{},
  9. name:'',
  10. from:0,
  11. size:6,
  12. list:[
  13. ]
  14. },
  15. /**
  16. * 生命周期函数--监听页面加载
  17. */
  18. onLoad: function ( ) {
  19. app.checkLogin( ()=>{
  20. this.loadData()
  21. this.getuserInfo()
  22. } )
  23. },
  24. search(e){
  25. let {name} = e.detail.value;
  26. this.setData({name})
  27. this.getTaskList( 0 )
  28. },
  29. getuserInfo( cb ){
  30. app.getMakerInfo( (userInfo)=>{
  31. this.setData({userInfo})
  32. } )
  33. },
  34. onReachBottom: function () {
  35. var that = this
  36. let newFrom = that.data.from
  37. if (newFrom == -1) {
  38. wx.stopPullDownRefresh();
  39. return;
  40. }
  41. this.getTaskList(newFrom, wx.stopPullDownRefresh);
  42. },
  43. bidTask: function( e ){
  44. let index = e.currentTarget.dataset.index;
  45. let item = this.data.list[index]
  46. util.http("/wx/applyWxB2B", {id:item.id}, (err, res) =>{
  47. if( err != 0) return;
  48. item.target_id = this.data.userInfo.ID
  49. this.setData({ list: this.data.list})
  50. util.showSuccess("抢单子成功");
  51. })
  52. },
  53. goDetail(e){
  54. let id = e.currentTarget.dataset.id;
  55. wx.navigateTo({
  56. url: `/pages/task/info/b2bInfo?id=${id}`,
  57. })
  58. },
  59. getTaskList: function( newFrom, cb){
  60. let param = { from: newFrom, size:this.data.size,name: this.data.name }
  61. let list = this.data.list
  62. let that = this
  63. util.http("/wx/getDemandCenter", param, function (err, res) {
  64. if( err != 0) return;
  65. if (newFrom == 0) list = [];
  66. let newlist = res.list.map( item =>{
  67. item.bid_end_at = item.bid_end_at.substr(0,10);
  68. return item
  69. });
  70. that.setData({
  71. from: res.from || -1,
  72. list: list.concat(newlist)
  73. })
  74. cb && cb()
  75. });
  76. },
  77. loadData :function( ){
  78. this.getTaskList(0)
  79. },
  80. })