goods_setting.js 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. import { connect } from 'dva/index';
  2. import React, { Component, Fragment } from 'react';
  3. import { Form, Spin } from 'antd';
  4. import {
  5. failTip,
  6. sucTip,
  7. sldComLanguage,
  8. } from '@/utils/utils';
  9. import { sld_config_save_btn,sld_need_update_setting } from '@/utils/util_data';
  10. import global from '@/global.less';
  11. import SldTableEdit from '@/components/SldTableEdit/SldTableEdit';
  12. import SldComHeader from '@/components/SldComHeader';
  13. let sthis = '';
  14. @connect(({ common }) => ({
  15. common,
  16. }))
  17. @Form.create()
  18. export default class GoodsSetting extends Component {
  19. constructor(props) {
  20. super(props);
  21. sthis = this;
  22. this.state = {
  23. flag: 0,
  24. submitting: false,//提交按钮加载状态
  25. initLoading: false,//页面初始化加载状态
  26. info_data: [],
  27. };
  28. }
  29. allowUpdateRequestFlag = true;//立即更新商品数据的允许请求标识
  30. componentDidMount() {
  31. this.get_setting();
  32. }
  33. componentWillUnmount() {
  34. }
  35. //获取设置信息
  36. get_setting = () => {
  37. const { dispatch } = this.props;
  38. let { info_data } = this.state;
  39. this.setState({initLoading: true})
  40. // let str_info = 'goods_publish_need_audit,goods_sort_weight_sale,goods_sort_weight_view';
  41. let str_info = 'goods_publish_need_audit';
  42. dispatch({
  43. type: 'common/getSetting',
  44. payload: { str: str_info },
  45. callback: (res) => {
  46. if (res.state == 200) {
  47. res.data.map(item => {
  48. if(item.name == 'goods_publish_need_audit'){
  49. info_data.push({
  50. type: 'switch',
  51. label: item.title,
  52. extra: item.description,
  53. name: item.name,
  54. placeholder: '',
  55. initialValue: item.value,
  56. });
  57. }else{
  58. info_data.push({
  59. type: 'inputnum',
  60. label: item.title,
  61. extra: item.description,
  62. name: item.name,
  63. placeholder: '',
  64. min:0,
  65. max:100,
  66. initialValue: item.value,
  67. });
  68. }
  69. });
  70. if (info_data.length > 0) {
  71. info_data.push(sld_config_save_btn);
  72. }
  73. }
  74. this.setState({ info_data, flag: 1, initLoading: false });
  75. },
  76. });
  77. };
  78. //保存事件
  79. handleSubmit = (values) => {
  80. this.setState({ submitting: true });
  81. const { dispatch } = this.props;
  82. values.goods_publish_need_audit = values.goods_publish_need_audit ? 1 : 0;
  83. dispatch({
  84. type: 'common/saveSetting',
  85. payload: values,
  86. callback: (res) => {
  87. this.setState({ submitting: false });
  88. if (res.state == 200) {
  89. sucTip(res.msg);
  90. } else {
  91. failTip(res.msg);
  92. }
  93. },
  94. });
  95. };
  96. //立即更新商品数据
  97. updateGoods = () => {
  98. if(!this.allowUpdateRequestFlag)return;//上一次请求还没有结束,不继续请求
  99. this.allowUpdateRequestFlag = false;
  100. const { dispatch } = this.props;
  101. dispatch({
  102. type: 'common/updateEsGoods',
  103. callback: (res) => {
  104. this.allowUpdateRequestFlag = true;
  105. if (res.state == 200) {
  106. sucTip(res.msg);
  107. } else {
  108. failTip(res.msg);
  109. }
  110. },
  111. });
  112. }
  113. render() {
  114. const { info_data, submitting, initLoading, flag } = this.state;
  115. return (
  116. <Spin spinning={initLoading}>
  117. <div className={global.common_page}>
  118. <SldComHeader
  119. type={2}
  120. title={`${sldComLanguage('商品设置')}`}
  121. tip_title={''}
  122. tip_data={sld_need_update_setting()}
  123. />
  124. {flag == 1 &&
  125. <SldTableEdit
  126. submiting={submitting}
  127. width={1000}
  128. data={info_data}
  129. handleSubmit={this.handleSubmit}
  130. showOtherBtn={{
  131. text:`${sldComLanguage('立即更新商品数据')}`,
  132. callback:this.updateGoods,
  133. }}
  134. />
  135. }
  136. </div>
  137. </Spin>
  138. );
  139. }
  140. }