index.jsx 11KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385
  1. import React, { useRef, useState } from 'react'
  2. import moment from 'moment';
  3. import { history } from 'umi';
  4. import { DatePicker, Button, Modal, Table, message, Form, Input, Select } from 'antd';
  5. import { PageHeaderWrapper } from '@ant-design/pro-layout';
  6. import PageTable from '@/components/PageTable'
  7. import { getMakeList, getApplicationDetail, updateBindCard, updateMake, exportCardList } from '@/services/application'
  8. const { RangePicker } = DatePicker;
  9. const { Option } = Select;
  10. const formatterTime = (val) => {
  11. return val ? moment(val).format('YYYY-MM-DD HH:mm') : '';
  12. };
  13. const FormItem = Form.Item;
  14. export default (props) => {
  15. const actionRef = useRef();
  16. const [applyStart, setStart] = useState()
  17. const [applyEnd, setEnd] = useState()
  18. //选中的id列表
  19. const [selectedRowKeys, setSelectedRowKeys] = useState([])
  20. const [selectedRows, setSelectedRows] = useState([])
  21. const [application, setApplication] = useState();
  22. const formItemLayout = { labelCol: { span: 6 }, wrapperCol: { span: 14 } };
  23. //绑卡弹窗
  24. const [form] = Form.useForm();
  25. const [visible, setVisible] = useState(false);
  26. const [loading, setLoading] = useState(false);
  27. //发证弹窗
  28. const [outForm] = Form.useForm();
  29. const [outVisible, setOutVisible] = useState(false);
  30. const [outLoading, setOutLoading] = useState(false);
  31. const goDetail = (id) => {
  32. history.push(`certificateIssuance/issuance.jsx?id=${id}`);
  33. }
  34. const handelApplyDateChange = (date, dateStrings) => {
  35. setStart(dateStrings[0])
  36. setEnd(dateStrings[1])
  37. }
  38. const handleReset = () => {
  39. setStart()
  40. setEnd()
  41. }
  42. const handleExport = () => {
  43. // console.log(selectedRows);
  44. const cardNoList = selectedRows.map(item => item.originCardNo)
  45. if (cardNoList.some(item => item == null)) {
  46. message.info('您选中的犬证有未绑卡数据,请先绑卡再导出数据')
  47. } else {
  48. exportCardList({ cardNoList: cardNoList }).then((res) => {
  49. message.success('导出' + cardNoList.length + '条数据');
  50. })
  51. }
  52. // setSelectedRows([])
  53. // setSelectedRowKeys([])
  54. }
  55. //绑卡弹窗
  56. const bindCard = (val) => {
  57. setLoading(true)
  58. updateBindCard(
  59. application.applyId,
  60. { cardNo: val.originCardNo }
  61. ).then((res) => {
  62. message.success('绑卡成功')
  63. handleBindCancel();
  64. actionRef.current.reload()
  65. setLoading(false)
  66. }).catch(err => {
  67. setLoading(false)
  68. console.log(err.message)
  69. })
  70. }
  71. const handleBindShow = (id) => {
  72. getApplicationDetail(id).then((res) => {
  73. form.setFieldsValue(res);
  74. setApplication(res)
  75. setVisible(true)
  76. }).catch((err) => {
  77. console.log(err.message)
  78. });
  79. }
  80. const handleBindCancel = () => {
  81. setVisible(false)
  82. setTimeout(() => {
  83. setApplication();
  84. form.resetFields()
  85. }, 100);
  86. }
  87. //发证弹窗
  88. const outCard = (val) => {
  89. setOutLoading(true)
  90. updateMake(application.applyId, {
  91. makeStatus: application.makeStatus,
  92. trackingType: val.trackingType,
  93. trackingNo: val.trackingNo
  94. }).then((res) => {
  95. message.success('发证成功')
  96. handleOutCancel();
  97. actionRef.current.reload()
  98. setOutLoading(false)
  99. }).catch((err) => {
  100. console.log(err.message)
  101. setOutLoading(false)
  102. })
  103. }
  104. const handleOutShow = (id) => {
  105. getApplicationDetail(id).then((res) => {
  106. outForm.setFieldsValue(res);
  107. setApplication(res)
  108. setOutVisible(true)
  109. }).catch((err) => {
  110. console.log(err.message)
  111. });
  112. }
  113. const handleOutCancel = () => {
  114. setOutVisible(false)
  115. setTimeout(() => {
  116. setApplication();
  117. outForm.resetFields()
  118. }, 100);
  119. }
  120. const columns = [
  121. {
  122. title: '证件号',
  123. dataIndex: 'originCardNo',
  124. key: 'originCardNo',
  125. search: true,
  126. },
  127. {
  128. title: '犬主',
  129. dataIndex: 'personName',
  130. key: 'personName',
  131. search: true,
  132. },
  133. {
  134. title: '是否企业',
  135. dataIndex: 'isOrg',
  136. key: 'isOrg',
  137. search: true,
  138. hideInTable: true,
  139. render: (_, record) => {
  140. return record.isOrg
  141. ? '企业' : '个人'
  142. },
  143. valueType: 'select',
  144. valueEnum: {
  145. true: { text: '企业' },
  146. false: { text: '个人' },
  147. },
  148. },
  149. {
  150. title: '企业名称',
  151. dataIndex: 'orgName',
  152. key: 'orgName',
  153. search: true,
  154. },
  155. {
  156. title: '手机号',
  157. dataIndex: 'phone',
  158. key: 'phone',
  159. search: true,
  160. },
  161. {
  162. title: '犬名',
  163. dataIndex: 'petName',
  164. key: 'petName',
  165. search: false,
  166. },
  167. {
  168. title: '申领方式',
  169. dataIndex: 'applyMethod',
  170. key: 'applyMethod',
  171. search: true,
  172. render: (_, record) => {
  173. return record.applyMethod === 1
  174. ? '上门自取'
  175. : record.applyMethod === 2
  176. ? '快递到家' : ''
  177. },
  178. valueType: 'select',
  179. valueEnum: {
  180. 1: { text: '上门自取' },
  181. 2: { text: '快递到家' },
  182. },
  183. },
  184. {
  185. title: '申请时间',
  186. dataIndex: 'createDate',
  187. key: 'createDate',
  188. width: 160,
  189. render: (t) => formatterTime(t),
  190. renderFormItem: (_, record) => <RangePicker placeholder={['开始日期', '结束日期']} format='YYYY-MM-DD' onChange={handelApplyDateChange} />
  191. },
  192. {
  193. title: '制证状态',
  194. dataIndex: 'status',
  195. key: 'status',
  196. render: (_, record) => {
  197. return record.status === 2
  198. ? '待发放'
  199. : record.status === 3
  200. ? '已发放' : ''
  201. },
  202. valueType: 'select',
  203. valueEnum: {
  204. 2: { text: '待发放' },
  205. 3: { text: '已发放' },
  206. },
  207. },
  208. {
  209. title: '发放人',
  210. dataIndex: 'makeUserName',
  211. key: 'makeUserName',
  212. search: false,
  213. },
  214. {
  215. title: '发放时间',
  216. dataIndex: 'makeDate',
  217. width: 160,
  218. key: 'makeDate',
  219. render: (t) => t != '-' ? formatterTime(t) : '-',
  220. search: false
  221. },
  222. {
  223. title: '操作',
  224. valueType: 'option',
  225. width: 160,
  226. render: (_, record) => [
  227. <Button key={1} style={{ padding: 0 }} type="link"
  228. onClick={() => handleBindShow(record.applyId)}
  229. >绑卡</Button>,
  230. <Button key={2} style={{ padding: 0 }} type="link"
  231. onClick={() => handleOutShow(record.applyId)}
  232. >发证
  233. </Button>,
  234. <Button key={3} style={{ padding: 0 }} type="link"
  235. onClick={() => goDetail(record.applyId)}
  236. >详情</Button>
  237. ],
  238. },
  239. ]
  240. return (
  241. <PageHeaderWrapper>
  242. <PageTable
  243. rowSelection={{
  244. selectedRowKeys,
  245. selections: [Table.SELECTION_ALL, Table.SELECTION_INVERT],
  246. onChange: (selectedRowKeys, selectedRows) => {
  247. setSelectedRowKeys(selectedRowKeys);
  248. setSelectedRows(selectedRows)
  249. },
  250. }}
  251. tableAlertRender={({ selectedRowKeys, selectedRows, onCleanSelected }) => (
  252. <>
  253. 已选 {selectedRowKeys.length} 张犬证
  254. <a style={{ marginLeft: 8 }} onClick={onCleanSelected}>
  255. 取消选择
  256. </a>
  257. </>
  258. )}
  259. tableAlertOptionRender={() => {
  260. return (
  261. <Button style={{ padding: 0 }} type="link" onClick={handleExport}>导出制证</Button>
  262. );
  263. }}
  264. actionRef={actionRef}
  265. columns={columns}
  266. request={getMakeList}
  267. params={{ applyStart, applyEnd }}
  268. options={false}
  269. onReset={handleReset}
  270. rowKey="applyId"
  271. />
  272. <Modal
  273. forceRender
  274. title='犬证绑卡'
  275. visible={visible}
  276. onCancel={handleBindCancel}
  277. keyboard={false}
  278. maskClosable={false}
  279. destroyOnClose={true}
  280. footer={null}
  281. >
  282. <Form {...formItemLayout} onFinish={bindCard} form={form}>
  283. <FormItem label="证件号" name="originCardNo" rules={[{ required: true, message: '请输入证件号' }]}>
  284. <Input placeholder="请输入证件号" readOnly={application?.originCardNo != null} />
  285. </FormItem>
  286. {
  287. !application?.originCardNo &&
  288. <FormItem label=" " colon={false}>
  289. <Button type="default" onClick={handleBindCancel}>
  290. 取消
  291. </Button>
  292. <Button
  293. type="primary"
  294. loading={loading}
  295. htmlType="Submit"
  296. style={{ marginLeft: '4em' }}
  297. >
  298. 确认
  299. </Button>
  300. </FormItem>
  301. }
  302. </Form>
  303. </Modal>
  304. <Modal
  305. forceRender
  306. title='犬证发放'
  307. visible={outVisible}
  308. onCancel={handleOutCancel}
  309. keyboard={false}
  310. maskClosable={false}
  311. destroyOnClose={true}
  312. footer={null}
  313. >
  314. <Form {...formItemLayout} onFinish={outCard} form={outForm}>
  315. <FormItem label="证件号" name='originCardNo' rules={[{ required: true, message: '请先绑卡再发证' }]}>
  316. <Input
  317. readOnly
  318. placeholder='请先绑卡再发证'
  319. />
  320. </FormItem>
  321. {
  322. application?.applyMethod == 2 && <>
  323. <FormItem label="快递公司" name='trackingType' rules={[{ required: true, message: '请选择快递公司' }]}>
  324. {
  325. application?.makeStatus == 0 ?
  326. <Select placeholder="请选择快递公司">
  327. <Option value={'中国邮政'}>中国邮政</Option>
  328. <Option value={'圆通快递'}>圆通快递</Option>
  329. <Option value={'中通快递'}>中通快递</Option>
  330. <Option value={'申通快递'}>申通快递</Option>
  331. <Option value={'韵达快递'}>韵达快递</Option>
  332. <Option value={'顺丰快递'}>顺丰快递</Option>
  333. <Option value={'京东快递'}>京东快递</Option>
  334. <Option value={'极兔快递'}>极兔快递</Option>
  335. <Option value={'百世快递'}>百世快递</Option>
  336. <Option value={'天天快递'}>天天快递</Option>
  337. </Select> :
  338. <Input
  339. readOnly={application?.makeStatus != 0}
  340. />
  341. }
  342. </FormItem>
  343. <FormItem label="快递单号" name='trackingNo' rules={[{ required: true, message: '请输入快递单号' }]}>
  344. <Input
  345. placeholder='请输入快递单号(必填)'
  346. readOnly={application?.makeStatus != 0}
  347. />
  348. </FormItem>
  349. </>
  350. }
  351. {
  352. application?.makeStatus == 0 &&
  353. <FormItem label=" " colon={false}>
  354. <Button type="default" onClick={handleOutCancel}>
  355. 取消
  356. </Button>
  357. <Button
  358. type="primary"
  359. loading={outLoading}
  360. htmlType="Submit"
  361. style={{ marginLeft: '4em' }}
  362. >
  363. 确认
  364. </Button>
  365. </FormItem>
  366. }
  367. </Form>
  368. </Modal>
  369. </PageHeaderWrapper>
  370. )
  371. }