import type { CrudSchema } from '@/hooks/web/useCrudSchemas'
import { dateFormatter,dateFormatter2 } from '@/utils/formatTime'
import * as SupplierApi from '@/api/wms/supplier'
import { Supplier } from '@/views/wms/basicDataManage/supplierManage/supplier/supplier.data'
import * as getRequestsettingApi from '@/api/wms/requestsetting/index'
// import { PurchasePlanMain } from '../purchasePlanMain/purchasePlanMain.data'
import * as PurchasePlanMainApi from '@/api/wms/purchasePlanMain'
import * as PurchasePlanDetailApi from '@/api/wms/purchasePlanDetail'
import { PurchasePlanDetail, PurchasePlanMain } from '../purchasePlanMain/purchasePlanMain.data'
import { validateHanset, validateEmail } from '@/utils/validator'
import { Itempackaging } from '@/views/wms/basicDataManage/itemManage/itempackage/itempackage.data'
import * as ItemPackageApi from '@/api/wms/itempackage/index'

const { t } = useI18n() // 国际化

// 获取自动提交自动通过自动执行,跳过任务直接删生成记录的默认值
const queryParams = {
  pageSize: 10,
  pageNo: 1,
  code: 'SupplierDeliverRequest'
}
const data = await getRequestsettingApi.getRequestsettingPage(queryParams)
const requestsettingData = data?.list[0] || {}

 // 获取当前操作人的部门
 import { useUserStore } from '@/store/modules/user'
 import { TableColumn } from '@/types/table'
import { tr } from 'element-plus/es/locale'
 const userStore = useUserStore()
 const userDept = userStore.userSelfInfo.dept
 // id 转str 否则form回显匹配不到
 userDept.id = userDept.id.toString()
 const userDeptArray:any = [userDept] 

/**
 * @returns {Array} 供应商发货申请主表
 */
