“react“: “^16.14.0“,打开弹窗数据发生变化

"react": "^16.14.0",

弹窗

打开弹窗数据发生变化

cpp 复制代码
// 这里对比changeHistoryVisible是否发生改变调用后端方法改变数据
 componentDidUpdate(prevProps) {
    if (prevProps.changeHistoryVisible !== this.props.changeHistoryVisible && this.props.changeHistoryVisible) {
      this.getStockLogList()
    }
  }

  componentDidMount() {
    this.getStockLogList()
  }
cpp 复制代码
<Modal
                        title={'变更记录'}
                        visible={changeHistoryVisible}
                        onCancel={() => this.changeHistoryCancel()}
                        footer={false}
                        width={800}
                    >
                        <ModelCom changeHistoryVisible={changeHistoryVisible} ref={this.ModelCom} id={id} type={type}></ModelCom>
                    </Modal>
cpp 复制代码
import React, { Component, useEffect } from 'react';
import { connect } from 'dva';
import PropTypes from 'prop-types';
import { Button, Card, Form, Table, message, Modal } from 'antd';
import moment from 'moment';
import { enterStockTypeStatus, orderTypeNewRetail } from '@/utils/enumType'

@connect((RetailGoodsInBound) => ({
  ...RetailGoodsInBound,
}))
// 变更记录弹窗
export default class ModelCom extends Component {
  static propTypes = {
    dispatch: PropTypes.func,
    match: PropTypes.shape,
  }

  static defaultProps = {
    dispatch: PropTypes.dispatch,
    match: PropTypes.match,
  }
  state = {
    // changeHistoryVisible: false,
    loadingLog: false,
    currentObj: {},
    params: {
      currentPage: 1,
      pageSize: 10,
      id: ''
    }
  }

  columns = [
    {
      title: '变更用户',
      dataIndex: 'operatorName',
      key: 'operatorName',
    },
    {
      title: '变更时间',
      dataIndex: 'gmtCreate',
      key: 'gmtCreate',
      render: (text) => <>{text ? moment(text).format('YYYY-MM-DD') : ''}</>
    },
    {
      title: '条码',
      dataIndex: 'oldData',
      key: 'oldData',
    },
    {
      title: '操作',
      dataIndex: 'orderType',
      key: 'orderType',
      render: (text, record) => <><span>{`${orderTypeNewRetail(record.orderType)}${enterStockTypeStatus(record.type)}`}</span></>
  
    },
  ]
  componentDidUpdate(prevProps) {
    if (prevProps.changeHistoryVisible !== this.props.changeHistoryVisible && this.props.changeHistoryVisible) {
      this.getStockLogList()
    }
  }

  componentDidMount() {
    this.getStockLogList()
  }
  columnsFilter() { }

  getStockLogList = () => {
    const { dispatch } = this.props
    this.state.params.id = this.props.id
    const currentObj = {
      type: this.props.type,
      id: this.props.id,
    }
    this.setState({
      currentObj
    })
    this.setState({
      loadingLog: true
    })
    dispatch({
      type: 'RetailGoodsInBound/getGoodsUpdateLog',
      payload: { ...this.state.params },
    }).then(res => {
      if (res.code === 20000) {
        this.setState({
          loadingLog: false
        })
      }
    })
  }
  // 改变每页条数&下一页 上一页
  pageChange = (current, pageSize) => {
    this.state.params.currentPage = current;
    this.state.params.pageSize = pageSize;
    this.getStockLogList();
  };
  render() {
    const { RetailGoodsInBound: { stockLogList } } = this.props;
    const { changeHistoryVisible, loadingLog } = this.state
    return (
      // <Modal
      //   title={'变更记录'}
      //   visible={changeHistoryVisible}
      //   onCancel={() => this.changeHistoryCancel()}
      //   footer={false}
      //   width={800}
      // >
      <div className="contentModel">
        <Table
          rowKey="barCode"
          columns={this.columns}
          dataSource={stockLogList.rows ? stockLogList.rows : []}
          bordered
          loading={loadingLog}
          scroll={{ y: 400 }}
          pagination={{
            showSizeChanger: true,
            showQuickJumper: true,
            current: stockLogList.currentPage, // 当前页
            pageSize: stockLogList.pageSize, // 每页几条
            total: stockLogList.totalCount, // 总共条数
            onShowSizeChange: (current, pageSize) => {
              this.pageChange(current, pageSize);
            },
            onChange: (current, pageSize) => {
              this.pageChange(current, pageSize);
            },
            showTotal: (total) => `共 ${total} 条记录    第
                          ${stockLogList.currentPage ? stockLogList.currentPage : 1}/
                          ${stockLogList.totalPage ? stockLogList.totalPage : 1}页`
          }}
        />
      </div>
      // </Modal>

    )
  }
}
相关推荐
一头小鹿26 分钟前
【JS】原型和原型链 | 笔记整理
javascript
red润1 小时前
封装hook,复刻掘金社区,暗黑白天主题切换功能
前端·javascript·vue.js
葬送的代码人生1 小时前
React组件化哲学:如何优雅地"变秃也变强"
前端·javascript·react.js
Bl_a_ck1 小时前
【JS进阶】ES6 实现继承的方式
开发语言·前端·javascript
小马虎本人1 小时前
如果接口返回的数据特别慢?要怎么办?难道就要在当前页面一直等吗
前端·react.js·aigc
咪库咪库咪1 小时前
js的浅拷贝与深拷贝
javascript
幸福的猪在江湖1 小时前
第一章:变量筑基 - 内力根基修炼法
javascript
Ryan今天学习了吗1 小时前
💥不说废话,带你使用原生 JS + HTML 实现超丝滑拖拽排序效果
javascript·html
Momoly081 小时前
vue3+el-table 利用插槽自定义数据样式
前端·javascript·vue.js
多啦C梦a1 小时前
从 React 初体验到数据驱动的界面开发:一步步解析 Todo List 组件
javascript·react.js