table.js 2.07 KB
/*
 * @Description: 
 * @Autor: renchao
 * @LastEditTime: 2023-11-10 10:34:55
 */
import { mapGetters } from 'vuex'
import { defaultParameters } from "../../views/ywbl/ywsq/javascript/publicDefaultPar";
export default {
  data () {
    return {
      pageData: {
        currentPage: 1,
        pageSize: 10
      }
    }
  },
  computed: {
    ...mapGetters(['dictData']),
  },
  mounted () {
    window.addEventListener('keydown', this.handkeyCode, true)//开启监听键盘按下事件
    this.handleSearch()
  },
  methods: {
    /**
     * @description: handkeyCode
     * @param {*} e
     * @author: renchao
     */
    handkeyCode (e) {
      if (e.keyCode === 13) {
        this.handleSearch()
      }
    },
    /**
     * @description: handleSearch
     * @author: renchao
     */
    handleSearch () {
      this.pageData.currentPage = 1
      if (this.fetchData) {
        this.fetchData()
      }
      if (this.queryClick) {
        this.queryClick()
      }
    },
    /**
     * @description: handleSizeChange
     * @param {*} val
     * @author: renchao
     */
    handleSizeChange (val) {
      this.pageData.currentPage = 1
      this.pageData.pageSize = val
      this.queryClick()
    },
    /**
     * @description: handleCurrentChange
     * @param {*} val
     * @author: renchao
     */
    handleCurrentChange (val) {
      this.pageData.currentPage = val
      if (this.queryClick) {
        this.queryClick()
      }
    },
    /**
     * @description: handleDel
     * @author: renchao
     */
    handleDel () {
      let deleteAfterPage = Math.ceil((this.tableData.total - 1) / this.pageData.pageSize)
      let currentPage = this.pageData.currentPage > deleteAfterPage ? deleteAfterPage : this.pageData.currentPage
      this.pageData.currentPage = currentPage < 1 ? 1 : currentPage
    },
    /**
     * @description: resetForm
     * @param {*} isYwbl
     * @author: renchao
     */
    resetForm (isYwbl) {
      if (isYwbl) {
        this.queryForm = defaultParameters.defaultParameters();
        this.pageData.currentPage = 1;
        this.queryClick()
      }
    }
  }
}