123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216 |
- 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, asyncForm } from '@src/services/AsyncTools';
- import { ServiceParamMap, ServiceKey, ServiceSource } from '../../../../Constant';
- import { User } from '../../../stores/user';
- const ServiceKeyMap = getMap(ServiceKey, 'value', 'label');
- const ServiceSourceMap = getMap(ServiceSource, '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.timeout = null;
- this.mobile = null;
- this.actionList = [{
- key: 'add',
- type: 'primary',
- name: '创建',
- }];
- this.formF = null;
- this.itemList = [{
- key: 'id',
- type: 'hidden',
- }, {
- key: 'mobile',
- type: 'input',
- name: '手机号',
- placeholder: '请输入',
- option: {
- normalize: (value) => {
- if (this.mobile === value) return value;
- if (this.timeout) {
- clearTimeout(this.timeout);
- this.timeout = null;
- }
- this.timeout = setTimeout(() => {
- User.validMobile({ mobile: value }).then(result => {
- this.mobile = value;
- this.itemList[1].suffix = result ? '已注册' : '未注册';
- this.formF.setFieldsValue({ load: true });
- });
- }, 1500);
- return value;
- },
- },
- }, {
- key: 'service',
- type: 'select',
- name: '开通服务',
- select: ServiceKey,
- placeholder: '请选择',
- onChange: (value) => {
- this.itemList[3].select = ServiceParamList[value] || [];
- this.formF.setFieldsValue({ param: '' });
- },
- }, {
- key: 'param',
- type: 'select',
- name: '服务参数',
- select: [],
- }, {
- key: 'source',
- type: 'select',
- name: '开通方式',
- select: ServiceSource,
- placeholder: '请选择',
- }];
- this.filterForm = [{
- key: 'userId',
- type: 'select',
- allowClear: true,
- name: '用户',
- select: [],
- number: true,
- placeholder: '请输入',
- }, {
- key: 'service',
- type: 'select',
- allowClear: true,
- name: '服务',
- select: ServiceKey,
- onChange: (value) => {
- this.filterForm[2].select = ServiceParamList[value] || [];
- },
- }, {
- key: 'param',
- type: 'select',
- name: '参数',
- select: [],
- allowClear: true,
- notFound: null,
- }];
- this.columns = [{
- title: '用户ID',
- dataIndex: 'userId',
- }, {
- title: '用户手机',
- dataIndex: 'user.mobile',
- }, {
- title: '用户姓名',
- dataIndex: 'user.nickname',
- }, {
- title: '开通服务',
- dataIndex: 'service',
- render: (text, record) => {
- return `${ServiceKeyMap[text]}${(ServiceParamRelation[record.service] || {})[text] || ''}`;
- },
- }, {
- title: '开通时间',
- dataIndex: 'time',
- render: (text, record) => {
- return `${record.startTime ? formatDate(record.startTime) : ''} - ${record.endTime ? formatDate(record.endTime) : ''}`;
- },
- }, {
- title: '开通方式',
- dataIndex: 'source',
- render: (text) => {
- return ServiceSourceMap[text] || '';
- },
- }, {
- title: '累计消费金额',
- dataIndex: 'user.totalMoney',
- render: (text) => {
- return formatMoney(text);
- },
- }, {
- title: '操作',
- dataIndex: 'handler',
- render: (text, record) => {
- return <div className="table-button">
- {!record.isUsed && (
- <a onClick={() => {
- this.editAction(record);
- }}>编辑</a>
- )}
- </div>;
- },
- },
- ];
- 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);
- }
- initData() {
- User.listService(this.state.search).then(result => {
- this.setTableData(result.list, result.total);
- });
- }
- addAction() {
- this.itemList[1].disabled = false;
- asyncForm('新建', this.itemList, {}, data => {
- return User.addService(data).then(() => {
- asyncSMessage('添加成功!');
- this.refresh();
- });
- }).then(component => {
- this.formF = component;
- });
- }
- editAction(row) {
- this.itemList[1].disabled = true;
- asyncForm('编辑', this.itemList, row, data => {
- return User.editService(data).then(() => {
- asyncSMessage('编辑成功!');
- this.refresh();
- });
- }).then(component => {
- this.formF = component;
- });
- }
- renderView() {
- return <Block flex>
- <FilterLayout
- show
- itemList={this.filterForm}
- data={this.state.search}
- onChange={data => {
- this.search(data);
- }} />
- <ActionLayout
- itemList={this.actionList}
- selectedKeys={this.state.selectedKeys}
- onAction={key => this.onAction(key)}
- />
- <TableLayout
- columns={this.columns}
- list={this.state.list}
- pagination={this.state.page}
- loading={this.props.core.loading}
- onChange={(pagination, filters, sorter) => this.tableChange(pagination, filters, sorter)}
- onSelect={(keys, rows) => this.tableSelect(keys, rows)}
- selectedKeys={this.state.selectedKeys}
- />
- </Block>;
- }
- }
|