<template>
	<scroll-view v-if="show && data.length > 0" @scrolltolower="upLoad" scroll-y>
		<block v-for="(page, pIndex) in data" :key="pIndex">
			<block v-for="(item, index) in page" :key="index">
				<view class="probody">
					<company-list :companyitem="item" :noApply="false"></company-list>
					<view class="baddd"></view>
					<block v-if="mark">
						<image src="/static/img/tab.orange.svg" mode="" v-if="item.status === 1"></image>
						<image src="/static/img/tab.blue.svg" mode="" v-else-if="item.status === 2"></image>
						<image src="/static/img/tab.green.svg" mode="" v-else-if="item.status === 3"></image>
						<image src="/static/img/tab.gray.svg" mode="" v-else></image>
					</block>
				</view>
			</block>
		</block>
	</scroll-view>
	<view class="nothing" v-else-if="show">
		<image src="/static/img/pic_notask.svg" mode=""></image>
		<view class="nothingContnt">
			暂无任务信息
		</view>
	</view>
</template>

<script>
	import companyList from '@/components/companyList/companyList.vue';
	import {
		myMission
	} from '@/api/mission.js';

	export default {
		components: {
			companyList
		},
		props: {
			show: Boolean,
			mark: Boolean,
			status: Number
		},
		data() {
			return {
				initialized: false,
				data: [],
				current: 1,
				size: 10,
				total: 0
			}
		},
		created() {
			this.init()
		},
		
		methods: {
			init() {
				if (this.show && !this.initialized) {
					this.getData()
					this.initialized = true
				}
			},
			getData(point) {
				myMission(this.current, this.size, this.status).then(res => {
					if (this.current === 1) {
						this.data = [];
					}
					this.current += 1;
					this.total = res.data.data.total;
					if (res.data.data && res.data.data.records.length) {
						this.data.push(res.data.data.records);
					}
				})
			},
			upLoad() {
				if (this.current <= Math.ceil(this.total / this.size)) {
					this.getData();
				} else {
					uni.showToast({
						icon: "none",
						title: '已经是最后一页',
					})
				}
			}
		},
		watch: {
			show(val) {
				this.init()
			}
		}
	}
</script>

<style scoped>
	.probody image {
		width: 88rpx;
		height: 88rpx;
		position: absolute;
		right: 0;
		top: 0;
	}

	.probody {
		width: 100%;
		position: relative;
	}

	.baddd {
		background: #f6f6f6;
		height: 20rpx;
	}

	.nothing {
		height: 100%;
		padding-top: 50%;
		box-sizing: border-box;
	}

	.nothing image {
		width: 400rpx;
		height: 200rpx;
		display: block;
		margin: 0 auto;
	}

	.nothingContnt {
		font-family: PingFangSC-Regular;
		font-size: 28rpx;
		color: #666;
		margin-top: 30rpx;
		text-align: center;
	}
</style>
