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

  /**
   * 页面的初始数据
   */
  data: {
    data,
    form:{
      projectlearders:[]
    }
  },
  async onClick (data) {
    this.data.form = Object.assign({},this.data.form,data.detail)
    console.log(data,'onClick')
    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',
    })
    wx.navigateBack({
      delta:0
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    let that = this
    let obj = getApp().globalData.handelSelect.data.billData

    that.data.form = Object.assign({},this.data.form,obj)
    Object.keys(that.data.form).map((key,index)=>{
      that.data.data.formLayout.formInfo.forEach(e=>{
        if (e.id === key) {
          e.inputValue = obj[key]
        }
        if (e.id === 'provinceArr') {
          e.inputValue = `${obj.province},${obj.city},${obj.county}`
        }
      })
    })
    that.setData({
      form:this.data.form,
      data:that.data.data,
      linkStopClick:options.class
    })
  },

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

  },

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

  },

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

  },

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

  },

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

  },

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

  },

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

  }
})