PackageCreate.js 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291
  1. import React, { Component } from 'react';
  2. import { connect } from 'dva';
  3. import { routerRedux } from 'dva/router';
  4. import { message, Modal, Table, Card, Button } from 'antd';
  5. import Selector from '../../../components/AXTableSelector/Selector';
  6. import FooterToolbar from '../../../components/FooterToolbar';
  7. import { Hotax } from '../../../utils/config';
  8. import { renderCategory, statusCodeToName } from '../../../utils/utils';
  9. import styles from './PackageCreate.less';
  10. const Message = message;
  11. @connect(({ loading, shelves, product, merchant }) => ({
  12. product,
  13. shelves,
  14. merchant,
  15. mLoading: loading.models.merchant,
  16. pLoading: loading.models.product,
  17. submitting: loading.models.shelves,
  18. }))
  19. export default class PackageCreatePage extends Component {
  20. constructor(props) {
  21. super(props);
  22. this.state = {
  23. productItem: {},
  24. merchantItem: {},
  25. productSelectorDestroy: true,
  26. merchantSelectorDestroy: true,
  27. };
  28. }
  29. handleProductSelectorModalShow = () => {
  30. this.setState({
  31. productSelectorDestroy: false,
  32. });
  33. this.props.dispatch({
  34. type: 'product/fetchPackageList',
  35. payload: {},
  36. });
  37. };
  38. handleMerchantSelectorModalShow = () => {
  39. this.setState({
  40. merchantSelectorDestroy: false,
  41. });
  42. this.props.dispatch({
  43. type: 'merchant/fetchMerchantList',
  44. payload: {},
  45. });
  46. };
  47. handleProductSelectorChange = (params) => {
  48. this.props.dispatch({
  49. type: 'product/fetchPackageList',
  50. payload: params,
  51. });
  52. };
  53. handleMerchantSelectorChange = (params) => {
  54. this.props.dispatch({
  55. type: 'merchant/fetchMerchantList',
  56. payload: params,
  57. });
  58. };
  59. handleProductSelectorFinish = (rows) => {
  60. this.setState({
  61. productSelectorDestroy: true,
  62. productItem: rows[0],
  63. });
  64. };
  65. handleMerchantSelectorFinish = (rows) => {
  66. this.setState({
  67. merchantSelectorDestroy: true,
  68. merchantItem: rows[0],
  69. });
  70. };
  71. handleProductSelectorCancel = () => {
  72. this.setState({
  73. productSelectorDestroy: true,
  74. });
  75. };
  76. handleMerchantSelectorCancel = () => {
  77. this.setState({
  78. merchantSelectorDestroy: true,
  79. });
  80. };
  81. handlePageBack = () => {
  82. this.props.dispatch(routerRedux.push({
  83. pathname: '/shelves/package/list',
  84. state: this.props.location.state,
  85. }));
  86. };
  87. handlePageSubmit = (e) => {
  88. e.preventDefault();
  89. const { productItem, merchantItem } = this.state;
  90. const { pid } = productItem;
  91. const { id } = merchantItem;
  92. if (!pid) {
  93. Message.error('请选择要上架的套餐包!');
  94. return;
  95. }
  96. if (!id) {
  97. Message.error('请选择要上架的渠道!');
  98. return;
  99. }
  100. this.props.dispatch({
  101. type: 'shelves/createItem',
  102. payload: {
  103. pid,
  104. merchantId: id,
  105. status: Hotax.STATUS_NORMAL,
  106. },
  107. states: this.props.location.state,
  108. });
  109. };
  110. render() {
  111. const { submitting, pLoading, mLoading, merchant, product } = this.props;
  112. const {
  113. productSelectorDestroy, merchantSelectorDestroy, productItem, merchantItem,
  114. } = this.state;
  115. // format selected data
  116. const productItemFormatter = () => {
  117. const { code, name, status } = productItem;
  118. return [{
  119. key: '套餐包编号:',
  120. value: code,
  121. }, {
  122. key: '套餐包名称:',
  123. value: name,
  124. }, {
  125. key: '套餐包状态:',
  126. value: statusCodeToName(status),
  127. }];
  128. };
  129. const merchantItemFormatter = () => {
  130. const { code, name, status, simple, contactName, mobile, domain } = merchantItem;
  131. return [{
  132. key: '商户编号:',
  133. value: code,
  134. }, {
  135. key: '商户名称:',
  136. value: name,
  137. }, {
  138. key: '商户简称:',
  139. value: simple,
  140. }, {
  141. key: '商户类型:',
  142. value: renderCategory(domain),
  143. }, {
  144. key: '商户联系人:',
  145. value: contactName,
  146. }, {
  147. key: '联系人电话:',
  148. value: mobile,
  149. }, {
  150. key: '商户状态:',
  151. value: statusCodeToName(status),
  152. }];
  153. };
  154. // table columns
  155. const columns = [{
  156. title: '字段名',
  157. key: 1,
  158. dataIndex: 'key',
  159. width: '15%',
  160. }, {
  161. title: '字段值',
  162. key: 2,
  163. dataIndex: 'value',
  164. width: '65%',
  165. }];
  166. // render modal selector
  167. const getProductModal = () => {
  168. return (
  169. <Modal
  170. visible
  171. width={900}
  172. footer={null}
  173. title="套餐包列表"
  174. maskClosable={false}
  175. onCancel={this.handleProductSelectorCancel}
  176. >
  177. <Selector
  178. multiple={false}
  179. loading={pLoading}
  180. selectorName="Course"
  181. list={product.list}
  182. pageNo={product.pageNo}
  183. pageSize={product.pageSize}
  184. totalSize={product.totalSize}
  185. onCancel={this.handleProductSelectorCancel}
  186. onChange={this.handleProductSelectorChange}
  187. onFinish={this.handleProductSelectorFinish}
  188. />
  189. </Modal>
  190. );
  191. };
  192. const getMerchantModal = () => {
  193. return (
  194. <Modal
  195. visible
  196. width={1100}
  197. footer={null}
  198. title="商户列表"
  199. maskClosable={false}
  200. onCancel={this.handleMerchantSelectorCancel}
  201. >
  202. <Selector
  203. multiple={false}
  204. loading={mLoading}
  205. selectorName="Merchant"
  206. list={merchant.list}
  207. pageNo={merchant.pageNo}
  208. pageSize={merchant.pageSize}
  209. totalSize={merchant.totalSize}
  210. onCancel={this.handleMerchantSelectorCancel}
  211. onChange={this.handleMerchantSelectorChange}
  212. onFinish={this.handleMerchantSelectorFinish}
  213. />
  214. </Modal>
  215. );
  216. };
  217. // render card title
  218. const renderProductCardName = () => {
  219. return (
  220. <div className={styles.cardName}>
  221. <span>
  222. <a onClick={this.handleProductSelectorModalShow}>
  223. 选择套餐包
  224. </a>
  225. </span>
  226. </div>
  227. );
  228. };
  229. const renderMerchantCardName = () => {
  230. return (
  231. <div className={styles.cardName}>
  232. <span>
  233. <a onClick={this.handleMerchantSelectorModalShow}>
  234. 选择商户
  235. </a>
  236. </span>
  237. </div>
  238. );
  239. };
  240. return (
  241. <div>
  242. {/* 产品选择Card */}
  243. <Card title={renderProductCardName()} style={{ marginBottom: 16 }}>
  244. <Table
  245. bordered
  246. showHeader={false}
  247. pagination={false}
  248. columns={columns}
  249. className={styles.table}
  250. dataSource={productItemFormatter()}
  251. />
  252. {!productSelectorDestroy && getProductModal()}
  253. </Card>
  254. {/* 渠道选择Card */}
  255. <Card title={renderMerchantCardName()} style={{ marginBottom: 70 }}>
  256. <Table
  257. bordered
  258. showHeader={false}
  259. pagination={false}
  260. columns={columns}
  261. className={styles.table}
  262. dataSource={merchantItemFormatter()}
  263. />
  264. {!merchantSelectorDestroy && getMerchantModal()}
  265. </Card>
  266. <FooterToolbar style={{ width: '100%' }}>
  267. <Button
  268. onClick={this.handlePageBack}
  269. style={{ marginRight: 10 }}
  270. >取消
  271. </Button>
  272. <Button
  273. type="primary"
  274. loading={submitting}
  275. onClick={this.handlePageSubmit}
  276. >提交
  277. </Button>
  278. </FooterToolbar>
  279. </div>
  280. );
  281. }
  282. }