export const SupplierdeliverRequestMain = useCrudSchemas(reactive<CrudSchema[]>([
  {
    label: '单据号',
    field: 'number',
    sort: 'custom',
    table: {
      width: 180,
      fixed: 'left'
    },
    isForm: false,
    isSearch: true,
  },
  {
    label: '供应商代码',
    field: 'supplierCode',
    sort: 'custom',
    table: {
      width: 150
    },
    isSearch: true,
    form: {
      // labelMessage: '信息提示说明!!!',
      componentProps: {
        isSearchList: true, // 开启查询弹窗
        searchListPlaceholder: '请选择供应商代码', // 输入框占位文本
        searchField: 'code', // 查询弹窗赋值字段
        searchTitle: '供应商信息', // 查询弹窗标题
        searchAllSchemas: Supplier.allSchemas, // 查询弹窗所需类
        searchPage: SupplierApi.getSupplierPage // 查询弹窗所需分页方法
      }
    }
  },
  {
    label: '发货单号',
    field: 'asnNumber',
    sort: 'custom',
    table: {
      width: 150
    },
    isSearch: true,
    isForm: true
  },
  {
    label: '要货计划单号',
    field: 'ppNumber',
    sort: 'custom',
    table: {
      width: 150
    },
    form: {
      // labelMessage: '信息提示说明!!!',
      componentProps: {
        isSearchList: true, // 开启查询弹窗
        searchListPlaceholder: '请选择要货计划单号', // 输入框占位文本
        searchField: 'number', // 查询弹窗赋值字段
        searchTitle: '要货计划信息', // 查询弹窗标题
        searchAllSchemas: PurchasePlanMain.allSchemas, // 查询弹窗所需类
        searchPage: PurchasePlanMainApi.getPurchasePlanMainPage, // 查询弹窗所需分页方法
        searchCondition: [
          {
            key: 'supplierCode',
            value: 'supplierCode',
            message: '请填写供应商代码!',
            isMainValue: true
          },
          {
            key: 'status',
            value: 4,
            isMainValue: false
          },
          {
            key: 'available',
            value: "TRUE",
            isMainValue: false
          }]
      }
    }
  },
  {
    label: '联系人姓名',
    field: 'contactName',
    sort: 'custom',
    table: {
      width: 150
    },
  },
  {
    label: '联系人电话',
    field: 'contactPhone',
    sort: 'custom',
    table: {
      width: 150
    },
  },
  {
    label: '联系人电子邮件',
    field: 'contactEmail',
    sort: 'custom',
    table: {
      width: 150
    },
  },
  {
    label: '供应商发货仓库代码',
    field: 'fromWarehouseCode',
    sort: 'custom',
    table: {
      width: 150
    },
    form: {
      componentProps: {
        disbaled: true
      }
    },
    isForm: true
  },
  {
    label: '到仓库代码',
    field: 'toWarehouseCode',
    sort: 'custom',
    table: {
      width: 150
    },
    isForm: false
  },
  {
    label: '到月台代码',
    field: 'toDockCode',
    sort: 'custom',
    table: {
      width: 150
    },
    isForm: false
  },
  {
    label: '时间窗口',
    field: 'timeWindow',
    sort: 'custom',
    table: {
      width: 150
    },
    isForm: false
  },
  {
    label: '计划到货时间',
    field: 'planArriveTime',
    formatter: dateFormatter,
    detail: {
      dateFormat: 'YYYY-MM-DD HH:mm:ss'
    },
    sort: 'custom',
    table: {
      width: 180
    },
    form: {
      component: 'DatePicker',
      componentProps: {
        style: { width: '100%' },
        type: 'datetime',
        dateFormat: 'YYYY-MM-DD HH:mm:ss',
        valueFormat: 'x',
      }
    },
  },
  {
    label: '承运商',
    field: 'carrierCode',
    sort: 'custom',
    table: {
      width: 150
    },
  },
  {
    label: '运输方式',
    field: 'transferMode',
    dictType: DICT_TYPE.TRANSFER_MODE,
    sort: 'custom',
    table: {
      width: 150
    },
  },
  {
    label: '车牌号',
    field: 'vehiclePlateNumber',
    sort: 'custom',
    table: {
      width: 150
    },
  },
  // {
  //   label: '业务类型',
  //   field: 'businessType',
  //   sort: 'custom',
  //   table: {
  //     width: 150
  //   },
  //   form: {
  //     value: 'SupplierDeliver',
  //     componentProps: {
  //       disabled: true,
  //     }
  //   }
  // },
  {
    label: '备注',
    field: 'remark',
    sort: 'custom',
    table: {
      width: 150
    },
    isTable: false
  },
  {
    label: '创建时间',
    field: 'createTime',
    formatter: dateFormatter,
    detail: {
      dateFormat: 'YYYY-MM-DD HH:mm:ss'
    },
    sort: 'custom',
    table: {
      width: 180
    },
    form: {
      component: 'DatePicker',
      componentProps: {
        style: { width: '100%' },
        type: 'datetime',
        dateFormat: 'YYYY-MM-DD HH:mm:ss',
        valueFormat: 'x',
      }
    },
    isForm: false
  },
  {
    label: '创建者',
    field: 'creator',
    sort: 'custom',
    table: {
      width: 150
    },
    isForm: false
  },
  {
    label: '申请时间',
    field: 'requestTime',
    formatter: dateFormatter,
    detaul: {
      dateFormat: 'YYYY-MM-DD HH:mm:ss'
    },
    sort: 'custom',
    table: {
      width: 180
    },
    form: {
      component: 'DatePicker',
      componentProps: {
        style: { width: '100%' },
        type: 'datetime',
        dateFormat: 'YYYY-MM-DD HH:mm:ss',
        valueFormat: 'x',
      }
    },
    isForm: false
  },
  {
    label: '截止时间',
    field: 'dueTime',
    formatter: dateFormatter,
    detaul: {
      dateFormat: 'YYYY-MM-DD HH:mm:ss'
    },
    sort: 'custom',
    table: {
      width: 180
    },
    form: {
      component: 'DatePicker',
      componentProps: {
        style: { width: '100%' },
        type: 'datetime',
        dateFormat: 'YYYY-MM-DD HH:mm:ss',
        valueFormat: 'x',
      }
    },
    isForm: false
  },
  // {
  //   label: '部门',
  //   field: 'departmentCode',
  //   sort: 'custom',
  //   table: {
  //     width: 150
  //   },
  //   formatter: (_: Recordable, __: TableColumn, cellValue: number) => {
  //     return userDeptArray.find((account) => account.id == cellValue)?.name
  //   },
  //   form: {
  //     value: userDept.id,
  //     component: 'Select',
  //     api: () => userDeptArray,
  //     componentProps: {
  //       disabled: true,
  //       optionsAlias: {
  //         labelField: 'name',
  //         valueField: 'id'
  //       }
  //     }
  //   }
  // },
  {
    label: '状态',
    field: 'status',
    dictType: DICT_TYPE.REQUEST_STATUS,
    dictClass: 'string',
    isTable: true,
    isForm:false,
    isSearch: true,
    sort: 'custom',
    table: {
      width: 150
    },
    form: {
      value: '1',
      componentProps: {
        disabled: true
      }
    }
  },
  {
    label: '最后更新时间',
    field: 'updateTime',
    formatter: dateFormatter,
    detail: {
      dateFormat: 'YYYY-MM-DD HH:mm:ss'
    },
    sort: 'custom',
    table: {
      width: 180
    },
    form: {
      component: 'DatePicker',
      componentProps: {
        style: { width: '100%' },
        type: 'datetime',
        dateFormat: 'YYYY-MM-DD HH:mm:ss',
        valueFormat: 'x',
      }
    },
    isForm: false
  },
  {
    label: '最后更新者',
    field: 'updater',
    sort: 'custom',
    table: {
      width: 150
    },
    isForm: false
  },
  {
    label: '自动提交',
    field: 'autoCommit',
    dictType: DICT_TYPE.TRUE_FALSE,
    dictClass: 'string',
    isTable: true,
    sort: 'custom',
    isForm:false,
    table: {
      width: 150
    },
    form: {
      component: 'Switch',
      value: requestsettingData.autoCommit,
      componentProps: {
        inactiveValue: 'FALSE',
        activeValue: 'TRUE',
        disabled: true,
      }
    }
  },
  {
    label: '自动通过',
    field: 'autoAgree',
    dictType: DICT_TYPE.TRUE_FALSE,
    dictClass: 'string',
    isTable: true,
    sort: 'custom',
    table: {
      width: 150
    },
    isForm:false,
    form: {
      component: 'Switch',
      value: requestsettingData.autoAgree,
      componentProps: {
        inactiveValue: 'FALSE',
        activeValue: 'TRUE',
        disabled: true,
      }
    }
  },
  {
    label: '自动执行',
    field: 'autoExecute',
    dictType: DICT_TYPE.TRUE_FALSE,
    dictClass: 'string',
    isTable: true,
    sort: 'custom',
    table: {
      width: 150
    },
    isForm:false,
    form: {
      component: 'Switch',
      value: requestsettingData.autoExecute,
      componentProps: {
        inactiveValue: 'FALSE',
        activeValue: 'TRUE',
        disabled: true,
      }
    }
  },
  {
    label: '直接生成记录',
    field: 'directCreateRecord',
    dictType: DICT_TYPE.TRUE_FALSE,
    dictClass: 'string',
    isForm: false,
    isTable: false,
    sort: 'custom',
    table: {
      width: 150
    },
    form: {
      component: 'Switch',
      value: requestsettingData.directCreateRecord,
      componentProps: {
        inactiveValue: 'FALSE',
        activeValue: 'TRUE',
        disabled: true,
      }
    }
  },
  {
    label: '操作',
    field: 'action',
    isDetail: false,
    isForm: false,
    table: {
      width: 300,
      fixed: 'right'
    },
  }
]))

