<template>
	<view class="content">
		<view class="param">
			<view class="all-text">创建项目需求</view>
			<view class="proName">项目标题</view>
			<input class="proINname" v-model="data.projectName" placeholder="请输入项目标题"/>
			<view class="proMiao">项目描述</view>
			<textarea class="proINname proIMi" v-model="data.projectContent" placeholder="请输入项目描述"/>
			<view class="proMiao">附件</view>
			<view class="upload-img">
				<uni-file-picker limit="3" 
					@select='selectUpload' 
					@delete="deleteHandle"
					:auto-upload='false' 
					file-extname='pdf,docx,jpg,png,jpeg' 
					file-mediatype="all" 
					@success='uploadSuccess'	
					@fail='uploadFail' 
					:list-styles='listStyles' 
					v-model='fileList2'
				></uni-file-picker>
			</view>
			<span style="margin: 20rpx 0 0 20rpx;">支持pdf/word/xlsx格式，单个文件大小不超过5MB</span>
			<view class="proMiao">主办单位</view>
			<uni-data-select class="proINname"
				v-model="value" placeholder="请选择主办单位"
				:localdata="range"
				@change="change"
			></uni-data-select>
			<view class="proMiao">主办人</view>
			<uni-data-select class="proINname"
				v-model="peopleValue" placeholder="请选择主办人"
				:localdata="rangePeople"
				@change="change"
			></uni-data-select>
			<view class="proMiao">协办单位</view>
			<mySelectCheckbox class="proINname" placeholder="请选择协办单位" v-model="value2" multiple dataKey="label" dataValue="value" :localdata="data2"
				@change="changeXie"></mySelectCheckbox>
			<view class="proMiao">协办人</view>
			<mySelectCheckbox class="proINname" placeholder="请选择协办人" v-model="peopleValue2" multiple dataKey="label" dataValue="value" :localdata="dataPeople"
				@change="changeXiePeo"></mySelectCheckbox>
			
			<view class="proMiao">项目级别</view>
			<uni-data-select class="proINname"
				v-model="jibieValue" placeholder="请选择项目级别"
				:localdata="jibie"
				@change="change"
			></uni-data-select>
			<view class="proMiao">项目来源</view>
			<uni-data-select class="proINname"
				v-model="fromValue" placeholder="请选择项目来源"
				:localdata="from"
				@change="change"
			></uni-data-select>
			<view class="proMiao">项目评分人</view>
			<mySelectCheckbox class="proINname" placeholder="请选择项目评分人" v-model="value2" multiple dataKey="label" dataValue="value" :localdata="data"
				@change="changeXie"></mySelectCheckbox>
			<view class="proMiao jindu">完成进度</view>
			<view class="weidu">维度权重40%</view>
			<view class="addRen" @click="addRen">新增任务</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 style="display: flex;">
						<view class="renwu-bu bianji" @click.stop="bianjiRenwu(item)">编辑</view>
						<view class="renwu-bu delete" @click.stop="deleteRenwu(item)">删除</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>30%</view>
					<view>{{item.scoreLimit}}</view>
					<view style="color: rgba(0, 97, 255, 1);" @click="updateJin(item)">更新进度</view>
					<view style="color: rgba(0, 97, 255, 1);" @click="cuirenwu(item)">催办</view>
				</view>
			</view>
			<view class="proMiao jindu" v-if="data.progress>0">进度详情</view>
			<!-- 进度 -->
			<view style="margin: 33rpx 0 0 19rpx;" v-if="data.progress>0">
				<view v-for="(item,index) in 5" :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;">周提</view>
									<view class="jindu-type lixiang">已立项</view>
								</view>
								<!-- <view class="jindu-type cuiban">已催办</view>
								<view class="jindu-type tijiao">已提交</view> -->
								<view>2024-06-10 12:00:00</view>
							</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 style="margin:7rpx 0 0 28rpx;">任务指派：xxx，xxx，xxx</view>
						</view>
					</view>
					<view class="jindu-line" v-if="index<4"></view>
					
				</view>
			</view>
			<view class="project">
				<view class="butt queren" @click="updatePro">保存</view>
			</view>
			<view style="width: 100%;height: 60rpx;"></view>
		</view>
	</view>
