index.js 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  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. from:0,
  9. size:6,
  10. TabCur:0,
  11. scrollLeft:0,
  12. tabList:["待接任务","已确认","已交付","已完成"],
  13. list:[
  14. ]
  15. },
  16. /**
  17. * 生命周期函数--监听页面加载
  18. */
  19. onLoad: function ( opt) {
  20. let TabCur = +opt.tab||0
  21. this.setData( {TabCur} )
  22. app.checkLogin( ()=>{
  23. this.loadData()
  24. } )
  25. },
  26. tabSelect(e){
  27. this.setData({
  28. TabCur: e.currentTarget.dataset.id,
  29. list:[],
  30. scrollLeft: (e.currentTarget.dataset.id - 1) * 80
  31. })
  32. this.getTaskList(0)
  33. },
  34. bidTask: function( e ){
  35. let index = e.currentTarget.dataset.index;
  36. let item = this.data.list[index]
  37. util.http("/wx/applyWxTask", {id:item.id}, (err, res) =>{
  38. if( err != 0) return;
  39. item.is_bid = 1
  40. this.setData({ list: this.data.list})
  41. util.showMsg("抢单子成功");
  42. })
  43. },
  44. onPullDownRefresh: function () {
  45. this.getTaskList( 0, ()=>{
  46. wx.stopPullDownRefresh();
  47. })
  48. },
  49. onReachBottom: function () {
  50. var that = this
  51. let newFrom = that.data.from
  52. if (newFrom == -1) {
  53. wx.stopPullDownRefresh();
  54. return;
  55. }
  56. this.getTaskList(newFrom, wx.stopPullDownRefresh);
  57. },
  58. doUpload( err, {url} ){
  59. if( err !=0 || !url ) {
  60. util.showMsg("图片上传失败")
  61. return
  62. }
  63. let {index,list} = this.data
  64. let id = list[index].id
  65. util.http( '/maker/addDeliverImg', {id, url}, (err,res)=>{
  66. if( err!= 0 ) return;
  67. list[index].deliver_img = url;
  68. this.setData({list});
  69. })
  70. },
  71. getTaskList: function( newFrom, cb){
  72. let type = this.data.TabCur +1;
  73. let param = { from: newFrom, size:this.data.size, type }
  74. let list = this.data.list
  75. let that = this
  76. util.http("/wx/getWxTaskList", param, function (err, res) {
  77. if( err != 0) return;
  78. if (newFrom == 0) list = [];
  79. let newlist = res.list.map( item =>{
  80. return item
  81. });
  82. that.setData({
  83. from: res.from || -1,
  84. list: list.concat(newlist)
  85. })
  86. cb && cb()
  87. });
  88. },
  89. loadData :function( ){
  90. this.getTaskList(0)
  91. },
  92. previewImage: function (e) {
  93. var current = e.target.dataset.src;
  94. wx.previewImage({
  95. current: current,
  96. urls: [current]
  97. })
  98. } ,
  99. uplodImg: function(e ){
  100. let index = e.currentTarget.dataset.index;
  101. console.log("uplodImg", e.currentTarget.dataset)
  102. this.setData({index});
  103. wx.chooseImage({
  104. count: 1,
  105. sizeType: ['compressed'],
  106. sourceType: ['album', 'camera'],
  107. success: (res) =>{
  108. var tempImagePath = res.tempFilePaths[0];
  109. util.uploadFile( tempImagePath, this.doUpload )
  110. },
  111. fail:()=>{
  112. app.showMsg('选择失败')
  113. }
  114. })
  115. }
  116. })