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

import * as QadCostcentreApi from '@/api/wms/qadCostcentre'
import { QadCostcentre } from '@/views/wms/basicDataManage/subject/qadCostcentre/qadCostcentre.data'

import * as InspectionQ1Api from '@/api/qms/inspectionQ1'
import { Q1 } from '@/views/qms/inspectionQ1/inspectionQ1.data'

import * as SupplieritemApi from '@/api/wms/supplieritem'
import { Supplieritem } from '@/views/wms/basicDataManage/supplierManage/supplieritem/supplieritem.data'

import * as PurchasereceiptRecordDetailApi from '@/api/wms/purchasereceiptRecordDetail'
import { PurchasereceiptRecordDetail } from '@/views/wms/purchasereceiptManage/purchasereceipt/purchasereceiptRecordMain/purchasereceiptRecordMain.data'

import * as ItembasicApi from '@/api/wms/itembasic'
import { Itembasic } from '@/views/wms/basicDataManage/itemManage/itembasic/itembasic.data'

import { useUserStore } from '@/store/modules/user'
const userStore = useUserStore()

// 表单校验
export const Q2Rules = reactive({
  itemCode: [{ required: true, message: '请选择供应商物料代码', trigger: 'change' }],
  supplierCode: [{ required: true, message: '请选择供应商代码', trigger: 'change' }],
  purchaseReceiptNumber: [
    { required: true, message: '请选择采购收货单号', trigger: 'change' },
    { max: 50, message: '不得超过50个字符', trigger: 'blur' }
  ],
  claimTime: [{ required: true, message: '请选择索赔日期', trigger: 'change' }],
  lightItemCode: [{ required: true, message: '请选择整灯物料代码', trigger: 'change' }],
  lightQty: [{ required: true, message: '请选择整灯数量', trigger: 'change' }],
  code: [{ required: true, message: '请选择缺陷代码', trigger: 'change' }],
  priority: [{ required: true, message: '请选择优先级', trigger: 'change' }],
  claimMultiple: [{ required: true, message: '请选择索赔倍数', trigger: 'change' }],
  claimAmount: [{ required: true, message: '请输入索赔金额', trigger: 'change' }],
  costCode: [{ required: true, message: '请选择选择成本中心代码', trigger: 'change' }],
  cashierEmail: [{ required: true, message: '请选择选择出纳邮件地址', trigger: 'change' }],
  handleTime: [{ required: true, message: '请选择选择处理时间', trigger: 'change' }]
})

