import {
  genWarehouseAuthSearchModal,
  genCargoownerAuthSearchModal,
} from '@/views/kzyWMS/SearchModal'

const items = function(self) {
  let grid = {
    span: 8
  }
  return [
    { type: 'input', name: 'warehouseId', label: '仓库id', hidden: true },
    ...genWarehouseAuthSearchModal(
      1,
      true,
      false,
      null,
      (modalRowData, form) => {
        console.log(modalRowData, form, 'modalRowData,formmodalRowData,form')
      },
      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: 'batchId', title: '批次Id', key: 'batchId', hidden: true },
    { dataIndex: 'batchNum', title: '批次号', key: 'batchNum', hidden: true },
    // { dataIndex: 'pieceBarcode', title: '商品条码', key: 'pieceBarcode' },
    { dataIndex: 'warehouseName', title: '仓库名称', key: 'warehouseName', width:80 },
    { dataIndex: 'cargoOwnerName', title: '货主名称', key: 'cargoOwnerName', width:80 },
    { dataIndex: 'code', title: '单据编号', key: 'code', width:80 },
    { dataIndex: 'gmtCreate', title: '单据时间', key: 'gmtCreate', width:80 },
    { dataIndex: 'itemCode', title: '商品编码', key: 'itemCode', width:80 },
    { dataIndex: 'itemName', title: '商品名称', key: 'itemName', width:160 },
    { dataIndex: 'specification', title: '商品规格', key: 'specification', width:100 },
    { dataIndex: 'conversionRate', title: '包装数量', key: 'conversionRate',  width:80 },
    { dataIndex: 'uom', title: '包装单位', key: 'uom', width: 80 },
    { dataIndex: 'rqcComments', title: '检验情况', key: 'rqcComments', width: 80 },
    { dataIndex: 'comments', title: '处理意见', key: 'comments', width: 80 },
    {dataIndex: 'checkComments',key:'checkComments',title: '审核意见',width: 100},
    {dataIndex: 'statusName',key:'statusName',title: 'ERP审核状态',width: 100},
    { dataIndex: 'wmsStatusName', title: 'WMS库存状态', key: 'wmsStatusName', width: 80 },
    { dataIndex: 'erpStatusName', title: 'ERP库存状态', key: 'erpStatusName', width: 80 },
    { 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: 'creatorName', title: '锁定人', key: 'creatorName', width: 80 },
    { dataIndex: 'countryOriginId', title: '产地', key: 'countryOriginId', width: 300 },
    { dataIndex: 'manufacturerId', title: '生产厂家', key: 'manufacturerId', width: 200 },
  ]
}

export function detailConfig(self) {
  return [
    {
      key: 'one',
      checkedKey: 'main',
      btns: [
        {
          label: '查询',
          click() {
            self.queryDetailList()
            // 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 refMain = self.queryRefFromName('main')
            let ref = self.queryRefFromName('baseMtlItemUomConversionsList')
            refMain.form.enableItem(['warehouseName', 'cargoOwnerName'])
            // refMain.form.resetFields()
            refMain.form.setFieldsValue({
              warehouseName: '',
              cargoOwnerId: '',
              cargoOwnerName: '',
            })
          }
        },
        {
          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: [
          ],
          item: {
            type: 'p-table-sheet',
            config: columns(self),
            rowKey: '_row_count',
            rowSelectType: 2,
            colChange({ record, name, value, index }) {
            }
          }
        }
      ]
    }
  ]
}
