import type { CrudSchema } from '@/hooks/web/useCrudSchemas'
import { dateFormatter } from '@/utils/formatTime'

import * as BalanceApi  from '@/api/wms/balance'
import { Balance } from '@/views/wms/inventoryManage/balance/balance.data'
import * as getBusinessTypeApi  from '@/api/wms/businesstype/index'
const businessTypeQueryParams = {
  pageSize:10,
  pageNo:1,
  code:'Productredress'
}
const businessTypeValue = await getBusinessTypeApi.getBusinesstypePage(businessTypeQueryParams)
const businessTypeData =businessTypeValue?.list[0]||{}
// 表单校验
export const ProductredressRequestMainRules = reactive({
  autoCommit: [required],
  autoAgree: [required],
  autoExecute: [required],
  directCreateRecord: [required],
})

export const ProductredressRequestMain = useCrudSchemas(reactive<CrudSchema[]>([
  {
    label: '单据号',
    field: 'number',
    sort: 'custom',
    table: {
      width: 180,
      fixed: 'left'
    },
    isForm: false,
    isSearch: true,
  },
  // {
  //   label: '生产计划单号',
  //   field: 'productionPlanNumber',
  //   sort: 'custom',
  // },
  {
    label: '状态',
    field: 'status',
    dictType: DICT_TYPE.REQUEST_STATUS,
    dictClass: 'string',
    isSearch: true,
    isForm:false,
    isTable: true,
    sort: 'custom',
    table: {
      width: 150
    },
    form: {
      value: '1',
      componentProps: {
        disabled: true
      }
    }
  },
  // {
  //   label: '车间代码',
  //   field: 'workshopCode',
  //   sort: 'custom',
  //   isSearch: true,
  // },
  // {
  //   label: '班组',
  //   field: 'team',
  //   sort: 'custom',
  // },
  // {
  //   label: '班次',
  //   field: 'shift',
  //   sort: 'custom',
  // },
  {
    label: '申请时间',
    field: 'requestTime',
    sort: 'custom',
    formatter: dateFormatter,
    detail: {
      dateFormat: 'YYYY-MM-DD HH:mm:ss'
    },
    table: {
      width: 180
    },
    isTable: false,
    form: {
      component: 'DatePicker',
      componentProps: {
        style: {width: '100%'},
        type: 'datetime',
        dateFormat: 'YYYY-MM-DD HH:mm:ss',
        valueFormat: 'x',
      }
    },
    isForm: false
  },
  {
    label: '截止时间',
    field: 'dueTime',
    sort: 'custom',
    formatter: dateFormatter,
    detail: {
      dateFormat: 'YYYY-MM-DD HH:mm:ss'
    },
    table: {
      width: 180
    },
    isTable: false,
    form: {
      component: 'DatePicker',
      componentProps: {
        style: {width: '100%'},
        type: 'datetime',
        dateFormat: 'YYYY-MM-DD HH:mm:ss',
        valueFormat: 'x',
      }
    },
    isForm: false
  },
  {
    label: '到仓库代码',
    field: 'toWarehouseCode',
    sort: 'custom',
    isForm:false,
    isTable:false,
    table: {
      width: 150
    },
  },
  {
    label: '部门',
    field: 'departmentCode',
    sort: 'custom',
    isForm:false,
    isTable:false,
    table: {
      width: 150
    },
  },
  {
    label: '自动提交',
    field: 'autoCommit',
    sort: 'custom',
    dictType: DICT_TYPE.TRUE_FALSE,
    dictClass: 'string',
    isForm:false,
    isTable:false,
  },
  {
    label: '自动通过',
    field: 'autoAgree',
    sort: 'custom',
    dictType: DICT_TYPE.TRUE_FALSE,
    dictClass: 'string',
    isForm:false,
    isTable:false,
  },
  {
    label: '自动执行',
    field: 'autoExecute',
    sort: 'custom',
    dictType: DICT_TYPE.TRUE_FALSE,
    dictClass: 'string',
    isForm:false,
    isTable:false,
  },
  {
    label: '直接生成记录',
    field: 'directCreateRecord',
    sort: 'custom',
    dictType: DICT_TYPE.TRUE_FALSE,
    dictClass: 'string',
    isForm:false,
    isTable:false,
  },
  {
    label: '业务类型',
    field: 'businessType',
    sort: 'custom',
    isForm:false,
    isTable:false,
  },
  // {
  //   label: '原因',
  //   field: 'remark',
  //   sort: 'custom',
  //   isTable:true,
  // },
  {
    label: '到库区类型范围',
    field: 'toAreaTypes',
    sort: 'custom',
    dictType: DICT_TYPE.AREA_TYPE,
    dictClass: 'string',
    isForm:false,
    isTable:false,
  },
  {
    label: '到库区代码范围',
    field: 'toAreaCodes',
    sort: 'custom',
    isForm:false,
    isTable:false,
  },
  {
    label: '入库库存状态范围',
    field: 'inInventoryStatuses',
    sort: 'custom',
    dictType: DICT_TYPE.INVENTORY_STATUS,
    dictClass: 'string',
    isForm:false,
    isTable:false,
  },
  {
    label: '出库库存状态范围',
    field: 'outInventoryStatuses',
    sort: 'custom',
    dictType: DICT_TYPE.INVENTORY_STATUS,
    dictClass: 'string',
    isForm:false,
    isTable:false,
  },
  {
    label: '创建者',
    field: 'creator',
    sort: 'custom',
    isForm: false,
    isTable: true,
    table: {
      width: 150
    },
  },
  {
    label: '创建时间',
    field: 'createTime',
    sort: 'custom',
    formatter: dateFormatter,
    detail: {
      dateFormat: 'YYYY-MM-DD HH:mm:ss'
    },
    table: {
      width: 180
    },
    isTable: true,
    form: {
      component: 'DatePicker',
      componentProps: {
        style: {width: '100%'},
        type: 'datetime',
        dateFormat: 'YYYY-MM-DD HH:mm:ss',
        valueFormat: 'x',
      }
    },
    isForm: false,
    isSearch: true,
    search: {
      component: 'DatePicker',
      componentProps: {
        valueFormat: 'YYYY-MM-DD HH:mm:ss',
        type: 'daterange',
        defaultTime: [new Date('1 00:00:00'), new Date('1 23:59:59')]
      }
    },
  },
  {
    label: '最后更新者',
    field: 'updater',
    sort: 'custom',
    isForm: false,
    table: {
      width: 150
    },
    isTable: false,
  },
  {
    label: '最后更新时间',
    field: 'updateTime',
    sort: 'custom',
    formatter: dateFormatter,
    detail: {
      dateFormat: 'YYYY-MM-DD HH:mm:ss'
    },
    table: {
      width: 180
    },
    isTable: false,
    form: {
      component: 'DatePicker',
      componentProps: {
        style: {width: '100%'},
        type: 'datetime',
        dateFormat: 'YYYY-MM-DD HH:mm:ss',
        valueFormat: 'x',
      }
    },
    isForm: false
  },
  {
    label: '操作',
    field: 'action',
    isForm: false,
    table: {
      width: 180,
      fixed: 'right'
    }
  }
]))

