pagination.js 1.58 KB
/**
 * 组件描述:官网通用模态窗 第二类
 * PC端样式为左图标右文案
 * 主要用于错误提示
 */
export default {
	name: "pagination",
	props: {
		// 总页数
		total: {
			type: Number,
			default: 1
		},
		// 总条数
		totalItem: {
			type: Number,
			default: 1
		}
	},
	data() {
		return {
			cur: 1, // 当前页码
			sel: 1, // 选择的页码
		}
	},
	components: {},
	computed: {
		offSet: function () {
			return (this.cur - 1) * 5
		},
		indexs: function () {
			var left = 1
			var right = this.total
			var ar = []
			if (this.total >= 11) {
				if (this.cur > 5 && this.cur < this.total - 4) {
					left = this.cur - 5
					right = this.cur + 4
				} else {
					if (this.cur <= 5) {
						left = 1
						right = 10
					} else {
						right = this.total
						left = this.total - 9
					}
				}
			}
			while (left <= right) {
				ar.push(left)
				left++
			}
			return ar
		}
	},
	methods: {
		jumpPage() {
			this.cur = this.sel;
			if (this.cur < 1) this.cur = 1;
			if (this.cur > this.total) this.cur = this.total;
			this.sendPage();
		},
		selPage(data) { //页码点击事件
			if (data == this.cur) return;
			this.cur = data;
			this.sel = this.cur;
			this.sendPage();
		},
		prevPage() {
			this.cur--;
			if (this.cur < 1) this.cur = 1;
			this.sel = this.cur;
			this.sendPage();
		},
		nextPage() {
			this.cur++;
			if (this.cur > this.total) this.cur = this.total;
			this.sel = this.cur;
			this.sendPage();
		},
		sendPage() {
			// 发送选页事件
			this.$emit("selpage", {
				page: this.cur
			});
		},
		initData() {}
	},
	mounted() {},
	created() {}
}