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, asyncDelConfirm } from '@src/services/AsyncTools'; import { ServiceParamMap, ServiceKey, MobileArea, RecordSource, ProductTypeMain } 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 RecordSourceMap = getMap(RecordSource, '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: 'addService', type: 'primary', name: '添加服务', }, { key: 'addData', type: 'primary', name: '添加资料', }]; this.formF = null; this.serviceList = [{ key: 'id', type: 'hidden', }, { key: 'area', type: 'select', name: '国际码', select: MobileArea, required: true, }, { key: 'mobile', type: 'input', name: '手机号', placeholder: '请输入', required: true, option: { normalize: (value) => { if (!value) return value; if (this.mobile === value) return value; if (this.timeout) { clearTimeout(this.timeout); this.timeout = null; } this.timeout = setTimeout(() => { User.validMobile({ area: this.formF.getFieldValue('area'), mobile: value }).then(result => { this.mobile = value; this.serviceList[2].suffix = !result ? '已注册' : '未注册'; this.formF.setFieldsValue({ load: true }); }); }, 1500); return value; }, }, }, { key: 'service', type: 'select', name: '开通服务', select: ServiceKey, placeholder: '请选择', required: true, onChange: (value) => { this.serviceList[4].select = ServiceParamList[value] || []; this.serviceList[4].disabled = !this.serviceList[4].select.length; this.formF.setFieldsValue({ param: '' }); }, }, { key: 'param', type: 'select', name: '服务参数', select: [], }]; this.dataList = [{ key: 'id', type: 'hidden', }, { key: 'area', type: 'select', name: '国际码', select: MobileArea, required: true, }, { key: 'mobile', type: 'input', name: '手机号', placeholder: '请输入', required: true, option: { normalize: (value) => { if (!value) return value; if (this.mobile === value) return value; if (this.timeout) { clearTimeout(this.timeout); this.timeout = null; } this.timeout = setTimeout(() => { User.validMobile({ area: this.formF.getFieldValue('area'), mobile: value }).then(result => { this.mobile = value; this.dataList[2].suffix = !result ? '已注册' : '未注册'; this.formF.setFieldsValue({ load: true }); }); }, 1500); return value; }, }, }, { key: 'dataId', type: 'select', name: '开通资料', required: true, select: [], placeholder: '请选择', }]; 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.filterF, value, null); this.filterF.setFieldsValue({ productId: null, service: 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: RecordSource, }]; 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 RecordSourceMap[text] || ''; }, }, { title: '累计消费金额', dataIndex: 'user.totalMoney', render: (text) => { return formatMoney(text); }, }, { title: '操作', dataIndex: 'handler', render: (text, record) => { return