index.tsx 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350
  1. import React, { useCallback, useEffect, useRef, useState } from 'react'
  2. import styles from './index.module.scss'
  3. import {
  4. Button,
  5. Cascader,
  6. Checkbox,
  7. DatePicker,
  8. Form,
  9. FormInstance,
  10. Input,
  11. Radio,
  12. Select
  13. } from 'antd'
  14. import MyPopconfirm from '@/components/MyPopconfirm'
  15. import { nationSelect } from '../data'
  16. import { useDispatch, useSelector } from 'react-redux'
  17. import { A1_APIgetInfo, A1_APIgetNumList, A1_APIsave } from '@/store/action/A1record'
  18. import { RootState } from '@/store'
  19. import A1num from '../A1num'
  20. import { myCity } from '@/utils/history'
  21. import TextArea from 'antd/es/input/TextArea'
  22. import ZupTypes from '@/components/ZupTypes'
  23. import ZupVideos from '@/components/ZupVideos'
  24. import dayjs from 'dayjs'
  25. import { MessageFu } from '@/utils/message'
  26. type Props = {
  27. sId: number
  28. closeFu: () => void
  29. addTableFu: () => void
  30. upTableFu: () => void
  31. }
  32. function A1add({ sId, closeFu, addTableFu, upTableFu }: Props) {
  33. // 表单的ref
  34. const FormBoxRef = useRef<FormInstance>(null)
  35. // 多张图片的ref
  36. const ZupImgsRef = useRef<any>(null)
  37. // 多个视频的ref
  38. const ZupVideosRef = useRef<any>(null)
  39. // 编辑进来获取详情
  40. const getInfoFu = useCallback(async (id: number) => {
  41. const res = await A1_APIgetInfo(id)
  42. if (res.code === 0) {
  43. const obj = res.data
  44. if (obj.dictPanId) fanHaoRef.current = obj.dictPanId
  45. // 生卒日期
  46. if (obj.dateStart) obj.dateStart = dayjs(obj.dateStart)
  47. if (obj.dateEnd) obj.dateEnd = dayjs(obj.dateEnd)
  48. // 籍贯
  49. if (obj.nativeProvince) obj.myNative = [obj.nativeProvince]
  50. if (obj.nativeCity) obj.myNative.push(obj.nativeCity)
  51. if (obj.nativeRegion) obj.myNative.push(obj.nativeRegion)
  52. // 牺牲地
  53. if (obj.lossProvince) obj.myLoss = [obj.lossProvince]
  54. if (obj.lossCity) obj.myLoss.push(obj.lossCity)
  55. if (obj.lossRegion) obj.myLoss.push(obj.lossRegion)
  56. FormBoxRef.current?.setFieldsValue(obj)
  57. }
  58. const file = res.data.img || []
  59. // 传给 附件 组件的
  60. const sonInfo = {
  61. type: 'img',
  62. fileList: file
  63. }
  64. ZupImgsRef.current?.setFileComFileFu(sonInfo)
  65. ZupVideosRef.current?.setFileComFileFu(res.data.video || [])
  66. }, [])
  67. useEffect(() => {
  68. if (sId > 0) getInfoFu(sId)
  69. else FormBoxRef.current?.setFieldsValue({ nation: '汉族' })
  70. }, [getInfoFu, sId])
  71. // 没有通过校验
  72. const onFinishFailed = useCallback(() => {}, [])
  73. // 通过校验点击确定
  74. const onFinish = useCallback(
  75. async (values: any) => {
  76. // 多张图片
  77. const { sonFileIds, sonIsOk, coverUrl, coverUrlBig } = ZupImgsRef.current?.fileComFileResFu()
  78. // 多个视频
  79. const list = ZupVideosRef.current?.fileComFileResFu() || []
  80. // 生卒日期
  81. let dateStart = ''
  82. if (values.dateStart) dateStart = dayjs(values.dateStart).format('YYYY-MM-DD')
  83. let dateEnd = ''
  84. if (values.dateEnd) dateEnd = dayjs(values.dateEnd).format('YYYY-MM-DD')
  85. // 籍贯
  86. let nativeProvince = ''
  87. let nativeCity = ''
  88. let nativeRegion = ''
  89. if (values.myNative && values.myNative.length) {
  90. nativeProvince = values.myNative[0] || ''
  91. nativeCity = values.myNative[1] || ''
  92. nativeRegion = values.myNative[2] || ''
  93. }
  94. // 牺牲地
  95. let lossProvince = ''
  96. let lossCity = ''
  97. let lossRegion = ''
  98. if (values.myLoss && values.myLoss.length) {
  99. lossProvince = values.myLoss[0] || ''
  100. lossCity = values.myLoss[1] || ''
  101. lossRegion = values.myLoss[2] || ''
  102. }
  103. const obj = {
  104. ...values,
  105. id: sId > 0 ? sId : null,
  106. dateStart,
  107. dateEnd,
  108. nativeProvince,
  109. nativeCity,
  110. nativeRegion,
  111. lossProvince,
  112. lossCity,
  113. lossRegion,
  114. thumb: coverUrl || '',
  115. thumbPc: coverUrlBig || '',
  116. imgIds: sonIsOk ? '' : sonFileIds.join(','),
  117. videoIds: list.map((v: any) => v.id).join(',')
  118. }
  119. const res = await A1_APIsave(obj)
  120. if (res.code === 0) {
  121. MessageFu.success(sId > 0 ? '编辑成功' : '新增成功')
  122. sId > 0 ? upTableFu() : addTableFu()
  123. closeFu()
  124. }
  125. // if (1 + 1 === 2) {
  126. // console.log('------222', obj)
  127. // return
  128. // }
  129. },
  130. [addTableFu, closeFu, sId, upTableFu]
  131. )
  132. const formDomRef = useRef<HTMLDivElement>(null)
  133. // -------------获取番号列表--------------
  134. const dispatch = useDispatch()
  135. useEffect(() => {
  136. dispatch(A1_APIgetNumList())
  137. }, [dispatch])
  138. const numList = useSelector((state: RootState) => state.A1record.numList)
  139. const [numShow, setNumShow] = useState(false)
  140. const fanHaoRef = useRef(0)
  141. return (
  142. <div className={styles.A1add}>
  143. <div className='A1addMain'>
  144. <div className='A1aTit'>{sId > 0 ? '编辑' : '新增'}烈士</div>
  145. <div className='A1accc' ref={formDomRef}>
  146. <div>
  147. <Form
  148. ref={FormBoxRef}
  149. name='basic'
  150. onFinish={onFinish}
  151. onFinishFailed={onFinishFailed}
  152. autoComplete='off'
  153. scrollToFirstError
  154. >
  155. <div className='A1aRow A1aRow3'>
  156. <Form.Item
  157. label='姓名'
  158. name='name'
  159. rules={[{ required: true, message: '请输入姓名' }]}
  160. // getValueFromEvent={(e) => e.target.value.replace(/\s+/g, "")}
  161. getValueFromEvent={e => e.target.value.trim()}
  162. >
  163. <Input maxLength={10} showCount placeholder='请输入内容' />
  164. </Form.Item>
  165. <Form.Item
  166. label='性别'
  167. name='gender'
  168. rules={[{ required: true, message: '请选择性别' }]}
  169. >
  170. <Radio.Group
  171. options={[
  172. { value: 1, label: '男' },
  173. { value: 2, label: '女' }
  174. ]}
  175. />
  176. </Form.Item>
  177. <Form.Item valuePropName='checked' label='寻亲烈士' name='display'>
  178. <Checkbox></Checkbox>
  179. </Form.Item>
  180. </div>
  181. <div className='A1aRow'>
  182. <Form.Item label='民族' name='nation'>
  183. <Select
  184. getPopupContainer={() => formDomRef.current!}
  185. allowClear
  186. placeholder='请搜索并选择'
  187. showSearch
  188. options={nationSelect}
  189. />
  190. </Form.Item>
  191. <div className='A1aRowSon'>
  192. <Form.Item label='番号' name='dictPanId'>
  193. <Select
  194. onChange={e => (fanHaoRef.current = e)}
  195. getPopupContainer={() => formDomRef.current!}
  196. filterOption={(input, option) =>
  197. (option?.label ?? '').toLowerCase().includes(input.toLowerCase())
  198. }
  199. allowClear
  200. placeholder='请搜索并选择'
  201. showSearch
  202. options={numList.map(v => ({ value: v.id, label: v.name }))}
  203. />
  204. </Form.Item>
  205. <Button type='primary' onClick={() => setNumShow(true)}>
  206. 管理
  207. </Button>
  208. </div>
  209. </div>
  210. <div className='A1aRow'>
  211. <Form.Item label='籍贯' name='myNative'>
  212. <Cascader options={myCity} placeholder='请选择' allowClear changeOnSelect />
  213. </Form.Item>
  214. <Form.Item label='籍贯详址' name='nativeAddress'>
  215. <Input maxLength={50} showCount placeholder='请输入内容' />
  216. </Form.Item>
  217. </div>
  218. <div className='A1aRow'>
  219. <Form.Item label='牺牲地' name='myLoss'>
  220. <Cascader options={myCity} placeholder='请选择' allowClear changeOnSelect />
  221. </Form.Item>
  222. <Form.Item label='牺牲详址' name='lossAddress'>
  223. <Input maxLength={50} showCount placeholder='请输入内容' />
  224. </Form.Item>
  225. </div>
  226. <div className='A1aRow'>
  227. <Form.Item label='出生年月' name='dateStart'>
  228. <DatePicker picker='month' placeholder='请选择年月' />
  229. </Form.Item>
  230. <Form.Item label='牺牲年月' name='dateEnd'>
  231. <DatePicker picker='month' placeholder='请选择年月' />
  232. </Form.Item>
  233. </div>
  234. {/* <div className='A1aRowAll'>
  235. <Form.Item label='个人介绍' name='intro'>
  236. <TextArea maxLength={500} showCount placeholder='请输入内容' />
  237. </Form.Item>
  238. </div> */}
  239. {/* 多个图片 */}
  240. <div className='formRow'>
  241. <div className='formLeft'>图片:</div>
  242. <div className='formRight'>
  243. <ZupTypes
  244. ref={ZupImgsRef}
  245. isLook={false}
  246. fileCheck={false}
  247. selecFlag='图片'
  248. imgSize={5}
  249. imgLength={50}
  250. dirCode='A1record'
  251. myUrl='cms/martyr/upload'
  252. isTypeShow={true}
  253. oneIsCover={true}
  254. />
  255. </div>
  256. </div>
  257. {/* 多个视频 */}
  258. <div className='formRow formRow2'>
  259. <div className='formLeft'>视频:</div>
  260. <div className='formRight'>
  261. <ZupVideos
  262. isLook={false}
  263. size={500}
  264. fileNum={50}
  265. dirCode='A1recordVideo'
  266. myUrl='cms/martyr/upload'
  267. upTxt=';数量不超过50个。'
  268. ref={ZupVideosRef}
  269. />
  270. </div>
  271. </div>
  272. <div className='A1aRowAll'>
  273. <Form.Item label='场景链接' name='link'>
  274. <TextArea maxLength={500} showCount placeholder='请输入内容' />
  275. </Form.Item>
  276. </div>
  277. <div className='A1aRowAll'>
  278. <Form.Item label='备注' name='remark'>
  279. <TextArea maxLength={500} showCount placeholder='请输入内容' />
  280. </Form.Item>
  281. </div>
  282. {/* 确定和取消按钮 */}
  283. <Form.Item className='A1aBtn'>
  284. <Button type='primary' htmlType='submit'>
  285. 提交
  286. </Button>
  287. <br />
  288. <br />
  289. <MyPopconfirm txtK='取消' onConfirm={closeFu} />
  290. </Form.Item>
  291. </Form>
  292. </div>
  293. </div>
  294. </div>
  295. {/* 番号管理 */}
  296. {numShow ? (
  297. <A1num
  298. AcId={fanHaoRef.current}
  299. closeFu={() => setNumShow(false)}
  300. upNumList={() => dispatch(A1_APIgetNumList())}
  301. />
  302. ) : null}
  303. </div>
  304. )
  305. }
  306. const MemoA1add = React.memo(A1add)
  307. export default MemoA1add