// 表单校验
export const ProductredressRequestDetailRules = reactive({
})

export const ProductredressRequestDetail = useCrudSchemas(reactive<CrudSchema[]>([
  // {
  //   label: 'BOM版本',
  //   field: 'bomVersion',
  //   sort: 'custom',
  // },

  {
    label: '物料代码',
    field: 'itemCode',
    sort: 'custom',
    table: {
      width: 150
    },
    form: {
      // labelMessage: '信息提示说明!!!',
      // componentProps: {
      //   isSearchList: true, // 开启查询弹窗
      //   searchListPlaceholder: '请选择物料代码', // 输入框占位文本
      //   searchField: 'itemCode', // 查询弹窗赋值字段
      //   searchTitle: '库存余额信息', // 查询弹窗标题
      //   searchAllSchemas: Balance.allSchemas, // 查询弹窗所需类
      //   searchPage: BalanceApi.getBalancePageByBusinessTypeByItemType, // 查询弹窗所需分页方法
      //   searchCondition: [{
      //     key: 'businessType',
      //     value: businessTypeData.code,
      //     action: '==', // 查询拼接条件
      //     isSearch: true, // 使用自定义拼接条件
      //     isMainValue: false // 拼接条件必须要 false 同时不能与 isMainValue: true 同用
      //   },{
      //     key: 'packingNumber', // 查询列表中字段
      //     value: '', // 指查询具体值
      //     action: 'isNotStr', // 查询拼接条件
      //     isSearch: true, // 使用自定义拼接条件
      //     isMainValue: false // 拼接条件必须要 false 同时不能与 isMainValue: true 同用
      //   }]
      // }
    },
    tableForm:{
      disabled: true,
      multiple:true,
      // isInpuFocusShow: true,
      searchListPlaceholder: '请选择物料代码', // 输入框占位文本
      searchField: 'itemCode', // 查询弹窗赋值字段
      searchTitle: '库存余额信息', // 查询弹窗标题
      searchAllSchemas: Balance.allSchemas, // 查询弹窗所需类
      searchPage: BalanceApi.getBalancePageByBusinessTypeByItemType, // 查询弹窗所需分页方法
      searchCondition: [{
        key: 'businessType',
        value: businessTypeData.code,
        action: '==', // 查询拼接条件
        isSearch: true, // 使用自定义拼接条件
        isMainValue: false // 拼接条件必须要 false 同时不能与 isMainValue: true 同用
      },{
        key: 'packingNumber', // 查询列表中字段
        value: '', // 指查询具体值
        action: 'isNotStr', // 查询拼接条件
        isSearch: true, // 使用自定义拼接条件
        isMainValue: false // 拼接条件必须要 false 同时不能与 isMainValue: true 同用
      },
      {
        key: 'inOrOut',
        value: "out",
        action: '==', // 查询拼接条件
        isSearch: true, // 使用自定义拼接条件
        isMainValue: false // 拼接条件必须要 false 同时不能与 isMainValue: true 同用
      }]
    },
  },
  {
    label: '物品名称',
    field: 'itemName',
    sort: 'custom',
    table: {
      width: 150
    },
    isForm: false,
    isTableForm: false,
  },
  {
    label: '物品描述1',
    field: 'itemDesc1',
    sort: 'custom',
    table: {
      width: 150
    },
    isForm: false,
    isTableForm: false,
    hiddenInMain:true,
  },
  {
    label: '物品描述2',
    field: 'itemDesc2',
    sort: 'custom',
    table: {
      width: 150
    },
    isForm: false,
    isTableForm: false,
    hiddenInMain:true,
  },
  {
    label: '批次',
    field: 'batch',
    sort: 'custom',
    isSearch: true,
    table: {
      width: 150
    },
    tableForm: {
      disabled: true
    },
    form: {
      componentProps: {
        disabled: true
      }
    }
  },
  {
    label: '回收数量',
    field: 'qty',
    sort: 'custom',
    table: {
      width: 150
    },
    tableForm: {
      disabled: true
    },
    form: {
      componentProps: {
        disabled: true
      }
    }
  },
  {
    label: '包装号',
    field: 'packingNumber',
    sort: 'custom',
    table: {
      width: 150
    },
    tableForm: {
      disabled: true
    },
    form: {
      componentProps: {
        disabled: true
      }
    }
  },
  {
    label: '包装规格',
    field: 'packUnit',
    sort: 'custom',
    table: {
      width: 150
    },
    tableForm: {
      disabled: true
    },
    form: {
      componentProps: {
        disabled: true
      }
    }
  },
  {
    label: '包装数量',
    field: 'packQty',
    sort: 'custom',
    table: {
      width: 150
    },
    tableForm: {
      disabled: true
    },
    form: {
      componentProps: {
        disabled: true
      }
    }
  },
  {
    label: '计量单位',
    field: 'uom',
    dictType: DICT_TYPE.UOM,
    dictClass: 'string',
    sort: 'custom',
    table: {
      width: 150
    },
    tableForm: {
      disabled: true,
      type: 'Select'
    },
    form: {
      componentProps: {
        disabled: true
      }
    }
  },
  {
    label: '库存状态',
    field: 'inventoryStatus',
    dictType: DICT_TYPE.INVENTORY_STATUS,
    dictClass: 'string',
    sort: 'custom',
    table: {
      width: 150
    },
    tableForm: {
      type:'Select',
      disabled: true
    },
    form: {
      componentProps: {
        disabled: true
      }
    }
  },
  {
    label: '库位',
    field: 'toLocationCode',
    sort: 'custom',
    table: {
      width: 150
    },
    tableForm: {
      disabled: true
    },
    form: {
      componentProps: {
        disabled: true
      }
    }
  },
  {
    label: '项目代码',
    field: 'projectCode',
    sort: 'custom',
    table: {
      width: 150
    },
    isForm: false,
    isTableForm: false,
    hiddenInMain:true,

  },{
    label: '单据号',
    field: 'number',
    sort: 'custom',
    table: {
      width: 180
    },
    isForm: false,
    isTableForm: false,
    hiddenInMain:true,
  },

  // {
  //   label: '备注',
  //   field: 'remark',
  //   sort: 'custom',
  //   table: {
  //     width: 150
  //   },
  //   isTable:false,
  //   hiddenInMain:true
  // },
  {
    label: '创建者',
    field: 'creator',
    sort: 'custom',
    table: {
      width: 150
    },
    isTableForm: false,
    isForm: false,
    isTable:true,
    hiddenInMain:true
  },
  {
    label: '创建时间',
    field: 'createTime',
    formatter: dateFormatter,
    detail: {
      dateFormat: 'YYYY-MM-DD HH:mm:ss'
    },
    sort: 'custom',
    table: {
      width: 180
    },
    isTable:true,
    hiddenInMain:true,
    form: {
      component: 'DatePicker',
      componentProps: {
        style: {width: '100%'},
        type: 'datetime',
        dateFormat: 'YYYY-MM-DD HH:mm:ss',
        valueFormat: 'x',
      }
    },
    isTableForm: false,
    isForm: false
  },
  {
    label: '最后更新者',
    field: 'updater',
    sort: 'custom',
    table: {
      width: 150
    },
    isTable:false,
    hiddenInMain:true,
    isForm: false,
    isTableForm: false,
  },
  {
    label: '最后更新时间',
    field: 'updateTime',
    formatter: dateFormatter,
    detail: {
      dateFormat: 'YYYY-MM-DD HH:mm:ss'
    },
    sort: 'custom',
    table: {
      width: 180
    },
    isTable:false,
    hiddenInMain:true,
    form: {
      component: 'DatePicker',
      componentProps: {
        style: {width: '100%'},
        type: 'datetime',
        dateFormat: 'YYYY-MM-DD HH:mm:ss',
        valueFormat: 'x',
      }
    },
    isTableForm: false,
    isForm: false
  },

  {
    label: '操作',
    field: 'action',
    isForm: false,
    isTableForm: false,
    hiddenInMain:true,
    table: {
      width: 150,
      fixed: 'right'
    }
  }
]))