import {
  MyBetaModalFormProps,
  MyButtons,
  MyFormItems,
  MyModalFormProps,
  rulesHelper,
} from '@/common';
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.Contract.ContractArchives.Update>
      {...MyModalFormProps.props}
      title={`归档信息${props.title}`}
      trigger={<MyButtons.Edit />}
      wrapperCol={{ span: 24 }}
      width="600px"
      key={new Date().getTime()}
      form={form}
      onOpenChange={(open: any) => {
        if (open && props.item) {
          form.setFieldsValue(props.item);
        }
      }}
      onFinish={async (values: any) =>
        Apis.Contract.ContractDisputeRecords.Update({
          ...values,
          id: props?.item?.id ?? 0,
        })
          .then(() => {
            props.reload?.();
            message.success('编辑成功！');
            return true;
          })
          .catch(() => false)
      }
      columns={[
        {
          title: '争议原因',
          key: 'reason',
          formItemProps: { ...rulesHelper.text },
          valueType: 'textarea',
          colProps: { span: 24 },
        },
        {
          title: '处理内容',
          key: 'content',
          valueType: 'textarea',
          colProps: { span: 24 },
        },
        MyFormItems.UploadImages({
          key: 'attachments',
          title: '附件',
          uploadType: 'file',
          colProps: { span: 24 },
          max: 100,
          className: 'my_upload_file',
        }),
      ]}
    />
  );
}
