index.tsx 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266
  1. import { Dialog, Picker, Popup, Toast, Uploader, UploaderValueItem, hooks } from 'react-vant';
  2. import './index.less'
  3. import React, { useRef, useState } from "react";
  4. import downArrow from './../../assets/images/downArrow.png'
  5. import api from '~/api';
  6. export const InviteBusiness: React.FC = (props: any) => {
  7. let [imgList,setImgList] = useState<UploaderValueItem[]>([])
  8. const [careerVisible, setCareerVisible] = useState(false)
  9. const [sexVisible, setSexVisible] = useState(false)
  10. const [projectVisible, setProjectVisible] = useState(false)
  11. const [businessForm, updateBusinessForm] = hooks.useSetState({
  12. career: 0,
  13. careerName: '',
  14. sexName: '',
  15. document: '',
  16. name: '',
  17. phone: '',
  18. project: 0,
  19. projectName: '',
  20. reason: '',
  21. sex: 0,
  22. wechar: ''
  23. })
  24. const submitBusinessForm = () => {
  25. if (!businessForm.name) {
  26. Toast({
  27. type: 'fail',
  28. message: "请填写名字"
  29. })
  30. return
  31. }
  32. if (!businessForm.sex) {
  33. Toast({
  34. type: 'fail',
  35. message: "请填写性别"
  36. })
  37. return
  38. }
  39. if (!businessForm.career) {
  40. Toast({
  41. type: 'fail',
  42. message: "请填写职业"
  43. })
  44. return
  45. }
  46. if (imgList.length === 0) {
  47. console.log(imgList)
  48. Toast({
  49. type: 'fail',
  50. message: "请上传图片"
  51. })
  52. return
  53. }
  54. if (!/^1(3\d|4[5-9]|5[0-35-9]|6[567]|7[0-8]|8\d|9[0-35-9])\d{8}$/.test(businessForm.phone)) {
  55. Toast({
  56. type: 'fail',
  57. message: "请填写正确电话号码"
  58. })
  59. return
  60. }
  61. if (!businessForm.wechar) {
  62. Toast({
  63. type: 'fail',
  64. message: "请填写微信号"
  65. })
  66. return
  67. }
  68. if (!businessForm.project) {
  69. Toast({
  70. type: 'fail',
  71. message: "请填写代理项目"
  72. })
  73. return
  74. }
  75. if (!businessForm.reason) {
  76. Toast({
  77. type: 'fail',
  78. message: "请填写缘由"
  79. })
  80. return
  81. }
  82. Dialog.confirm({
  83. title: '提交',
  84. message: '是否提交你的表单',
  85. }).then(async () => {
  86. if (imgList.length > 0) {
  87. let data1 = new FormData()
  88. data1.append('coverFiles', imgList[0].file as File)
  89. data1.append('businessType', '招商文件')
  90. let res1
  91. try {
  92. res1 = await api.openApiFileInfoFileUp(data1)
  93. }
  94. catch (e) {
  95. Toast('图片上传失败')
  96. }
  97. api.openApiAentInfo({ ...businessForm, document: res1?.data.data }).then(res => {
  98. if (res.data.code == 200) {
  99. Toast.success({
  100. message: '上传成功'
  101. })
  102. }
  103. })
  104. }
  105. })
  106. }
  107. const saveImgListFile = (file: File, files: File[]) => {
  108. setImgList(files)
  109. return files
  110. }
  111. return (
  112. <div className="bg">
  113. <div className="form">
  114. <div className="content">
  115. <div className="field">
  116. <div className="left">姓名</div>
  117. <div className='right'> <input value={businessForm.name} onChange={val => updateBusinessForm({ name: val.target.value })} placeholder="请填写姓名" type="text" /></div>
  118. </div>
  119. <div onClick={() => setSexVisible(true)} className="field">
  120. <div className="left">性别</div>
  121. <div className='right'>
  122. <input readOnly={true} value={businessForm.sexName} placeholder="请选择性别" type="text" />
  123. <img src={downArrow}></img>
  124. </div>
  125. </div>
  126. <div onClick={() => setCareerVisible(true)} className="field">
  127. <div className="left">职业</div>
  128. <div className='right'> <input readOnly={true} value={businessForm.careerName} placeholder="请选择职业" type="text" /> <img src={downArrow}></img></div>
  129. </div>
  130. <div className='upload' style={{ 'background': 'transparent' }} >
  131. <Uploader
  132. upload-text="上传图片"
  133. maxCount={1}
  134. accept='*'
  135. beforeRead={saveImgListFile}
  136. />
  137. <div style={{ color: '#adb4bf' }}>
  138. 请上传身份证或驾照或营业执照等 身份证明
  139. </div>
  140. </div>
  141. <div className="field">
  142. <div className="left">手机</div>
  143. <div className='right'>
  144. <input onChange={(val) => updateBusinessForm({
  145. phone: val.target.value
  146. })} value={businessForm.phone} placeholder="请填写手机" type="text" />
  147. </div>
  148. </div>
  149. <div className="field">
  150. <div className="left">微信</div>
  151. <div className='right'>
  152. <input onChange={(val) => updateBusinessForm({
  153. wechar: val.target.value
  154. })} value={businessForm.wechar} placeholder="请填写微信号" type="text" />
  155. </div>
  156. </div>
  157. <div onClick={() => { setProjectVisible(true) }} className="field">
  158. <div className="left">代理项目</div>
  159. <div className='right'>
  160. <input readOnly value={businessForm.projectName} placeholder="请选择代理项目" type="text" />
  161. <img src={downArrow}></img>
  162. </div>
  163. </div>
  164. <div style={{
  165. 'borderRadius': '2.5vw',
  166. 'padding': '1.5vw'
  167. }} className="field">
  168. <textarea value={businessForm.reason} onChange={val => updateBusinessForm({
  169. reason: val.target.value
  170. })} style={{ 'background': 'transparent', outline: 'none', 'border': 'none', height: '50vw', width: '100%' }} placeholder='请写出你的加盟缘由'></textarea>
  171. </div>
  172. </div>
  173. <div className='submit'>
  174. <div onClick={() => submitBusinessForm()} className='button1'>提交</div>
  175. </div>
  176. </div>
  177. <Popup position='bottom' visible={projectVisible} onClose={() => setProjectVisible(false)}>
  178. <Picker
  179. title='代理项目'
  180. onCancel={() => setProjectVisible(false)}
  181. onConfirm={(val: string, item: string, index: number | undefined) => {
  182. setProjectVisible(false)
  183. updateBusinessForm({
  184. project: index === undefined ? 0 : (index + 1),
  185. projectName: val
  186. })
  187. return val
  188. }}
  189. columns={[
  190. '软件代理', '书籍代理', '软件+书籍', '软件开发'
  191. ]}
  192. />
  193. </Popup>
  194. <Popup position='bottom' visible={careerVisible} onClose={() => setCareerVisible(false)}>
  195. <Picker
  196. title='职业'
  197. onCancel={() => setCareerVisible(false)}
  198. onConfirm={(val: string, item: string, index: number | undefined) => {
  199. setCareerVisible(false)
  200. updateBusinessForm({
  201. career: index === undefined ? 0 : (index + 1),
  202. careerName: val
  203. })
  204. return val
  205. }}
  206. columns={[
  207. '教练', '驾校', '自媒体', '相关从业者'
  208. ]}
  209. />
  210. </Popup>
  211. <Popup position='bottom' visible={sexVisible} onClose={() => setSexVisible(false)}>
  212. <Picker
  213. title='性别'
  214. onCancel={() => setSexVisible(false)}
  215. onConfirm={(val: string, item: string, index: number | undefined) => {
  216. setSexVisible(false)
  217. updateBusinessForm({
  218. sex: index === undefined ? 0 : (index + 1),
  219. sexName: val
  220. })
  221. return val
  222. }}
  223. columns={[
  224. '男', '女'
  225. ]}
  226. />
  227. </Popup>
  228. </div>
  229. )
  230. }