知与行后台管理端

helpRecord.jsx 14KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502
  1. import React, { useState, useEffect } from 'react';
  2. import { Form, Icon, Input, Button, DatePicker, Select, Card, Row, Col, Pagination, Alert, Table, Avatar, Radio, Modal, Descriptions, message } from 'antd';
  3. import moment from 'moment';
  4. import request from '../../../utils/request';
  5. import apis from '../../../services/apis';
  6. import router from 'umi/router';
  7. import BuildSelect from '../../../components/SelectButton/BuildSelect'
  8. import AuthButton from '@/components/AuthButton';
  9. const { Option } = Select;
  10. // eslint-disable-next-line @typescript-eslint/no-unused-vars
  11. const { Meta } = Card;
  12. /**
  13. * 助力者弹框
  14. */
  15. class InviteTable extends React.Component {
  16. constructor(props) {
  17. super(props);
  18. this.state = {
  19. dataSource: { records: [] },
  20. visibleData: { visible: false, customerId: '', realtyConsultant: '' },
  21. }
  22. }
  23. // 挂载之后
  24. componentDidMount () {
  25. const { customerId } = this.state.visibleData
  26. this.getList({ helpRecordInitiateId: customerId, pageNumber: 1, pageSize: 5 })
  27. }
  28. componentDidUpdate (preProps, preState) {
  29. const { customerId } = this.state.visibleData
  30. if (this.props.visibleData.customerId !== preState.visibleData.customerId) {
  31. this.getList({ helpRecordInitiateId: customerId, pageNumber: 1, pageSize: 5 })
  32. this.setState({ visibleData: this.props.visibleData });
  33. }
  34. }
  35. // 弹框确定按钮
  36. // eslint-disable-next-line react/sort-comp
  37. handleOk () {
  38. this.setState({ visibleData: { visible: false, customerId: '', realtyConsultant: '' } })
  39. }
  40. // 弹框取消按钮
  41. handleCancel () {
  42. this.setState({ visibleData: { visible: false, customerId: '', realtyConsultant: '' } })
  43. }
  44. getList (params) {
  45. request({ ...apis.helpActivity.helpPeopleDetails, params: { ...params } }).then(res => {
  46. this.setState({ dataSource: res })
  47. }).catch(err => {
  48. // eslint-disable-next-line no-unused-expressions
  49. <Alert
  50. style={{
  51. marginBottom: 24,
  52. }}
  53. message={err}
  54. type="error"
  55. showIcon
  56. />
  57. })
  58. }
  59. // 分页
  60. onChange (pageNum) {
  61. this.getList({ pageNumber: pageNum, pageSize: 5 })
  62. }
  63. render () {
  64. const columns = [
  65. {
  66. title: '用户姓名',
  67. dataIndex: 'name',
  68. key: 'name',
  69. align: 'center',
  70. },
  71. {
  72. title: '手机号',
  73. dataIndex: 'phone',
  74. key: 'phone',
  75. align: 'center',
  76. render: text => <a>{text}</a>,
  77. },
  78. {
  79. title: '助力时间',
  80. dataIndex: 'createDate',
  81. key: 'createDate',
  82. align: 'center',
  83. },
  84. ]
  85. return (
  86. <>
  87. <Modal
  88. title="助力者"
  89. destroyOnClose="true"
  90. width={900}
  91. footer={null}
  92. visible={this.state.visibleData.visible}
  93. // onOk={() => this.handleOk()}
  94. onCancel={(e) => this.handleCancel(e)}
  95. >
  96. <Table rowKey="independent" dataSource={this.state.dataSource.records} columns={columns} pagination={{ total: this.state.dataSource.total, onChange: e => this.onChange(e) }} />
  97. </Modal>
  98. </>
  99. );
  100. }
  101. }
  102. /**
  103. * 助力者弹框
  104. */
  105. class Verifier extends React.Component {
  106. constructor(props) {
  107. super(props);
  108. this.state = {
  109. verification: { verificationCode: '' },
  110. visibleData: { visible: false, customerId: '', realtyConsultant: '', helpRecordInitiateId: '', verificationCode: '' },
  111. }
  112. }
  113. // 挂载之后
  114. componentDidMount () {
  115. const { customerId } = this.state.visibleData
  116. }
  117. componentDidUpdate (preProps, preState) {
  118. const { customerId } = this.state.visibleData
  119. if (this.props.visibleData.customerId !== preState.visibleData.customerId) {
  120. this.setState({ visibleData: { visible: this.props.visibleData.visible, customerId: this.props.visibleData.customerId, verificationCode: '' } })
  121. }
  122. }
  123. // 弹框确定按钮
  124. // eslint-disable-next-line react/sort-comp
  125. handleOk () {
  126. this.setState({ visibleData: { visible: false, customerId: '', realtyConsultant: '' } })
  127. }
  128. // 弹框取消按钮
  129. handleCancel () {
  130. this.setState({ visibleData: { visible: false, customerId: '', realtyConsultant: '' } })
  131. }
  132. // eslint-disable-next-line class-methods-use-this
  133. getList (params) {
  134. request({ ...apis.helpActivity.verification, params: { ...params } }).then(res => {
  135. // eslint-disable-next-line no-undef
  136. message.info('核销成功')
  137. }).catch(err => {
  138. // eslint-disable-next-line no-unused-expressions
  139. <Alert
  140. style={{
  141. marginBottom: 24,
  142. }}
  143. message={err}
  144. type="error"
  145. showIcon
  146. />
  147. })
  148. }
  149. // eslint-disable-next-line class-methods-use-this
  150. verify(e) {
  151. this.setState({ visibleData: { visible: true, customerId: this.props.visibleData.customerId, verificationCode: e.target.value } })
  152. }
  153. // eslint-disable-next-line class-methods-use-this
  154. verification(e) {
  155. this.getList({ helpRecordInitiateId: this.state.visibleData.customerId, verifyCode: this.state.visibleData.verificationCode })
  156. }
  157. render () {
  158. return (
  159. <>
  160. <Modal
  161. title="核销"
  162. destroyOnClose="true"
  163. width={300}
  164. footer={null}
  165. visible={this.state.visibleData.visible}
  166. // onOk={() => this.handleOk()}
  167. onCancel={(e) => this.handleCancel(e)}
  168. >
  169. <div><span>核销码:<input onChange={this.verify.bind(this)}/></span>
  170. <Button onClick={(e) => this.verification(e)}>立即核销</Button>
  171. </div>
  172. </Modal>
  173. </>
  174. );
  175. }
  176. }
  177. /**
  178. *主体列表
  179. *
  180. * @param {*} props
  181. * @returns
  182. */
  183. function body(props) {
  184. const [gInviteData, setGInviteData] = useState({ visible: false, customerId: '', realtyConsultant: '' })
  185. const [gVerifierData, setVerifierData] = useState({ visible: false, customerId: '', realtyConsultant: '', helpRecordInitiateId: '' })
  186. const { getFieldDecorator, getFieldsValue } = props.form
  187. // eslint-disable-next-line react-hooks/rules-of-hooks
  188. const [dataSource, setDataSource] = useState({ records: [] })
  189. // eslint-disable-next-line react-hooks/rules-of-hooks
  190. // const [columns, setColumns] = useState(privateColumns)
  191. // 默认成功
  192. // eslint-disable-next-line react-hooks/rules-of-hooks
  193. const [customerType, setCustomerType] = useState('helpSucceed')
  194. // 调整归属 ============ start
  195. // eslint-disable-next-line react-hooks/rules-of-hooks
  196. const [gVisibleData, setGVisibleData] = useState({ visible: false, customerId: '', realtyConsultant: '' })
  197. // 变更状态 ============= end
  198. // eslint-disable-next-line react-hooks/rules-of-hooks
  199. const { helpActivityId } = props.location.query
  200. useEffect(() => {
  201. console.log('customerType', customerType)
  202. getList({ pageNumber: 1, pageSize: 10, status: customerType, helpActivityId })
  203. }, [])
  204. function getList(params) {
  205. // 网路请求
  206. request({ ...apis.helpActivity.record, params: { ...params } }).then(res => {
  207. setDataSource(res)
  208. }).catch(err => {
  209. // eslint-disable-next-line no-unused-expressions
  210. <Alert
  211. style={{
  212. marginBottom: 24,
  213. }}
  214. message={err}
  215. type="error"
  216. showIcon
  217. />
  218. })
  219. }
  220. function displayNone() {
  221. setGVisibleData({ visible: false, customerId: '', realtyConsultant: '' })
  222. }
  223. // 提交事件
  224. function handleSubmit(e) {
  225. displayNone()
  226. e.preventDefault();
  227. props.form.validateFields((err, values) => {
  228. if (!err) {
  229. getList({ pageNum: 1, pageSize: 10, customerType, ...values })
  230. }
  231. });
  232. }
  233. // Change 事件
  234. function handleSelectChange(e) {
  235. // eslint-disable-next-line no-console
  236. console.log(e)
  237. }
  238. // 分页
  239. function onChange(pageNum) {
  240. // eslint-disable-next-line react-hooks/rules-of-hooks
  241. getList({ pageNumber: pageNum, pageSize: 10, customerType })
  242. }
  243. // 助力成功/进行中/助力失败
  244. function radioButtonHandleSizeChange(e) {
  245. setGInviteData({ visible: false, customerId: '', realtyConsultant: '' })
  246. displayNone()
  247. const { value } = e.target
  248. setCustomerType(value)
  249. // setColumns(value === 'helpSucceed' ? privateColumns : publicColumns)
  250. getList({ pageNumber: 1, pageSize: 10, status: value, helpActivityId })
  251. }
  252. function handleReset() {
  253. props.form.resetFields();
  254. getList({ pageNumber: 1, pageSize: 10, customerType })
  255. }
  256. function toCustomerDateil(record) {
  257. router.push({
  258. pathname: '/customer/customerlist/customerDetail',
  259. query: {
  260. id: record.customerId,
  261. },
  262. });
  263. }
  264. function exportCustomer () {
  265. const fieldsValue = getFieldsValue()
  266. // request({ ...apis.helpActivity.HelpInitiateRecordSucceed, responseType: 'blob', params: { ...fieldsValue, customerType } })
  267. request({ ...apis.helpActivity.HelpInitiateRecordSucceed, responseType: 'blob', params: { helpActivityId: 6 } })
  268. .then(response => {
  269. download(response)
  270. }).catch(error => {
  271. })
  272. }
  273. function download (data) {
  274. if (!data) {
  275. return
  276. }
  277. const url = window.URL.createObjectURL(new Blob([data]))
  278. const link = document.createElement('a')
  279. link.style.display = 'none'
  280. link.href = url
  281. link.setAttribute('download', '客户列表.xlsx')
  282. document.body.append(link)
  283. link.click()
  284. }
  285. // 助力记录弹框
  286. function helpRecord(row) {
  287. // 关闭核销
  288. console.log('gInviteData', gInviteData)
  289. setGInviteData({ visible: true, customerId: row.helpRecordInitiateId, realtyConsultant: row.realtyConsultant })
  290. setVerifierData({ visible: false, customerId: row.helpRecordInitiateId, realtyConsultant: row.realtyConsultant })
  291. }
  292. // 核销
  293. function helpInitiateRecordVerify(row) {
  294. console.log('gVerifierData', gVerifierData)
  295. // 关闭助力记录弹框
  296. setGInviteData({ visible: false, customerId: row.helpRecordInitiateId, realtyConsultant: row.realtyConsultant })
  297. setVerifierData({ visible: true, customerId: row.helpRecordInitiateId, realtyConsultant: row.realtyConsultant })
  298. }
  299. const publicColumns = [
  300. {
  301. title: '发起者',
  302. dataIndex: 'name',
  303. key: 'name',
  304. align: 'center',
  305. width: '15%',
  306. },
  307. {
  308. title: '发起者手机号',
  309. dataIndex: 'phone',
  310. key: 'phone',
  311. align: 'center',
  312. width: '10%',
  313. },
  314. {
  315. title: '发起时间',
  316. dataIndex: 'createDate',
  317. key: 'createDate',
  318. align: 'center',
  319. width: '15%',
  320. },
  321. {
  322. title: '助力者',
  323. dataIndex: 'helpCount',
  324. key: 'helpCount',
  325. align: 'center',
  326. width: '15%',
  327. render: (text, record) => <a style={ { color: '#66B3FF' } } onClick={() => helpRecord(record)}>{record.helpCount}/{record.persionNumCount}</a>,
  328. },
  329. ]
  330. const privateColumns = [
  331. {
  332. title: '发起者',
  333. dataIndex: 'name',
  334. key: 'name',
  335. align: 'center',
  336. width: '15%',
  337. // render: (_, record) => <Avatar shape="square" src={customerType === 'helpSucceed' ? record.picture : record.avatarurl} size={64} icon="user" />,
  338. },
  339. {
  340. title: '手机号',
  341. dataIndex: 'phone',
  342. key: 'phone',
  343. align: 'center',
  344. width: '10%',
  345. // eslint-disable-next-line no-nested-ternary
  346. // render: (_, record) => <><span>{customerType === 'helpSucceed' ? record.name : record.nickname}</span></>,
  347. },
  348. {
  349. title: '发起时间',
  350. dataIndex: 'createDate',
  351. key: 'createDate',
  352. align: 'center',
  353. width: '10%',
  354. // eslint-disable-next-line no-nested-ternary
  355. },
  356. {
  357. title: '助力者',
  358. dataIndex: 'helpCount',
  359. key: 'helpCount',
  360. align: 'center',
  361. width: '15%',
  362. render: (text, record) => <a style={ { color: '#66B3FF' } } onClick={() => helpRecord(record)}>{record.helpCount}人</a>,
  363. },
  364. {
  365. title: '核销状态',
  366. dataIndex: 'reportRecommendStatus',
  367. key: 'reportRecommendStatus',
  368. align: 'center',
  369. width: '10%',
  370. // eslint-disable-next-line no-nested-ternary
  371. render: (text, records) => {
  372. if (records.verificationStatus === 0) { return '未核销' }
  373. if (records.verificationStatus === 1) { return '已核销' }
  374. },
  375. },
  376. {
  377. title: '操作',
  378. dataIndex: 'customerId',
  379. key: 'customerId',
  380. align: 'center',
  381. width: '25%',
  382. render: (x, row) => (
  383. <>
  384. {row.verificationStatus === 0 &&
  385. <AuthButton name="admin.SignList.get" noRight={null}>
  386. <span style={{ color: '#1990FF', cursor: 'pointer' }} onClick={() => helpInitiateRecordVerify(row)}>核销</span>
  387. </AuthButton>
  388. }
  389. </>
  390. ),
  391. },
  392. ]
  393. return (
  394. <>
  395. {console.log('customerType', customerType)}
  396. <Form layout="inline" onSubmit={e => handleSubmit(e, props)}>
  397. <Form.Item>
  398. {getFieldDecorator('tel')(
  399. <Input
  400. prefix={<Icon type="text" style={{ color: 'rgba(0,0,0,.25)' }} />}
  401. placeholder="电话"
  402. />,
  403. )}
  404. </Form.Item>
  405. <Form.Item>
  406. <Button type="primary" htmlType="submit" >
  407. 查询
  408. </Button>
  409. <Button style={{ marginLeft: 8 }} onClick={handleReset}>
  410. 重置
  411. </Button>
  412. <Button style={{ marginLeft: 8 }} onClick={handleReset}>
  413. 返回
  414. </Button>
  415. </Form.Item>
  416. </Form>
  417. <Button type="primary" onClick={() => exportCustomer()} style={{ float: 'right', margin: '20px 0', zIndex: 1 }}>
  418. 导出
  419. </Button>
  420. <div style={{ margin: '20px 0' }}>
  421. <AuthButton name="admin.customer.recommend.get" noRight={null}>
  422. <Radio.Group value={customerType} onChange={radioButtonHandleSizeChange} buttonStyle="solid">
  423. <Radio.Button value="helpSucceed">助力成功</Radio.Button>
  424. <Radio.Button value="helpUnderway">进行中</Radio.Button>
  425. <Radio.Button value="helpUnfinished">助力失败</Radio.Button>
  426. </Radio.Group>
  427. </AuthButton>
  428. </div>
  429. {customerType === 'helpSucceed' ?
  430. <Table dataSource={dataSource.list} columns={privateColumns} pagination={{ total: dataSource.total, onChange }} rowKey="customerList" /> :
  431. <Table dataSource={dataSource.list} columns={publicColumns} pagination={{ total: dataSource.total, onChange }} rowKey="customerList" />
  432. }
  433. <InviteTable visibleData={gInviteData} />
  434. <Verifier visibleData={gVerifierData} />
  435. </>
  436. );
  437. }
  438. const WrappedBody = Form.create({ name: 'body' })(body);
  439. export default WrappedBody