index.tsx 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384
  1. import React, { useCallback, useEffect, useMemo, useRef, useState } from 'react'
  2. import styles from './index.module.scss'
  3. import { A1addType } from '@/pages/A1Camera/data'
  4. import { Button, DatePicker, Form, FormInstance, Input, Select, Table, Tag, Tooltip } from 'antd'
  5. import { A2A_APIadd, A2A_APIgetInfo } from '@/store/action/A2Abusiness'
  6. import { MessageFu } from '@/utils/message'
  7. import ZRichTexts from '@/components/ZRichTexts'
  8. import Z3upFiles from '@/components/Z3upFiles'
  9. import MyPopconfirm from '@/components/MyPopconfirm'
  10. import { mapDataAll3 } from '@/pages/C1User/AddUser/city'
  11. import UpXlsx from '@/components/UpXlsx'
  12. import AddCamera from '@/pages/A1Camera/AddCamera'
  13. import dayjs from 'dayjs'
  14. import { TopTypeType } from '../data'
  15. type Props = {
  16. topType: TopTypeType
  17. openInfo: A1addType
  18. closeFu: () => void
  19. upTableFu: () => void
  20. addTableFu: () => void
  21. }
  22. export type TableListType = {
  23. cameraSn: string
  24. cameraType: string
  25. remark: string
  26. id: number
  27. idxx: string
  28. }
  29. function AddBusiness({ topType, openInfo, closeFu, upTableFu, addTableFu }: Props) {
  30. // 表格数据
  31. const [tableList, setTableList] = useState<TableListType[]>([])
  32. // 点击表格里面新增的数据
  33. const [tableAdd, setTableAdd] = useState<A1addType>({ id: 0, txt: '' })
  34. const getListFu = useCallback(
  35. (info: any) => {
  36. const arr = info.camera || []
  37. setTableList([...arr, ...tableList])
  38. },
  39. [tableList]
  40. )
  41. // 表格点击删除
  42. const delTableFu = useCallback(
  43. (idxx: string) => {
  44. setTableList(tableList.filter(v => v.idxx !== idxx))
  45. },
  46. [tableList]
  47. )
  48. const columns = useMemo(() => {
  49. return [
  50. {
  51. title: '相机类型',
  52. render: (item: TableListType) =>
  53. item.cameraType ? (item.cameraType === 'KK' ? '看看' : '看见') : '(空)'
  54. },
  55. {
  56. title: 'SN码',
  57. render: (item: TableListType) => (
  58. <>
  59. {item.cameraSn}
  60. {item.id ? (
  61. ''
  62. ) : (
  63. <Tooltip title='此SN编码未录入在相机列表中'>
  64. &nbsp;
  65. <Tag>new</Tag>
  66. </Tooltip>
  67. )}
  68. </>
  69. )
  70. },
  71. {
  72. title: '备注',
  73. render: (item: TableListType) => item.remark || '(空)'
  74. },
  75. {
  76. title: '操作',
  77. render: (item: TableListType) => (
  78. <MyPopconfirm txtK='删除' onConfirm={() => delTableFu(item.idxx)} />
  79. )
  80. }
  81. ]
  82. }, [delTableFu])
  83. // 表单的ref
  84. const FormBoxRef = useRef<FormInstance>(null)
  85. // 通过id获取详情
  86. const getInfoFu = useCallback(async (id: number) => {
  87. const res = await A2A_APIgetInfo(id)
  88. if (res.code === 0) {
  89. const data = res.data
  90. // 回显 合同附件
  91. listFilesRef.current.sonFilesShowFu(data.files)
  92. // 设置富文本
  93. ZRichTextsRef1.current?.ritxtShowFu(JSON.parse(data.rtf))
  94. // 回显表格
  95. setTableList(
  96. data.cameras.map((v: any) => ({
  97. ...v,
  98. idxx: v.id
  99. }))
  100. )
  101. const obj = {
  102. ...data,
  103. city: data.zlProvince + '-' + data.zlCity,
  104. dateStart: dayjs(data.dateStart),
  105. dateEnd: data.dateEnd ? dayjs(data.dateEnd) : null
  106. }
  107. FormBoxRef.current?.setFieldsValue(obj)
  108. }
  109. }, [])
  110. // 拿来占位,不然会报错
  111. const onChange = useCallback((value: string) => {
  112. // console.log(`selected ${value}`)
  113. }, [])
  114. const onSearch = useCallback((value: string) => {
  115. // console.log(`search ${value}`)
  116. }, [])
  117. // 没有通过校验
  118. const onFinishFailed = useCallback(() => {}, [])
  119. // 通过校验点击确定
  120. const onFinish = useCallback(
  121. async (value: any) => {
  122. // 附件
  123. const listFilesRes = listFilesRef.current.sonFilesIdRes()
  124. // 日期处理
  125. const dateStart = dayjs(value.dateStart).format('YYYY-MM-DD')
  126. let dateEnd = ''
  127. if (value.dateEnd) dateEnd = dayjs(value.dateEnd).format('YYYY-MM-DD')
  128. // 城市处理
  129. const zlProvince = value.city.split('-')[0]
  130. const zlCity = value.city.split('-')[1]
  131. // 富文本
  132. const rtf = ZRichTextsRef1.current?.fatherBtnOkFu() || { flag: true }
  133. const obj = {
  134. ...value,
  135. id: openInfo.txt === '新增' ? null : openInfo.id,
  136. fileIds: listFilesRes.join(','),
  137. rtf: JSON.stringify(rtf.val || ''),
  138. cameras: tableList,
  139. dateStart,
  140. dateEnd,
  141. zlProvince,
  142. zlCity,
  143. type: topType
  144. }
  145. // if (1 + 1 === 2) {
  146. // console.log(obj)
  147. // return
  148. // }
  149. const res = await A2A_APIadd(obj)
  150. if (res.code === 0) {
  151. MessageFu.success(openInfo.txt + '成功!')
  152. openInfo.txt === '新增' ? addTableFu() : upTableFu()
  153. closeFu()
  154. }
  155. },
  156. [addTableFu, closeFu, openInfo.id, openInfo.txt, tableList, topType, upTableFu]
  157. )
  158. useEffect(() => {
  159. if (openInfo.txt === '新增') {
  160. } else getInfoFu(openInfo.id)
  161. }, [getInfoFu, openInfo])
  162. // 富文本的ref
  163. const ZRichTextsRef1 = useRef<any>(null)
  164. // 合同附件的ref
  165. const listFilesRef = useRef<any>(null)
  166. // 上传xlsx 的ref
  167. const upXlsxRef = useRef<any>(null)
  168. return (
  169. <div className={styles.AddBusiness}>
  170. <div className='A2AaddMain'>
  171. <Form
  172. scrollToFirstError={true}
  173. ref={FormBoxRef}
  174. // labelCol={{ span: 4 }}
  175. name='basicWai'
  176. onFinish={onFinish}
  177. onFinishFailed={onFinishFailed}
  178. autoComplete='off'
  179. >
  180. <div className='A2Atit'>订单信息</div>
  181. <Form.Item
  182. label='钉钉审批编号'
  183. name='dingNum'
  184. rules={[{ required: true, message: '请输入内容!' }]}
  185. getValueFromEvent={e => e.target.value.replace(/\s+/g, '')}
  186. >
  187. <Input maxLength={20} showCount placeholder='请输入内容' />
  188. </Form.Item>
  189. <div className='formBox formBox2'>
  190. <div className='formBoxLL'>合同附件:</div>
  191. <div className='formBoxRR'>
  192. <Z3upFiles
  193. max={5}
  194. accept='*'
  195. isLook={false}
  196. ref={listFilesRef}
  197. fileCheck={false}
  198. dirCode='A2business'
  199. myUrl='cms/order/upload'
  200. topType={topType}
  201. />
  202. </div>
  203. </div>
  204. <Form.Item
  205. label='租凭日期'
  206. name='dateStart'
  207. rules={[{ required: true, message: '请选择日期!' }]}
  208. >
  209. <DatePicker placeholder='请选择日期' />
  210. </Form.Item>
  211. <Form.Item label='预计归还日期' name='dateEnd'>
  212. <DatePicker placeholder='请选择日期' />
  213. </Form.Item>
  214. <div className='formBox'>
  215. <div className='formBoxLL'>备注:</div>
  216. <div className='formBoxRR'>
  217. <ZRichTexts
  218. check={false}
  219. dirCode='A2business'
  220. isLook={false}
  221. ref={ZRichTextsRef1}
  222. myUrl='cms/order/upload'
  223. topType={topType}
  224. />
  225. </div>
  226. </div>
  227. <div className='A2Atit'>租凭方信息</div>
  228. <Form.Item
  229. label='租赁方名称'
  230. name='zlName'
  231. rules={[{ required: true, message: '请输入内容!' }]}
  232. getValueFromEvent={e => e.target.value.replace(/\s+/g, '')}
  233. >
  234. <Input maxLength={20} showCount placeholder='请输入内容' />
  235. </Form.Item>
  236. <Form.Item
  237. label='城市:'
  238. name='city'
  239. rules={[{ required: true, message: '请选择城市!' }]}
  240. >
  241. <Select
  242. style={{ width: 400 }}
  243. showSearch
  244. placeholder='请选择城市'
  245. optionFilterProp='label'
  246. onChange={onChange}
  247. onSearch={onSearch}
  248. options={mapDataAll3}
  249. />
  250. </Form.Item>
  251. <Form.Item
  252. label='负责人'
  253. name='zlUser'
  254. rules={[{ required: true, message: '请输入内容!' }]}
  255. getValueFromEvent={e => e.target.value.replace(/\s+/g, '')}
  256. >
  257. <Input maxLength={20} showCount placeholder='请输入内容' />
  258. </Form.Item>
  259. <Form.Item
  260. label='联系方式'
  261. name='zlPhone'
  262. rules={[{ required: true, message: '请输入内容!' }]}
  263. getValueFromEvent={e => e.target.value.replace(/\s+/g, '')}
  264. >
  265. <Input maxLength={20} showCount placeholder='请输入内容' />
  266. </Form.Item>
  267. {/* 确定和取消按钮 */}
  268. <Form.Item className='A2AaddBtn'>
  269. <Button type='primary' htmlType='submit'>
  270. 提交
  271. </Button>
  272. <br />
  273. <br />
  274. <MyPopconfirm txtK='取消' onConfirm={closeFu} />
  275. </Form.Item>
  276. </Form>
  277. <div className='A2Atit A2Atit2'>
  278. <div>
  279. <div>相机清单</div>
  280. <div>
  281. <a href='/xlsx/相机列表导入模板.xlsx' download>
  282. <Button type='primary'>下载模块</Button>
  283. </a>
  284. <UpXlsx
  285. url='cms/order/upload/excel'
  286. ref={upXlsxRef}
  287. xlsxResInfoFu={info => getListFu(info)}
  288. />
  289. <Button type='primary' onClick={() => upXlsxRef.current?.myInputClickFu()}>
  290. 批量导入
  291. </Button>
  292. <Button
  293. type='primary'
  294. onClick={() => {
  295. if (tableList.length >= 200) return MessageFu.warning('最多支持200条数据!')
  296. setTableAdd({ id: -1, txt: '新增' })
  297. }}
  298. >
  299. 新增
  300. </Button>
  301. </div>
  302. </div>
  303. </div>
  304. {/* --------------表格-------------- */}
  305. <div className='tableListBox'>
  306. <Table
  307. size='small'
  308. dataSource={tableList}
  309. columns={columns}
  310. rowKey='idxx'
  311. pagination={false}
  312. />
  313. {/* 右下角的列表数量 */}
  314. <div className='tableNumBox'>
  315. 共 <span>{tableList.length}</span> 条数据
  316. </div>
  317. </div>
  318. </div>
  319. {/* 点击表格里面的新增 出来的页面 */}
  320. {tableAdd.id ? (
  321. <div className='A2AtableBoxAdd'>
  322. <div>
  323. <AddCamera
  324. isLoc={true}
  325. existSn={tableList.map(v => v.cameraSn)}
  326. openInfo={tableAdd}
  327. closeFu={() => setTableAdd({ id: 0, txt: '' })}
  328. upTableFu={() => {}}
  329. addTableFu={info => setTableList([info, ...tableList])}
  330. />
  331. </div>
  332. </div>
  333. ) : null}
  334. </div>
  335. )
  336. }
  337. const MemoAddBusiness = React.memo(AddBusiness)
  338. export default MemoAddBusiness