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 Archives(props: MyBetaModalFormProps) {
  const [form] = Form.useForm();
  return (
    <BetaSchemaForm<ApiTypes.Contract.ContractArchives.Store>
      {...MyModalFormProps.props}
      title={`${props.title}`}
      wrapperCol={{ span: 24 }}
      width="600px"
      key={new Date().getTime()}
      form={form}
      onOpenChange={(open: any) => {
        if (open) {
          form.resetFields(); // 清空表单数据
        }
      }}
      trigger={<MyButtons.Create title={props.title} />}
      onFinish={async (values: any) => {
        console.log(values, 'values');
        return Apis.Contract.ContractDisputeRecords.Store({
          ...values,
          contracts_id: props?.item?.id,
        })
          .then(() => {
            props.reload?.();
            message.success(props.title + '成功');
            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 },
          // accept: '.docx,.doc,.pdf',
          max: 100,
          className: 'my_upload_file',
        }),
      ]}
    />
  );
}
