const mixins = require('@/mixins/index.js')
Page({
  mixins: [mixins],
  /**
   * 页面的初始数据
   */
  data: {
    tableData: [],
    // 路由
    routeObjName: 'inboundItem',
    buttonSaveList: [
      { code: 'add', title: mixins.$t('costCheck'), },
    ],
    // 内容一定
    content: [
      {
        left: { tag: 'brandName', title: 'skuModel', type: 'title' },
      },
      {
        left: { name: 'skuName', },
      },
      {
        left: { name: 'priceInto', type: 'price' },
        right: { name: 'costPrice', title: '入库核对单价', type: 'price' }
      },
      {
        left: { name: 'nonStdCode', title: '色号：' },
        right: { name: 'whName' },

      },
      {
        left: { name: 'skuSpec', title: '规格：' },
        right: { name: 'packBox', title: '箱片：' },
      },
      {
        left: { name: 'intoQty', title: '入库数量：' },
        right: { name: 'seriesName', title: '系列：' },
      }
    ],
    
  },
  /**
  * @desc : 入库单据输入事件
  * @date : 2024/2/1 15:49
  * @author : 于继渤
  */
  changeAmount(e) {
    let index = e.detail.index
    let key = e.detail.key
    let value = e.detail.value
    let tableData = this.data.tableData;
    if (tableData && tableData[index]) {
      tableData[index][key] = Number(value)
      tableData[index].costAmt = (Number(tableData[index][key] * tableData[index].intoQty)).toFixed(2)
    }
    this.setData({
      tableData: tableData
    })
  },
  /**
   * @desc : 设置保存参数
   * @date : 2024/2/1 15:49
   * @author : 于继渤
   */
  setParams(params) {
    params = []
    params = this.data.tableData
    return params
  },

  /**
   * @desc : 保存数据服务
   * @date : 2024/2/1 15:49
   * @author : 于继渤
   */
  saveData() {
    return this.excute(this.data.service, this.data.service.costCheckOk, this.data.params);
  },
  /**
  * 生命周期函数--监听页面加载
  */
  loadInit() {
    let that = this
    const eventChannel = this.getOpenerEventChannel()
    eventChannel.on('params', function (data) {
      data.chooseList.forEach(it => {
        it.costPrice = Number(0)
        it.costAmt = Number(0)
      })
      that.setData({
        tableData: data.chooseList
      })
    })
  }
})