index.js 1.9 KB

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