const api = require("../api/api")
// import Dialog from 'tdesign-miniprogram/dialog/index';

// pages/workOrderDetail/index.js
Page({

  /**
   * 页面的初始数据
   */
  data: {

  },
  async mainData () {
    const res = await api._post({
      "id": "20230208140103",
      "content": {
        "sa_workorderid":this.data.id
      }
    })
    this.setData({
      billData:res.data
    })
  },
  changeBillStatus(data) {
    let id = data.currentTarget.dataset.id
    const dialogConfig = {
      context: this,
      title: '提示',
      content: '确认执行当前操作吗?',
      confirmBtn: '确定',
      cancelBtn: '取消',
    };

    Dialog.confirm(dialogConfig)
      .then(async () => {
        const res = await api._post({
          "id": id,
          "content": {
            "sa_workorderid":this.data.id
          }
        })
        this.mainData()
      })
      .catch(() => console.log('点击了取消'))
      .finally(() => Dialog.close());
  },

  async addConfirmBill () {
    const res = await api._post({
      "id": "20230211105703",
      "version":1,
      "content": {
        "sa_workorder_confirmationid":0,
        "sa_workorderid":this.data.id,
        "attitudescore":0,
        "responsescore":0,
      }
    })
    if (this.data.billData.type === '安装培训') {
      wx.navigateTo({
        url: '/Eservice/trainConfirmBill/index?id=' + res.data.sa_workorder_confirmationid,
      })
    } else if (this.data.billData.type === '安装调试') {
      wx.navigateTo({
        url: '/Eservice/installConfirmBill/index?id=' + res.data.sa_workorder_confirmationid,
      })
    } else {
      wx.navigateTo({
        url: '/Eservice/serviceConfirmBill/index?id=' + res.data.sa_workorder_confirmationid,
      })
    }
    
  },
  toConfirmBill (data) {
    if (this.data.billData.type === '安装培训') {
      wx.navigateTo({
        url: '/Eservice/trainConfirmBill/index?id=' + data.currentTarget.dataset.item.sa_workorder_confirmationid + '&class=' + this.data.stopClick,
      })
    } else if (this.data.billData.type === '安装调试') {
      wx.navigateTo({
        url: '/Eservice/installConfirmBill/index?id=' + data.currentTarget.dataset.item.sa_workorder_confirmationid + '&class=' + this.data.stopClick,
      })
    } else {
      wx.navigateTo({
        url: '/Eservice/serviceConfirmBill/index?id=' + data.currentTarget.dataset.item.sa_workorder_confirmationid + '&class=' + this.data.stopClick,
      })
    }
     
  },
  async confirmBillList () {
    const res = await api._post({
      "id": "20230211105903",
      "content": {
        "where":{
          "condition":"",
          "sa_workorderid":this.data.id
        }
      }
    })
    this.setData({
      confirmBills:res.data
    })
  },

  toWorkConfirmInfo () {
    getApp().globalData.handelSelect = this

    wx.navigateTo({
      url: '/Eservice/workBillConfirmInfo/index?class=' + this.data.stopClick,
    })
  },
  
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    this.setData({
      id:options.id,
      stopClick:options.class
    })
    
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {
    this.mainData()
    this.confirmBillList()
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})