RecommendEdit.js 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. import React, { Component } from 'react';
  2. import pathToRegexp from 'path-to-regexp';
  3. import { connect } from 'dva';
  4. import { routerRedux } from 'dva/router';
  5. import { Card, Modal, Button } from 'antd';
  6. import RBDragSortTable from '../../../components/RBDragSortTable';
  7. import Selector from '../../../components/RBTableSelector/Selector';
  8. import FooterToolbar from '../../../components/FooterToolbar/index';
  9. @connect(({ loading, merchant, shelves }) => ({
  10. shelves,
  11. merchant,
  12. sLoading: loading.models.product,
  13. submitting: loading.models.merchant,
  14. }))
  15. export default class RecommendEditPage extends Component {
  16. state = {
  17. productSelectorDestroy: true,
  18. };
  19. componentDidMount() {
  20. this.props.dispatch({
  21. type: 'merchant/queryMerchantRecommend',
  22. payload: { merchantId: this.getMerchantId() },
  23. });
  24. }
  25. getMerchantId = () => {
  26. const match = pathToRegexp('/frontend/recommend/edit/:id')
  27. .exec(this.props.location.pathname);
  28. return match[1];
  29. }
  30. handleSelectorModalShow = () => {
  31. this.setState({ productSelectorDestroy: false });
  32. this.props.dispatch({
  33. type: 'shelves/fetchCourseItemList',
  34. payload: { merchantId: this.getMerchantId() },
  35. });
  36. }
  37. handleSelectorChange = (params) => {
  38. this.props.dispatch({
  39. type: 'shelves/fetchCourseItemList',
  40. payload: params,
  41. });
  42. }
  43. handleSelectorFinish = (rows) => {
  44. this.setState({ productSelectorDestroy: true });
  45. this.props.dispatch({
  46. type: 'merchant/fixRecommendList',
  47. payload: rows,
  48. });
  49. }
  50. handleSelectorCancel = () => {
  51. this.setState({ productSelectorDestroy: true });
  52. }
  53. handleDragSortTableChange = (rows) => {
  54. this.props.dispatch({
  55. type: 'merchant/fixRecommendList',
  56. payload: rows,
  57. });
  58. }
  59. handlePageBack = () => {
  60. this.props.dispatch(routerRedux.push({
  61. pathname: '/frontend/recommend',
  62. state: this.props.location.state,
  63. }));
  64. }
  65. handlePageSubmit = () => {
  66. const { merchant } = this.props;
  67. const { recommendList } = merchant;
  68. const idList = recommendList.map(item => item.pid);
  69. this.props.dispatch({
  70. type: 'merchant/updateMerchantRecommend',
  71. payload: {
  72. idList,
  73. merchantId: this.getMerchantId(),
  74. },
  75. });
  76. }
  77. render() {
  78. const { productSelectorDestroy } = this.state;
  79. const { merchant, shelves, sLoading, submitting } = this.props;
  80. const { recommendList } = merchant;
  81. const productColumns = [{
  82. title: '课程编号',
  83. key: 1,
  84. dataIndex: 'code',
  85. width: '40%',
  86. }, {
  87. title: '课程名称',
  88. key: 2,
  89. dataIndex: 'name',
  90. }];
  91. const getProductModal = () => {
  92. return (
  93. <Modal
  94. visible
  95. width={1100}
  96. footer={null}
  97. title="课程资源"
  98. maskClosable={false}
  99. onCancel={this.handleSelectorCancel}
  100. >
  101. <Selector
  102. multiple
  103. loading={sLoading}
  104. selectorName="Course"
  105. selectedRows={recommendList}
  106. list={shelves.list}
  107. pageNo={shelves.pageNo}
  108. pageSize={shelves.pageSize}
  109. totalSize={shelves.totalSize}
  110. onCancel={this.handleSelectorCancel}
  111. onChange={this.handleSelectorChange}
  112. onFinish={this.handleSelectorFinish}
  113. />
  114. </Modal>
  115. );
  116. };
  117. return (
  118. <div>
  119. <Card
  120. title={<a onClick={this.handleSelectorModalShow}>选择课程</a>}
  121. style={{ marginBottom: 70 }}
  122. >
  123. <RBDragSortTable
  124. columns={productColumns}
  125. data={recommendList}
  126. onChange={this.handleDragSortTableChange}
  127. />
  128. {!productSelectorDestroy && getProductModal()}
  129. </Card>
  130. <FooterToolbar style={{ width: '100%' }}>
  131. <Button
  132. onClick={this.handlePageBack}
  133. style={{ marginRight: 10 }}
  134. >取消
  135. </Button>
  136. <Button
  137. type="primary"
  138. loading={submitting}
  139. onClick={this.handlePageSubmit}
  140. >提交
  141. </Button>
  142. </FooterToolbar>
  143. </div>
  144. );
  145. }
  146. }