|
@@ -1,315 +0,0 @@
|
|
|
-import React, { Component } from 'react';
|
|
|
-import { connect } from 'dva';
|
|
|
-import { routerRedux } from 'dva/router';
|
|
|
-import { message, Modal, Table, Card, Button } from 'antd';
|
|
|
-import Selector from '../../../components/RBTableSelector/Selector';
|
|
|
-import FooterToolbar from '../../../components/FooterToolbar/index';
|
|
|
-import { STATUS_NORMAL } from '../../../utils/config';
|
|
|
-import { renderCategory, statusCodeToName } from '../../../utils/utils';
|
|
|
-import styles from './ShelvesCreate.less';
|
|
|
-
|
|
|
-const Message = message;
|
|
|
-
|
|
|
-function firstLetterUpper(str) {
|
|
|
- return str.substring(0, 1).toUpperCase() + str.substring(1);
|
|
|
-}
|
|
|
-
|
|
|
-function getItemName(str) {
|
|
|
- if (str === 'course') {
|
|
|
- return '课程';
|
|
|
- } else if (str === 'support') {
|
|
|
- return '配套';
|
|
|
- } else if (str === 'package') {
|
|
|
- return '套餐包';
|
|
|
- } else {
|
|
|
- return '产品';
|
|
|
- }
|
|
|
-}
|
|
|
-
|
|
|
-@connect(({ loading, shelves, product, merchant }) => ({
|
|
|
- product,
|
|
|
- shelves,
|
|
|
- merchant,
|
|
|
- mLoading: loading.models.merchant,
|
|
|
- pLoading: loading.models.product,
|
|
|
- submitting: loading.models.shelves,
|
|
|
-}))
|
|
|
-export default class ShelvesCreatePage extends Component {
|
|
|
- constructor(props) {
|
|
|
- super(props);
|
|
|
- const { location } = props;
|
|
|
- const { state } = location;
|
|
|
- const { itemType } = state;
|
|
|
- this.state = {
|
|
|
- itemType,
|
|
|
- productItem: {},
|
|
|
- merchantItem: {},
|
|
|
- productSelectorDestroy: true,
|
|
|
- merchantSelectorDestroy: true,
|
|
|
- };
|
|
|
- }
|
|
|
- handleProductSelectorModalShow = () => {
|
|
|
- const { itemType } = this.state;
|
|
|
- this.setState({
|
|
|
- productSelectorDestroy: false,
|
|
|
- });
|
|
|
- this.props.dispatch({
|
|
|
- type: `product/fetch${firstLetterUpper(itemType)}List`,
|
|
|
- payload: {},
|
|
|
- });
|
|
|
- };
|
|
|
- handleMerchantSelectorModalShow = () => {
|
|
|
- this.setState({
|
|
|
- merchantSelectorDestroy: false,
|
|
|
- });
|
|
|
- this.props.dispatch({
|
|
|
- type: 'merchant/fetchMerchantList',
|
|
|
- payload: {},
|
|
|
- });
|
|
|
- };
|
|
|
- handleProductSelectorChange = (params) => {
|
|
|
- const { itemType } = this.state;
|
|
|
- this.props.dispatch({
|
|
|
- type: `product/fetch${firstLetterUpper(itemType)}List`,
|
|
|
- payload: params,
|
|
|
- });
|
|
|
- };
|
|
|
- handleMerchantSelectorChange = (params) => {
|
|
|
- this.props.dispatch({
|
|
|
- type: 'merchant/fetchMerchantList',
|
|
|
- payload: params,
|
|
|
- });
|
|
|
- };
|
|
|
- handleProductSelectorFinish = (rows) => {
|
|
|
- this.setState({
|
|
|
- productSelectorDestroy: true,
|
|
|
- productItem: rows[0],
|
|
|
- });
|
|
|
- };
|
|
|
- handleMerchantSelectorFinish = (rows) => {
|
|
|
- this.setState({
|
|
|
- merchantSelectorDestroy: true,
|
|
|
- merchantItem: rows[0],
|
|
|
- });
|
|
|
- };
|
|
|
- handleProductSelectorCancel = () => {
|
|
|
- this.setState({
|
|
|
- productSelectorDestroy: true,
|
|
|
- });
|
|
|
- };
|
|
|
- handleMerchantSelectorCancel = () => {
|
|
|
- this.setState({
|
|
|
- merchantSelectorDestroy: true,
|
|
|
- });
|
|
|
- };
|
|
|
- handlePageBack = () => {
|
|
|
- const { itemType } = this.state;
|
|
|
- this.props.dispatch(routerRedux.push({
|
|
|
- pathname: `/shelves/${itemType}`,
|
|
|
- state: this.props.location.state,
|
|
|
- }));
|
|
|
- };
|
|
|
- handlePageSubmit = (e) => {
|
|
|
- e.preventDefault();
|
|
|
- const { productItem, merchantItem, itemType } = this.state;
|
|
|
- const { pid } = productItem;
|
|
|
- const { id } = merchantItem;
|
|
|
- if (!pid) {
|
|
|
- Message.error(`请选择要上架的${getItemName(itemType)}!`);
|
|
|
- return;
|
|
|
- }
|
|
|
- if (!id) {
|
|
|
- Message.error('请选择要上架的渠道!');
|
|
|
- return;
|
|
|
- }
|
|
|
- this.props.dispatch({
|
|
|
- type: 'shelves/createItem',
|
|
|
- payload: {
|
|
|
- pid,
|
|
|
- merchantId: id,
|
|
|
- status: STATUS_NORMAL,
|
|
|
- },
|
|
|
- states: this.props.location.state,
|
|
|
- });
|
|
|
- };
|
|
|
-
|
|
|
- render() {
|
|
|
- const { submitting, pLoading, mLoading, merchant, product } = this.props;
|
|
|
- const {
|
|
|
- productSelectorDestroy, merchantSelectorDestroy, itemType, productItem, merchantItem,
|
|
|
- } = this.state;
|
|
|
-
|
|
|
- // format selected data
|
|
|
- const productTypeName = getItemName(itemType);
|
|
|
- const productItemFormatter = () => {
|
|
|
- const { code, name, status } = productItem;
|
|
|
- return [{
|
|
|
- key: `${productTypeName}编号:`,
|
|
|
- value: code,
|
|
|
- }, {
|
|
|
- key: `${productTypeName}名称:`,
|
|
|
- value: name,
|
|
|
- }, {
|
|
|
- key: `${productTypeName}状态:`,
|
|
|
- value: statusCodeToName(status),
|
|
|
- }];
|
|
|
- };
|
|
|
- const merchantItemFormatter = () => {
|
|
|
- const { code, name, status, simple, contactName, mobile, domain } = merchantItem;
|
|
|
- return [{
|
|
|
- key: '商户编号:',
|
|
|
- value: code,
|
|
|
- }, {
|
|
|
- key: '商户名称:',
|
|
|
- value: name,
|
|
|
- }, {
|
|
|
- key: '商户简称:',
|
|
|
- value: simple,
|
|
|
- }, {
|
|
|
- key: '商户类型:',
|
|
|
- value: renderCategory(domain),
|
|
|
- }, {
|
|
|
- key: '商户联系人:',
|
|
|
- value: contactName,
|
|
|
- }, {
|
|
|
- key: '联系人电话:',
|
|
|
- value: mobile,
|
|
|
- }, {
|
|
|
- key: '商户状态:',
|
|
|
- value: statusCodeToName(status),
|
|
|
- }];
|
|
|
- };
|
|
|
-
|
|
|
- // table columns
|
|
|
- const columns = [{
|
|
|
- title: '字段名',
|
|
|
- key: 1,
|
|
|
- dataIndex: 'key',
|
|
|
- width: '15%',
|
|
|
- }, {
|
|
|
- title: '字段值',
|
|
|
- key: 2,
|
|
|
- dataIndex: 'value',
|
|
|
- width: '65%',
|
|
|
- }];
|
|
|
-
|
|
|
- // render modal selector
|
|
|
- const getProductModal = () => {
|
|
|
- return (
|
|
|
- <Modal
|
|
|
- width={900}
|
|
|
- footer={null}
|
|
|
- visible
|
|
|
- title={`${getItemName(itemType)}列表`}
|
|
|
- maskClosable={false}
|
|
|
- onCancel={this.handleProductSelectorCancel}
|
|
|
- >
|
|
|
- <Selector
|
|
|
- multiple={false}
|
|
|
- loading={pLoading}
|
|
|
- selectorName={firstLetterUpper(itemType)}
|
|
|
- list={product.list}
|
|
|
- pageNo={product.pageNo}
|
|
|
- pageSize={product.pageSize}
|
|
|
- totalSize={product.totalSize}
|
|
|
- onCancel={this.handleProductSelectorCancel}
|
|
|
- onChange={this.handleProductSelectorChange}
|
|
|
- onFinish={this.handleProductSelectorFinish}
|
|
|
- />
|
|
|
- </Modal>
|
|
|
- );
|
|
|
- };
|
|
|
- const getMerchantModal = () => {
|
|
|
- return (
|
|
|
- <Modal
|
|
|
- width={1100}
|
|
|
- footer={null}
|
|
|
- visible
|
|
|
- title="商户列表"
|
|
|
- maskClosable={false}
|
|
|
- onCancel={this.handleMerchantSelectorCancel}
|
|
|
- >
|
|
|
- <Selector
|
|
|
- multiple={false}
|
|
|
- loading={mLoading}
|
|
|
- selectorName="Merchant"
|
|
|
- list={merchant.list}
|
|
|
- pageNo={merchant.pageNo}
|
|
|
- pageSize={merchant.pageSize}
|
|
|
- totalSize={merchant.totalSize}
|
|
|
- onCancel={this.handleMerchantSelectorCancel}
|
|
|
- onChange={this.handleMerchantSelectorChange}
|
|
|
- onFinish={this.handleMerchantSelectorFinish}
|
|
|
- />
|
|
|
- </Modal>
|
|
|
- );
|
|
|
- };
|
|
|
-
|
|
|
- // render card title
|
|
|
- const renderProductCardName = () => {
|
|
|
- return (
|
|
|
- <div className={styles.cardName}>
|
|
|
- <span>
|
|
|
- <a onClick={this.handleProductSelectorModalShow}>
|
|
|
- {`选择${getItemName(itemType)}`}
|
|
|
- </a>
|
|
|
- </span>
|
|
|
- </div>
|
|
|
- );
|
|
|
- };
|
|
|
- const renderMerchantCardName = () => {
|
|
|
- return (
|
|
|
- <div className={styles.cardName}>
|
|
|
- <span>
|
|
|
- <a onClick={this.handleMerchantSelectorModalShow}>
|
|
|
- 选择商户
|
|
|
- </a>
|
|
|
- </span>
|
|
|
- </div>
|
|
|
- );
|
|
|
- };
|
|
|
-
|
|
|
- return (
|
|
|
- <div>
|
|
|
- {/* 产品选择Card */}
|
|
|
- <Card title={renderProductCardName()} style={{ marginBottom: 16 }}>
|
|
|
- <Table
|
|
|
- bordered
|
|
|
- showHeader={false}
|
|
|
- pagination={false}
|
|
|
- columns={columns}
|
|
|
- className={styles.table}
|
|
|
- dataSource={productItemFormatter()}
|
|
|
- />
|
|
|
- {!productSelectorDestroy && getProductModal()}
|
|
|
- </Card>
|
|
|
- {/* 渠道选择Card */}
|
|
|
- <Card title={renderMerchantCardName()} style={{ marginBottom: 70 }}>
|
|
|
- <Table
|
|
|
- bordered
|
|
|
- showHeader={false}
|
|
|
- pagination={false}
|
|
|
- columns={columns}
|
|
|
- className={styles.table}
|
|
|
- dataSource={merchantItemFormatter()}
|
|
|
- />
|
|
|
- {!merchantSelectorDestroy && getMerchantModal()}
|
|
|
- </Card>
|
|
|
- <FooterToolbar style={{ width: '100%' }}>
|
|
|
- <Button
|
|
|
- onClick={this.handlePageBack}
|
|
|
- style={{ marginRight: 10 }}
|
|
|
- >取消
|
|
|
- </Button>
|
|
|
- <Button
|
|
|
- type="primary"
|
|
|
- loading={submitting}
|
|
|
- onClick={this.handlePageSubmit}
|
|
|
- >提交
|
|
|
- </Button>
|
|
|
- </FooterToolbar>
|
|
|
- </div>
|
|
|
- );
|
|
|
- }
|
|
|
-}
|
|
|
-
|