import React from 'react'; import './index.less'; import Page from '@src/containers/Page'; import Block from '@src/components/Block'; import FilterLayout from '@src/layouts/FilterLayout'; // import ActionLayout from '@src/layouts/ActionLayout'; import TableLayout from '@src/layouts/TableLayout'; import { getMap, formatDate, formatMoney, bindSearch } from '@src/services/Tools'; // import { asyncSMessage } from '@src/services/AsyncTools'; import { ServiceParamMap, ServiceKey, ProductTypeMain, RecordBuySource } from '../../../../Constant'; import { User } from '../../../stores/user'; import { Course } from '../../../stores/course'; const ServiceKeyMap = getMap(ServiceKey, 'value', 'label'); const ProductTypeMainMap = getMap(ProductTypeMain, 'value', 'label'); const RecordBuySourceMap = getMap(RecordBuySource, 'value', 'label'); // const ServiceParamList = getMap(Object.keys(ServiceParamMap).map(key => { // return { list: ServiceParamMap[key], key }; // }), 'key', 'list'); const ServiceParamRelation = getMap(Object.keys(ServiceParamMap).map(key => { return { map: getMap(ServiceParamMap[key], 'value', 'label'), key }; }), 'key', 'map'); export default class extends Page { init() { this.filterF = null; this.filterForm = [{ key: 'userId', type: 'select', allowClear: true, name: '用户', select: [], number: true, placeholder: '请输入', }, { key: 'productType', type: 'select', allowClear: true, name: '种类', select: ProductTypeMain, onChange: (value) => { // 根据服务 this.changeSearch(this.filterForm, this, value, null); }, }, { key: 'productId', type: 'select', allowClear: true, name: '具体名称', number: true, select: [], }, { key: 'service', type: 'select', allowClear: true, name: '服务', select: ServiceKey, }, { key: 'source', type: 'select', allowClear: true, name: '开通方式', select: RecordBuySource, }, { key: 'orderId', type: 'input', allowClear: true, name: '订单id', }]; this.columns = [{ title: '用户ID', dataIndex: 'userId', }, { title: '用户手机', dataIndex: 'user.mobile', }, { title: '用户姓名', dataIndex: 'user.nickname', }, { title: '种类', dataIndex: 'productType', render: (text) => { return `${ProductTypeMainMap[text]}`; }, }, { title: '权限', dataIndex: 'service', render: (text, record) => { if (record.productType === 'course') { return (record.course || {}).title; } if (record.productType === 'data') { return (record.data || {}).title; } if (record.productType === 'service') { return `${ServiceKeyMap[text]}${record.param ? (ServiceParamRelation[record.service] || {})[record.param] || '' : ''}`; } return ''; }, }, { title: '开通时间', dataIndex: 'time', render: (text, record) => { return `${record.startTime ? formatDate(record.startTime, 'YYYY-MM-DD HH:mm:ss') : ''} - ${record.endTime ? formatDate(record.endTime, 'YYYY-MM-DD HH:mm:ss') : ''}`; }, }, { title: '开通方式', dataIndex: 'source', render: (text) => { return RecordBuySourceMap[text] || ''; }, }, { title: '购买金额', dataIndex: 'money', render: (text, record) => { return `${formatMoney(text)}${text !== record.originMoney ? `(${formatMoney(record.originMoney)})` : ''}`; }, }, { title: '购买时间', dataIndex: 'createTime', render: (text) => { return formatDate(text, 'YYYY-MM-DD HH:mm:ss'); }, }]; bindSearch(this.filterForm, 'userId', this, (search) => { return User.list(search); }, (row) => { return { title: `${row.nickname}(${row.mobile})`, value: row.id, }; }, this.state.search.userId ? Number(this.state.search.userId) : null, null); this.changeSearch(this.filterForm, this, this.state.search.productType, this.state.search.productId); } changeSearch(list, component, key, value) { if (key === 'service') { list[2].disabled = true; list[3].disabled = false; } else if (key === 'course' || key === 'data') { list[2].disabled = false; list[3].disabled = true; bindSearch(list, 'productId', component, (search) => { if (key === 'course') { return Course.list(search); } return Course.listData(search); }, (row) => { return { title: row.title, value: row.id, }; }, value ? Number(value) : null, null); } else { list[2].disabled = true; list[3].disabled = true; } component.setState({ load: false }); } initData() { User.listRecord(Object.assign({ needMoney: true, needPackage: false }, this.state.search)).then(result => { this.setTableData(result.list, result.total); }); } renderView() { return { this.filterF = ref; }} itemList={this.filterForm} data={this.state.search} onChange={data => { data.page = 1; this.search(data); }} /> this.tableChange(pagination, filters, sorter)} onSelect={(keys, rows) => this.tableSelect(keys, rows)} selectedKeys={this.state.selectedKeys} /> ; } }