import { selectboxMaterie } from "@/services/craft";
import {
  productionLineSelectByMaterieId,
  shiftSelectByMaterieId,
  groupSelectByMaterieId,
  factorySelect,
  shopSelectByFactory,
  productionLineSelectByShop,
  shiftSelectByShopId,
  factorySelectByuser,
} from "@/services/system";
import regValue from "@/utils/regValue";
const addFields = {
  materieId: {
    value: null,
    type: "select",
    title: "物料编号-名称-单位",
    name: ["materieId"],
    required: true,
    options: {
      database: selectboxMaterie,
      params: { materieType: 0 },
    },
    linked: true,
  },
  scheduledProductionNum: {
    value: null,
    type: "inputnumber",
    title: "排产数量",
    name: ["scheduledProductionNum"],
    required: true,
    ...regValue(null, 6, 3),
  },
  productionLineId: {
    value: null,
    type: "select",
    title: "产线",
    name: ["productionLineId"],
    required: true,
    belinked: {
      options: {
        database: productionLineSelectByMaterieId,
        params: { materieId: "linked" },
      },
    },
  },
  productionDate: {
    value: null,
    type: "datepicker",
    title: "生产日期",
    name: ["productionDate"],
    required: true,
    format: "YYYY-MM-DD",
    showTime: false,
    disabledDate: null,
    disabledDateTime: null,
  },
  shiftId: {
    value: null,
    type: "select",
    title: "班次",
    name: ["shiftId"],
    required: true,
    belinked: {
      options: {
        database: shiftSelectByMaterieId,
        params: { materieId: "linked" },
      },
    },
  },
  groupId: {
    value: null,
    type: "select",
    title: "班组",
    name: ["groupId"],
    required: false,
    belinked: {
      options: {
        database: groupSelectByMaterieId,
        params: { materieId: "linked" },
      },
    },
  },
  description: {
    value: null,
    type: "textarea",
    title: "描述",
    name: ["description"],
    required: false,
    col: {
      span: 24,
    },
  },
  shopPlanNo: {
    value: null,
    type: "input",
    title: "车间计划编号",
    name: ["shopPlanNo"],
    required: false,
  },
  productionOrderNo: {
    value: null,
    type: "input",
    title: "生产订单编号",
    name: ["productionOrderNo"],
    required: false,
  },
  saleOrderNo: {
    value: null,
    type: "input",
    title: "销售订单号",
    name: ["saleOrderNo"],
    required: false,
  },
  lineNo: {
    value: null,
    type: "input",
    title: "行号",
    name: ["lineNo"],
    required: false,
  },
  customerName: {
    value: null,
    type: "input",
    title: "客户名称",
    name: ["customerName"],
    required: false,
  },
  specs: {
    value: null,
    type: "input",
    title: "规格",
    name: ["specs"],
    required: false,
  },
  color: {
    value: null,
    type: "input",
    title: "颜色",
    name: ["color"],
    required: false,
  },
};

const waitFields = {
  factoryId: {
    value: null,
    type: "select",
    title: "所属工厂",
    name: ["factoryId"],
    required: true,
    options: {
      database: factorySelect,
      params: {},
    },
    linked: true,
  },
  shopId: {
    value: null,
    type: "select",
    title: "所属车间",
    name: ["shopId"],
    required: true,
    belinked: {
      options: {
        database: shopSelectByFactory,
        params: { factoryId: "linked" },
      },
    },
  },
  dateTimeList: {
    value: null,
    type: "daterange",
    title: "计划时间",
    name: ["dateTimeList"],
    required: false,
    format: "YYYY-MM-DD",
    showTime: false,
    disabledDate: null,
    disabledDateTime: null,
    col: { span: 24 },
  },
};

const schedulingFields = {
  productionLineId: {
    value: null,
    type: "select",
    title: "产线",
    name: ["productionLineId"],
    required: true,
    options: {
      database: productionLineSelectByShop,
      params: {},
    },
    col: { span: 8 },
  },
  productionDate: {
    value: null,
    type: "datepicker",
    title: "生产日期",
    name: ["productionDate"],
    required: true,
    format: "YYYY-MM-DD",
    showTime: false,
    disabledDate: null,
    disabledDateTime: null,
    col: { span: 8 },
  },
  shiftId: {
    value: null,
    type: "select",
    title: "班次",
    name: ["shiftId"],
    required: true,
    options: {
      database: shiftSelectByShopId,
      params: {},
    },
    col: { span: 8 },
  },
};

const tableFields = {
  list: {
    value: [],
    title: "生产计划",
    type: "table",
    col: { span: 24 },
    name: ["list"],
    required: false,
    columns: [
      {
        title: "车间计划编号",
        dataIndex: "shopPlanNo",
        key: "shopPlanNo",
        search: false,
        editable: false,
        ellipsis: true,
      },
      {
        title: "物料名称",
        dataIndex: "materieName",
        key: "materieName",
        search: false,
        editable: false,
        ellipsis: true,
      },
      {
        title: "未排产数量",
        dataIndex: "unscheduledQuantity",
        key: "unscheduledQuantity",
        search: false,
        editable: false,
      },
      {
        title: "计划时间",
        dataIndex: "planStartDate",
        key: "planStartDate",
        search: false,
        editable: false,
        render: (_, row) => {
          return <span>{`${row.planStartDate}~${row.planEndDate}`}</span>;
        },
        ellipsis: true,
      },
      {
        title: "车间",
        dataIndex: "shopName",
        key: "shopName",
        search: false,
        editable: false,
        ellipsis: true,
      },
      {
        title: "排产数量",
        dataIndex: "scheduledNum",
        key: "scheduledNum",
        search: false,
        editable: true,
        valueType: "digit",
      },
    ],
    rowKey: "id",
    pagination: "false",
    recordCreatorProps: "false",
  },
};

const sortFields = {
  factoryId: {
    value: null,
    type: "select",
    title: "工厂",
    name: ["factoryId"],
    required: true,
    options: {
      database: factorySelectByuser,
      params: {},
    },
    linked: true,
    col: { span: 8 },
  },
  shopId: {
    value: null,
    type: "select",
    title: "车间",
    name: ["shopId"],
    required: true,
    belinked: {
      options: {
        database: shopSelectByFactory,
        params: { factoryId: "linked" },
      },
    },
    linked: true,
    col: { span: 8 },
  },
  productionLineId: {
    value: null,
    type: "select",
    title: "产线",
    name: ["productionLineId"],
    required: true,
    belinked: {
      options: {
        database: productionLineSelectByShop,
        params: { shopId: "linked" },
      },
    },
    col: { span: 8 },
  },
  productionDate: {
    value: null,
    type: "datepicker",
    title: "生产日期",
    name: ["productionDate"],
    required: true,
    format: "YYYY-MM-DD",
    showTime: false,
    disabledDate: null,
    disabledDateTime: null,
    col: { span: 8 },
  },
  shiftId: {
    value: null,
    type: "select",
    title: "班次",
    name: ["shiftId"],
    required: true,
    col: { span: 8 },
    belinked: {
      options: {
        database: shiftSelectByShopId,
        params: { shopId: "linked" },
      },
    },
  },
};

export { addFields, waitFields, schedulingFields, tableFields, sortFields };
