<template>
	<view class="content">
		<view class="param">
			<view class="proName">项目标题</view>
			<view class="prolittle">{{data.projectName}}</view>
			<view class="proMiao">项目描述</view>
			<view class="prolittle">{{data.projectContent}}</view>
			<view class="proMiao">附件</view>
			<view class="prolittle" v-for="(item,index) in fileList2">
				<view style="color: rgba(0, 97, 255, 1);" @click="navigateToTU(item.name)">{{item.name}}</view>
			</view>
			<!-- <view class="upload-img">
				<uni-file-picker limit="3" 
					@select='selectUpload' 
					:auto-upload='false' 
					file-extname='pdf,docx,jpg,png,jpeg,doc,docm,dot,dotm,dotx,xlsx,xls,csv,xlsm,slxb,xlt,xltx' 
					file-mediatype="all" 
					@success='uploadSuccess'	
					@fail='uploadFail' 
					:list-styles='listStyles' 
					v-model='fileList2'
				></uni-file-picker>
			</view> -->
			<view class="proMiao">主办单位</view>
			<view class="prolittle">{{data.organize}}</view>
			<view class="proMiao">主办人</view>
			<view class="prolittle">{{data.sposonerName}}</view>
			<view class="proMiao">协办单位</view>
			<view class="prolittle">{{data.coOrganize}}</view>
			<view class="proMiao">协办人</view>
			<view class="prolittle">{{data.coSposonerName}}</view>
			<view class="proMiao">评分人</view>
			<view class="prolittle">{{data.scorerName}}</view>
			
			<view class="proMiao">项目级别</view>
			<view class="prolittle">{{data.projectLevel}}</view>
			<view class="proMiao">项目来源</view>
			<view class="prolittle">{{data.projectFrom}}</view>
			<view class="proMiao jindu">完成进度</view>
			<view class="weidu">维度权重{{weidu}}%</view>
			<view class="addRen" @click="addRen" v-if="crerenwu==1&& (select==5 || select==3)">新增任务</view>
			<!-- 任务列表 -->
			<view style="width: 100%;margin: 50rpx 0 0 20rpx;">
				<view class="renwu" v-for="(item,index) in renwu" :key="index" @click="clickRenwu(item)">
					<view>{{item.taskName}}</view>
					<view>{{item.createTime}}</view>
					<view v-if="item.finishTime!=null">{{item.finishRemark}}</view>
					<view v-if="gengrenwu==1">{{item.weight}}</view>
					<view v-if="item.state==1">已完成</view>
					<view style="color: rgba(0, 97, 255, 1);" @click.stop="updateJin(item)" v-if="gengrenwu==1&& (select==5 || select==3|| select==4)">更新进度</view>
					<view style="color: rgba(0, 97, 255, 1);" @click.stop="cuirenwu2(item)" v-if="cuirenwu==1">催办</view>
					<view style="display: flex;">
						<view class="renwu-bu bianji" v-if="item.finishTime==null&&uprenwu==1&& (select==5 || select==3)" @click.stop="bianjiRenwu(item)">编辑</view>
						<view class="renwu-bu delete" @click.stop="deleteRenwu(item)" v-if="delerenwu==1&& (select==5 || select==3)">删除</view>
					</view>
				</view>
			</view>
			
			<!-- <view style="width: 100%;margin: 50rpx 0 0 20rpx;">
				<view class="renwu" v-for="(item,index) in renwu" :key="index">
					<view>{{item.taskName}}</view>
					<view>{{item.createTime}}</view>
					<view>{{item.weight}}</view>
					<view>{{item.scoreLimit}}</view>
					<view style="color: rgba(0, 97, 255, 1);">更新进度</view>
				</view>
			</view> -->
			<view class="proMiao jindu" v-if="data.progress>0">进度详情</view>
			<!-- 进度 -->
			<view style="margin: 33rpx 0 0 19rpx;">
				<view v-for="(item,index) in rizhi" :key="index" class="jindu-kuang">
					<view style="display: flex;">
						<view class="jindu-circle"></view>
						<view>
							<view style="width: 600rpx;display: flex;justify-content: space-between;margin-top: 20rpx;">
								<view style="display: flex;">
									<view style="margin-left: 28rpx;">{{item.createName}}</view>
									<view class="jindu-type lixiang">{{item.content}}</view>
								</view>
								<!-- <view class="jindu-type cuiban">已催办</view>
								<view class="jindu-type tijiao">已提交</view> -->
								<view>{{item.createTime}}</view>
							</view>
							<view style="margin:7rpx 0 0 28rpx;">项目名：{{item.projectName}}</view>
							<!-- <view style="margin:7rpx 0 0 28rpx;">任务指派：xxx，xxx，xxx</view>
							<view style="margin:7rpx 0 0 28rpx;">任务指派：xxx，xxx，xxx</view>
							<view style="margin:7rpx 0 0 28rpx;">任务指派：xxx，xxx，xxx</view> -->
						</view>
					</view>
					<!-- <view class="jindu-line" v-if="index<(rizhi.length-1)"></view> -->
					
				</view>
			</view>
			<view style="width: 100%;height: 60rpx;"></view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				data:{},
				fileList2: [],
				fileList22:'',
				listStyles: {
					"borderStyle": {
						"width": "0", // 边框宽度
					},
					"border": false, // 是否显示边框
					"dividline": false
				},
				renwu:[],
				rizhi:[],//日志
				weidu:'',
				
				crerenwu:1,//添加任务
				uprenwu:1,//修改任务
				delerenwu:1,//是否删除任务
				cuirenwu:1,//催办任务
				gengrenwu:1,//是否更新任务
				select:0,//状态
			}
		},
		onShow() {
			this.crerenwu=sessionStorage.getItem("crerenwu")
			this.uprenwu=sessionStorage.getItem("uprenwu")
			this.delerenwu=sessionStorage.getItem("delerenwu")
			this.cuirenwu=sessionStorage.getItem("cuirenwu")
			this.gengrenwu=sessionStorage.getItem("gengrenwu")
		},
		onLoad(option) {
			
			this.select=option.select
			
			console.log(JSON.parse(decodeURIComponent(option.data)))
			console.log(JSON.parse(decodeURIComponent(option.weidu)))
			var wei=JSON.parse(decodeURIComponent(option.weidu))
			this.data=JSON.parse(decodeURIComponent(option.data))
			this.weidu=(wei[2].configValue)
			var image=[]
			image=this.data.fileUrl.split(',')
			this.fileList2 =image.map(item =>{
				return {
					name: item
				}
			})
			this.fileList22=image.join(",")
			console.log(this.fileList2)
			this.getRenwu()
			this.getRizhi()
		},
		methods: {
			 change(e) {
			  console.log("e:", e);
			},
			//跳转页面
			navigateToTU(url) {
			  window.location.href = url;
			},
			//新增任务
			addRen(){
				var shuzu=[
					{userName:'',department:'',id:''}
				]
				var xieban=[]
				var xiebanpeo=[]
				var tt=[]
				var xiebanV=[]
				var a1=this.data.sposonerName+','+this.data.coSposonerName
				var a2=this.data.organize+','+this.data.coOrganize
				var a3=this.data.sposoner+','+this.data.coSposoner
				xieban=a1.split(',')
				xiebanpeo=a2.split(',')
				xiebanV=a3.split(',')
				shuzu=xieban.map(item =>{
					console.log(item)
					return {
						userName: item,
					}
				})
				shuzu.forEach((item,index) => {
					console.log(item);
					this.$set(item,"department",xiebanpeo[index])
					this.$set(item,"id",xiebanV[index])
				})
				let t2=JSON.stringify(shuzu)
				//这里———————————————————————————
				let query2 = encodeURIComponent(t2)
				uni.navigateTo({
					url:'/pages/project/addRenwu?proId='+this.data.id+'&people='+query2
				})
			},
			//编辑任务
			bianjiRenwu(item){
				var shuzu=[
					{userName:'',department:'',id:''}
				]
				var xieban=[]
				var xiebanpeo=[]
				var tt=[]
				var xiebanV=[]
				var a1=this.data.sposonerName+','+this.data.coSposonerName
				var a2=this.data.organize+','+this.data.coOrganize
				var a3=this.data.sposoner+','+this.data.coSposoner
				xieban=a1.split(',')
				xiebanpeo=a2.split(',')
				xiebanV=a3.split(',')
				shuzu=xieban.map(item =>{
					console.log(item)
					return {
						userName: item,
					}
				})
				shuzu.forEach((item,index) => {
					console.log(item);
					this.$set(item,"department",xiebanpeo[index])
					this.$set(item,"id",xiebanV[index])
				})
				let t2=JSON.stringify(shuzu)
				//这里———————————————————————————
				let query2 = encodeURIComponent(t2)
				
				//传参对象，使用encodeURIComponent编码
				let str = JSON.stringify(item)
				//注意这里——————————————————————
				str = str.replace(/%/g, '%25')
				//这里———————————————————————————
				let query = encodeURIComponent(str)
				uni.navigateTo({
					url:'/pages/project/changeRenwu?data='+query+'&people='+query2
				})
			},
			//删除任务
			deleteRenwu(item){
				let that = this
				uni.showModal({
					title: '提示',
					content: '确定删除任务吗？',
					success: function(res) {
						if (res.confirm) {
							console.log('用户点击确定');
							uni.showLoading({
								title: '加载中',
								mask: true, // 是否显示透明蒙层，防止触摸穿透
							});
							let data={
								id:item.id,
							}
							that.$Request.postT('/api/sysTask/del',data).then(res => {
								if (res.code==200) {
									uni.showToast({
										title: '删除成功',
										icon: 'none',
										duration:800
									});
									uni.hideLoading()
													
									setTimeout(function() {
										that.getRenwu()
									}, 1000)
								} else {
									uni.hideLoading();
									uni.showToast({
										title: res.message,
										icon: 'none',
										duration:800
									});
								}
							});
						} else if (res.cancel) {
							console.log('用户点击取消');
						}
					}
				})
			},
			//任务详情
			clickRenwu(item){
				var shuzu=[
					{userName:'',department:'',id:''}
				]
				var xieban=[]
				var xiebanpeo=[]
				var tt=[]
				var xiebanV=[]
				var a1=this.data.sposonerName+','+this.data.coSposonerName
				var a2=this.data.organize+','+this.data.coOrganize
				var a3=this.data.sposoner+','+this.data.coSposoner
				xieban=a1.split(',')
				xiebanpeo=a2.split(',')
				xiebanV=a3.split(',')
				shuzu=xieban.map(item =>{
					console.log(item)
					return {
						userName: item,
					}
				})
				shuzu.forEach((item,index) => {
					console.log(item);
					this.$set(item,"department",xiebanpeo[index])
					this.$set(item,"id",xiebanV[index])
				})
				let t2=JSON.stringify(shuzu)
				//这里———————————————————————————
				let query2 = encodeURIComponent(t2)
				
				//传参对象，使用encodeURIComponent编码
				let str = JSON.stringify(item)
				//注意这里——————————————————————
				str = str.replace(/%/g, '%25')
				//这里———————————————————————————
				let query = encodeURIComponent(str)
				uni.navigateTo({
					url:'/pages/project/renwuX?data='+query+'&people='+query2
				})
			},
			//更新进度
			updateJin(item){
				//传参对象，使用encodeURIComponent编码
				let str = JSON.stringify(item)
				//注意这里——————————————————————
				str = str.replace(/%/g, '%25')
				//这里———————————————————————————
				let query = encodeURIComponent(str)
				uni.navigateTo({
					url:'/pages/project/renwuUpdateJin?data='+query
				})
			},
			//催办任务
			cuirenwu2(item){
				let that = this
				uni.showModal({
					title: '提示',
					content: '确定催办任务吗？',
					success: function(res) {
						if (res.confirm) {
							console.log('用户点击确定');
							uni.showLoading({
								title: '加载中',
								mask: true, // 是否显示透明蒙层，防止触摸穿透
							});
							let data={
								taskId:item.id,
							}
							that.$Request.postT('/api/sysTask/urge',data).then(res => {
								if (res.code==200) {
									uni.showToast({
										title: '催办成功',
										icon: 'none',
										duration:800
									});
									uni.hideLoading()
													
									setTimeout(function() {
										that.getRenwu()
									}, 1000)
								} else {
									uni.hideLoading();
									uni.showToast({
										title: res.message,
										icon: 'none',
										duration:800
									});
								}
							});
						} else if (res.cancel) {
							console.log('用户点击取消');
						}
					}
				})
			},
			// 查找任务
			getRenwu(){
				let that = this
				that.renwu=[]
				uni.showLoading({
					title: '加载中',
					mask: true, // 是否显示透明蒙层，防止触摸穿透
				});
				var data={
					"projectId": that.data.id
				}
				that.$Request.postT('/api/sysTask/queryTaskByProject',data).then(res => {
					if (res.code==200) {
						that.renwu=res.data
						console.log(that.renwu,'任务')
					}
					uni.hideLoading();
				});
			},
			//项目日志
			getRizhi(){
				let that = this
				that.rizhi=[]
				uni.showLoading({
					title: '加载中',
					mask: true, // 是否显示透明蒙层，防止触摸穿透
				});
				var data={
					"projectId": that.data.id
				}
				that.$Request.postT('/api/sysProject/queryLogs',data).then(res => {
					if (res.code==200) {
						that.rizhi=res.data
						console.log(that.rizhi,'日志')
					}
					uni.hideLoading();
				});
			}
		}
	}