</template>

<script>
	import configdata from '@/common/config.js'
	import mySelectCheckbox from '../../components/my-selectCheckbox.vue'
	export default {
		data() {
			return {
				data:{},
				//主办单位
				value: '',
				range: [],
				//主办人
				peopleValue:'',
				rangePeople:[],
				//协办
				value2:[],
				data2: [],
				xieban:[],//协办传入值数组
				xieValue:[],//协办传入id
				//协办人
				peopleValue2:[],
				dataPeople: [],
				xiebanPeople:[],//协办传入值数组
				xieValuePeople:[],//协办传入id
				// 项目级别
				jibieValue:0,
				jibie:[
					{ value: 0, text: "正常" },
					{ value: 1, text: "紧急" },
				],
				// 项目来源
				fromValue:0,
				from:[
					{ value: 0, text: "涉内" },
					{ value: 1, text: "涉外" },
				],
				fileList2: [],
				fileList22:'',
				// fileList: [
				// 	{name:'111'},
				// 	{name:'333'}
				// ],
				listStyles: {
					"borderStyle": {
						"width": "0", // 边框宽度
					},
					"border": false, // 是否显示边框
					"dividline": false
				},
				renwu:[],
			}
		},
		onLoad(option) {
			console.log(JSON.parse(decodeURIComponent(option.data)))
			this.data=JSON.parse(decodeURIComponent(option.data))
			this.getDanwei()
			for(var i=0;i<this.jibie.length;i++){
				if(this.jibie[i].text==this.data.projectLevel){
					this.jibieValue=this.jibie[i].value
				}
			}
			for(var i=0;i<this.from.length;i++){
				if(this.from[i].text==this.data.projectFrom){
					this.fromValue=this.from[i].value
				}
			}
			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()
		},
		methods: {
			 change(e) {
			  console.log("e:", e);
			},
			//新增任务
			addRen(){
				uni.navigateTo({
					url:'/pages/project/addRenwu?proId='+this.data.id
				})
			},
			//编辑任务
			bianjiRenwu(item){
				//传参对象，使用encodeURIComponent编码
				let str = JSON.stringify(item)
				//注意这里——————————————————————
				str = str.replace(/%/g, '%25')
				//这里———————————————————————————
				let query = encodeURIComponent(str)
				uni.navigateTo({
					url:'/pages/project/changeRenwu?data='+query
				})
			},
			//删除任务
			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){
				//传参对象，使用encodeURIComponent编码
				let str = JSON.stringify(item)
				//注意这里——————————————————————
				str = str.replace(/%/g, '%25')
				//这里———————————————————————————
				let query = encodeURIComponent(str)
				uni.navigateTo({
					url:'/pages/project/renwuX?data='+query
				})
			},
			//更新进度
			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
				})
			},
			//催办任务
			cuirenwu(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('用户点击取消');
						}
					}
				})
			},
			//获取单位
			getDanwei(){
				this.range=[]
				this.data2=[]
				uni.showLoading({
					title: '加载中',
					mask: true, // 是否显示透明蒙层，防止触摸穿透
				});
				this.$Request.postT('/api/Organize/query').then(res => {
					if (res.code==200&&res.data) {
						this.range =res.data.map(item =>{
							return {
								value: item.id,
								text: item.oname,
								id:item.oid
							}
						})
						this.data2 =res.data.map(item =>{
							return {
								value: item.id,
								label: item.oname,
								id:item.oid
							}
						})
						for(var i=0;i<this.range.length;i++){
							if(this.range[i].text==this.data.organize){
								this.value=this.range[i].value
							}
						}
						// for(var i=0;i<this.data2.length;i++){
						// 	if(this.data2[i].label==this.data.){
						// 		this.value2=this.data2[i].value
						// 	}
						// }
					}
					uni.hideLoading();
				});
			},
			// 查找任务
			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();
				});
			},
			// 上传附件
			uploadSuccess(e) {
			console.log('上传成功', e)
			},
			uploadFail(e) {
				console.log('上传失败：', e)
			},
			//保存编辑项目
			updatePro(){
				let that = this
				if (!that.data.projectName) {
					that.$queue.showToast("请输入项目标题");
				}else if (!that.data.projectContent) {
					that.$queue.showToast("请输入项目描述");
				} else if (!that.value) {
					that.$queue.showToast("请选择主办单位");
				} else if (!that.value2) {
					that.$queue.showToast("请选择协办单位");
				}else {
					uni.showLoading({
						title: '加载中',
						mask: true, // 是否显示透明蒙层，防止触摸穿透
					});
					that.$Request.postJson("/api/sysProject/update", {
						"id": that.data.id,
						"projectName": that.data.projectName,   // 项目名称
						"projectFrom": that.from[that.fromValue].text,    // 项目来源
						"projectLevel": that.jibie[that.jibieValue].text,    // 项目等级
						"projectContent": that.data.projectContent,    // 项目描述
						"fileUrl": that.fileList22,   // 附件
						"organize": that.range[that.value].text,   // 主办单位-单选
						"sposoner": "25",   // 主办人ID-单选
						"coOrganize": "产教融合处,信息与控制技术研究所",   // 协办单位-多选
						"coSposoner": "20,23"    // 协办人ID-多选
					}).then(res => {
						if (res.code == 200) {
							uni.showToast({
								title: '修改成功',
								icon: 'none',
								duration:800
							});
							uni.hideLoading()
				
							setTimeout(function() {
								uni.switchTab({
									url:'/pages/project/index'
								})
							}, 1000)
						} else {
							uni.hideLoading();
							uni.showToast({
								title: res.message,
								icon: 'none',
								duration:800
							});
						}
					});
				}
			},
			//删除文件
			deleteHandle(index){
				console.log(index)
				this.fileList2.splice(index.index,1)
				console.log(this.fileList2)
				this.fileList22=this.fileList2.join(",")
			},
			async selectUpload(e) {
				console.log('上传：', e)
				 let data = new FormData();
				  data.set("file", e.tempFiles[0].file);
				  let res = await this.$axios({
				    method: "post",
				    url: this.config('APIHOST1') + "/api/sysFile/upload",
				    headers: {
						tokenW: localStorage.getItem("token"),
						"Content-Type": "multipart/form-data"
				    },
				    data: data,
				  });
					// return res
				  console.log(res, "图片上传成功");
				  if (res.data.code == 200) {
					console.log(this.fileList2)
				    this.fileList2.push(res.data.data);
					this.fileList22=this.fileList2.join(",")
					// console.log(this.fileList2.join(","))
				  } else if(res.message=="登录凭证已过去，请重新登录"){
					uni.removeStorageSync("tokenW")
					uni.removeStorageSync("roleId")
					uni.showModal({
						title: '提示',
						content: '用户信息失效，请重新登录！',
						showCancel: false, // 是否显示取消按钮，默认为 true // 是否显示取消按钮，默认为 true
						success: function(res) {
							if (res.confirm) {
							}
						}
					});
				   }else {
			    		uni.showToast({
							title: res.message,
							icon: 'none',
							duration:800
						});
				    }
			},
			config: function (name) {
				var info = null
				if (name) {
					var name2 = name.split('.') //字符分割
					if (name2.length > 1) {
						info = configdata[name2[0]][name2[1]] || null
					} else {
						info = configdata[name] || null
					}
					if (info == null) {
						let web_config = cache.get('web_config')
						if (web_config) {
							if (name2.length > 1) {
								info = web_config[name2[0]][name2[1]] || null
							} else {
								info = web_config[name] || null
							}
						}
					}
				}
				return info
			},
		}
	}
</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);
	}
	.all-text{
		margin: 22rpx 0 0 20rpx;
		font-size: 32rpx;
		font-weight: 500;
		color: rgba(0, 0, 0, 1);
	}
	.proName{
		margin: 23rpx 0 0 20rpx;
	}
	.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>