<template>

	<view>
		<u-tabs-swiper ref="tabs" :list="crowdslist" :is-scroll="false" @change="tabsChange" :current="current"
			bg-color='#FFFFFF' active-color="#1578ED" inactive-color='#666666' bar-width='180'>
		</u-tabs-swiper>
		<view class="navTab">
			<view v-if="currenttasklist&&currenttasklist.length>0">
				<view v-if="current==0">
					<view v-for="(item,key) of currenttasklist" class="sign_list" @click="signupdetails(item.task_id)">
						<view
							style="display:flex;margin:0 12px 8px 0;justify-content: space-between;align-items: flex-end;">
							<view class="rightb" style="background: linear-gradient(90deg, #FFDC00, #ED9706);"> 竞标中
							</view>
							<p v-if="item.price == 0" style="color:#FD461A;">赏金金额：面议 </p>
							<p v-else style="color:#FD461A;">赏金金额：{{item.price}} </p>
						</view>
						<view class="fline"> </view>
						<view style="margin:12px 15px 0 15px;color:#333333;font-size:13px;line-height:27px;">
							<p>项目名称：{{item.project_name}}</p>
							<p>竞标时间：{{item.create_time.slice(0,10)}}</p>
							<p>项目周期：{{item.period}}</p>
							<p>技能要求：{{item.tech_need}}</p>
						</view>
					</view>
				</view>
				<view v-if="current==1">
					<!-- <p>竞标成功，在实施的项目还有待验收的项目</p> -->
					<view v-for="(item,key) of currenttasklist" class="sign_list" @click="signupdetails(item.task_id)">
						<view
							style="display:flex;margin:0 12px 8px 0;justify-content: space-between;align-items: flex-end;">
							<view v-if='item.status==1' class="rightb"> 实施中 </view>
							<view v-if='item.status==3' class="rightb"
								style="background: linear-gradient(90deg, #FCA141, #FD6940);"> 待验收 </view>
							<view v-if='item.status==4' class="rightb"
								style="background: linear-gradient(90deg, #FCA141, #FD6940);"> 待付款 </view>
							<p style="color:#FD461A;">赏金金额：{{item.price}} </p>
						</view>
						<view class="fline"></view>
						<view style="margin:12px 15px 0 15px;color:#333333;font-size:13px;line-height:27px;">
							<p>项目名称：{{item.project_name}}</p>
							<p>竞标时间：{{item.create_time.slice(0,10)}}</p>
							<p>项目周期：{{item.period}}</p>
							<p>技能要求：{{item.tech_need}}</p>
						</view>
					</view>
				</view>
				<view v-if="current==2">
					<!-- <p>竞标成功，已完成的项目</p> -->
					<view v-for="(item,key) of currenttasklist" class="sign_list" @click="signupdetails(item.task_id)">
						<view
							style="display:flex;margin:0 12px 8px 0;justify-content: space-between;align-items: flex-end;">
							<view v-if='item.status==2' class="rightb"
								style="background: linear-gradient(90deg, #FCA141, #FD6940);">竞标失败</view>
							<view v-if='item.status==5' class="rightb"
								style="background: linear-gradient(90deg, #1BF5B3, #08C78F);"> 已完成 </view>
							<view v-if='item.status==6' class="rightb"
								style="background: linear-gradient(90deg, #FCA141, #FD6940);"> 验收不通过 </view>
							<!-- <view v-if='item.status==2 && item.process_status==3' class="rightb" style="background: linear-gradient(90deg, #FCA141, #FD6940);">竞标成功</view> -->
							<p style="color:#FD461A;">赏金金额：{{item.price}} </p>
						</view>
						<view class="fline"></view>
						<view style="margin:12px 15px 0 15px;color:#333333;font-size:13px;line-height:27px;">
							<p>项目名称：{{item.project_name}}</p>
							<p>竞标时间：{{item.create_time.slice(0,10)}}</p>
							<p>项目周期：{{item.period}}</p>
							<p>技能要求：{{item.tech_need}}</p>
							<view class="reviewbtnbox" v-if="item.status==5 && item.is_comment == 0">
								<view class="reviewbtn" @click.stop="openreviewDialog(item.task_id)">
									去评价
								</view>
							</view>
						</view>
					</view>
				</view>
			</view>
			<view v-else style="font-size:46rpx;
				font-weight: bold;
				color: #9D9D9D; text-align:center;margin-top:100px">暂无竞标信息</view>
			<view style="height:10px;"></view>
		</view>


		<!-- 评价弹层 -->
		<view class="reviewDialog" v-if="showReviewDialog">
			<view class="reviewbox">
				<view class="closereview" @click="closeReview">
					x
				</view>
				<view class="titlereview">
					评价
				</view>
				<view class="tipcon">
					这次合作还愉快吗，评价一下可以帮助到其他人哦！
				</view>
				<view class="ratebox">
					<u-rate v-model="rateValue" active-color="#fa9c22" inactive-color="#CDCECE"></u-rate>
				</view>
				<view class="remarkbox">
					<u-input :clearable="false" v-model="remarkValue" type="textarea" border height="150" />
				</view>
				<view class="reviewbtn" @click="fabuReview">
					发布评价
				</view>
			</view>
		</view>

		<!-- 评价成功 -->
		<view class="reviewDialog" v-if="showSuccessInfo">
			<view class="successbox">
				<image src="../../../static/crowd/success.png" mode=""></image>
				感谢您的评价!
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				crowdslist: [{
					name: '竞标中'
				}, {
					name: '实施中'
				}, {
					name: '已完成'
				}, ],
				alltasklist: [], //全部任务
				currenttasklist: [], //当前状态任务
				current: 0,
				showReviewDialog: false,
				showSuccessInfo: false,
				rateValue: null,
				remarkValue: null,
				taskId: null
			}
		},
		onLoad() {
			let wxUserInfo = uni.getStorageSync('wxUserInfo');
			if (wxUserInfo) {
				this.http.quickGet(`/crowdsource/claim/my/${wxUserInfo.userId}`, true).then(res => {
					console.log('我的众包--', res)
					// status=0竞标中,1被选中也就是实施中,2项目结束
					this.alltasklist = res.data.rows
					this.currenttasklist = this.alltasklist
					this.currenttasklist = this.alltasklist.filter(item => item.status == 0);
				})
			}
		},
		methods: {
			tabsChange(e) {
				this.current = e
				if (this.alltasklist.length > 0) {
					if (this.current == 0) {
						this.currenttasklist = this.alltasklist.filter(item => item.status == 0);
					} else if (this.current == 1) {
						this.currenttasklist = this.alltasklist.filter(item => item.status == 1 || item.status == 3 || item
							.status == 4);
						console.log('status', this.currenttasklist)
					} else if (this.current == 2) {
						this.currenttasklist = this.alltasklist.filter(item => item.status == 2 || item.status == 5 || item
							.status == 6);
					}
				}
			},
			signupdetails(id) {
				uni.navigateTo({
					url: `/pages/index/testcrowdsourc/crowdsourcingdetails?id=${id}&type=1`

				})
			},
			// 打开弹层
			openreviewDialog(id) {
				this.showReviewDialog = true
				this.taskId = id
			},
			closeReview() {
				this.showReviewDialog = false
				this.rateValue = null
				this.remarkValue = null
				this.taskId = null
			},
			fabuReview() {
				console.log(this.rateValue);
				if (!this.rateValue) {
					uni.showToast({
						title: '请选择评分',
						icon: 'none'
					})
					return 
				}
				if (!this.remarkValue) {
					uni.showToast({
						title: '请填写内容',
						icon: 'none'
					})
					return 
				}
				const data = {
					taskId: this.taskId,
					star: this.rateValue,
					content: this.remarkValue,
				}
				this.http.quickPost(`/comment/addComm`, data, true).then(res => {
					this.closeReview()
					this.showSuccessInfo = true
					this.current = 0
					let wxUserInfo = uni.getStorageSync('wxUserInfo');
					this.http.quickGet(`/crowdsource/claim/my/${wxUserInfo.userId}`, true).then(res => {
						this.alltasklist = res.data.rows
						this.currenttasklist = this.alltasklist
						this.currenttasklist = this.alltasklist.filter(item => item.status == 0);
					})
					setTimeout(() => {
						this.showSuccessInfo = false
					}, 1000)
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.navTab {
		padding: 2vh 13px;
	}

	.sign_list {
		width: 100%;
		background: #FFFFFF;
		border-radius: 10px;
		margin-bottom: 20px;
		padding-bottom: 15px;
	}

	.rightb {
		width: 183rpx;
		height: 54rpx;
		background: linear-gradient(90deg, #5EA6FD, #1A81F9);
		border-radius: 9px 0px 46px 0px;
		color: #FFFFFF;
		font-size: .8rem;
		line-height: 54rpx;
		text-align: center;

	}

	.fline {
		width: 100%;
		height: 1rpx;
		border: 1px solid #999999;
		opacity: 0.15;
	}

	.reviewbtnbox {
		display: flex;
		justify-content: flex-end;
	}

	.reviewbtn {
		width: 150rpx;
		height: 50rpx;
		background: #FBA02A;
		border-radius: 6rpx;
		font-weight: 500;
		font-size: 24rpx;
		color: #FFFFFF;
		line-height: 50rpx;
		text-align: center;
	}

	.reviewDialog {
		position: fixed;
		z-index: 99999999999999999999999999999999;
		top: 0;
		left: 0;
		width: 100vw;
		height: 100vh;
		background: rgba(0, 0, 0, 0.5);
		display: flex;
		justify-content: center;
		align-items: center;

		.reviewbox {
			position: relative;
			width: 559rpx;
			height: 593rpx;
			background: #FFFFFF;
			box-shadow: 0rpx 4rpx 21rpx 4rpx rgba(19, 106, 189, 0.15);
			padding: 25rpx;
			box-sizing: border-box;

			.titlereview {
				font-weight: bold;
				font-size: 30rpx;
				color: #1A1A1A;
				text-align: center;
				height: 70rpx;
				line-height: 70rpx;
			}

			.closereview {
				font-weight: bold;
				font-size: 30rpx;
				color: #1A1A1A;
				font-weight: 400;
				font-size: 40rpx;
				color: #858994;
				position: absolute;
				top: 0;
				right: 20rpx;
			}

			.tipcon {
				font-weight: 500;
				font-size: 22rpx;
				color: #333333;
				text-align: center;
				margin: 20rpx 0;
			}

			.ratebox {
				display: flex;
				justify-content: center;
				margin-bottom: 23rpx;
			}

			.ratebox ::v-deep .u-icon {
				font-size: 20px !important;
			}

			.remarkbox {
				margin-bottom: 30rpx;
			}

			.reviewbtn {
				width: 100%;
				height: 60rpx;
				background: #2084F9;
				border-radius: 6rpx;
				line-height: 60rpx;
				text-align: center;
			}
		}

		.successbox {
			width: 500rpx;
			height: 70rpx;
			background: #FDF7EE;
			box-shadow: 0rpx 1rpx 15rpx 0rpx rgba(39, 50, 63, 0.15);
			border-radius: 6rpx;
			font-weight: bold;
			font-size: 26rpx;
			color: #000000;
			display: flex;
			align-items: center;
			justify-content: center;

			image {
				width: 30rpx;
				height: 30rpx;
				margin-right: 20rpx;
			}
		}
	}
</style>