index.js 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. import React, { PureComponent } from 'react';
  2. import { connect } from 'dva';
  3. import { routerRedux } from 'dva/router';
  4. import PageHeaderLayout from '../../layouts/PageHeaderLayout';
  5. import RecommendList from './recommend';
  6. import { getLocalUser } from '../../utils/config';
  7. import { pageSize } from '../../utils/config';
  8. @connect(state => ({
  9. recommend: state.recommend,
  10. mproduct: state.mproduct,
  11. }))
  12. export default class FrontendConfiger extends PureComponent {
  13. state = { curTab: 'recommend' };
  14. handleTabChange = (key) => {
  15. this.setState({ curTab: key });
  16. }
  17. // 点击调整推荐位按钮 - 弹出模态框
  18. handleRecommendAdjustClick = () => {
  19. this.props.dispatch({ type: 'recommend/showModal' });
  20. }
  21. // 点击模态框的取消按钮 - 隐藏
  22. handleRecommendModalCancel = () => {
  23. this.props.dispatch({ type: 'recommend/hideModal' });
  24. }
  25. // 点击模态框的确定按钮 -> 更新recommend model state -> 隐藏
  26. handleRecommendModalOk = (data) => {
  27. this.props.dispatch({
  28. type: 'recommend/saveSortResult',
  29. payload: data,
  30. });
  31. }
  32. // 点击模态框的搜索按钮 -> 查询相关产品
  33. handleRecommendModalSearch = (data) => {
  34. const { merchantId } = getLocalUser();
  35. const newData = { ...data };
  36. if (newData.keyword) {
  37. newData[newData.field] = newData.keyword;
  38. }
  39. delete newData.field;
  40. delete newData.keyword;
  41. this.props.dispatch({
  42. type: 'mproduct/query',
  43. payload: {
  44. merchantId,
  45. pageNo: 1,
  46. pageSize,
  47. },
  48. });
  49. }
  50. // 模态框中表格翻页
  51. handleRecommendModalTableChange = (pagination, filterArgs, filters) => {
  52. const { merchantId } = getLocalUser();
  53. const newFilters = { ...filters };
  54. if (newFilters.keyword) {
  55. newFilters[newFilters.field] = newFilters.keyword;
  56. }
  57. delete newFilters.field;
  58. delete newFilters.keyword;
  59. const data = {
  60. ...newFilters,
  61. merchantId,
  62. pageNo: pagination.current,
  63. pageSize: pagination.pageSize,
  64. };
  65. Object.keys(data).map(key => (data[key] ? null : delete data[key]));
  66. dispatch({ type: 'mproduct/query', payload: data });
  67. }
  68. // 页面退出 - 跳首页
  69. handleRecommendPageCancel = () => {
  70. const { dispatch } = this.props;
  71. dispatch(routerRedux.push('/'));
  72. }
  73. // 页面提交[params: merchantId, idList] - 成功跳首页
  74. handleRecommendPageSubmit = () => {
  75. const { merchantId } = getLocalUser();
  76. const { dispatch, recommend } = this.props;
  77. const { item } = recommend;
  78. const idList = item.map(one => one.id);
  79. dispatch({
  80. type: 'recommend/updateMerchantRecommend',
  81. payload: { merchantId, idList },
  82. callback: () => {
  83. dispatch(routerRedux.push('/'));
  84. },
  85. });
  86. }
  87. render() {
  88. const { recommend, mproduct } = this.props;
  89. const { item, loading, modalShow } = recommend;
  90. const tabList = [{
  91. key: 'recommend',
  92. tab: '推荐位设置',
  93. }];
  94. const contentMap = {
  95. recommend:
  96. <RecommendList
  97. rowKeyName="id"
  98. loading={loading}
  99. selTableData={item}
  100. modalVisible={modalShow}
  101. fsTableDataSource={mproduct.list}
  102. fsTablePagination={mproduct.pagination}
  103. fsTableLoading={mproduct.listLoading}
  104. fsTableOnChange={this.handleRecommendModalTableChange}
  105. onOk={this.handleRecommendModalOk}
  106. onCancel={this.handleRecommendModalCancel}
  107. onSearch={this.handleRecommendModalSearch}
  108. modalShowController={this.handleRecommendAdjustClick}
  109. onPageCancel={this.handleRecommendPageCancel}
  110. onPageSubmit={this.handleRecommendPageSubmit}
  111. />,
  112. };
  113. return (
  114. <PageHeaderLayout
  115. tabList={tabList}
  116. onTabChange={this.handleTabChange}
  117. >
  118. {contentMap[this.state.curTab]}
  119. </PageHeaderLayout>
  120. );
  121. }
  122. }