//表单校验
export const SupplierdeliverRequestMainRules = reactive({
  supplierCode: [
    { required: true, message: '请输入供应商代码', trigger: 'blur' }
  ],
  ppNumber: [
    { required: true, message: '请输入要货计划单号', trigger: 'blur' }
  ],
  asnNumber: [
    { max: 50, message: '不得超过50个字符', trigger: 'blur' }
  ],
  contactName: [
    { max: 50, message: '不得超过50个字符', trigger: 'blur' }
  ],
  contactPhone: [
    { max: 50, message: '不得超过50个字符', trigger: 'blur' },
    { validator: validateHanset, message: '请输入正确的手机号', trigger: 'blur' }
  ],
  contactEmail: [
    { max: 50, message: '不得超过50个字符', trigger: 'blur' },
    { validator: validateEmail, message: '请输入正确的邮箱地址', trigger: 'blur' }
  ],
  carrierCode: [
    { max: 50, message: '不得超过50个字符', trigger: 'blur' }
  ],
  transferMode: [
    { max: 50, message: '不得超过50个字符', trigger: 'blur' }
  ],
  vehiclePlateNumber: [
    { max: 50, message: '不得超过50个字符', trigger: 'blur' }
  ],
  remark: [
    { max: 50, message: '不得超过50个字符', trigger: 'blur' }
  ],
  planArriveTime: [
    { required: true, message: '请输入计划到货时间', trigger: 'blur' }
  ],
  // departmentCode: [
  //   { required: true, message: '请输入部门', trigger: 'blur' }
  // ],
  autoCommit: [
    { required: true, message: '请选择是否自动提交', trigger: 'change' }
  ],
  autoAgree: [
    { required: true, message: '请选择是否自动通过', trigger: 'change' }
  ],
  autoExecute: [
    { required: true, message: '请选择是否自动执行', trigger: 'change' }
  ],
  directCreateRecord: [
    { required: true, message: '请选择是否跳过任务直接生成记录', trigger: 'change' }
  ],
  // businessType: [
  //   { required: true, message: '请输入业务类型', trigger: 'blur' }
  // ],
})

