import {
  MyBetaModalFormProps,
  MyButtons,
  MyModalFormProps,
  rulesHelper,
} from '@/common';
import { Selects } from '@/components/Select';
import { Apis } from '@/gen/Apis';
import { BetaSchemaForm } from '@ant-design/pro-components';
import { Form, message } from 'antd';

export default function Index(props: MyBetaModalFormProps) {
  const [form] = Form.useForm();
  return (
    <BetaSchemaForm<ApiTypes.Contract.ContractArchiveTransfers.Store>
      {...MyModalFormProps.props}
      title={`${props.title}`}
      wrapperCol={{ span: 24 }}
      width="600px"
      key={new Date().getTime()}
      form={form}
      onOpenChange={(open: any) => {
        if (open) {
          form.setFieldsValue({
            files: props?.item?.archive_files,
          });
        }
      }}
      trigger={
        <MyButtons.Default
          size="small"
          type="primary"
          title={props?.title ?? '转交'}
        />
      }
      onFinish={async (values: any) => {
        console.log(values, 'values');
        return Apis.Contract.ContractArchiveTransfers.Store({
          ...values,
          contract_archives_id: props?.item?.id,
        })
          .then(() => {
            props.reload?.();
            message.success(props.title + '成功');
            return true;
          })
          .catch(() => false);
      }}
      columns={[
        Selects?.Employees({
          title: '新保管人',
          dataIndex: 'new_keeper_id',
          key: 'new_keeper_id',
          colProps: { span: 24 },
          formItemProps: { ...rulesHelper.text },
          fieldProps: {
            showSearch: true,
          },
          required: true,
        }),
        // Address.Cascader({
        //   key: 'casacader',
        //   title: '选择地址',
        //   colProps: { span: 12 },
        //   keys: ['province', 'city', 'area', 'street'],
        // }),
        // {
        //   key: 'address',
        //   title: '详细地址',
        //   dataIndex: 'address',
        //   colProps: { span: 12 },
        // },
        // {
        //   key: 'file_number',
        //   title: '案卷编号',
        //   dataIndex: 'file_number',
        //   colProps: { span: 12 },
        // },
        // {
        //   key: 'box_number',
        //   title: '文件盒编号',
        //   dataIndex: 'box_number',
        //   colProps: { span: 12 },
        // },
        // {
        //   key: 'cabinet_number',
        //   title: '文件柜编号',
        //   dataIndex: 'cabinet_number',
        //   colProps: { span: 12 },
        // },
        {
          key: 'remark',
          title: '备注',
          dataIndex: 'remark',
          valueType: 'textarea',
          colProps: { span: 24 },
        },
      ]}
    />
  );
}
