import { doFetch } from '@/utils/doFetch';
import { Image } from 'antd';
import fieldsDetail from '@/utils/fieldsDetail';
import { useState, useEffect } from 'react';
function getcolumns(setDrawer, ifs, formRef, isLease) {
  return [
    {
      title: '用户名-姓名',
      dataIndex: 'username',
      width: 120,
      key: 'usernamefullname',
      hideInTable: true,
      search: false,
      formItemProps: { rules: [{ required: true, message: '此项为必填项' }] },
      fieldProps: {
        placeholder: '请输入',
      },
      valueType: 'MyAutoComplete',
      onSelect: (value, option) => {
        formRef.current.setFieldValue('telephone', option?.phone);
        formRef.current.setFieldValue('fullName', option?.fullName);
        formRef.current.setFieldValue('mailNo', option?.mailbox);
        formRef.current.setFieldValue('status', option?.enabled);
      },
      disabled: ifs,
    },
    {
      title: '用户名',
      dataIndex: 'username',
      hideInForm: true,
      width: 120,
      key: 'username',
    },

    // {
    //   title: '用户名',
    //   dataIndex: 'username',
    //   width: 120,
    //   key: 'username',
    //   formItemProps: { rules: [{ required: true, message: '此项为必填项' }] },
    //   valueType: 'select',
    //   options,
    // },
    {
      title: '姓名',
      dataIndex: 'fullName',
      width: 100,
      key: 'fullName',
      hideInForm: true,
      formItemProps: { rules: [{ required: true, message: '此项为必填项' }] },
      render: (text, row) => {
        return (
          <a
            onClick={() => {
              fieldsDetail(
                [
                  {
                    title: '用户名',
                    dataIndex: 'username',
                    key: 'username',
                  },
                  {
                    title: '姓名',
                    dataIndex: 'fullName',
                    key: 'fullName',
                  },
                  { title: '手机号', dataIndex: 'telephone', key: 'telephone' },
                  {
                    title: '邮箱',
                    dataIndex: 'mailNo',
                    key: 'mailNo',
                  },
                  {
                    title: '公司名称',
                    dataIndex: 'organizationName',
                    key: 'organizationId',
                  },
                  {
                    title: '部门名称',
                    dataIndex: 'departmentName',
                    key: 'departmentId',
                  },
                  {
                    title: '负责工厂',
                    dataIndex: 'factoryNames',
                    key: 'factoryNames',
                  },
                  {
                    title: '负责车间',
                    dataIndex: 'shopNames',
                    key: 'shopNames',
                  },
                  {
                    title: '负责工段',
                    dataIndex: 'sectionNames',
                    key: 'sectionIdList',
                  },
                  {
                    title: '负责产线',
                    dataIndex: 'productionLines',
                    key: 'productionLineIdList',
                  },
                  {
                    title: '角色配置',
                    dataIndex: 'roleNames',
                    key: 'roleIdList',
                  },
                  {
                    title: '直属领导',
                    dataIndex: 'parentName',
                    key: 'parentId',
                  },
                  {
                    title: '状态',
                    dataIndex: 'statusName',
                    key: 'status',
                  },
                  {
                    title: '个人图片',
                    dataIndex: 'pictureUrl',
                    key: 'pictureUrl',
                    render: (text, row) => {
                      if (row?.userImgList == null || row?.userImgList.length == 0) {
                        return '暂无图片';
                      } else {
                        return <Image width={70} src={row.userImgList[0]?.url} />;
                      }
                    },
                  },
                  {
                    title: '备注',
                    dataIndex: 'remarks',
                    key: 'remarks',
                  },
                ],
                setDrawer,
                row,
                '1',
                '/auth/sysUser/detail',
              );
            }}
          >
            {row.fullName}
          </a>
        );
      },
    },
    {
      title: '手机号',
      hideInTable: true,
      dataIndex: 'telephone',
      key: 'telephone',
      fieldProps: {
        disabled: true,
      },
      hideInTable: true,
      search: false,
    },
    {
      title: '邮箱',
      dataIndex: 'mailNo',
      key: 'mailNo',
      hideInTable: true,
      search: false,
      fieldProps: {
        disabled: true,
      },
    },
    {
      title: '公司名称',

      dataIndex: 'organizationName',
      width: 120,
      key: 'organizationId',
      valueType: 'select',
      fieldProps: {
        placeholder: '请选择',
        showSearch: true,
      },
      formItemProps: { rules: [{ required: true, message: '此项为必填项' }] },
      options: { path: '/auth/sysDepartment/query/organization/selectbox', params: {} },
    },
    {
      title: '部门名称',
      width: 120,
      valueType: 'treeSelect',
      dataIndex: 'departmentName',
      search: false,
      formItemProps: { rules: [{ required: true, message: '此项为必填项' }] },
      key: 'departmentId',
      options: {
        path: '/auth/sysDepartment/query/children/tree',
        linkParams: {
          organizationId: 'parentId',
        },
      },
    },
    {
      title: '部门名称',
      width: 120,
      valueType: 'select',
      dataIndex: 'departmentName',
      formItemProps: { rules: [{ required: true, message: '此项为必填项' }] },
      key: 'departmentId',
      options: {
        path: '/auth/sysDepartment/query/all/department/selection',
      },
      fieldProps: {
        showSearch: true,
      },
      hideInForm: true,
      hideInTable: true,
    },
    {
      title: '用户类型',
      dataIndex: 'customerTypeName',
      key: 'customerType',
      formItemProps: {
        rules: [
          {
            required: true,
            message: '此项为必填项',
          },
        ],
      },
      colProps: {
        span: 12,
      },
      valueType: 'select',
      mode: 'radio',
      options: [
        {
          label: '平台用户',
          value: 1,
        },
        {
          label: '租户用户',
          value: 2,
        },
      ],
      hideInForm: isLease == 1 ? false : true,
      hideInTable: true,
      hideInDescriptions: isLease == 1 ? false : true
    },
    {
      title: '所属客户',
      dataIndex: 'customerName',
      key: 'customerId',
      formItemProps: {
        rules: [
          {
            required: true,
            message: '此项为必填项',
          },
        ],
      },
      colProps: {
        span: 12,
      },
      valueType: 'select',
      options: {
        path: '/lease/umLeaseCustomer/getSelection',
        params: {},
      },
      hideInForm: {
        customerType: {
          reverse: [2],
        },
      },
      hideInTable: true,
      hideInDescriptions: isLease == 1 ? false : true
    },
    {
      title: '角色名称',
      dataIndex: 'roleNames',
      key: 'roleNames',
      hideInForm: true,
      hideInTable: true,
    },
    {
      title: '负责工厂',
      dataIndex: 'factoryNames',
      key: 'factoryIdList',
      fieldProps: {
        placeholder: '请选择',
        showSearch: true,
        mode: 'multiple',
      },
      width: 120,
      valueType: 'select',
      searchKey: 'factoryNames',
      searchValueType: 'input',
      options: { path: '/auth/sysFactory/getAllFactorySelection', params: {} },
      showAll: true
    },
    {
      title: '负责车间',
      dataIndex: 'shopNames',
      fieldProps: {
        placeholder: '请选择',
        showSearch: true,
        mode: 'multiple',
      },
      searchKey: 'shopNames',
      searchValueType: 'input',
      width: 120,
      valueType: 'select',
      options: {
        path: '/auth/sysShop/getShopSelectionByFactoryIdList',
        linkParams: {
          factoryIdList: '',
        },
      },
      key: 'shopIdList',
      formItemProps: { rules: [{ required: false, message: '此项为必填项' }] },
      showAll: true,
    },
    {
      title: '负责工段',
      width: 120,
      dataIndex: 'sectionNames',

      search: false,
      key: 'sectionIdList',
      hideInTable: true,
      fieldProps: {
        placeholder: '请选择',
        showSearch: true,
        mode: 'multiple',
      },
      valueType: 'select',
      options: {
        path: '/auth/sysSection/getAllSectionSelectionByShopIdList',
        linkParams: {
          shopIdList: '',
        },
      },
      showAll: true,
    },
    {
      title: '负责产线',
      width: 120,
      dataIndex: 'productionLines',
      valueType: 'select',
      fieldProps: {
        placeholder: '请选择',
        showSearch: true,
        mode: 'multiple',
      },
      search: false,
      hideInTable: true,
      key: 'productionLineIdList',
      options: {
        path: '/auth/sysProductionLine/getAllProductLineSelectionByShopIdList',
        linkParams: {
          shopIdList: '',
        },
      },
      showAll: true,
    },
    {
      title: '角色配置',
      dataIndex: 'roleNames',
      key: 'roleIdList',
      valueType: 'select',
      fieldProps: {
        placeholder: '请选择',
        showSearch: true,
        mode: 'multiple',
      },
      options: {
        path: '/auth/sysRole/selection',
      },
      search: false,
    },

    {
      title: '直属领导',
      valueType: 'select',
      dataIndex: 'parentName',
      key: 'parentId',
      options: {
        path: '/auth/sysUser/selection',
      },
      fieldProps: {
        placeholder: '请选择',
        showSearch: true,
      },
    },
    {
      title: '状态',
      hideInTable: true,
      hideInForm: true,
      dataIndex: 'statusName',
      key: 'status',
      valueType: 'select',
      formItemProps: { rules: [{ required: true, message: '此项为必填项' }] },
      options: [
        {
          label: '启用',
          value: 1,
        },
        {
          label: '禁用',
          value: 0,
        },
      ],
    },
    {
      title: '状态',
      dataIndex: 'statusName',
      search: false,
      key: 'status',
      fieldProps: { disabled: true },
      formItemProps: { rules: [{ required: true, message: '此项为必填项' }] },
      valueType: 'radio',
      options: [
        {
          label: '启用',
          value: 1,
        },
        {
          label: '禁用',
          value: 0,
        },
      ],
    },
    {
      title: '备注',
      hideInTable: true,
      dataIndex: 'remarks',
      valueType: 'textarea',
      width: 120,
      key: 'remarks',
      search: false,
    },
    {
      title: '个人图片',
      search: false,
      dataIndex: 'userImgList',
      key: 'userImgList',
      valueType: 'uploadImage',
      hideInTable: true,
      fieldProps: {
        limit: 1,
      },

      render: (text, row) => {
        if (row?.pictureUrl == null) {
          return '暂无图片';
        } else {
          return <Image width={70} src={row.pictureUrl} />;
        }
      },
    },
  ];
}

export default getcolumns;