pageMixin.js 1.01 KB
export default {
	data () {
		return {
			tabIndex: 0,
			pageNum: 1,
			list: [],
			total: 0,
			flag: false,
			updata: new Date().getTime()
		}
	},
	mounted () {
		let { tabIndex } = this.getQuery()
		if (tabIndex) {
			this.tabIndex = Number(tabIndex)
			// this.updata = new Date().getTime()
			this.init()
			return
		}
		if (this.$route.meta.isTab) this.init()
	},
	methods: {
		init () {
			this.showLoading()
			this.getList(this.pageNum)
		},
		change (index) {
			this.tabIndex = index
			this.clearData()
		},
		clearData () {
			this.flag = false
			this.pageNum = 1
			this.list = []
			if (this.$refs.scrollView) this.$refs.scrollView.finished = false
			this.init()
		},
		onReachBottom () {
			let { total, pageNum, list } = this
			this.$refs.scrollView.loading = false
			if (list.length == total) {
				this.$refs.scrollView.finished = true
				return
			}
			if (Math.ceil(total / 10) > pageNum) {
				this.pageNum = pageNum + 1
				this.init()
			} else {
				this.$refs.scrollView.finished = true
			}
		}
	}
}