// pages/workBillConfirmInfo/index.js
import data from './formData'
import api from '../api/api'
Page({

  /**
   * 页面的初始数据
   */
  data: {
    data,
    form: {
      projectlearders: []
    },
    hideBtn: false
  },
  async onClick(data) {
    this.data.form = Object.assign(this.data.billData, this.data.form, data.detail, {
      projectlearders: []
    })
    const res = await api._post({
      "id": "20230208140003",
      "version": 1,
      "content": this.data.form
    })
    const rs = await api._post({
      "classname": "system.attachment.Attachment",
      "method": "createFileLink",
      "content": {
        "ownertable": "sa_workorder",
        "ownerid": this.data.form.sa_workorderid,
        "usetype": "附件",
        "attachmentids": data.detail.attinfos
      }
    })
    if (res.code === 0) return wx.showToast({
      title: res.msg,
      duration: 3000,
      icon: 'none',
    })
    this.callBack()
    wx.navigateBack({
      delta: 0
    })
  },
  async callBack() {
    const res = await api._post({
      "id": '20230209144503',
      "content": {
        "sa_workorderid": this.data.form.sa_workorderid
      }
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    let that = this
    let obj = getApp().globalData.handelSelect.data.billData
    this.setData({
      hideBtn: obj.status === '待开始' ? false : true
    })
    that.data.form = Object.assign(this.data.form, obj);
    that.setData({
      form: that.data.data.formLayout.formInfo.map(v => {
        v.inputValue = that.data.form[v.id];
        if (v.id === "attinfos") {
          v.bindData = {
            "ownertable": "sa_workorder",
            "ownerid": this.data.form.sa_workorderid,
            "usetype": "附件",
            "attachmentids": []
          };
          v.originFiles = that.data.form.attinfos;
        }
        if (v.id === 'provinceArr') {
          v.inputValue = `${obj.province},${obj.city},${obj.county}`
        }
        if (v.id === "attinfos") console.log(v)
        return v
      }),
      data: this.data.data,
      linkStopClick: obj.status === '待开始' ? "" : 'stopClick',
      billData: obj,
    })
  },

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

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

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

  },

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

  },

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

  },

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

  },

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

  }
})