/**
 * @returns {Array} 供应商发货申请子表
 */
export const SupplierdeliverRequestDetail = useCrudSchemas(reactive<CrudSchema[]>([
  {
    label: '订单号',
    field: 'poNumber',
    sort: 'custom',
    table: {
      width: 150
    },
    form: {
      // labelMessage: '信息提示说明!!!',
      componentProps: {
        isSearchList: true,
        searchListPlaceholder: '请选择订单号',
        searchField: 'number',
        searchTitle: '要货计划信息',
        searchAllSchemas: PurchasePlanDetail.allSchemas,
        searchPage: PurchasePlanDetailApi.getPurchasePlanDetailPage,
        searchCondition: [
          {
            key: 'number',
            value: 'ppNumber',
            message: '请填写要货计划单号!',
            isMainValue: true
          },
          {
            key: 'available',
            value: 'TRUE',
            isMainValue: false
          }

        ]
      }
    },
    tableForm: {
      isInpuFocusShow: true,
      searchListPlaceholder: '请选择订单号',
      searchField: 'number',
      searchTitle: '要货计划信息',
      searchAllSchemas: PurchasePlanDetail.allSchemas,
      searchPage: PurchasePlanDetailApi.getPurchasePlanDetailPage,
      searchCondition: [
        {
          key: 'number',
          value: 'ppNumber',
          message: '请填写要货计划单号!',
          isMainValue: true
        },
        {
          key: 'available',
          value: 'TRUE',
          isMainValue: false
        }]
    }
  },
  {
    label: '订单行',
    field: 'poLine',
    sort: 'custom',
    table: {
      width: 150
    },
    form: {
      componentProps: {
        disabled: true
      }
    },
    tableForm: {
      disabled: true
    }
  },
  {
    label: '物料代码',
    field: 'itemCode',
    sort: 'custom',
    table: {
      width: 150
    },
    form: {
      componentProps: {
        disabled: true
      }
    },
    tableForm: {
      disabled: true
    }
  },
  {
    label: '批次',
    field: 'batch',
    sort: 'custom',
    table: {
      width: 150
    },
    tableForm: {
      disabled: false
    }
  },
  {
    label: '生产日期',
    field: 'produceDate',
    formatter: dateFormatter2,
    detail: {
      dateFormat: 'YYYY-MM-DD'
    },
    sort: 'custom',
    table: {
      width: 180
    },
    form: {
      component: 'DatePicker',
      componentProps: {
        style: {width: '100%'},
        type: 'date',
        dateFormat: 'YYYY-MM-DD',
        valueFormat: 'x',
      }
    },
    tableForm: {
      type: 'FormDate',
      dateFormat: 'YYYY-MM-DD',
      valueFormat: 'x',
    }
  },
  
  // {
  //   label: '替代批次',
  //   field: 'altBatch',
  //   sort: 'custom',
  //   table: {
  //     width: 150
  //   },
  //   isTableForm: false,
  //   isForm: false
  // },
  {
    label: '到货日期',
    field: 'arriveDate',
    formatter: dateFormatter2,
    detail: {
      dateFormat: 'YYYY-MM-DD'
    },
    sort: 'custom',
    table: {
      width: 180
    },
    isForm: false,
    form: {
      component: 'DatePicker',
      componentProps: {
        style: {width: '100%'},
        type: 'date',
        dateFormat: 'YYYY-MM-DD',
        valueFormat: 'x',
      }
    },
    
    isTableForm: false,
    tableForm: {
      type: 'FormDate',
      dateFormat: 'YYYY-MM-DD',
      valueFormat: 'x',
    }
  },
  {
    label: '过期日期',
    field: 'expireDate',
    formatter: dateFormatter2,
    detail: {
      dateFormat: 'YYYY-MM-DD'
    },
    sort: 'custom',
    table: {
      width: 180
    },
    form: {
      component: 'DatePicker',
      componentProps: {
        style: {width: '100%'},
        type: 'date',
        dateFormat: 'YYYY-MM-DD',
        valueFormat: 'x',
      }
    },
    // tableForm: {
    //   type: 'FormDate',
    //   dateFormat: 'YYYY-MM-DD',
    //   valueFormat: 'x',
    // }
    tableForm:{
      type: 'slot',
      disabled: true
    }
  },
  
  {
    label: '订单数量',
    field: 'orderQty',
    table: {
      width: 150
    },
    form: {
      component: 'InputNumber',
      componentProps: {
        disabled: true,
        min: 0,
        precision: 6
      }
    },
    tableForm: {
      disabled: true,
      type: 'InputNumber',
      min: 0,
      precision: 6
    }
  },
  
  {
    label: '供应商计量数量',
    field: 'supplierPackQty',
    sort: 'custom',
    table: {
      width: 150
    },
    form: {
      component: 'InputNumber',
      componentProps: {
        min: 1,
        precision: 6
      }
    },
    isTableForm: false,
    isForm: false,
    tableForm: {
      type: 'InputNumber',
      min: 1,
      precision: 6
    }
  },
  {
    label: '供应商计量单位',
    field: 'supplierPackUnit',
    dictType: DICT_TYPE.UOM,
    dictClass: 'string',
    isTable: true,
    sort: 'custom',
    table: {
      width: 150
    },
    isTableForm: false,
    isForm: false,
    tableForm: {
      type: 'Select'
    }
  },
  {
    label: '转换率',
    field: 'convertRate',
    sort: 'custom',
    table: {
      width: 150
    },
    form: {
      component: 'InputNumber',
      componentProps: {
        min: 0
      }
    },
    isTableForm: false,
    isForm: false,
    tableForm: {
      type: 'InputNumber',
      min: 0
    }
  },
  {
    label: '单据号',
    field: 'number',
    sort: 'custom',
    table: {
      width: 180
    },
    isTableForm: false,
    form: {
      componentProps: {
        disabled: true
      }
    }
  },
  
  {
    label: '计量单位',
    field: 'uom',
    sort: 'custom',
    dictType: DICT_TYPE.UOM,
    dictClass: 'string',
    isSearch: true,
    isTable: true,
    table: {
      width: 150
    },
    tableForm: {
      type: 'Select'
    }
  },
  {
    label: '数量',
    field: 'qty',
    sort: 'custom',
    table: {
      width: 150
    },
    form: {
      component: 'InputNumber',
      componentProps: {
        min: 1,
        precision: 6
      }
    },
    tableForm: {
      type: 'InputNumber',
      min: 1,
      precision: 6
    }
  },
  {
    label: '从货主代码',
    field: 'fromOwnerCode',
    sort: 'custom',
    table: {
      width: 150
    },
    isTableForm: false,
    isForm: false
  },
  {
    label: '到货主代码',
    field: 'toOwnerCode',
    sort: 'custom',
    table: {
      width: 150
    },
    isTableForm: false,
    isForm: false
  },
  {
    label: '物料名称',
    field: 'itemName',
    sort: 'custom',
    table: {
      width: 150
    },
    isTableForm: false,
    isForm: false
  },
  {
    label: '物料描述1',
    field: 'itemDesc1',
    sort: 'custom',
    table: {
      width: 150
    },
    isTableForm: false,
    isForm: false
  },
  {
    label: '物料描述2',
    field: 'itemDesc2',
    sort: 'custom',
    table: {
      width: 150
    },
    isTableForm: false,
    isForm: false
  },
  {
    label: '项目代码',
    field: 'projectCode',
    sort: 'custom',
    table: {
      width: 150
    },
    isTableForm: false,
    isForm: false
  },
  {
    label: '创建时间',
    field: 'createTime',
    formatter: dateFormatter,
    detail: {
      dateFormat: 'YYYY-MM-DD HH:mm:ss'
    },
    form: {
      component: 'DatePicker',
      componentProps: {
        style: { width: '100%' },
        type: 'datetime',
        dateFormat: 'YYYY-MM-DD HH:mm:ss',
        valueFormat: 'x',
      }
    },
    sort: 'custom',
    table: {
      width: 180
    },
    isTableForm: false,
    isForm: false,
  },
  {
    label: '创建者',
    field: 'creator',
    sort: 'custom',
    table: {
      width: 150
    },
    isTableForm: false,
    isForm: false,
  },
  {
    label: '最后更新时间',
    field: 'updateTime',
    formatter: dateFormatter,
    detail: {
      dateFormat: 'YYYY-MM-DD HH:mm:ss'
    },
    form: {
      component: 'DatePicker',
      componentProps: {
        style: { width: '100%' },
        type: 'datetime',
        dateFormat: 'YYYY-MM-DD HH:mm:ss',
        valueFormat: 'x',
      }
    },
    sort: 'custom',
    table: {
      width: 180
    },
    isTableForm: false,
    isForm: false,
  },
  {
    label: '最后更新者',
    field: 'updater',
    sort: 'custom',
    table: {
      width: 150
    },
    isTableForm: false,
    isForm: false,
  },
  {
    label: '备注',
    field: 'remark',
    sort: 'custom',
    table: {
      width: 150
    },
  },
  {
    label: '操作',
    field: 'action',
    isDetail: false,
    isForm: false,
    table: {
      width: 180,
      fixed: 'right'
    },
    isTableForm: false,
  }
]))