export const Q2 = useCrudSchemas(
  reactive<CrudSchema[]>([
    {
      label: '通知单号',
      field: 'number',
      sort: 'custom',
      isSearch: true,
      isForm: false,
      table: {
        width: 150,
        fixed: 'left'
      }
    },
    {
      label: '供应商物料代码',
      field: 'itemCode',
      sort: 'custom',
      table: {
        width: 150
      },
      isSearch: true,
      form: {
        // labelMessage: '信息提示说明!!!',
        componentProps: {
          enterSearch: true,
          isSearchList: true, // 开启查询弹窗
          searchListPlaceholder: '请选择物料代码', // 输入框占位文本
          searchField: 'itemCode', // 查询弹窗赋值字段
          searchTitle: '供应商物料信息', // 查询弹窗标题
          searchAllSchemas: Supplieritem.allSchemas, // 查询弹窗所需类
          searchPage: SupplieritemApi.getSupplieritemPage, // 查询弹窗所需分页方法
          searchCondition: [
            {
              key: 'available',
              value: 'TRUE',
              isMainValue: false
            },
            {
              key: 'type',
              value: 'Q2',
              isMainValue: false
            }
          ],
          verificationParams: [
            {
              key: 'itemCode',
              action: '==',
              value: '',
              isMainValue: false,
              isSearch: true,
              isFormModel: true
            }
          ] // 失去焦点校验参数
        }
      }
    },
    {
      label: '供应商物料名称',
      field: 'itemName',
      sort: 'custom',
      dictClass: 'string',
      isSearch: false,
      isTable: true,
      tableForm: {
        disabled: true
      },
      table: {
        width: 150
      },
      form: {
        componentProps: {
          disabled: true
        }
      }
    },
    {
      label: '供应商代码',
      field: 'supplierCode',
      sort: 'custom',
      dictClass: 'string',
      isSearch: false,
      isTable: true,
      tableForm: {
        disabled: true
      },
      table: {
        width: 120
      },
      form: {
        component: 'Select',
        componentProps: {
          options: [],
          optionsAlias: {
            labelField: 'supplierCode',
            valueField: 'supplierCode'
          },
          filterable: true
        }
      }
    },
    {
      label: '供应商名称',
      field: 'supplierName',
      sort: 'custom',
      dictClass: 'string',
      isSearch: false,
      isTable: true,
      table: {
        width: 180
      },
      tableForm: {
        disabled: true
      },
      form: {
        componentProps: {
          disabled: true
        }
      }
    },
    {
      label: '采购收货单号',
      field: 'purchaseReceiptNumber',
      sort: 'custom',
      isTable: true,
      table: {
        width: 180
      },
      form: {
        // labelMessage: '信息提示说明!!!',
        componentProps: {
          disabled: true,
          multiple: true,
          isSearchList: true, // 开启查询弹窗
          searchListPlaceholder: '请选择采购收货记录单号', // 输入框占位文本
          searchField: 'number', // 查询弹窗赋值字段
          searchTitle: '采购收货记录', // 查询弹窗标题
          searchAllSchemas: PurchasereceiptRecordDetail.allSchemas, // 查询弹窗所需类
          searchPage: PurchasereceiptRecordDetailApi.pageForQ2, // 查询弹窗所需分页方法
          searchCondition: [
            {
              key: 'supplierCode',
              value: 'supplierCode',
              isMainValue: true
            },
            {
              key: 'itemCode',
              value: 'itemCode',
              isMainValue: true
            }
          ]
        }
      }
    },
    {
      label: '索赔日期',
      field: 'claimTime',
      isTable: true,
      table: {
        width: 180
      },
      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: 'lightItemCode',
      sort: 'custom',
      table: {
        width: 150
      },
      isSearch: true,
      form: {
        // labelMessage: '信息提示说明!!!',
        componentProps: {
          enterSearch: true,
          isSearchList: true, // 开启查询弹窗
          searchListPlaceholder: '请选择物料代码', // 输入框占位文本
          searchField: 'code', // 查询弹窗赋值字段
          searchTitle: '物料基础信息', // 查询弹窗标题
          searchAllSchemas: Itembasic.allSchemas, // 查询弹窗所需类
          searchPage: ItembasicApi.getItembasicPage, // 查询弹窗所需分页方法
          searchCondition: [
            {
              key: 'available',
              value: 'TRUE',
              isMainValue: false
            },
            {
              key: 'type',
              value: 'CCP',
              isMainValue: false
            }
          ],
          verificationParams: [
            {
              key: 'code',
              action: '==',
              value: '',
              isMainValue: false,
              isSearch: true,
              isFormModel: true
            }
          ] // 失去焦点校验参数
        }
      }
    },
    {
      label: '整灯物料名称',
      field: 'lightItemName',
      sort: 'custom',
      dictClass: 'string',
      isSearch: false,
      isTable: true,
      table: {
        width: 150
      },
      tableForm: {
        disabled: true
      },
      form: {
        componentProps: {
          disabled: true
        }
      }
    },
    {
      label: '整灯数量',
      field: 'lightQty',
      sort: 'custom',
      isTable: true,
      isSearch: false,
      table: {
        width: 150
      },
      form: {
        component: 'InputNumber',
        componentProps: {
          min: 0,
          precision: 2
        }
      }
    },
    {
      label: '缺陷编码',
      field: 'code',
      sort: 'custom',
      dictType: DICT_TYPE.QMS_Q2_CODE,
      dictClass: 'string',
      isSearch: false,
      isTable: true,
      table: {
        width: 180
      },
      tableForm: {
        type: 'Select'
      }
    },
    {
      label: '优先级',
      field: 'priority',
      sort: 'custom',
      dictType: DICT_TYPE.QUALITY_NOTIFICATION_PRIORITY,
      dictClass: 'string',
      isSearch: false,
      isTable: true,
      tableForm: {
        type: 'Select'
      }
    },
    {
      label: '索赔倍数',
      field: 'claimMultiple',
      sort: 'custom',
      dictType: DICT_TYPE.QMS_CLAIM_MULTIPLE,
      dictClass: 'string',
      isTable: true,
      isSearch: false,
      table: {
        width: 100
      },
      tableForm: {
        type: 'Select',
        disabled: true
      },
      form: {
        componentProps: {}
      }
    },
    {
      label: '标准成本价格',
      field: 'standardCostPrice',
      sort: 'custom',
      isSearch: false,
      isTable: true,
      table: {
        width: 150
      },
      form: {
        component: 'InputNumber',
        componentProps: {
          min: 0,
          precision: 6,
          disabled: true
        }
      }
    },
    {
      label: '索赔金额',
      field: 'claimAmount',
      sort: 'custom',
      isTable: true,
      isSearch: false,
      table: {
        width: 150
      },
      form: {
        component: 'InputNumber',
        componentProps: {
          min: 0,
          precision: 6
        }
      }
    },

    {
      label: '其他索赔描述',
      field: 'otherClaimDesc',
      sort: 'custom',
      isSearch: false,
      isTable: true,
      table: {
        width: '150'
      },
      form: {
        component: 'Input',
        componentProps: {}
      }
    },
    {
      label: '其他索赔金额',
      field: 'otherclaimAmount',
      sort: 'custom',
      isSearch: false,
      isTable: true,
      table: {
        width: 150
      },
      form: {
        component: 'InputNumber',
        componentProps: {
          min: 0,
          precision: 6
        }
      }
    },
    {
      label: '汇总金额',
      field: 'summaryAmount',
      sort: 'custom',
      isSearch: false,
      isTable: true,
      table: {
        width: 150
      },
      form: {
        component: 'InputNumber',
        componentProps: {
          min: 0,
          precision: 6,
          disabled: true
        }
      }
    },
    {
      label: '抛账金额',
      field: 'disbursementAmount',
      sort: 'custom',
      isSearch: false,
      isTable: true,
      table: {
        width: 150
      },
      form: {
        component: 'InputNumber',
        componentProps: {
          min: 0,
          precision: 6,
          disabled: true
        }
      }
    },
    {
      label: '剩余金额',
      field: 'remainingAmount',
      sort: 'custom',
      isSearch: false,
      isTable: true,
      table: {
        width: 150
      },
      form: {
        component: 'InputNumber',
        componentProps: {
          min: 0,
          precision: 6,
          disabled: true
        }
      }
    },
    {
      label: 'Q1通知单号',
      field: 'q1Number',
      sort: 'custom',
      table: {
        width: 150
      },
      form: {
        // labelMessage: '信息提示说明!!!',
        componentProps: {
          enterSearch: true,
          multiple: true,
          isSearchList: true, // 开启查询弹窗
          searchListPlaceholder: '请选择Q1通知单', // 输入框占位文本
          searchField: 'number', // 查询弹窗赋值字段
          searchTitle: 'Q1通知单', // 查询弹窗标题
          searchAllSchemas: Q1.allSchemas, // 查询弹窗所需类
          searchPage: InspectionQ1Api.getQ1Page, // 查询弹窗所需分页方法
          searchCondition: [
            {
              key: 'available',
              value: 'TRUE',
              isMainValue: false
            },
            {
              key: 'status',
              value: '0',
              isMainValue: false
            }
          ],
          verificationParams: [
            {
              key: 'number',
              action: '==',
              value: '',
              isMainValue: false,
              isSearch: true,
              isFormModel: true
            }
          ] // 失去焦点校验参数
        }
      },
      isSearch: true
    },
    {
      label: '成本中心代码',
      field: 'costCode',
      sort: 'custom',
      isSearch: false,
      isTable: true,
      isForm: true,
      table: {
        width: '120'
      },
      form: {
        // labelMessage: '信息提示说明!!!',
        componentProps: {
          enterSearch: true,
          isSearchList: true, // 开启查询弹窗
          searchListPlaceholder: '请选择成本中心', // 输入框占位文本
          searchField: 'costcentreCode', // 查询弹窗赋值字段
          searchTitle: '成本中心信息', // 查询弹窗标题
          searchAllSchemas: QadCostcentre.allSchemas, // 查询弹窗所需类
          searchPage: QadCostcentreApi.getQadCostcentrePage, // 查询弹窗所需分页方法
          searchCondition: [
            {
              key: 'available',
              value: 'TRUE',
              isMainValue: false
            }
          ],
          verificationParams: [
            {
              key: 'costcentreCode',
              action: '==',
              value: '',
              isMainValue: false,
              isSearch: true,
              isFormModel: true
            }
          ] // 失去焦点校验参数
        }
      }
    },
    {
      label: '出纳邮件地址',
      field: 'cashierEmail',
      sort: 'custom',
      isSearch: false,
      isTable: false,
      table: {
        width: '150'
      },
      form: {
        component: 'Input',
        componentProps: {}
      }
    },

    {
      label: '负责用户',
      field: 'responUser',
      sort: 'custom',
      isSearch: false,
      isTable: true,
      isForm: true,
      table: {
        width: 120
      },
      form: {
        componentProps: {
          value: userStore.getUser.nickname,
          disabled: true
        }
      }
    },
    {
      label: '处理时间',
      field: 'handleTime',
      isTable: true,
      table: {
        width: 180
      },
      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: 'status',
      sort: 'custom',
      dictType: DICT_TYPE.PUBLISHE_STATUS,
      dictClass: 'string',
      isForm: false,
      isTable: true,
      isSearch: false,
      tableForm: {
        type: 'Select',
        disabled: true
      },
      form: {
        componentProps: {
          disabled: true
        }
      }
    },
    {
      label: '描述',
      field: 'desc',
      sort: 'custom',
      isSearch: false,
      isTable: true,
      table: {
        width: '150'
      },
      form: {
        component: 'Input',
        componentProps: {
          type: 'textarea'
        }
      }
    },
    {
      label: '是否可用',
      field: 'available',
      sort: 'custom',
      isSearch: false,
      isForm: false,
      isTable: false,
      isDetail: false
    },
    {
      label: '创建时间',
      field: 'createTime',
      isForm: false,
      isTable: true,
      table: {
        width: 180
      },
      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'
        }
      },
      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: 'creator',
      table: {
        width: 130
      },
      isForm: false,
      isTable: true
    },
    {
      label: '操作',
      field: 'action',
      isForm: false,
      isDetail: false,
      table: {
        width: 150,
        fixed: 'right'
      }
    }
  ])
)