<template>
	<view class="content">
		<view class="param">
			<view class="proMiao mingchen">{{data.taskName}}</view>
			<view class="proMiao title">评分标准</view>
			<view class="prolittle">{{data.scoreStandard}}</view>
			<view class="proMiao title">任务负责人</view>
			<view class="prolittle">{{data.headerName}}</view>
			<view class="proMiao title">评分上限</view>
			<view class="prolittle">{{data.scoreLimit}}</view>
			<view class="proMiao">附件</view>
			<view class="prolittle" v-for="(item,index) in fileList3">
				<view style="color: rgba(0, 97, 255, 1);" @click="navigateToTU(item.name)">{{item.name}}</view>
			</view>
			<view class="proMiao title">权重</view>
			<view class="prolittle">{{data.weight}}</view>
			<view class="proMiao title">提醒时间</view>
			<view class="prolittle">{{data.remindTime}}</view>
			<view class="proMiao title">预警时间</view>
			<view class="prolittle">{{data.warnTime}}</view>
			<view class="proMiao title">任务周期</view>
			<view class="prolittle">{{data.startTime}}  -  {{data.endTime}}</view>
			<view class="proMiao title">完成说明</view>
			<textarea class="proINname proIMi" v-model="finishRemark" 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,doc,docm,dot,dotm,dotx,xlsx,xls,csv,xlsm,slxb,xlt,xltx' 
					file-mediatype="all" 
					@success='uploadSuccess'	
					@fail='uploadFail' 
					:list-styles='listStyles' 
					v-model='fileList'
				></uni-file-picker>
			</view>
			<span style="margin: 20rpx 0 0 20rpx;width: 700rpx;">支持pdf,docx,jpg,png,jpeg,doc,docm,dot,dotm,dotx,xlsx,xls,csv,xlsm,slxb,xlt,xltx格式，单个文件大小不超过5MB</span>
			<!-- 操作键 -->
			<view class="project">
				<view class="butt quxiao" @click="quxiao">取消</view>
				<view class="butt queren" @click="updateJindu">确定</view>
			</view>
			<view style="width: 100%;height: 60rpx;"></view>
		</view>
	</view>
</template>

<script>
	import configdata from '@/common/config.js'
	export default {
		data() {
			return {
				data:{},
				fileList3: [],
				// 完成进度上传附件
				fileList: [],
				fileList2: [],
				fileList22:'',
				listStyles: {
					"borderStyle": {
						"width": "0", // 边框宽度
					},
					"border": false, // 是否显示边框
					"dividline": false
				},
				finishRemark:'',//完成说明
			}
		},
		onLoad(option) {
			console.log(JSON.parse(decodeURIComponent(option.data)))
			this.data=JSON.parse(decodeURIComponent(option.data))
			var image=[]
			image=this.data.fileUrl.split(',')
			this.fileList3 =image.map(item =>{
				return {
					name: item
				}
			})
		},
		methods: {
			//跳转页面
			navigateToTU(url) {
			  window.location.href = url;
			},
			//取消
			quxiao(){
				uni.navigateBack({
					delta:1
				})
			},
			//更新进度
			updateJindu(){
				let that = this
				uni.showLoading({
					title: '加载中',
					mask: true, // 是否显示透明蒙层，防止触摸穿透
				});
				var data={
					"taskId": that.data.id,  
					"finishRemark": that.finishRemark,
					"fileUrl":that.fileList22
				}
				that.$Request.postT('/api/sysTask/submitTask',data).then(res => {
					if (res.code==200) {
						uni.showToast({
							title: '更新成功',
							icon: 'none',
							duration:800
						});
						uni.hideLoading()
										
						setTimeout(function() {
							uni.navigateBack({
								delta:1
							})
							// uni.switchTab({
							// 	url:'/pages/project/index'
							// })
						}, 1000)
					} else {
						uni.hideLoading();
						uni.showToast({
							title: res.message,
							icon: 'none',
							duration:800
						});
					}
				});
			},
			// 上传附件
			uploadSuccess(e) {
			console.log('上传成功', e)
			},
			uploadFail(e) {
				console.log('上传失败：', e)
			},
			//删除文件
			deleteHandle(index){
				console.log(index)
				this.fileList2.splice(index.index,1)
				console.log(this.fileList2)
				this.fileList22=this.fileList2.join(",")
				console.log(this.fileList22)
				// uni.showLoading({
				// 	title: '删除中',
				// 	mask: true, // 是否显示透明蒙层，防止触摸穿透
				// });
				// var data={
				// 	"fileName": this.fileList2[index]
				// }
				// this.$Request.postT('/api/sysFile/delete',data).then(res => {
				// 	if (res.code==200) {
				// 		uni.showToast({
				// 			title: '删除成功',
				// 			icon: 'none',
				// 			duration:800
				// 		});
				// 		uni.hideLoading()
				// 	} else {
				// 		uni.hideLoading();
				// 		uni.showToast({
				// 			title: res.message,
				// 			icon: 'none',
				// 			duration:800
				// 		});
				// 	}
				// });
			},
			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: sessionStorage.getItem("token"),
						// tokenP: sessionStorage.getItem("token"),
						"Content-Type": "multipart/form-data"
				    },
				    data: data,
				  });
					// return res
				  console.log(res, "图片上传成功");
				  if (res.data.code == 200) {
					console.log(this.fileList)
				    this.fileList2.push(res.data.data);
					this.fileList22=this.fileList2.join(",")
					console.log(this.fileList2.join(","))
				  } else if(res.message=="登录凭证已过去，请重新登录"){
					sessionStorage.removeItem("token")
					sessionStorage.removeItem("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);
	}
	.proMiao{
		margin: 31rpx 0 0 20rpx;
		width: 710rpx;
	}
	.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;
	}
	.mingchen{
		font-size: 32rpx;
		font-weight: 500;
		line-height: 46rpx;
	}
	.title{
		color: rgba(102, 102, 102, 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>