知与行后台管理端

helpRecord.jsx 16KB

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