import {
  genWarehouseAuthSearchModal,
  genCargoownerAuthSearchModal,
} from '@/views/kzyWMS/SearchModal'
const items = function(self) {
  let grid = {
    span: 8
  }
  return [
    ...genWarehouseAuthSearchModal(
      1,
      true,
      false,
      null,
      (modalRowData, form) => {
        console.log(modalRowData, form, 'modalRowData,formmodalRowData,form')
        if (modalRowData) {
          self.remoteParams.warehouseId = modalRowData[0].warehouseId ? modalRowData[0].warehouseId : modalRowData[0].companyId
        } else {
          self.remoteParams.warehouseId = ''
        }
      },
      grid
    ),
    ...genCargoownerAuthSearchModal(1, true, false, null, null, grid),
    { type: 'input', name: 'warehouseWorkerId', label: '操作员Id', hidden: true },
    { type: 'input', name: 'warehouseWorkerName', label: '操作员',disabled: true},
    {
      type: "date",
      name: "today",
      label: "单据日期",
      disabled:true,
      placeholder: "请输入开始日期",
      value: "",
      format: "YYYY-MM-DD",
    },
  ]
}
const columns = function(self) {
  return [
    { dataIndex: 'itemId', title: '商品Id', key: 'itemId', hidden: true },
    { dataIndex: 'rowIndex', title: '列表序号', key: 'rowIndex', hidden: true },
    { dataIndex: 'batchId', title: '批次Id', key: 'batchId', hidden: true },
    { dataIndex: 'batchNum', title: '批次号', key: 'batchNum', hidden: true },
    // { dataIndex: 'pieceBarcode', title: '商品条码', key: 'pieceBarcode' },
    { dataIndex: 'itemCode', title: '商品编码', key: 'itemCode', width:80 },
    { dataIndex: 'itemName', title: '商品名称', key: 'itemName', width:160 },
    { dataIndex: 'specification', title: '商品规格', key: 'specification', width:100 },
    { dataIndex: 'caseConversionRate', title: '包装数量', key: 'caseConversionRate',  width:80 },
    { dataIndex: 'pieceUom', title: '包装单位', key: 'pieceUom', width: 80 },
    { dataIndex: 'countryOriginId', title: '产地', key: 'countryOriginId', width: 300 },
    { dataIndex: 'manufacturerId', title: '生产厂家', key: 'manufacturerId', width: 200 },
    { dataIndex: 'warehouseLocatorCode', title: '货位', key: 'warehouseLocatorCode', width: 100 },
    { dataIndex: 'manufacturerLotNum', title: '批号', key: 'manufacturerLotNum', width: 80 },
    { dataIndex: 'batchProductionDateShow', title: '生产日期', key: 'batchProductionDateShow', width: 100 },
    { dataIndex: 'batchExpiredDateShow', title: '有效期至', key: 'batchExpiredDateShow', width: 100 },
    { dataIndex: 'quantity', title: '数量', key: 'quantity', width: 80 },
    { dataIndex: 'oddCaseQuantity', title: '件数', key: 'oddCaseQuantity', width: 80 },
    { dataIndex: 'oddPieceQuantity', title: '零散数', key: 'oddPieceQuantity', width: 80 },
    { dataIndex: 'statusName', title: '库存状态', key: 'statusName', width: 80 },
    { dataIndex: 'status', title: '库存状态', key: 'status', width: 80 ,hidden:true,},
    {
      dataIndex: 'rqcComments',
      title: '检验情况',
      width: 100,
      required: true,
      fixed:'right',
      key: 'rqcComments',
      type: 'input',
    },
    {
      dataIndex: 'comments',
      title: '处理意见',
      required:true,
      width: 100,
      fixed:'right',
      key: 'comments',
      type: 'input',
    },
  ]
}

export function detailConfig(self) {
  return [
    {
      key: 'one',
      checkedKey: 'main',
      btns: [
        {
          label: '重置',
          click() {
            let refMain = self.queryRefFromName('main')
            let ref = self.queryRefFromName('baseMtlItemUomConversionsList')
            refMain.form.enableItem(['warehouseName', 'cargoOwnerName'])
            // refMain.form.resetFields()
            refMain.form.setFieldsValue({
              warehouseName: '',
              cargoOwnerId: '',
              cargoOwnerName: '',
            })
            ref.delItems() // 删除附表信息
          }
        },
        {
          label: '保存',
          click() {
            let ref = self.queryRefFromName('baseMtlItemUomConversionsList')
            self.saveData(ref.getFieldsValue(true))
          }
        }
      ],
      list: [
        {
          key: 'main',
          tab: '主要信息',
          btns: [],
          item: { type: 'p-grid-form', config: items(self) }
        },
      ]
    },
    {
      key: 'two',
      checkedKey: 'baseMtlItemUomConversionsList',
      list: [
        {
          key: 'baseMtlItemUomConversionsList',
          tab: '锁定明细',
          btns: [
            {
              label: '提取库存',
              click() {
                // let ref = self.queryRefFromName('baseMtlItemUomConversionsList')
                self.visible = true
                // let refMain = self.queryRefFromName('main')
                // let formsVal = refMain.form.getFieldsValue()
                // if (!formsVal.warehouseId) return self.$message.warn('请选择仓库')
                // if (!formsVal.cargoOwnerId) return self.$message.warn('请选择货主')
                // ref.addItem() // 新增
                // // self.formsVal = formsVal  disabled
                // refMain.form.disableItem(['warehouseName', 'cargoOwnerName', ])
              }
            },
            {
              label: '删除',
              click() {
                self.$confirm({
                  content: self.$lang('确定删除?'),
                  onOk: () => {
                    let ref = self.queryRefFromName('baseMtlItemUomConversionsList')
                    ref.removeSelectedRow()
                  }
                })
              }
            }
          ],
          item: {
            type: 'p-table-sheet',
            config: columns(self),
            rowKey: '_row_count',
            rowSelectType: 2,
            colChange({ record, name, value, index }) {
            }
          }
        }
      ]
    }
  ]
}
