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
{!record.isUsed && ( { this.editAction(record); }}>编辑 )}
; }, }, ]; 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 { this.search(data); }} /> this.onAction(key)} /> this.tableChange(pagination, filters, sorter)} onSelect={(keys, rows) => this.tableSelect(keys, rows)} selectedKeys={this.state.selectedKeys} /> ; } }