const Constants = require('@/utils/Constants.js');
const util = require('@/utils/util.js')
const mixins = require('@/mixins/index.js');
const { onLoad } = require('@/mixins/index.js');
Page({
  mixins: [mixins],
  /**
   * 页面的初始数据
   */

  data: {
    // 主键Id
    primaryKey: 'orderId',
    routeObjName: 'order',
    pageFlag: false,
    other: {
      id: ''
    },
    cardList: [
      { name: 'items', title: '商品明细', chooseGoodsFlag: false, displayNum: 2 },
      { name: 'other', title: '其他信息' }
    ],
    contentObj: {
      items: [
        { code: 'collectType', name: 'collectName', type: 'drop', required: true, dropType: 'collect' },
        { code: 'collectAmount', type: 'number', title: '收款金额', required: true }
      ],
      other: [
        { code: 'contractNo', type: 'textarea', title: '合同号', readonly: true },
        { code: 'deliveryDate', type: 'textarea', title: '送货日期', readonly: true },
        { code: 'remarks', type: 'textarea', title: '备注', readonly: false, readonly: true },
        { code: 'file', type: 'uploader', title: '附件', readonly: true }
      ]
    },
    //按钮
    buttonSaveList: [
      { code: 'collection', title: '收款', width: '120rpx', color: '#CAA977' },
      { code: 'save', title: '保存', width: '120rpx', color: '#1B365D' }
    ],
    contentSaveList: [
      { code: 'flag', title: '开单并出库办理', type: 'checkbox' },
      { code: 'need', title: '需收款', type: 'str' },
      { code: 'receivable', content: 0, type: 'number' }
    ],
    popContent: [
      { code: 'itemQty', type: 'step', title: '数量', required: true },
      { code: 'priceSale', type: 'number', title: '销售价格', required: true },
      {
        code: 'whId', name: 'whName', title: '库区', type: 'choose', urlKey: 'openingInventory',
      },
      { code: 'nonStdCode', title: '商品批次', type: 'str', },
      { code: 'flgGift', title: '赠品标识', type: 'checkbox', },
    ],

    //按钮
    buttonSaveList: [
      { code: 'collection', title: '收款', width: '120rpx', color: '#CAA977' }
    ],
    contentSaveList: [
      { code: 'need', title: '需收款', type: 'str' },
      { code: 'receivable', content: 0, type: 'number' }
    ],
  },



  /**
    * @desc : 给表单赋值
    * @date : 2024/2/1 15:49
    * @author : 于继渤
    */
  setValuesByEdit(data) {
    let cardList = this.data.cardList
    let contentSaveList = this.data.contentSaveList
    let formData = JSON.parse(this.data.formData)
    formData = data.data
    formData.goodsList = data.dataItem
    cardList[0].sumAmount = data.data.sumAmount
    cardList[0].sumStandard = data.data.sumStandard
    cardList[0].sumQuantity = data.data.sumQuantity
    cardList[0].saleDiscount = data.data.saleDiscount
    contentSaveList[1]['content']  = data.data.sumAmount

    
    this.setData({
      item: data.data,
      contentSaveList:contentSaveList,
      formData: JSON.stringify(formData),
      cardList: cardList
    })
  },


  /**
     * @desc : 加载数据
     * @author : 于继渤
     * @date : 2024/1/23 9:16
     */
  getData(params) {
    return this.excute(this.data.service, this.data.service.getOrderForUpdate + '/' + this.data.item.orderId, params);
  },


})