// 批次校验
const validateBatch = (rule: any, value: any, callback: any) => {
  const reg = /^[_a-zA-Z0-9]+$/;
  if (value == '' || value == undefined || value == null) {
      callback();
  } else {
      if (!reg.test(value)) {
          callback(new Error('英文字母、数字或下划线'));
      } else {
          callback();
      }
  }
}
//表单校验
export const SupplierdeliverRequestDetailRules = reactive({
  // packingNumber: [
  //   { required: true, message: '请输入包装号', trigger: 'blur' }
  // ],
  batch: [
    { required: true, message: '请输入批次', trigger: 'blur' },
    { max: 50, message: '不得超过50个字符', trigger: 'blur' },
    { validator: validateBatch, trigger: 'change' }
  ],
  produceDate: [
    { required: true, message: '请输入生产日期', trigger: 'blur' }
  ],
  packQty: [
    { required: true, message: '请输入包装数量', trigger: 'blur' }
  ],
  poNumber: [
    { required: true, message: '请选择订单号', trigger: 'change' }
  ],
  poLine: [
    { required: true, message: '请选择订单行', trigger: 'change' }
  ],
  packUnit: [
    { required: true, message: '请选择包装规格', trigger: 'change' }
  ],
  convertRate: [
    { required: true, message: '请输入转换率', trigger: 'blur' }
  ],
  itemCode: [
    { required: true, message: '请选择物料代码', trigger: 'change' }
  ],
  remark: [
    { max: 50, message: '不得超过50个字符', trigger: 'blur' }
  ],
})

