import printerApi, { type addRequest } from "@/api/account/printer";
import { options } from './config'

import type { IModalConfig } from "@/components/CURD/types";

const modalConfig: IModalConfig<addRequest> = {
  pageName: "sys:user",
  dialog: {
    title: "新增打印机",
    width: 800,
    draggable: true,
  },
  form: {
    labelWidth: 100,
  },
  formAction: function (data) {
    let obj = { ...data }
    console.log("打印类型", data);
    // obj.printType = data.printType.join(',')
    obj.categoryIds = JSON.stringify(data.categoryIdsArr)
    obj.categoryList = JSON.stringify(data.categoryIdsArr)
    if (data.classifyPrint == 0) {
      obj.categoryIds = ''
    }
    // obj.categoryIds = '[' + data.categoryIdsArr.join(',') + ']'
    return printerApi.add(obj);
  },
  beforeSubmit(data) {
    console.log("提交之前处理", data);

  },
  formItems: [
    {
      label: "设备名称",
      prop: "name",
      rules: [{ required: true, message: "设备名称不能为空", trigger: "blur" }],
      type: "input",
      attrs: {
        placeholder: "请输入设备名称",
      },
      col: {
        xs: 24,
        sm: 12,
      },
    },
    {
      type: "select",
      label: "类型",
      prop: "connectionType",
      rules: [{ required: true, message: "请选择设备类型", trigger: "blur" }],
      attrs: {
        placeholder: "请选择设备类型",
        clearable: true,
        style: {
          width: "200px",
        },
      },
      options: options.connectionType,
      col: {
        xs: 24,
        sm: 12,
      },
    },
    {
      label: "ip地址",
      prop: "address",
      rules: [{ required: true, message: "请输入ip地址", trigger: "blur" }],
      type: "input",
      attrs: {
        placeholder: "请输入ip地址",
      },
      col: {
        xs: 24,
        sm: 12,
      },
    },
    {
      label: "端口",
      prop: "port",
      type: "input",
      attrs: {
        placeholder: "请输入端口",
      },
      col: {
        xs: 24,
        sm: 12,
      },
    },
    {
      type: "select",
      label: "打印类型",
      prop: "printType",
      rules: [{ required: false, message: "请选择打印类型", trigger: "blur" }],
      attrs: {
        placeholder: "请选择打印类型",
        clearable: true,
        style: {
          width: "200px",
        },
      },
      options: options.subType,
      col: {
        xs: 24,
        sm: 12,
      },
    },
    {
      type: "select",
      label: "打印机品牌",
      prop: "brand",
      rules: [{ required: true, message: "请选择打印机品牌", trigger: "blur" }],
      attrs: {
        placeholder: "请选择打印机品牌",
        clearable: true,
        style: {
          width: "200px",
        },
      },
      options: options.contentType,
      col: {
        xs: 24,
        sm: 12,
      },
    },
    {
      type: "radio-button",
      label: "小票尺寸",
      prop: "receiptSize",
      options: options.receiptSize,
      initialValue: options.receiptSize[0].value
    },
    {
      type: "radio-button",
      label: "分类打印",
      prop: "classifyPrint",
      options: options.classifyPrint,
      initialValue: options.classifyPrint[0].value
    },
    {
      type: "custom",
      slotName: 'classifyPrintData',
      prop: "categoryIdsArr",
      label: "",
      initialValue: []
    },
    {
      type: "radio",
      label: "打印数量",
      prop: "printNum",
      options: options.printQty,
      initialValue: options.printQty[0].value
    },
    {
      type: "radio",
      label: "打印方式",
      prop: "kitchenPrintMode",
      options: options.printMethod,
      initialValue: options.printMethod[0].value
    },
    {
      type: "custom",
      label: "打印类型",
      prop: "printContentType",
      options: options.printType,
      initialValue: options.printType.map(v => v.value),
      slotName: 'printTypeSlot'
    },
    {
      label: "打印机状态",
      prop: "status",
      type: "switch",
      initialValue: 1,
      attrs: {
        activeValue: 1,
        inactiveValue: 0,
      }
    },
  ],
};

// 如果有异步数据会修改配置的，推荐用reactive包裹，而纯静态配置的可以直接导出
export default reactive(modalConfig);
