index.js 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. import { Select, message, Modal } from "antd";
  2. import { connect } from "dva/index";
  3. import router from "umi/router";
  4. import { Component } from "react";
  5. import { businessStateEnum } from "@/utils/utils";
  6. import styles from "./index.less";
  7. @connect(({ store }) => ({
  8. store,
  9. }))
  10. export default class BusinessStateSelector extends Component {
  11. constructor(props) {
  12. super(props);
  13. this.state = {
  14. stateList: Object.keys(businessStateEnum).map((key) => ({
  15. name: businessStateEnum[key],
  16. value: Number(key),
  17. })),
  18. currentBusinessState: "",
  19. visible: false,
  20. };
  21. }
  22. handleChange = (value) => {
  23. const { dispatch } = this.props;
  24. dispatch({
  25. type: "store/update_business_state",
  26. payload: {
  27. businessState: value,
  28. },
  29. callback: (res) => {
  30. if (res.state === 200) {
  31. if (res.data) {
  32. this.setState({ visible: true });
  33. } else {
  34. message.success("设置成功");
  35. this.setState({ currentBusinessState: value });
  36. }
  37. } else {
  38. message.error(res.msg);
  39. }
  40. },
  41. });
  42. };
  43. componentDidMount() {
  44. const { dispatch } = this.props;
  45. dispatch({
  46. type: "store/get_business_state",
  47. callback: (res) => {
  48. if (res.state === 200) {
  49. this.setState({ currentBusinessState: res.data });
  50. } else {
  51. this.setState({ currentBusinessState: 2 });
  52. message.error(res.msg);
  53. }
  54. },
  55. });
  56. }
  57. confirmModal = () => {
  58. if (this.props.confirmModal) {
  59. this.props.confirmModal();
  60. } else {
  61. router.push({
  62. pathname: "/store/decorate_pc",
  63. query: {
  64. tab: "2",
  65. },
  66. });
  67. }
  68. this.setState({ visible: false });
  69. };
  70. cancelModel = () => {
  71. this.setState({ visible: false });
  72. };
  73. render() {
  74. const { stateList, currentBusinessState, visible } = this.state;
  75. return stateList.length ? (
  76. <div className={`${styles.state_warp}`}>
  77. <span className={`${styles.label}`}>经营状态</span>
  78. <Select
  79. value={currentBusinessState}
  80. style={{ width: 150 }}
  81. onChange={this.handleChange}
  82. >
  83. {stateList.map((state) => (
  84. <Select.Option key={state.name} value={state.value}>
  85. {state.name}
  86. </Select.Option>
  87. ))}
  88. </Select>
  89. <Modal
  90. visible={visible}
  91. onOk={this.confirmModal}
  92. onCancel={this.cancelModel}
  93. okText="去启用"
  94. cancelText="取消"
  95. wrapClassName={styles.model_wrap}
  96. width={526}
  97. height={324}
  98. >
  99. <div className={styles.model_content}>
  100. <div className={styles.model_icon}>
  101. <img
  102. className={styles.model_img}
  103. src={require("../../assets/warning.png")}
  104. />
  105. </div>
  106. <div className={styles.model_tip}>
  107. 请先在【店铺装修-首页装修】内,装修首页并将“启用状态”更改为“启用”
  108. </div>
  109. </div>
  110. </Modal>
  111. </div>
  112. ) : null;
  113. }
  114. }