export const SupplierdeliverRequestDetailLabel = useCrudSchemas(reactive<CrudSchema[]>([
  {
    label: '批次',
    field: 'batch',
    sort: 'custom',
    table: {
      width: 150
    },
    tableForm: {
      disabled: true
    }
  },
  {
    label: '生产日期',
    field: 'produceDate',
    formatter: dateFormatter2,
    detail: {
      dateFormat: 'YYYY-MM-DD'
    },
    sort: 'custom',
    table: {
      width: 180
    },
    form: {
      component: 'DatePicker',
      componentProps: {
        disabled:true,
        style: {width: '100%'},
        type: 'date',
        dateFormat: 'YYYY-MM-DD',
        valueFormat: 'x',
      }
    },
    tableForm: {
      disabled:true,
      type: 'FormDate',
      dateFormat: 'YYYY-MM-DD',
      valueFormat: 'x',
    }
  },
  // {
  //   label: '替代批次',
  //   field: 'altBatch',
  //   sort: 'custom',
  //   table: {
  //     width: 150
  //   },
  //   isTableForm: false,
  //   isForm: false,
  //   tableForm:{
  //     disabled:true
  //   }
  // },
  {
    label: '到货日期',
    field: 'arriveDate',
    formatter: dateFormatter2,
    detail: {
      dateFormat: 'YYYY-MM-DD'
    },
    sort: 'custom',
    table: {
      width: 180
    },
    isForm: false,
    form: {
      component: 'DatePicker',
      componentProps: {
        disabled:true,
        style: {width: '100%'},
        type: 'date',
        dateFormat: 'YYYY-MM-DD',
        valueFormat: 'x',
      }
    },
    isTableForm: false,
    tableForm: {
      disabled:true,
      type: 'FormDate',
      dateFormat: 'YYYY-MM-DD',
      valueFormat: 'x',
    }
  },
  {
    label: '过期日期',
    field: 'expireDate',
    formatter: dateFormatter2,
    detail: {
      dateFormat: 'YYYY-MM-DD',
    },
    sort: 'custom',
    table: {
      width: 180
    },
    form: {
      component: 'DatePicker',
      componentProps: {
        disabled:true,
        style: {width: '100%'},
        type: 'date',
        dateFormat: 'YYYY-MM-DD',
        valueFormat: 'x',
      }
    },
    tableForm: {
      disabled:true,
      type: 'FormDate',
      dateFormat: 'YYYY-MM-DD',
      valueFormat: 'x',
    }
  },
  {
    label: '订单号',
    field: 'poNumber',
    sort: 'custom',
    table: {
      width: 150
    },
    form: {
      // labelMessage: '信息提示说明!!!',
      componentProps: {
        disabled:true,
        isSearchList: false,
        searchListPlaceholder: '请选择订单号',
        searchField: 'number',
        searchTitle: '要货计划信息',
        searchAllSchemas: PurchasePlanDetail.allSchemas,
        searchPage: PurchasePlanDetailApi.getPurchasePlanDetailPage,
        searchCondition: [
          {
            key: 'number',
            value: 'ppNumber',
            message: '请填写要货计划单号!',
            isMainValue: true
          },
          {
            key: 'available',
            value: 'TRUE',
            isMainValue: false
          }

        ]
      }
    },
    tableForm: {
      isInpuFocusShow: false,
      disabled:true,
      searchListPlaceholder: '请选择订单号',
      searchField: 'number',
      searchTitle: '要货计划信息',
      searchAllSchemas: PurchasePlanDetail.allSchemas,
      searchPage: PurchasePlanDetailApi.getPurchasePlanDetailPage,
      searchCondition: [
        {
          key: 'number',
          value: 'ppNumber',
          message: '请填写要货计划单号!',
          isMainValue: true
        },
        {
          key: 'available',
          value: 'TRUE',
          isMainValue: false
        }]
    }
  },
  {
    label: '订单行',
    field: 'poLine',
    sort: 'custom',
    table: {
      width: 150
    },
    form: {
      componentProps: {
        disabled: true
      }
    },
    tableForm: {
      disabled: true
    }
  },
  {
    label: '订单数量',
    field: 'orderQty',
    table: {
      width: 150
    },
    form: {
      component: 'InputNumber',
      componentProps: {
        disabled: true,
        min: 0,
        precision: 6
      }
    },
    tableForm: {
      disabled: true,
      type: 'InputNumber',
      min: 0,
      precision: 6
    }
  },
  
  {
    label: '供应商计量数量',
    field: 'supplierPackQty',
    sort: 'custom',
    table: {
      width: 150
    },
    form: {
      component: 'InputNumber',
      componentProps: {
        disabled:true,
        min: 1,
        precision: 6
      }
    },
    isTableForm: false,
    isForm: false,
    tableForm: {
      disabled:true,
      type: 'InputNumber',
      min: 1,
      precision: 6
    }
  },
  {
    label: '供应商计量单位',
    field: 'supplierPackUnit',
    dictType: DICT_TYPE.UOM,
    dictClass: 'string',
    isTable: true,
    sort: 'custom',
    table: {
      width: 150
    },
    isTableForm: false,
    isForm: false,
    tableForm: {
      disabled:true,
      type: 'Select'
    }
  },
  {
    label: '转换率',
    field: 'convertRate',
    sort: 'custom',
    table: {
      width: 150
    },
    form: {
      component: 'InputNumber',
      componentProps: {
        min: 0
      }
    },
    isTableForm: false,
    isForm: false,
    tableForm: {
      disabled:true,
      type: 'InputNumber',
      min: 0
    }
  },
  {
    label: '单据号',
    field: 'number',
    sort: 'custom',
    table: {
      width: 180
    },
    isTableForm: false,
    form: {
      componentProps: {
        disabled: true
      }
    }
  },
  {
    label: '物料代码',
    field: 'itemCode',
    sort: 'custom',
    table: {
      width: 150
    },
    form: {
      componentProps: {
        disabled: true
      }
    },
    tableForm: {
      disabled: true
    }
  },
  {
    label: '计量单位',
    field: 'uom',
    sort: 'custom',
    dictType: DICT_TYPE.UOM,
    dictClass: 'string',
    isSearch: true,
    isTable: true,
    table: {
      width: 150
    },
    tableForm: {
      disabled:true,
      type: 'Select'
    }
  },
  {
    label: '数量',
    field: 'qty',
    sort: 'custom',
    table: {
      width: 150
    },
    form: {
      component: 'InputNumber',
      componentProps: {
        disabled:true,
        min: 1,
        precision: 6
      }
    },
    tableForm: {
      disabled:true,
      type: 'InputNumber',
      min: 1,
      precision: 6
    }
  },
  {
    label: '包装规格1',
    field: 'packUnit',
    isTable: true,
    sort: 'custom',
    table: {
      width: 150,
      componentProps: {
        disabled: true,
        isSearchList: true,
        searchListPlaceholder: '请选择包装',
        searchField: 'packUnit',
        searchTitle: '物品包装信息',
        searchAllSchemas: Itempackaging.allSchemas,
        searchPage: ItemPackageApi.getItempackagingPageBySupplierdeliver,
        searchCondition: [
          {
            key: 'itemCode',
            value: 'itemCode',
            message: '请选择订单行',
            isMainValue: true
          },
          {
            key: 'available',
            value: 'TRUE',
            isMainValue: false
          }
        ]

      }
    },
    tableForm: {
      disabled: true,
      isInpuFocusShow: true,
      searchListPlaceholder: '请选择包装',
      searchField: 'packUnit',
      searchTitle: '物品包装信息',
      searchAllSchemas: Itempackaging.allSchemas,
      searchPage: ItemPackageApi.getItempackagingPageBySupplierdeliver,
      searchCondition: [
        {
          key: 'itemCode',
          value: 'itemCode',
          message: '请选择订单行',
          isMainValue: true
        },
        {
          key: 'available',
          value: 'TRUE',
          isMainValue: false
        }]
    }
  },
  {
    label: '包装数量1',
    field: 'packQty',
    sort: 'custom',
    table: {
      width: 150
    },
    form: {
      componentProps: {
        disabled: true
      }
    },
    tableForm: {
      disabled: true,
    }
  },
  {
    label: '包装规格2',
    field: 'secondPackUnit',
    isTable: true,
    sort: 'custom',
    table: {
      width: 150,
      componentProps: {
        disabled: true,
        isSearchList: true,
        searchListPlaceholder: '请选择包装',
        searchField: 'packUnit',
        searchTitle: '物品包装信息',
        searchAllSchemas: Itempackaging.allSchemas,
        searchPage: ItemPackageApi.getItempackagingPageBySupplierdeliver,
        searchCondition: [
          {
            key: 'itemCode',
            value: 'itemCode',
            message: '请选择订单行',
            isMainValue: true
          },
          {
            key: 'available',
            value: 'TRUE',
            isMainValue: false
          }
        ]

      }
    },
    tableForm: {
      disabled: true,
      isInpuFocusShow: true,
      searchListPlaceholder: '请选择包装',
      searchField: 'packUnit',
      searchTitle: '物品包装信息',
      searchAllSchemas: Itempackaging.allSchemas,
      searchPage: ItemPackageApi.getItempackagingPageBySupplierdeliver,
      searchCondition: [
        {
          key: 'itemCode',
          value: 'itemCode',
          message: '请选择订单行',
          isMainValue: true
        },
        {
          key: 'available',
          value: 'TRUE',
          isMainValue: false
        }]
    }
  },
  {
    label: '包装数量2',
    field: 'secondPackQty',
    sort: 'custom',
    table: {
      width: 150
    },
    form: {
      componentProps: {
        disabled:true
      }
    },
    tableForm: {
      disabled: true,
    }
  },
  {
    label: '物料名称',
    field: 'itemName',
    sort: 'custom',
    table: {
      width: 150
    },
    isTableForm: false,
    isForm: false
  },
  {
    label: '物料描述1',
    field: 'itemDesc1',
    sort: 'custom',
    table: {
      width: 150
    },
    isTableForm: false,
    isForm: false
  },
  {
    label: '物料描述2',
    field: 'itemDesc2',
    sort: 'custom',
    table: {
      width: 150
    },
    isTableForm: false,
    isForm: false
  },
  {
    label: '项目代码',
    field: 'projectCode',
    sort: 'custom',
    table: {
      width: 150
    },
    isTableForm: false,
    isForm: false
  },
]))

export const UploadQualityReport = useCrudSchemas(reactive<CrudSchema[]>([
  {
    label: '上传质检报告',
    field: 'uploadFile',
    sort: 'custom',
    isTable:false,
    isTableForm:false,
    form: {
      component: 'UploadFile',
      componentProps: {
        upData:{
          tableId: '',
          tableName: ''
        },
        limit:1,
      }
    },
  },
  {
    label: '物料代码',
    field: 'itemCode',
    sort: 'custom',
    isForm:false,
    isTableForm:true,
    table: {
      width: 150,
    },
  },
  {
    label: '计量单位',
    field: 'uom',
    sort: 'custom',
    isForm:false,
    isTableForm:true,
    table: {
      width: 150,
    },
  },
  {
    label: '数量',
    field: 'orderQty',
    table: {
      width: 150
    },
    isForm:false,
    tableForm: {
      type: 'InputNumber',
      min: 0,
      precision: 6
    }
  },
  {
    label: '批次',
    field: 'batch',
    sort: 'custom',
    isForm:false,
    table: {
      width: 150
    },
  },
]))