import {
  MyBetaModalFormProps,
  MyButtons,
  MyModalFormProps,
  rulesHelper,
} from '@/common';
import { SysSelects } from '@/components/SysSelects';

import { Apis } from '@/gen/Apis';
import { BetaSchemaForm } from '@ant-design/pro-components';
import { Form, message } from 'antd';
export default function Update(props: MyBetaModalFormProps) {
  const [form] = Form.useForm();
  return (
    <BetaSchemaForm<ApiTypes.Company.CompanyEmployees.Update>
      {...MyModalFormProps.props}
      title={`角色调整`}
      trigger={<MyButtons.Default title="角色" type="primary" />}
      wrapperCol={{ span: 24 }}
      width="500px"
      key={new Date().getTime()}
      form={form}
      onOpenChange={(open: any) => {
        if (open) {
          form.resetFields(); // 清空表单数据
        }
      }}
      onFinish={async (values: any) =>
        Apis.Company.CompanyEmployees.Update({
          ...values,
          id: props.item?.id ?? 0,
          name: props.item?.name ?? '',
          phone: props.item?.phone ?? '',
          type: props.item?.type ?? '',
          organizations_id: props.item?.organizations_id ?? '',
        })
          .then(() => {
            props.reload?.();
            message.success(props.title + '成功');
            return true;
          })
          .catch(() => false)
      }
      columns={[
        SysSelects.SysRoles({
          formItemProps: { ...rulesHelper.array },
        }),
      ]}
    />
  );
}
