consultOrderList.jsx 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409
  1. import React from 'react';
  2. import { Icon, Button, Input, Select, Spin, Table, message, DatePicker, Modal, InputNumber, Radio } from 'antd';
  3. import ajax from 'jquery/src/ajax/xhr.js';
  4. import $ from 'jquery/src/ajax';
  5. import './content.less';
  6. import moment from 'moment';
  7. import { getTime } from '../../tools';
  8. const OrderList = React.createClass({
  9. loadData (pageNo) {
  10. this.state.data = [];
  11. this.setState({
  12. loading: true
  13. });
  14. $.ajax({
  15. method: "get",
  16. dataType: "json",
  17. crossDomain: false,
  18. url: globalConfig.context + "/api/admin/consultorder/list",
  19. data: {
  20. pageNo: pageNo || 1,
  21. pageSize: this.state.pagination.pageSize,
  22. number: this.state.searchNumber,
  23. toNumber: this.state.searchToNumber,
  24. id: this.state.searchId,
  25. paymentId: this.state.searchPaymentId,
  26. state: this.state.searchState
  27. },
  28. success: function (data) {
  29. if (!data.data || !data.data.list) {
  30. if (data.error && data.error.length) {
  31. message.warning(data.error[0].message);
  32. };
  33. } else {
  34. for (let i = 0; i < data.data.list.length; i++) {
  35. let thisdata = data.data.list[i];
  36. this.state.data.push({
  37. key: i,
  38. id: thisdata.id,
  39. price: thisdata.price,
  40. orderState: thisdata.orderState,
  41. orderTime: thisdata.orderTime,
  42. orderTimeFormatted: thisdata.orderTimeFormatted,
  43. userId: thisdata.userId,
  44. toUserId: thisdata.toUserId,
  45. nickname: thisdata.nickname,
  46. number: thisdata.number,
  47. toNickname: thisdata.toUsername || thisdata.toNickname,
  48. toNumber: thisdata.toNumber,
  49. paymentTime: thisdata.paymentTime,
  50. paymentTimeFormatted: thisdata.paymentTimeFormatted,
  51. paymentValue: thisdata.paymentValue,
  52. paymentType: thisdata.paymentType,
  53. paymentId: thisdata.paymentId,
  54. });
  55. };
  56. this.state.pagination.current = data.data.pNo;
  57. this.state.pagination.total = data.data.countWhere;
  58. };
  59. this.setState({
  60. dataSource: this.state.data,
  61. pagination: this.state.pagination
  62. });
  63. }.bind(this),
  64. }).always(function () {
  65. this.setState({
  66. loading: false
  67. });
  68. }.bind(this));
  69. },
  70. getInitialState () {
  71. return {
  72. searchMore: true,
  73. selectedRows: [],
  74. selectedRowKeys: [],
  75. data: [],
  76. modalData: {},
  77. visible: false,
  78. delVisible: false,
  79. searchTime: [],
  80. loading: false,
  81. pagination: {
  82. defaultCurrent: 1,
  83. defaultPageSize: 10,
  84. showQuickJumper: true,
  85. pageSize: 10,
  86. onChange: function (page) {
  87. this.loadData(page);
  88. }.bind(this),
  89. showTotal: function (total) {
  90. return '共' + total + '条数据';
  91. }
  92. },
  93. columns: [
  94. {
  95. title: '订单编号',
  96. dataIndex: 'id',
  97. key: 'id',
  98. }, {
  99. title: '用户编号',
  100. dataIndex: 'number',
  101. key: 'number',
  102. }, {
  103. title: '用户名称',
  104. dataIndex: 'nickname',
  105. key: 'nickname'
  106. }, {
  107. title: '专家编号',
  108. dataIndex: 'toNumber',
  109. key: 'toNumber',
  110. }, {
  111. title: '专家名称',
  112. dataIndex: 'toNickname',
  113. key: 'toNickname'
  114. }, {
  115. title: '订单状态',
  116. dataIndex: 'orderState',
  117. key: 'orderState',
  118. render: (text, record) => {
  119. if (text == 1) {
  120. return '已支付'
  121. } else if (text == 9) {
  122. return '已取消'
  123. } else if (text == 2) {
  124. return '支付中'
  125. } else {
  126. let now = new Date();
  127. let endTime = new Date(record.orderTime + 24 * 60 * 60 * 1000 * 15)
  128. if (now > endTime) {
  129. return '已失效'
  130. } else {
  131. return '未支付'
  132. }
  133. }
  134. }
  135. }, {
  136. title: '生成时间',
  137. dataIndex: 'orderTimeFormatted',
  138. key: 'orderTimeFormatted',
  139. }, {
  140. title: '支付金额',
  141. dataIndex: 'price',
  142. key: 'price',
  143. render: (index, record) => {
  144. if (record.paymentValue && record.paymentValue != 0) {
  145. return record.paymentValue
  146. } else {
  147. return index
  148. }
  149. }
  150. }, {
  151. title: '支付时间',
  152. dataIndex: 'paymentTimeFormatted',
  153. key: 'paymentTimeFormatted',
  154. }, {
  155. title: '支付流水',
  156. dataIndex: 'paymentId',
  157. key: 'paymentId'
  158. }
  159. ],
  160. dataSource: []
  161. };
  162. },
  163. componentWillMount () {
  164. this.loadData();
  165. },
  166. search () {
  167. this.loadData();
  168. },
  169. reset () {
  170. this.state.searchNumber = undefined;
  171. this.state.searchToNumber = undefined;
  172. this.state.searchId = undefined;
  173. this.state.searchPaymentId = undefined;
  174. this.state.searchState = undefined;
  175. this.state.searchTime = [];
  176. this.loadData();
  177. },
  178. submit () {
  179. if (this.state.modalData.paymentType == 1 && !this.state.modalData.paymentTimeFormatted) {
  180. message.warning('状态为已支付时支付时间必填');
  181. return
  182. }
  183. this.setState({ loading: true });
  184. $.ajax({
  185. method: "post",
  186. dataType: "json",
  187. crossDomain: false,
  188. url: globalConfig.context + "/api/admin/consultorder/update",
  189. data: {
  190. id: this.state.modalData.id,
  191. paymentValue: this.state.modalData.paymentValue,
  192. orderState: this.state.modalData.orderState,
  193. paymentTime: this.state.modalData.paymentTimeFormatted,
  194. paymentType: this.state.modalData.paymentType,
  195. paymentId: this.state.modalData.paymentId
  196. }
  197. }).done(function (data) {
  198. if (!data.error.length) {
  199. message.success('保存成功!');
  200. this.setState({ loading: false, visible: false });
  201. this.loadData();
  202. } else {
  203. message.warning(data.error[0].message);
  204. }
  205. }.bind(this)).always(function () {
  206. this.setState({ loading: false });
  207. }.bind(this));
  208. },
  209. tableRowClick (record, index) {
  210. let theObj = {};
  211. for (let item in record) {
  212. theObj[item] = record[item]
  213. }
  214. this.state.modalData = theObj;
  215. this.setState({ visible: true });
  216. },
  217. deleteRow () {
  218. let deletedId;
  219. for (let idx = 0; idx < this.state.selectedRows.length; idx++) {
  220. let rowItem = this.state.selectedRows[idx];
  221. if (rowItem.orderState !== 0) {
  222. message.warning('订单状态不是未支付,无法删除!');
  223. this.setState({ delVisible: false });
  224. return;
  225. }
  226. if (rowItem.id) {
  227. deletedId = rowItem.id
  228. };
  229. };
  230. this.setState({
  231. selectedRowKeys: [],
  232. loading: deletedId.length > 0
  233. });
  234. $.ajax({
  235. method: "POST",
  236. dataType: "json",
  237. crossDomain: false,
  238. url: globalConfig.context + "/api/admin/consultorder/del",
  239. data: {
  240. id: deletedId
  241. }
  242. }).done(function (data) {
  243. if (!data.error.length) {
  244. message.success('删除成功!');
  245. } else {
  246. message.warning(data.error[0].message);
  247. };
  248. this.setState({
  249. loading: false,
  250. delVisible: false
  251. });
  252. this.loadData();
  253. }.bind(this));
  254. },
  255. render () {
  256. const rowSelection = {
  257. selectedRowKeys: this.state.selectedRowKeys,
  258. onChange: (selectedRowKeys, selectedRows) => {
  259. this.setState({
  260. selectedRows: selectedRows.slice(-1),
  261. selectedRowKeys: selectedRowKeys.slice(-1)
  262. });
  263. }
  264. };
  265. const hasSelected = this.state.selectedRowKeys.length > 0;
  266. const { RangePicker } = DatePicker;
  267. const Option = Select.Option;
  268. return (
  269. <div className="user-content" >
  270. <div className="content-title">
  271. <span>专家咨询订单列表</span>
  272. </div>
  273. <div className="user-search">
  274. <Input placeholder="会员编号" value={this.state.searchNumber}
  275. onChange={(e) => { this.setState({ searchNumber: e.target.value }); }} />
  276. <Input placeholder="专家编号" value={this.state.searchToNumber}
  277. onChange={(e) => { this.setState({ searchToNumber: e.target.value }); }} />
  278. <Input placeholder="订单编号" value={this.state.searchId}
  279. onChange={(e) => { this.setState({ searchId: e.target.value }); }} />
  280. <Select placeholder="订单状态" value={this.state.searchState} style={{ width: 120 }}
  281. onChange={(e) => { this.setState({ searchState: e }) }}>
  282. <Option value="0">未付款</Option>
  283. <Option value="1">已付款</Option>
  284. <Option value="9">已取消</Option>
  285. <Option value="10">已失效</Option>
  286. </Select>
  287. <Input placeholder="支付流水" value={this.state.searchPaymentId}
  288. onChange={(e) => { this.setState({ searchPaymentId: e.target.value }); }} />
  289. <div className="search-div" style={{ display: "none" }}>
  290. <span>订单生成时间:</span>
  291. <RangePicker
  292. allowClear={false}
  293. value={[this.state.searchTime[0] ? moment(this.state.searchTime[0]) : null,
  294. this.state.searchTime[1] ? moment(this.state.searchTime[1]) : null]}
  295. onChange={(data, dataString) => { this.setState({ searchTime: dataString }); }} />
  296. </div>
  297. <Button type="primary" onClick={this.search}>搜索</Button>
  298. <Button onClick={this.reset}>重置</Button>
  299. <Button style={{ background: "#3fcf9e", border: "none", color: "#fff" }}
  300. disabled={!hasSelected}
  301. onClick={() => { this.setState({ delVisible: true }) }}>删除<Icon type="minus" /></Button>
  302. </div>
  303. <div className="patent-table">
  304. <Spin spinning={this.state.loading}>
  305. <Table columns={this.state.columns} class="no-all-select"
  306. dataSource={this.state.dataSource}
  307. rowSelection={rowSelection}
  308. pagination={this.state.pagination}
  309. onRowClick={this.tableRowClick} />
  310. </Spin>
  311. </div>
  312. <Modal title="订单详情" width={600} className="activity-modal"
  313. visible={this.state.visible}
  314. maskClosable={false}
  315. footer={null}
  316. afterClose={() => { this.state.modalData = {}; }}
  317. onCancel={() => { this.setState({ visible: false }) }} >
  318. <Spin spinning={this.state.loading}>
  319. <div className="clearfix">
  320. <div className="modal-box">
  321. <span className="modal-box-title">订单金额</span>
  322. <div className="modal-box-detail" style={{ width: '160px' }}>
  323. <span>{this.state.modalData.price}</span>
  324. <span> 元</span>
  325. </div>
  326. <span className="modal-box-title">实际支付金额</span>
  327. <div className="modal-box-detail" style={{ width: '160px' }}>
  328. <InputNumber value={this.state.modalData.paymentValue} step={0.01} onChange={(e) => {
  329. this.state.modalData.paymentValue = e;
  330. this.setState({ modalData: this.state.modalData });
  331. }} />
  332. <span> 元</span>
  333. </div>
  334. </div>
  335. <div className="modal-box">
  336. <span className="modal-box-title">支付方式</span>
  337. <div className="modal-box-detail" style={{ width: '160px' }}>
  338. <Input value={this.state.modalData.paymentType} onChange={(e) => {
  339. this.state.modalData.paymentType = e.target.value;
  340. this.setState({ modalData: this.state.modalData });
  341. }} />
  342. </div>
  343. <span className="modal-box-title">流水号</span>
  344. <div className="modal-box-detail" style={{ width: '160px' }}>
  345. <Input value={this.state.modalData.paymentId} onChange={(e) => {
  346. this.state.modalData.paymentId = e.target.value;
  347. this.setState({ modalData: this.state.modalData });
  348. }} />
  349. </div>
  350. </div>
  351. <div className="modal-box">
  352. <span className="modal-box-title">支付状态</span>
  353. <div className="modal-box-detail">
  354. <Radio.Group value={this.state.modalData.orderState}
  355. onChange={(e) => {
  356. this.state.modalData.orderState = e.target.value;
  357. this.setState({ modalData: this.state.modalData });
  358. }} >
  359. <Radio value={0}>未支付</Radio>
  360. <Radio value={1}>已支付</Radio>
  361. </Radio.Group>
  362. </div>
  363. </div>
  364. <div className="modal-box">
  365. <span className="modal-box-title">支付时间</span>
  366. <div className="modal-box-detail">
  367. <DatePicker style={{ width: '150px' }}
  368. showTime
  369. format="YYYY-MM-DD HH:mm:ss"
  370. placeholder="选择支付时间"
  371. value={this.state.modalData.paymentTimeFormatted ? moment(this.state.modalData.paymentTimeFormatted, "YYYY-MM-DD HH:mm:ss") : undefined}
  372. onChange={(t, str) => {
  373. this.state.modalData.paymentTimeFormatted = str;
  374. this.setState({ modalData: this.state.modalData });
  375. }} />
  376. </div>
  377. </div>
  378. </div>
  379. <div className="modal-box" style={{ marginTop: '100px' }}>
  380. <Button type="primary" onClick={this.submit}>提交</Button>
  381. <Button type="ghost" onClick={() => { this.setState({ visible: false }) }}>取消</Button>
  382. </div>
  383. </Spin>
  384. </Modal>
  385. <Modal title="删除确认" width={600} className="activity-modal"
  386. visible={this.state.delVisible}
  387. maskClosable={false}
  388. footer={null}
  389. onCancel={() => { this.setState({ delVisible: false }) }} >
  390. <Spin spinning={this.state.loading}>
  391. <div className="clearfix">
  392. <div className="modal-box">
  393. <span>是否确定删除这条记录?删除后数据不可恢复!</span>
  394. </div>
  395. <div className="modal-box" >
  396. <Button type="primary" onClick={this.deleteRow}>提交</Button>
  397. <Button type="ghost" onClick={() => { this.setState({ delVisible: false }) }}>取消</Button>
  398. </div>
  399. </div>
  400. </Spin>
  401. </Modal>
  402. </div >
  403. );
  404. }
  405. });
  406. export default OrderList;