import { doFetch } from '@/utils/doFetch';
import { Switch } from 'antd';
import fieldsDetail from '@/utils/fieldsDetail';

function getcolumns(ifs) {
  return [
    {
      title: '供应商编号',
      dataIndex: 'supplierNo',
      key: 'supplierNo',
      width: 120,
    },
    {
      title: '供应商名称',
      dataIndex: 'supplierName',
      key: 'supplierName',
      width: 150,
      formItemProps: {
        rules: [
          {
            required: true,
            message: '此项为必填项',
          },
        ],
      },
    },
    {
      title: '公司官网',
      dataIndex: 'officialWebsite',
      key: 'officialWebsite',
      hideInTable: true,
      search: false,
      formItemProps: {
        rules: [
          {
            required: false,
            message: '此项为必填项',
          },
        ],
      },
    },
    {
      title: '联系电话',
      dataIndex: 'telephone',
      key: 'telephone',
      formItemProps: {
        rules: [
          {
            required: false,
            message: '此项为必填项',
          },
        ],
      },
    },
    {
      title: '邮箱',
      dataIndex: 'email',
      key: 'email',
      formItemProps: {
        rules: [
          {
            required: false,
            message: '此项为必填项',
          },
        ],
      },
    },
    {
      title: '地址',
      dataIndex: 'address',
      key: 'address',
      search: false,
      width: 320,
      formItemProps: {
        rules: [
          {
            required: false,
            message: '此项为必填项',
          },
        ],
      },
    },
    {
      title: '状态',
      dataIndex: 'status',
      key: 'status',
      valueType: 'radio',
      formItemProps: {
        rules: [
          {
            required: false,
            message: '此项为必填项',
          },
        ],
      },
      options: [
        {
          label: '启用',
          value: 1,
        },
        {
          label: '禁用',
          value: 2,
        },
      ],
      fieldProps: {
        disabled: ifs,
      },
      render: (text, row) => {
        return (
          <Switch
            checkedChildren="启用"
            unCheckedChildren="禁用"
            defaultChecked={row.status == 1}
            disabled={row?.statusChangeable == 1 ? false : true}
            onChange={(flag) => {
              // //console.log(e);
              if (flag) {
                doFetch({
                  url: '/asset/equipmentSupplier/update/status',
                  params: { id: row.id, status: '1' },
                });
              } else {
                doFetch({
                  url: '/asset/equipmentSupplier/update/status',
                  params: { id: row.id, status: '2' },
                });
              }
            }}
          />
        );
      },
    },
    {
      title: '评分',
      dataIndex: 'score',
      key: 'score',
      width: 50,
      valueType: 'rate',
      searchValueType: 'digit',
      fieldProps: {
        defaultValue: 0,
        max: 5,
        precision: 1,
      },
      formItemProps: {
        rules: [
          {
            required: false,
            message: '此项为必填项',
          },
        ],
      },
    },
    {
      title: '备注',
      dataIndex: 'remark',
      key: 'remark',
      search: false,
      valueType: 'textarea',
      width: 300,
      fieldProps: {
        placeholder: '请输入',
        showCount: true,
        maxLength: 255,
      },
      formItemProps: {
        rules: [
          {
            required: false,
            message: '此项为必填项',
          },
        ],
      },
    },
    {
      title: '联系信息',
      valueType: 'formList',
      dataIndex: 'list',
      key: 'supplierUserList',
      initialValue: [
        {
          state: 'all',
          title: '标题',
        },
      ],
      colProps: {
        xs: 24,
        sm: 24,
      },
      columns: [
        {
          title: '联系人',
          dataIndex: 'userName',
          key: 'userName',
          formItemProps: {
            rules: [
              {
                required: true,
                message: '此项为必填项',
              },
            ],
          },
          colProps: {
            sm: 6,
          },
        },
        {
          title: '手机号码',
          dataIndex: 'telephone',
          key: 'telephone',
          colProps: {
            sm: 6,
          },
          formItemProps: {
            rules: [
              {
                required: false,
                message: '此项为必填项',
              },
              { pattern: new RegExp(/^1[3456789]\d{9}$/, 'g'), message: '' },
            ],
          },
        },
        {
          title: '邮箱',
          dataIndex: 'email',
          key: 'email',
          colProps: {
            sm: 6,
          },
        },
        {
          title: '职务',
          dataIndex: 'title',
          key: 'title',
          fieldProps: {
            placeholder: '请输入',
          },
          formItemProps: {
            rules: [
              {
                required: false,
                message: '此项为必填项',
              },
            ],
          },
          colProps: {
            sm: 6,
          },
        },
      ],
      search: false,
      hideInTable: true,
    },
  ];
}

export default getcolumns;
