<template>
	<view>
		<view class="position">
			<view class="audits">
				<view class="audit" :class="{ active: current == index }" v-for="(item, index) in audit" :key="index" @click="click({ index: index }, 'audit')">{{ item.name }}</view>
			</view>
			<view class="item" v-for="(item, index) in list" :key="index" @click="go('/pages/job/position/manage/part_time_push?id=' + item.id)">
				<view class="top">
					<view class="title omit">
						<text class="icon" :style="{ color: item.state == 0 ? '#4CAF50' : '#545555' }">&#xe614;</text>
						<text>{{ item.title }}</text>
					</view>
					<view class="audit" v-if="item.audit == 0">
						<text class="icon">&#xe642;</text>
						<text>审核中</text>
					</view>
					<view class="audit" style="color: #4caf50" v-if="item.audit == 1">
						<text class="icon">&#xe612;</text>
						<text>审核通过</text>
					</view>
					<view class="audit" v-if="item.audit == 2">
						<text class="icon">&#xec72;</text>
						<text>审核不通过</text>
					</view>
				</view>
				<view class="desc">
					<text class="tag org">{{ item.salary }}¥</text>
					<text class="tag">{{ item.regionName || '地点不限' }}</text>
					<text class="tag">周期:{{ item.days }}天</text>
					<text class="date">{{ item.createTime }}</text>
				</view>
				<view class="flex">
					<view class="f danger" @click.stop="manageRemove(item)" v-if="item.complete == 0 && item.audit == 0">删除</view>
					<view class="f" @click.stop="manageRemove(item)" v-else>查看</view>
				</view>
			</view>
			<view class="loading" v-if="loadMore"><u-loadmore :status="loadMore ? 'loading' : 'nomore'" /></view>
			<u-empty v-if="!loadMore && list.length == 0"></u-empty>
		</view>
		<view class="mfooter">
			<button class="btn" @click="go('/pages/job/position/manage/part_time_push')">
				<text class="icon">&#xe7c4;</text>
				<text>发布兼职</text>
			</button>
		</view>
	</view>
</template>

<script>
export default {
	data() {
		return {
			audit: [
				{ name: '全部', value: '' },
				{ name: '待审核', value: 0 },
				{ name: '审核通过', value: 1 },
				{ name: '未通过', value: 2 }
			],
			current: 0,
			list: [],
			param: { pageNum: 1, pageSize: 10, type: 1 },
			loadMore: true
		};
	},
	onLoad(e) {
		this.getData();
		uni.$on('position', (res) => {
			this.refresh();
		});
	},
	methods: {
		getData() {
			this.http.request({
				url: '/app/position/manage/list',
				data: this.param,
				loading: 'false',
				success: (res) => {
					this.loadMore = res.data.pages > this.param.pageNum ? true : false;
					res.data.rows.forEach((item) => {
						item.createTime = uni.$u.timeFrom(Date.parse(item.createTime));
						item.days = this.util.days(item.startDate, item.endDate);
						this.list.push(item);
					});
				}
			});
		},
		click(e) {
			this.param.audit = this.audit[e.index].value;
			this.current = e.index;
			this.refresh();
		},
		go(url) {
			uni.navigateTo({ url: url });
		},
		manageRemove(item) {
			uni.showModal({
				title: '提示',
				content: '确定删除该兼职？删除后兼职金额(不包含服务费)会退回到你的账户下',
				success: (res) => {
					if (res.confirm) {
						this.http.request({
							url: '/app/position/manage/remove/' + item.id,
							success: (res) => {
								uni.showToast({ title: '删除成功' });
								this.list.splice(this.list.indexOf(item), 1);
							}
						});
					}
				}
			});
		},
		//刷新数据
		refresh() {
			this.loadMore = true;
			this.param.pageNum = 1;
			this.list = [];
			this.getData();
		}
	},
	//下拉刷新
	onPullDownRefresh() {
		setTimeout(() => {
			this.refresh();
			uni.stopPullDownRefresh();
		}, 1000);
	},
	//上拉加载
	onReachBottom() {
		if (this.loadMore) {
			this.param.pageNum++;
			this.getData();
		}
	}
};
</script>

<style lang="scss"></style>
