import React from 'react'; import { Icon, Button, Input, Select, Spin, Table, message, DatePicker, Modal, InputNumber, Radio } from 'antd'; import ajax from 'jquery/src/ajax/xhr.js'; import $ from 'jquery/src/ajax'; import './content.less'; import moment from 'moment'; import { getTime } from '../../tools'; const OrderList = React.createClass({ loadData (pageNo) { this.state.data = []; this.setState({ loading: true }); $.ajax({ method: "get", dataType: "json", crossDomain: false, url: globalConfig.context + "/api/admin/member/selectMemberOrderBa", data: { pageNo: pageNo || 1, pageSize: this.state.pagination.pageSize, id: this.state.searchOrderNumber, nickname: this.state.searchName, mobile: this.state.searchAftNumber, orderState: this.state.searchOrderStatus, //支付状态 0,1 startTime: this.state.searchTime[0], endTime: this.state.searchTime[1] }, success: function (data) { if (!data.data || !data.data.list) { if (data.error && data.error.length) { message.warning(data.error[0].message); }; } else { for (let i = 0; i < data.data.list.length; i++) { let thisdata = data.data.list[i]; this.state.data.push({ key: i, id: thisdata.id, formattedOrderTime: thisdata.formattedOrderTime, formattedPaymentTime: thisdata.formattedPaymentTime, formattedValidTime: thisdata.formattedValidTime, gradeName: thisdata.gradeName, menberType: thisdata.menberType, nickname: thisdata.nickname, mobile: thisdata.mobile, orderState: thisdata.orderState, orderTime: thisdata.orderTime, paymentId: thisdata.paymentId, paymentTime: thisdata.paymentTime, paymentType: thisdata.paymentType, paymentValue: thisdata.paymentValue, price: thisdata.price, userId: thisdata.userId, validMonth: thisdata.validMonth, validTime: thisdata.validTime, }); }; this.state.pagination.current = data.data.pNo; this.state.pagination.total = data.data.countWhere; }; this.setState({ dataSource: this.state.data, pagination: this.state.pagination }); }.bind(this), }).always(function () { this.setState({ loading: false }); }.bind(this)); }, getInitialState () { return { searchMore: true, data: [], modalData: {}, visible: false, delVisible: false, searchTime: [], loading: false, selectedRowKeys: [], selectedRows: [], pagination: { defaultCurrent: 1, defaultPageSize: 10, showQuickJumper: true, pageSize: 10, onChange: function (page) { this.loadData(page); }.bind(this), showTotal: function (total) { return '共' + total + '条数据'; } }, columns: [ { title: '订单编号', dataIndex: 'id', key: 'id', }, { title: '账号', dataIndex: 'mobile', key: 'mobile', }, { title: '认证名称', dataIndex: 'nickname', key: 'nickname', }, { title: '会员类型', dataIndex: 'gradeName', key: 'gradeName', }, { title: '订单状态', dataIndex: 'orderState', key: 'orderState', render: (text) => { if (text == 1) { return '已支付' } else { return '未支付' }; } }, { title: '生成时间', dataIndex: 'formattedOrderTime', key: 'formattedOrderTime', }, { title: '支付时间', dataIndex: 'formattedPaymentTime', key: 'formattedPaymentTime', }, { title: '有效时间', dataIndex: 'formattedValidTime', key: 'formattedValidTime', render: (index, record) => { if (record.paymentTime && record.validMonth && record.orderState == 1) { return getTime(record.paymentTime) + ' -- ' + getTime(record.paymentTime, record.validMonth) } } } ], dataSource: [] }; }, componentWillMount () { this.loadData(); }, search () { this.loadData(); }, reset () { this.state.searchOrderNumber = undefined; this.state.searchAftNumber = undefined; this.state.searchOrderStatus = undefined; this.state.searchName = undefined; this.state.searchTime = []; this.loadData(); }, submit () { if (this.state.modalData.paymentType == 1 && !this.state.modalData.formattedPaymentTime) { message.warning('状态为已支付时支付时间必填'); return } this.setState({ loading: true }); $.ajax({ method: "post", dataType: "json", crossDomain: false, url: globalConfig.context + "/api/admin/member/updateMemberOrder", data: { id: this.state.modalData.id, userId: this.state.modalData.userId, memberRank: this.state.modalData.menberType, validMonth: this.state.modalData.validMonth, paymentValue: this.state.modalData.paymentValue, orderState: this.state.modalData.orderState, paymentTime: this.state.modalData.formattedPaymentTime, paymentType: this.state.modalData.paymentType, paymentId: this.state.modalData.paymentId } }).done(function (data) { if (!data.error.length) { message.success('保存成功!'); this.setState({ loading: false, visible: false }); this.loadData(); } else { message.warning(data.error[0].message); } }.bind(this)).always(function () { this.setState({ loading: false }); }.bind(this)); }, tableRowClick (record, index) { let theObj = {}; for (let item in record) { theObj[item] = record[item] } this.state.modalData = theObj; this.setState({ visible: true }); }, deleteRow () { let deletedId; for (let idx = 0; idx < this.state.selectedRows.length; idx++) { let rowItem = this.state.selectedRows[idx]; if (rowItem.orderState !== 0) { message.warning('订单状态不是未支付,无法删除!'); this.setState({ delVisible: false }); return; } if (rowItem.id) { deletedId = rowItem.id }; }; this.setState({ selectedRowKeys: [], loading: deletedId.length > 0 }); $.ajax({ method: "POST", dataType: "json", crossDomain: false, url: globalConfig.context + "/api/admin/member/delMemberOrder", data: { id: deletedId } }).done(function (data) { if (!data.error.length) { message.success('删除成功!'); } else { message.warning(data.error[0].message); }; this.setState({ loading: false, delVisible: false }); this.loadData(); }.bind(this)); }, render () { const rowSelection = { selectedRowKeys: this.state.selectedRowKeys, onChange: (selectedRowKeys, selectedRows) => { this.setState({ selectedRows: selectedRows.slice(-1), selectedRowKeys: selectedRowKeys.slice(-1) }); } }; const hasSelected = this.state.selectedRowKeys.length > 0; const { RangePicker } = DatePicker; const Option = Select.Option; return (