index.tsx 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293
  1. import React, { useCallback, useEffect, useRef, useState } from 'react'
  2. import styles from './index.module.scss'
  3. import { useParams } from 'react-router-dom'
  4. import ZexhiBtn from '@/components/ZexhiBtn'
  5. import { Button, Form, FormInstance, Input, InputNumber, Select } from 'antd'
  6. import ZinfoPop from '@/components/ZinfoPop'
  7. import history from '@/utils/history'
  8. import classNames from 'classnames'
  9. import { MessageFu } from '@/utils/message'
  10. import delImg from '@/assets/img/exhibit/del.png'
  11. import MyPopconfirm from '@/components/MyPopconfirm'
  12. import { B3_APIgetList, B4_APIsave } from '@/store/action/all'
  13. import { B3ListApiType } from '../B3start/type'
  14. import ZselectCity from '@/components/ZselectCity'
  15. import TextArea from 'antd/es/input/TextArea'
  16. import { papersSelArr } from './data'
  17. function B4form() {
  18. // useEffect(() => {
  19. // FormBoxRef.current?.setFieldsValue({
  20. // name1: '王大锤',
  21. // phone1: '18702025091',
  22. // identity1: '421083199504071212'
  23. // })
  24. // }, [])
  25. // 获取路由参数
  26. const [urlObj, setUrlObj] = useState({
  27. bookDate: '',
  28. bookId: 0,
  29. time: ''
  30. })
  31. // 路由参数key,1:个人/2:团体
  32. const urlObjTemp: any = useParams()
  33. const getInfoFu = useCallback(async () => {
  34. const res = await B3_APIgetList()
  35. if (res.code === 0) {
  36. const list: B3ListApiType[] = res.data
  37. const index = Number(urlObjTemp.index)
  38. setUrlObj({
  39. bookDate: urlObjTemp.bookDate.replaceAll('_', '-'),
  40. bookId: list[index].id,
  41. time: list[index].time
  42. })
  43. }
  44. }, [urlObjTemp])
  45. useEffect(() => {
  46. getInfoFu()
  47. }, [getInfoFu])
  48. // 表单的ref
  49. const FormBoxRef = useRef<FormInstance>(null)
  50. const [formArr, setFormArr] = useState([{ id: 1 }])
  51. const formArrNumRef = useRef(1)
  52. // 点击新增 参观人
  53. const addFormFu = useCallback(() => {
  54. if (formArr.length >= 5) return MessageFu.warning('最多5位!')
  55. setFormArr([...formArr, { id: formArrNumRef.current + 1 }])
  56. formArrNumRef.current += 1
  57. }, [formArr])
  58. // 点击删除 参观人
  59. const delFormFu = useCallback(
  60. (id: number) => {
  61. setFormArr(formArr.filter(v => v.id !== id))
  62. },
  63. [formArr]
  64. )
  65. // 选择地区的ref
  66. const selectCityRef = useRef<any>(null)
  67. // 没有通过校验
  68. const onFinishFailed = useCallback(() => {}, [])
  69. // 打开提示弹窗
  70. const [titPop, setTitPop] = useState('')
  71. // 通过校验点击确定
  72. const onFinish = useCallback(
  73. async (values: any) => {
  74. if (values.teamPcs && values.teamPcs > 20) return MessageFu.warning('参团人数最多20人!')
  75. const cityArr = selectCityRef.current.getValue()
  76. if (cityArr.length < 2) return MessageFu.warning('请选择地区!')
  77. const arr: any = []
  78. formArr.forEach(v => {
  79. arr.push({
  80. bookDate: urlObj.bookDate,
  81. bookId: urlObj.bookId,
  82. time: urlObj.time,
  83. name: values[`name${v.id}`],
  84. phone: values[`phone${v.id}`],
  85. identity: values[`identity${v.id}`],
  86. papers: values[`papers${v.id}`],
  87. province: cityArr[0],
  88. city: cityArr[1]
  89. })
  90. })
  91. const obj = {
  92. info: arr,
  93. teamDesc: values.teamDesc,
  94. teamPcs: values.teamPcs,
  95. type: urlObjTemp.key === '1' ? 'person' : 'team'
  96. }
  97. // if (1 + 1 === 2) {
  98. // console.log(123, obj)
  99. // return
  100. // }
  101. const res = await B4_APIsave(obj)
  102. if (res.code === 0) setTitPop('succ')
  103. },
  104. [formArr, urlObj.bookDate, urlObj.bookId, urlObj.time, urlObjTemp.key]
  105. )
  106. return (
  107. <div className={styles.B4form}>
  108. <div className='B4main'>
  109. <div className='B4top'>
  110. <p>
  111. <span>预约日期:</span>
  112. {urlObj.bookDate}
  113. </p>
  114. <p>
  115. <span>入馆时间:</span>
  116. {urlObj.time}
  117. </p>
  118. <p>
  119. <span>预约类型:</span>
  120. {urlObjTemp.key === '1' ? '个人预约' : '团队预约'}
  121. </p>
  122. </div>
  123. {/* 按钮 */}
  124. {/* 个人预约才有 */}
  125. {urlObjTemp.key === '1' ? (
  126. <div
  127. className={classNames('B4addBtn', formArr.length >= 5 ? 'myBtnNo' : '')}
  128. onClick={addFormFu}
  129. >
  130. 新增参观人(最多5位)
  131. </div>
  132. ) : null}
  133. {/* 地区选择 */}
  134. <div className='B4KaBox0'>
  135. <div className='B4KaBoxll'>
  136. <span>* </span>来自地区
  137. </div>
  138. <div className='B4KaBoxrr'>
  139. <ZselectCity ref={selectCityRef} />
  140. </div>
  141. </div>
  142. <div className='B4KaBox'>
  143. <Form
  144. ref={FormBoxRef}
  145. name='basic'
  146. // labelCol={{ span: 3 }}
  147. onFinish={onFinish}
  148. onFinishFailed={onFinishFailed}
  149. autoComplete='off'
  150. scrollToFirstError
  151. initialValues={{ papers1: '内地身份证' }}
  152. >
  153. {/* 卡片 */}
  154. {formArr.map((item, index) => (
  155. <div className='B4Ka' key={item.id}>
  156. <div className='B4tit'>
  157. <div className='B4titTxt'>
  158. {urlObjTemp.key === '1' ? `参观人信息${index + 1}` : '负责人信息'}
  159. </div>
  160. {formArr.length <= 1 ? (
  161. <div></div>
  162. ) : (
  163. <MyPopconfirm
  164. txtK='删除'
  165. onConfirm={() => delFormFu(item.id)}
  166. Dom={
  167. <div className='B4titDel'>
  168. <img src={delImg} alt='' /> 删除
  169. </div>
  170. }
  171. />
  172. )}
  173. </div>
  174. <Form.Item
  175. label='姓名'
  176. name={`name${item.id}`}
  177. rules={[{ required: true, message: '请输入姓名!' }]}
  178. getValueFromEvent={e => e.target.value.replace(/\s+/g, '')}
  179. >
  180. <Input placeholder='请输入内容,不超过6个字' maxLength={6} />
  181. </Form.Item>
  182. <Form.Item
  183. label='联系方式'
  184. name={`phone${item.id}`}
  185. rules={[
  186. { required: true, message: '请输入联系方式!' }
  187. // {
  188. // pattern: /^1[3-9][0-9]{9}$/,
  189. // message: '请输入正确格式的手机号!'
  190. // }
  191. ]}
  192. >
  193. <Input placeholder='请输入联系方式' maxLength={30} />
  194. </Form.Item>
  195. <Form.Item
  196. label='证件类型'
  197. name={`papers${item.id}`}
  198. rules={[{ required: true, message: '请选择证件类型!' }]}
  199. >
  200. <Select placeholder='请选择证件类型' options={papersSelArr} />
  201. </Form.Item>
  202. <Form.Item
  203. label='证件号码'
  204. name={`identity${item.id}`}
  205. rules={[
  206. { required: true, message: '请输入证件号码!' }
  207. // {
  208. // pattern:
  209. // /^[1-9]\d{5}(19|20)\d{2}((0[1-9])|(1[0-2]))(([0-2][1-9])|10|20|30|31)\d{3}[0-9Xx]$/,
  210. // message: '请输入正确格式的身份证号!'
  211. // }
  212. ]}
  213. >
  214. <Input placeholder='请输入证件号码' maxLength={30} />
  215. </Form.Item>
  216. </div>
  217. ))}
  218. {/* 团体才有的,团队信息 */}
  219. {urlObjTemp.key === '2' ? (
  220. <div className='B4Ka'>
  221. <div className='B4tit'>
  222. <div className='B4titTxt'>团队信息</div>
  223. </div>
  224. <Form.Item
  225. label='参团人数'
  226. name='teamPcs'
  227. rules={[{ required: true, message: '请输入参团人数!' }]}
  228. >
  229. <InputNumber min={1} max={999} precision={0} placeholder='请输入数字' />
  230. </Form.Item>
  231. <Form.Item label='团队描述' name='teamDesc' className='A5Text'>
  232. <TextArea autoSize maxLength={200} placeholder='请输入内容,不超过200个字' />
  233. </Form.Item>
  234. </div>
  235. ) : null}
  236. {/* 底部按钮 */}
  237. <ZexhiBtn
  238. nextFu={() => {}}
  239. FormBtn={
  240. <Button className='FormBtn' type='primary' htmlType='submit'>
  241. 提交
  242. </Button>
  243. }
  244. />
  245. </Form>
  246. </div>
  247. </div>
  248. {/* 预约成功的弹窗 */}
  249. {titPop ? (
  250. <ZinfoPop txt2='' type={titPop as 'succ'} callFu={() => history.push('/exhiMy')} />
  251. ) : null}
  252. </div>
  253. )
  254. }
  255. const MemoB4form = React.memo(B4form)
  256. export default MemoB4form