export default {
	watch: {
		'list.loading'(val) {
			if (val) {
				// uni.showLoading({
				// 	title: '加载中...',
				// 	mask: true
				// });
			} else {
				// uni.hideLoading();
			}
		}
	},
	computed: {
		totalPages() {
			if (!this.$util.isEmpty(this.list.total)) {
				return Math.ceil(this.list.total / this.list.limit);
			}
			return 0;
		}
	},
	data() {
		return {
			list: {
				data: [],
				page: 1,
				pageSize: 10,
				loading: true,
				finished: false,
				total: 0
			}
		};
	},
	methods: {
		resetList() {
			this.list = {
				data: [],
				page: 1,
				pageSize: 10,
				loading: true,
				finished: false,
				total: null
			};
		},
		completes(res, listKey) {
			this.list.loading = false;
			// if (res.code !== 1) {
			// 	this.list.finished = true;
			// }
			this.list.data =
				this.list.page === 1
					? res.list || res.data || res[listKey]
					: this.list.data.concat(res.list || res.data || res[listKey]);
			this.list.total = res.totalPage * this.list.pageSize;
			if (res.moreData == 0) {
				this.list.finished = true;
			} else {
				++this.list.page;
			}
		}
	}
};
