import {
  MyBetaModalFormProps,
  MyButtons,
  MyFormItems,
  MyModalFormProps,
  rulesHelper,
} from '@/common';
// import ModalsAssetItemsSelectList from '@/components/ModalsAssetItemsSelectList';
import { Selects } from '@/components/Select';
import { Apis } from '@/gen/Apis';
// import { AssetItemMaintenanceTypeEnum } from '@/gen/Enums';
import { BetaSchemaForm, ProCard } from '@ant-design/pro-components';
import { Form, message, Space } from 'antd';
export default function Index(props: MyBetaModalFormProps) {
  const [form] = Form.useForm();
  return (
    <BetaSchemaForm<ApiTypes.Asset.AssetItemMaintenances.Store>
      {...MyModalFormProps.props}
      title={`${props.title}工单`}
      trigger={
        <MyButtons.Create type="primary" size="middle" title={props.title} />
      }
      wrapperCol={{ span: 24 }}
      width="600px"
      key={new Date().getTime()}
      form={form}
      onOpenChange={(open: any) => {
        if (open) {
          form.resetFields();
        }
      }}
      onFinish={async (values: any) => {
        return Apis.Asset.AssetItemMaintenances.Store({
          ...values,
          asset_items_id: values?.asset_items?.id ?? 0,
        })
          .then(() => {
            props.reload?.();
            message.success(props.title + '成功');
            return true;
          })
          .catch(() => false);
      }}
      columns={[
        // MyFormItems.EnumRadio({
        //   key: 'type',
        //   title: '维护类型',
        //   formItemProps: { ...rulesHelper.text },
        //   valueEnum: AssetItemMaintenanceTypeEnum,
        //   colProps: { span: 24 },
        // }),
        {
          formItemProps: { ...rulesHelper.text },
          title: '请选择资产',
          key: 'asset_items',
          renderFormItem: (schema, config) => {
            return (
              <ProCard bordered>
                <Space direction="vertical">
                  {/* <ModalsAssetItemsSelectList
                    item={{
                      mode: 'radio',
                    }}
                    onChange={(e) => {
                      form.setFieldValue('asset_items', e?.[0]);
                    }}
                  /> */}
                  {config?.value?.name
                    ? `你已选择资产：${config?.value?.name}`
                    : ''}
                </Space>
              </ProCard>
            );
          },
        },
        Selects?.AssetProjects({
          title: '选择项目',
          key: 'asset_projects_id',
          colProps: { span: 12 },
          formItemProps: { ...rulesHelper.number },
        }),
        {
          title: '完成时间',
          key: 'deadline',
          colProps: { span: 12 },
          fieldProps: {
            style: {
              width: '100%',
            },
          },
          valueType: 'date',
        },
        {
          title: '维护内容',
          key: 'description',
          valueType: 'textarea',
          colProps: { span: 24 },
        },
        MyFormItems.UploadImages({
          key: 'attachments',
          title: '上传附件',
          tooltip: '仅支持docx,doc,pdf格式',
          uploadType: 'file',
          colProps: { span: 24 },
          max: 100,
        }),
      ]}
    />
  );
}
