ApplyResult.tsx 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. import React, { useEffect, useState } from 'react'
  2. import useRequest from '@ahooksjs/use-request'
  3. import { Button, Form, Input, message, Row, Modal, Upload } from 'antd'
  4. import { LoadingOutlined, PlusOutlined } from '@ant-design/icons'
  5. import type { UploadChangeParam } from 'antd/es/upload'
  6. import type { UploadFile, UploadProps } from 'antd/es/upload/interface'
  7. import SuccessSvg from 'assets/success.svg'
  8. import FailSvg from 'assets/fail.svg'
  9. import NButton from 'components/NButton/NButton'
  10. import { MaterialService } from '../Material.service'
  11. import { useLogin2p } from 'Login2p/Login2pContext'
  12. import { ITryType } from './NoPermission'
  13. import styles from '../css/NoPermission.module.scss'
  14. const { Item } = Form
  15. interface IApplyPermissionProps {
  16. visible: boolean
  17. detailID?: number
  18. tryType?: ITryType
  19. handleClose: () => void
  20. }
  21. /**
  22. * 支付结果
  23. */
  24. const ApplyResult: React.FC<IApplyPermissionProps> = props => {
  25. const { visible, detailID, tryType, handleClose } = props
  26. const login2p = useLogin2p()
  27. const [form] = Form.useForm()
  28. const [loading, setLoading] = useState(false)
  29. const [imageUrl, setImageUrl] = useState<string>()
  30. const uploadButton = (
  31. <div>
  32. {loading ? <LoadingOutlined /> : <PlusOutlined />}
  33. <div style={{ marginTop: 8 }}>上传名片</div>
  34. </div>
  35. )
  36. const { run } = useRequest(MaterialService.postApplyTry, {
  37. manual: true,
  38. onSuccess: res => {
  39. res.data.Ret === 200 ? message.success('已提交给您的对口销售,请耐心等待。') : message.info(res.data.Msg)
  40. handleToClose()
  41. setImageUrl(undefined)
  42. }
  43. })
  44. const { run: uploadImg } = useRequest(MaterialService.postUploadImage, {
  45. manual: true,
  46. onSuccess: res => {
  47. message.info(res.data.Msg)
  48. setImageUrl(res.data?.Data?.ResourceUrl)
  49. setLoading(false)
  50. }
  51. })
  52. useEffect(() => {
  53. return () => {
  54. form.resetFields()
  55. }
  56. // eslint-disable-next-line react-hooks/exhaustive-deps
  57. }, [form])
  58. // eslint-disable-next-line @typescript-eslint/no-explicit-any
  59. const handleFinish = (value: any) => {
  60. if (!imageUrl) {
  61. message.error('请上传名片')
  62. return
  63. }
  64. // 上传名片时,ApplyMethod为2,否则为1
  65. run({
  66. ApplyMethod: 2,
  67. BusinessCardUrl: imageUrl,
  68. CompanyName: value.CompanyName,
  69. DetailId: detailID,
  70. RealName: value.RealName,
  71. TryType: tryType
  72. })
  73. }
  74. const uploadProps: UploadProps = {
  75. name: 'file',
  76. multiple: false,
  77. listType: 'picture-card',
  78. showUploadList: false,
  79. withCredentials: true,
  80. customRequest: option => {
  81. uploadImg(option.file)
  82. },
  83. onChange: (info: UploadChangeParam<UploadFile>) => {
  84. if (info.file.status === 'uploading') {
  85. setLoading(true)
  86. return
  87. }
  88. }
  89. }
  90. // eslint-disable-next-line @typescript-eslint/no-explicit-any
  91. const normFile = (e: any) => {
  92. if (Array.isArray(e)) {
  93. return e
  94. }
  95. return e && e.fileList
  96. }
  97. const handleToClose = () => {
  98. // 关闭前把名片给清除了
  99. setImageUrl(undefined)
  100. handleClose()
  101. }
  102. const handleBackClose = () => {
  103. //
  104. handleClose()
  105. }
  106. return (
  107. <Modal
  108. open={visible}
  109. centered={true}
  110. onCancel={handleToClose}
  111. destroyOnClose={true}
  112. maskClosable={false}
  113. title="支付结果"
  114. footer={null}
  115. >
  116. <div className={styles['paymodel-content-wrapper']}>
  117. <div className="paymodel-title">
  118. <img src={SuccessSvg} alt="图标" className="paymodel-success-icon" />
  119. <img src={FailSvg} alt="图标" className="paymodel-success-icon" />
  120. <span>畅读卡购买成功</span>
  121. <span>支付成功</span>
  122. <span>支付失败</span>
  123. </div>
  124. <div className="paymodel-text">有效期至:2023.09.22 12:12:12</div>
  125. <div className="paymodel-text">请到活动页面选择参会方式</div>
  126. </div>
  127. <div className={styles['paymodel-footer-wrapper']}>
  128. <NButton type="primary" onClick={handleBackClose} size="large" className="pay-btn">
  129. 关闭
  130. </NButton>
  131. <NButton type="primary" onClick={handleBackClose} size="large" className="pay-btn">
  132. 返回活动页
  133. </NButton>
  134. </div>
  135. </Modal>
  136. )
  137. }
  138. export default ApplyResult