知与行后台管理端

helpRecord.jsx 16KB

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