</script>

<style>
	.content {
		display: flex;
		flex-direction: column;
		align-items: center;
		justify-content: center;
	}
	.param{
		margin: 20rpx 0 0 0;
		width: 100%;
		background-color: rgba(255, 255, 255, 1);
		font-size: 28rpx;
		font-weight: 400;
		line-height: 41rpx;
		color: rgba(0, 0, 0, 1);
	}
	.proName{
		margin: 23rpx 0 0 20rpx;
	}
	.prolittle{
		margin: 5rpx 0 0 20rpx;
		width: 710rpx;
		/* 自动换行 */
		word-wrap: break-word;
		word-break: break-all;
		white-space: pre-line;
	}
	.proINname{
		margin: 25rpx 0 0 21rpx;
		width: 709rpx;
		height: 90rpx;
		border-radius: 13rpx;
		background: rgba(245, 248, 252, 1);
		border: 1rpx solid rgba(229, 229, 229, 1);
		font-size: 28rpx;
		line-height: 90rpx;
		/* color: rgba(179, 179, 179, 1); */
	}
	.proIMi{
		height: 315rpx;
	}
	.proMiao{
		margin: 31rpx 0 0 20rpx;
	}
	/* 上传附件 */
	.upload-img{
		/* width: 200rpx;
		height: 80rpx;
		opacity: 1;
		border-radius: 13rpx;
		background: rgba(0, 97, 255, 0.1);
		border: 1rpx solid rgba(0, 97, 255, 1); */
	}
	.jindu{
		font-size: 32rpx;
		font-weight: 500;
		line-height: 46rpx;
	}
	/* 进度 */
	.jindu-kuang{
		font-size: 24rpx;
		line-height: 35rpx;
		color: rgba(128, 128, 128, 1);
	}
	.jindu-circle{
		margin-top: 10rpx;
		width: 100rpx;
		height: 100rpx;
		border-radius: 50%;
		opacity: 1;
		background-color:rgba(204, 204, 204, 1);
	}
	.jindu-type{
		/* width: 103rpx; */
		height: 40rpx;
		border-radius: 71rpx;
		font-size: 24rpx;
		line-height: 40rpx;
		color: rgba(255, 255, 255, 1);
		text-align: center;
		margin: 0 0 0 20rpx;
	}
	.lixiang{
		background: linear-gradient(90deg, rgba(54, 111, 255, 1) 0%, rgba(93, 160, 252, 1) 100%);
	}
	.cuiban{
		background: linear-gradient(90deg, rgba(57, 167, 139, 1) 0%, rgba(126, 224, 203, 1) 100%);
	}
	.tijiao{
		background: linear-gradient(90deg, rgba(255, 112, 69, 1) 0%, rgba(247, 161, 114, 1) 100%);
	}
	.jindu-line{
		width: 4rpx;
		height: 100rpx;
		background-color: rgba(166, 166, 166, 1);
	}
	.weidu{
		margin: 7rpx 0 0 20rpx;
		font-size: 24rpx;
		line-height: 35rpx;
		color: rgba(128, 128, 128, 1);
	}
	.addRen{
		margin: -80rpx 0 0 581rpx;
		width: 149rpx;
		height: 59rpx;
		border-radius: 92rpx;
		background: rgba(0, 97, 255, 1);
		font-size: 28rpx;
		line-height: 59rpx;
		color: rgba(255, 255, 255, 1);
		text-align: center;
	}
	/* 任务列表 */
	.renwu{
		display: flex;
		margin-top: 6rpx;
		width: 709rpx;
		height: 90rpx;
		border-radius: 13rpx;
		background: rgba(245, 248, 252, 1);
		border: 1rpx solid rgba(229, 229, 229, 1);
		font-size: 28rpx;
		justify-content: space-evenly;
		align-items: center;
	}
	.renwu-bu{
		width: 105rpx;
		height: 50rpx;
		border-radius: 110rpx;
		line-height:50rpx;
		text-align: center;
	}
	.bianji{
		border: 1rpx solid rgba(0, 97, 255, 1);
		color: rgba(0, 97, 255, 1);
	}
	.delete{
		margin-left: 20rpx;
		border: 1rpx solid rgba(212, 48, 48, 1);
		color: rgba(212, 48, 48, 1);
	}
	.project{
		display: flex;
		margin: 61rpx 0 0 0;
		justify-content: space-evenly;
	}
	.butt{
		width: 330rpx;
		height: 90rpx;
		border-radius: 117rpx;
		font-size: 32rpx;
		line-height: 90rpx;
		text-align: center;
	}
	.quxiao{
		border: 1rpx solid rgba(0, 97, 255, 1);
		color: rgba(0, 97, 255, 1);
	}
	.queren{
		background: rgba(0, 97, 255, 1);
		color: rgba(255, 255, 255, 1);
	}
</style>