import type { CrudSchema } from '@/hooks/web/useCrudSchemas'
import { dateFormatter } from '@/utils/formatTime'
import * as ProductionLineCodeApi from '@/api/wms/productionline'
import { Productionline } from './../../factoryModeling/productionline/productionline.data'
import * as LocationApi from '@/api/wms/location'

import * as ItembasicApi from '@/api/wms/itembasic'
import { Itembasic } from './../itembasic/itembasic.data'
import * as confgiApi  from '@/api/infra/config'
const { t } = useI18n() // 国际化


const confgiData = await confgiApi.queryByKey("Productionlineitem")
const lineCodeData = await ProductionLineCodeApi.getProductionlinePage({isSearch:false})

/**
 * @returns {Array} 生产线物料关系
 */
export const Productionlineitem = useCrudSchemas(reactive<CrudSchema[]>([
  // {
  //   label: '完工收货库位',
  //   field: 'fgLocationCode',
  //   isSearch: true,
  //   sort: 'custom',
  //   table: {
  //     width: 150,
  //     fixed: 'left'
  //   },
  //   form: {
  //     // labelMessage: '信息提示说明!!!',
  //     componentProps: {
  //       isSearchList: true,
  //       searchListPlaceholder: '请选择库位代码',
  //       searchField: 'code',
  //       searchTitle: '库位信息',
  //       searchAllSchemas: Location.allSchemas,
  //       searchPage: LocationApi.getLocationPage,
  //       searchCondition: [{
  //         key: 'available',
  //         value: 'TRUE',
  //         isMainValue: false
  //       }]
  //     }
  //   }
  // },
  // {
  //   label: '原料库位',
  //   field: 'rawLocationCode',
  //   isSearch: true,
  //   sort: 'custom',
  //   table: {
  //     width: 150,
  //     fixed: 'left'
  //   },
  //   form: {
  //     // labelMessage: '信息提示说明!!!',
  //     componentProps: {
  //       isSearchList: true,
  //       searchListPlaceholder: '请选择库位代码',
  //       searchField: 'code',
  //       searchTitle: '库位信息',
  //       searchAllSchemas: Location.allSchemas,
  //       searchPage: LocationApi.getLocationPage
  //     }
  //   }
  // },
  {
    label: '产线代码' ,
    field: 'productionLineCode',
    isSearch: true,
    sort: 'custom',
    table: {
      width: 150,
      fixed: 'left'
    },
    isForm:true,
    form: {
      show:true,
      component: 'SelectV2',
      value:'undefined',
      // labelMessage: '信息提示说明!!!',
      componentProps: {
        // isSearchList: true,
        placeholder:'请选择库位代码',
        searchField: 'code',
        // searchTitle: '生产线信息',
        // searchAllSchemas: Productionline.allSchemas,
        // searchPage: ProductionLineCodeApi.getProductionlinePage
        options:lineCodeData.list.map(item=>({
          label:item.code,
          value:item.code
        }))
      }
    },
  },
  {
    label: '物料代码',
    field: 'itemCode',
    isSearch: true,
    sort: 'custom',
    table: {
      width: 150
    },
    form: {
      // labelMessage: '信息提示说明!!!',
      componentProps: {
        isSearchList: true,
        searchListPlaceholder: '请选择物料代码',
        searchField: 'code',
        searchTitle: '物料信息',
        searchAllSchemas: Itembasic.allSchemas,
        searchPage: ItembasicApi.getItembasicPage,
        searchCondition: [
        {
          key:'enableMake',
          value:'TRUE',
          action: '==',
          isSearch: true,
          isMainValue: false
        },
        {
          key:'type',
          value:confgiData.itemType,
          action: 'notin',
          isSearch: true,
          isMainValue: false
        },
        {
          key:'available',
          value:'TRUE',
          action: '==',
          isSearch: true,
          isMainValue: false
        }
      ]
      }
    }
  },
  {
    label: '是否可用',
    field: 'available',
    dictType: DICT_TYPE.TRUE_FALSE,
    dictClass: 'string',
    sort: 'custom',
    isSearch: false,
    isTable: true,
    table: {
      width: 120
    },
    form: {
      component: 'Switch',
      value: 'TRUE',
      componentProps: {
        inactiveValue: 'FALSE',
        activeValue: 'TRUE'
      }
    }
  },
  {
    label: '生效时间',
    field: 'activeTime',
    sort: 'custom',
    formatter : dateFormatter,
    detail: {
      dateFormat: 'YYYY-MM-DD HH:mm:ss'
    },
    table: {
      width: 180
    },
    form: {
      component: 'DatePicker',
      componentProps: {
        type: 'datetime',
        dateFormat: 'YYYY-MM-DD HH:mm:ss',
        valueFormat: 'x',
      }
    }
  },
  {
    label: '失效时间',
    field: 'expireTime',
    sort: 'custom',
    formatter : dateFormatter,
    detail: {
      dateFormat: 'YYYY-MM-DD HH:mm:ss'
    },
    table: {
      width: 180
    },
    form: {
      component: 'DatePicker',
      componentProps: {
        type: 'datetime',
        dateFormat: 'YYYY-MM-DD HH:mm:ss',
        valueFormat: 'x',
      }
    }
  },
  {
    label:'备注',
    field: 'remark',
    isTable: false
  },
  {
    label: '创建时间',
    field: 'createTime',
    isForm: false,
    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',
      }
    }
  },
  {
    label: '创建者',
    field: 'creator',
    isForm: false,
    isTable: false
  },
  {
    label: '操作',
    field: 'action',
    isDetail: false,
    isForm: false ,
    table: {
      width: 150,
      fixed: 'right'
    }
  }
]))

//表单校验
export const ProductionlineitemRules = reactive({
  // fgLocationCode: [
  //   { required: true, message: '请输入完工收货库位', trigger: 'change' }
  // ],
  productionLineCode: [
    { required: true, message: '请输入产线代码', trigger: 'change' }
  ],
  itemCode: [
    { required: true, message: '请输入物料代码', trigger: 'change' }
  ],
  remark: [
    { max: 50, message: '不得超过50个字符', trigger: 'blur' }
  ],
  available:  [
    { required: true, message: '请选择是否可用', trigger: 'change' }
  ],
})