<template>
	<view>
		<u-navbar back-text="共享用工" back-icon-size="28" back-icon-color="#ffffff" :background="{backgroundColor: '#2795FD',}"
			:back-text-style="{color: '#ffffff'}"></u-navbar>
		<!-- 标签 -->
		<view class="tabs">
			<u-tabs :list="list" :is-scroll="false" :current="current" @change="change"></u-tabs>
		</view>
		<view class="content">
			<view class="info-card" v-for="(item,i) in list[current].list" :key="i">
				<!-- 卡片信息 -->
				<view class="detail" @click="gotoUrl('pages/packages/shareEmployment/articleDetail?id='+item.id)">
					{{item.title}}
				</view>
				<view class="tag" @click="gotoUrl('pages/packages/shareEmployment/articleDetail?id='+item.id)">
					<view class="item1" v-if="item.type == '1'">
						急需用工
					</view>
					<view class="item2" v-if="item.type == '2'">
						资源共享
					</view>
					<view class="date-item">
						{{item.createTime.slice(0,10)}}
					</view>
				</view>
				<u-line color="#CFD2D5" />
				<!-- 发布状态 -->
				<view class="check">
					<view class="state" v-if="item.status == '1'">
						发布中
					</view>
					<view class="state" v-if="item.status == '0'">
						待审核
					</view>
					<view class="state" v-if="item.status == '2'">
						未通过
					</view>
					<view class="handle">
						<view class="amend" @click="toPostMessage(item)">
							修改
						</view>
						<view class="delete" @click="deleteWork(item.id)">
							删除
						</view>
					</view>
				</view>
			</view>
		</view>

		<u-divider bg-color="#F0F0F2" margin-top="40" border-color="#CFD2D5"
			v-if="formList[current].recordsTotal==list[current].list.length"
			:isnone="formList[current].recordsTotal==0" nonetext="没有找到相关内容">
			已经到底了
		</u-divider>
		
		<!-- 底部按钮 -->
		<button class="btn" @click="toPostMessage()">发布信息
		</button>
	</view>
</template>

<script>
	import * as API_packages from '@/apis/pagejs/packages.js'
	
	export default {
		data() {
			return {
				formList: [
					{
						pageIndex: 1,
						pageSize: 20,
						recordsTotal: 1,
						status: "1",
					},
					{
						pageIndex: 1,
						pageSize: 20,
						recordsTotal: 1,
						status: "0",
					},
					{
						pageIndex: 1,
						pageSize: 20,
						recordsTotal: 1,
						status: "2",
					},
				],
				list: [{
					name: '发布中',
					list: []
				}, {
					name: '待审核',
					list: []
				}, {
					name: '未通过',
					list: []
				}],
				current: 0
			}
		},
		onReady() {
			this.getMyShareWorkList();
		},
		onReachBottom() {
			var obj = this.list[this.current];
			var objf = this.formList[this.current];
			if (obj.list.length < objf.recordsTotal) {
				this.myLoadmore();
			}
		},
		methods: {
			init() {
				this.current =1
				for(var i in this.list){
					this.formList[i].pageIndex = 1
					this.list[i].list = []
				}
				this.getMyShareWorkList()
			},
			toPostMessage(item) {
				var url = "";
				if(item) {
					var url = "/pages/packages/mine/employmentService/postMessage?id=" +item.id;
				} else {
					var url = "/pages/packages/mine/employmentService/postMessage";
				}
				uni.navigateTo({
					url: url,
					events: {
						refreshData: () => {
							this.init()
						}
					}
				})
			},
			deleteWork(id) {
				uni.showLoading({
					title: "加载中",
					mask: true,
				})
				API_packages.myShareWorkDelete({id: id}).then((res) => {
					this.getMyShareWorkList();
					uni.hideLoading();
				}).catch(error => {
					uni.showToast({icon: 'none',
						title: error,
						icon: "none"
					})
				})
			},
			getMyShareWorkList() {
				uni.showLoading({
					title: "加载中",
					mask: true,
				})
				var list = this.list[this.current].list
				var listForm = this.formList[this.current]
				
				API_packages.myShareWork(listForm).then((res) => {
					if (listForm.pageIndex == 1) {
						list = res.data.data;
					} else {
						list = [
							...list,
							...res.data.data
						];
					}
				
					this.list[this.current].list = list
					this.formList[this.current].recordsTotal = res.data.recordsTotal;
					uni.hideLoading();
				}).catch(error => {
					uni.showToast({icon: 'none',
						title: error,
						icon: "none"
					})
				})
			},
			myLoadmore() {
				this.formList[this.current].pageIndex += 1;
				this.getMyShareWorkList();
			},
			change(index) {
				
				this.current = index;
				var list = this.list[this.current].list
				this.list[this.current].pageIndex = 1;
				this.list[this.current].list = [];
				this.getMyShareWorkList();
			}
		}
	}
</script>

<style>
	page {
		background: #F0F0F2;
		padding-bottom: 120px;
	}
</style>
<style scoped lang="scss">
	// 标签
	.tabs {
		position: fixed;
		left: 0;
		right: 0;
		z-index: 99;
	}

	.content {
		margin-top: 108rpx;
	}

	.info-card {
		margin: 24rpx 32rpx 0;
		padding: 24rpx;
		background-color: #fff;
		border-radius: 24rpx;

		// 卡片信息
		.detail {
			color: rgba(16, 16, 16, 1);
			line-height: 40rpx;

		}

		.tag {
			display: flex;
			justify-content: space-between;
			margin-top: 16rpx;
			margin-bottom: 24rpx;

			.item1 {
				color: rgba(39, 149, 253, 1);
				font-size: 24rpx;
			}

			.item2 {
				color: rgba(0, 185, 98, 1);
				font-size: 24rpx;
			}
		}

		// 发布状态
		.check {
			display: flex;
			justify-content: space-between;
			align-items: center;
			margin-top: 32rpx;

			.state {
				color: rgba(51, 51, 51, 1);
				font-weight: 600;
			}

			.handle {
				display: flex;
				align-items: center;

				.unamend {
					width: 120rpx;
					height: 56rpx;
					line-height: 56rpx;
					text-align: center;
					font-family: Microsoft Yahei;
					border: 1px solid rgba(231, 232, 234, 1);
					border-radius: 50px;
					opacity: 0.4;
				}

				.amend {
					width: 120rpx;
					height: 56rpx;
					line-height: 56rpx;
					text-align: center;
					font-family: Microsoft Yahei;
					border: 1px solid rgba(231, 232, 234, 1);
					border-radius: 50px;

				}

				.delete {
					width: 120rpx;
					height: 56rpx;
					line-height: 56rpx;
					text-align: center;
					font-family: Microsoft Yahei;
					border: 1px solid rgba(231, 232, 234, 1);
					border-radius: 50px;
					margin-left: 24rpx;
					color: #E60012;
				}
			}
		}
	}

	// 底部按钮


	.btn {
		position: fixed;
		bottom: 40rpx;
		left: 0;
		right: 0;
		background-color: #F0F0F2;
		padding: 0 32rpx;
		border-radius: 50px;
		background-color: rgba(34, 149, 255, 1);
		color: rgba(241, 241, 241, 1);
		font-size: 36rpx;
		margin: 0 32rpx;
		box-shadow: 0px 0px 6px 0px rgba(0, 0, 0, 0.03);
	}
</style>