const app = getApp(),
  Api = require("../../../../utils/util.js");
Page({
  data: {
    currentTab: 0,
    tab: [],
    useFitting: [],
    applyFitting: []
  },
  // 点击切换工单
  swichNav: function(e) {
    this.setData({
      currentTab: e.currentTarget.dataset.current
    })
  },
  onLoad: function(options) {
    var that = this;
    wx.showLoading({
      title: '加载中...',
    })
    that.setData({
      status: options.status,
      id: options.id,
      imgUrl: app.globalData.imgUrl
    })
    if(options.status == '4'){//待接单
      this.setData({
        tab: ['基本信息','过程信息']
      })
    }else if(options.status == '5' || options.status == '6'){//服务中
      this.setData({
        tab: ['基本信息','过程信息']
      })
    }else if(options.status == '7'){//已完成
      this.setData({
        tab: ['基本信息','过程信息','反馈信息','物料信息']
      })
    }
    that.jc();
  },
  //基本信息
  jc: function() {
    var that = this;
    var data = {
      id: that.data.id,
    }
    wx.showLoading({
      title: '加载中...',
    }) 
    Api.req('sf/operationOrder/detail', data, 'get')
      .then(res => {
        wx.hideLoading()
        if(res.code == 200){
          res.data.bdImgs = res.data.bdImgs?res.data.bdImgs.split(','):[]
          that.setData({
            basic: res.data
          })
          that.getList()
        }else{
          wx.showToast({
            title: res.msg,
            icon: 'none'
          })
        } 
      })
  },
  //物料信息列表
  getList: function () {
    var that = this    
    wx.showLoading({
      title: '加载中...',
    })   
    Api.req('blade-operationOrderMaterial/operationOrderMaterial/materialListRelateOrder', {
      orderId: this.data.basic.id
    }, 'get').then(res => {
      wx.hideLoading()
      if(res.code== 200){
        this.setData({
          useFitting: res.data.useFitting, //使用物料
          applyFitting: res.data.applyFitting, //申请物料
        })
      }else{
        wx.showToast({
          title: res.errMsg,
          icon: 'none'
        })
      }
    })
  },
  //物料信息
  getDetail(e){
    let type = e.currentTarget.dataset.type
    if(type == '1'){//物料使用详情
      wx.navigateTo({
        url: '../../materialDetail/materialDetail?id=' + e.currentTarget.dataset.id + '&title=已用物料'
      })
    }else{//物料申请详情
      wx.navigateTo({
        url: '../../addMaterial/addMaterial?id=' + e.currentTarget.dataset.id + '&title=详情'
      })
    }
  },
})