ConsumeOrder.jsx 9.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252
  1. import React, { useState, useEffect } from 'react';
  2. import { PageHeaderWrapper } from '@ant-design/pro-layout';
  3. import { Form, Pagination, Button, Icon, message, Modal, Table, Select, Input, DatePicker } from 'antd';
  4. import router from 'umi/router';
  5. import moment from 'moment';
  6. import className from 'classnames';
  7. import Cell from '../../components/Cell';
  8. import styles from './style.less';
  9. import { fetch, apis } from '../../utils/request';
  10. import request from '../../utils/request';
  11. import AuthButton from '@/components/AuthButton';
  12. import { regFenToYuan } from '@/utils/money';
  13. const { MonthPicker, RangePicker, WeekPicker } = DatePicker;
  14. function header(props) {
  15. // 获取初始化数据
  16. const [data, setData] = useState({})
  17. const [visible, setVisible] = useState(false)
  18. const [demandIdList, setDemandIdList] = useState([])
  19. const [personInfo, setPersonInfo] = useState({})
  20. const orgId = props.orgId || ''
  21. useEffect(() => {
  22. getList({ pageNum: 1, pageSize: 10, orderType: 'RedPacket' });
  23. }, [])
  24. // 查询列表
  25. const getList = (params) => {
  26. request({ ...apis.fund.taOrgOrder, params: { ...params, orgId } }).then((data) => {
  27. console.log(data)
  28. setData(data)
  29. })
  30. }
  31. // 提交事件
  32. const handleSubmit = (e, props) => {
  33. e.preventDefault();
  34. props.form.validateFields((err, values) => {
  35. if (!err) {
  36. let { LocalDate, ...submitValue } = values
  37. if (null != LocalDate && LocalDate.length > 0) {
  38. const [startDate, endDate] = LocalDate
  39. submitValue.startDate = `${moment(startDate).format('YYYY-MM-DDT00:00:00')}Z`;
  40. submitValue.endDate = `${moment(endDate).format('YYYY-MM-DDT23:59:59')}Z`;
  41. } else {
  42. submitValue.startDate = null
  43. submitValue.endDate = null
  44. }
  45. getList({ pageNum: 1, pageSize: 10, orderType: 'RedPacket', ...submitValue })
  46. }
  47. });
  48. }
  49. const changePageNum = (pageNumber) => {
  50. let { LocalDate, ...submitValue } = props.form.getFieldsValue()
  51. if (null != LocalDate && LocalDate.length > 0) {
  52. const [startDate, endDate] = LocalDate
  53. submitValue.startDate = `${moment(startDate).format('YYYY-MM-DDT00:00:00')}Z`;
  54. submitValue.endDate = `${moment(endDate).format('YYYY-MM-DDT23:59:59')}Z`;
  55. } else {
  56. submitValue.startDate = null
  57. submitValue.endDate = null
  58. }
  59. getList({ pageNum: pageNumber, pageSize: 10, orderType: 'RedPacket', ...submitValue })
  60. }
  61. /**
  62. *
  63. * @param {*} props
  64. * @returns
  65. */
  66. const columns = [
  67. {
  68. title: '订单编号',
  69. dataIndex: 'tradeNo',
  70. key: 'tradeNo',
  71. align: 'center',
  72. },
  73. {
  74. title: '消费组织',
  75. dataIndex: 'miniAppName',
  76. key: 'miniAppName',
  77. align: 'center',
  78. },
  79. {
  80. title: '消费金额',
  81. dataIndex: 'amount',
  82. key: 'amount',
  83. align: 'center',
  84. render: (x, row) => <span>{regFenToYuan(x)}</span>
  85. },
  86. {
  87. title: '消费方式',
  88. dataIndex: 'consumeType',
  89. key: 'consumeType',
  90. align: 'center',
  91. render: (x, row) => <><span>{row.consumeType == 'RedPacket' ? '红包' : ''}</span></>
  92. },
  93. {
  94. title: '活动名称',
  95. dataIndex: 'activityName',
  96. key: 'activityName',
  97. align: 'center',
  98. },
  99. {
  100. title: '消费下单时间',
  101. dataIndex: 'createDate',
  102. key: 'createDate',
  103. align: 'center',
  104. render: (x, row) => <><span>{`${moment(row.createDate).format('YYYY-MM-DD HH:mm:ss')}`}</span></>,
  105. },
  106. {
  107. title: '接收人手机号',
  108. dataIndex: 'phone',
  109. key: 'phone',
  110. align: 'center',
  111. render: (x, row) => <><span className={styles.blue} onClick={() => Info(row)}>{row.phone || '13160056114'}</span></>
  112. },
  113. {
  114. title: '消费状态',
  115. dataIndex: 'tradingStatus',
  116. key: 'tradingStatus',
  117. align: 'center',
  118. render: (x, row) => <><span>{row.tradingStatus == 'success' ? '成功' : '失败'}</span></>
  119. },
  120. ];
  121. const Info = (row) => {
  122. request({ ...apis.fund.receiveInfo, params: { phone: row.phone, orgId: row.orgId } }).then((data) => {
  123. setPersonInfo(data)
  124. setVisible(true)
  125. })
  126. }
  127. function handleReset() {
  128. props.form.resetFields();
  129. getList({ pageNum: 1, pageSize: 10, orderType: 'RedPacket' })
  130. }
  131. // 导出
  132. const exportList = () => {
  133. let { LocalDate, ...submitValue } = props.form.getFieldsValue()
  134. if (null != LocalDate && LocalDate.length > 0) {
  135. const [startDate, endDate] = LocalDate
  136. submitValue.startDate = `${moment(startDate).format('YYYY-MM-DDT00:00:00')}Z`;
  137. submitValue.endDate = `${moment(endDate).format('YYYY-MM-DDT23:59:59')}Z`;
  138. } else {
  139. submitValue.startDate = null
  140. submitValue.endDate = null
  141. }
  142. request({ ...apis.fund.consumeOrderExport, params: { orderType: 'RedPacket', orgId, ...submitValue } }).then(data => {
  143. if (!data) {
  144. return
  145. }
  146. const url = window.URL.createObjectURL(new Blob([data]))
  147. const link = document.createElement('a')
  148. link.style.display = 'none'
  149. link.href = url
  150. link.setAttribute('download', '消费订单表.xlsx')
  151. document.body.append(link)
  152. link.click()
  153. }).catch()
  154. }
  155. const { getFieldDecorator } = props.form
  156. return (
  157. <>
  158. <Modal
  159. visible={visible}
  160. title="接收人消息"
  161. onCancel={() => setVisible(false)}
  162. footer={null}
  163. >
  164. <div style={{ paddingLeft: '36%' }}>
  165. <p>昵称:{personInfo.nickname || ''}</p>
  166. <p>头像:<img src={personInfo.avatarurl || ''} className={styles.touxiang} /></p>
  167. <p>姓名:{personInfo.name || personInfo.nickname}</p>
  168. <p>手机号:{personInfo.phone || ''}</p>
  169. </div>
  170. </Modal>
  171. <Form layout="inline" onSubmit={e => handleSubmit(e, props)} style={{ marginBottom: '16px' }}>
  172. <Form.Item>
  173. {getFieldDecorator('tradeNo')(
  174. <Input
  175. prefix={<Icon type="text" style={{ color: 'rgba(0,0,0,.25)' }} />}
  176. placeholder="订单编号"
  177. />,
  178. )}
  179. </Form.Item>
  180. <Form.Item>
  181. {getFieldDecorator('miniAppName')(
  182. <Input
  183. prefix={<Icon type="text" style={{ color: 'rgba(0,0,0,.25)' }} />}
  184. placeholder="消费组织"
  185. />,
  186. )}
  187. </Form.Item>
  188. <Form.Item>
  189. <span style={{ marginRight: '10px' }}>消费时间段:</span>
  190. {getFieldDecorator('LocalDate')(
  191. <RangePicker placeholder={['开始时间', '结束时间']} />
  192. )}
  193. </Form.Item>
  194. <Form.Item>
  195. {getFieldDecorator('itemType')(
  196. <Select style={{ width: '180px' }} placeholder="消费方式">
  197. <Select.Option value="">全部</Select.Option>
  198. <Select.Option value="RedPacket">红包</Select.Option>
  199. </Select>,
  200. )}
  201. </Form.Item>
  202. <Form.Item>
  203. {getFieldDecorator('tradingStatus')(
  204. <Select style={{ width: '180px' }} placeholder="消费状态">
  205. <Select.Option value="">全部</Select.Option>
  206. <Select.Option value="success">成功</Select.Option>
  207. <Select.Option value="fail">失败</Select.Option>
  208. </Select>,
  209. )}
  210. </Form.Item>
  211. <Form.Item>
  212. {getFieldDecorator('receivePhone')(
  213. <Input
  214. prefix={<Icon type="text" style={{ color: 'rgba(0,0,0,.25)' }} />}
  215. placeholder="接收人手机号"
  216. />,
  217. )}
  218. </Form.Item>
  219. <Form.Item>
  220. <Button type="primary" htmlType="submit" className={styles.searchBtn}>
  221. 搜索
  222. </Button>
  223. <Button style={{ marginLeft: 8 }} onClick={handleReset}>
  224. 重置
  225. </Button>
  226. </Form.Item>
  227. </Form>
  228. <div>
  229. <Button type="danger" style={{ float: 'right', marginBottom: '20px', zIndex: 1 }} onClick={() => exportList()} >导出</Button>
  230. </div>
  231. <Table rowKey={r => r.tradeNo} dataSource={data.records} columns={columns} pagination={false} />
  232. <div style={{ display: 'flex', justifyContent: 'flex-end', marginTop: '30px' }}>
  233. <Pagination showQuickJumper defaultCurrent={1} total={data.total} onChange={changePageNum} current={data.current} />
  234. </div>
  235. </>
  236. )
  237. }
  238. const WrappedHeader = Form.create({ name: 'header' })(header);
  239. export default WrappedHeader