<template>
	<view class='page'>
		<view class="top_container" style="padding-right: 30upx;clear: both;overflow: auto;">
			<view class="report_status">
				<text class="magtext">{{taskMain.statusName}}</text>
				<text class="magtext">(编号:{{taskMain.taskNo||''}})</text>
			</view>
			<view v-if="taskMain.statusId=='56'"> 
				<view class="btn"   @click="sendMsg()">回复</view>
				<view class="btn"   @click="dealTask()">处理</view>
				<view class="btn"   @click="sendPeople()">转派</view>
			</view>
			<view style="float: right;" v-if="taskMain.statusId=='57'">
				<view class="btn"   @click="avulate()">验收</view>
			</view>
		</view>
		<view class="detail_name_container">
			<view :class="[current_num==1?'current':'']" @click="changecurrent(1)">任务信息</view>
			<view :class="[current_num==2?'current':'']" @click="changecurrent(2)">回复信息</view>
			<view :class="[current_num==3?'current':'']" @click="changecurrent(3)">处理记录</view>
		</view>
		<view v-if="current_num==1">
			<view class="myContainer myContentBox">
				<view class="top_container">基本信息</view>
				<view class="list_item">
					<view class="list_item_name">任务主题</view>
					<view class="list_item_content content_right">{{taskMain.title}}</view>
				</view>
				<view class="list_item">
					<view class="list_item_name">任务类型</view>
					<view class="list_item_content content_right">{{taskMain.taskTypeName}}</view>
				</view>
				<view class="list_item">
					<view class="list_item_name">任务等级</view>
					<view class="list_item_content content_right">{{taskMain.taskLevelName}}</view>
				</view>
				<view class="list_item">
					<view class="list_item_name">期望完成时间</view>
					<view class="list_item_content content_right">{{taskMain.expireDate}}</view>
				</view>
				<view class="list_item">
					<view class="list_item_name">发起人</view>
					<view class="list_item_content content_right">{{taskMain.applyPersonName}}</view>
				</view>
				<view class="list_item">
					<view class="list_item_name">发起时间</view>
					<view class="list_item_content content_right">{{taskMain.createTime}}</view>
				</view>
			</view>
			<view class="myCon myContentBox">
				<view class="top_container">详细描述</view>
				<view class="resultContent">{{taskMain.detail}}</view>
				<view class="img-wrap" v-for="(items,index) in initFileList" :key='index'>
					<view class="img-box">
						<img :src="config.imgURL+items.filePath" />
					</view>
				</view>
			</view>
			<view class="myCon myContentBox">
				<view class="top_container">人员信息</view>
				<view class="list_item">
					<view class="list_item_name">责任人</view>
					<view class="list_item_content content_right">{{taskMain.heldPersonName}}</view>
				</view>
				<view class="list_item">
					<view class="list_item_name">抄送人</view>
					<view class="list_item_content content_right">{{formatCsrName(csr)}}</view>
				</view>
			</view>	
		</view>
		<view v-else-if="current_num==2">
			<view v-for="(item,index) in replyList" :key="index" class="example-box">
				<view class="myCon myContentBox">
					<view class="list_item">
						<view class="list_item_name" style="color: #000; font-size: 32upx;">{{item.replyername}}</view>
						<view class="list_item_content content_right">{{item.replytime}}</view>
					</view>
					<view class="list_item" style="padding: 0px 22upx;">
						<text style="color: rgb(255,130,0);">#原因分析#</text>{{item.reason}}
					</view>
					<view class="list_item" style="padding: 0px 22upx;">
						<text style="color: rgb(255,130,0);">#解决方案#</text>{{item.solution}}
					</view>
					<!-- <view class="list_item">
						<view class="list_item_content content_right" style="color: #007AFF;">查看回复详情</view>
					</view> -->
				</view>
			</view>
		</view>
		<view v-else-if="current_num==3">
			<view v-for="(item,index) in dealList" :key="index" class="example-box" @click="dealDetail(item)">
				<view class="myCon myContentBox">
					<view class="list_item">
						<view class="list_item_name" style="color: #000; font-size: 32upx;">{{item.replyername}}</view>
						<view class="list_item_content content_right">{{item.replytime}}</view>
					</view>
					<view class="list_item" style="padding: 0px 22upx;">
						<text style="color: rgb(255,130,0);">#原因分析#</text>{{item.reason}}
					</view>
					<view class="list_item" style="padding: 0px 22upx;">
						<text style="color: rgb(255,130,0);">#解决方案#</text>{{item.solution}}
					</view>
					<view class="list_item">
						<view class="list_item_name" style="color: #000; ">验收结果:  {{item.statusName}}</view>
						<view class="list_item_content content_right" style="color: #007AFF;" >查看处理详情</view>
					</view>
				</view>
			</view>
		</view>
		<view class="goHome" @click='goMain("taskInfo")'>
			<img src="../../static/img/gohome.png">
		</view>
		<view class="mysearchlist" style="z-index: 10000;">
			<chooseUserSingle ref="mysearchlist" 
				:showsearch.sync="show_search_user"
				:itemInfo_.sync="search_value_user">
			</chooseUserSingle>
		</view>
	</view>
</template>

<script>
	import chooseUserSingle from '@/components/xinsoft-search-list/chooseUserSingle.vue';
	import {
		config
	} from '../../request/js/config.js'
	export default{
		components: {
			chooseUserSingle,
		},
		data(){
			return {
				config:config,
				current_num:1,
				id:'',
				taskMain:{},
				initFileList:[],
				csr:[],
				replyList:[],
				dealList:[],
				reportDetail: [],
				show_search_user:false,
				search_value_user:"",
			}
		},
		onLoad(option) {
			  this.id=option.id;
			if(this.id==undefined){
				uni.reLaunch({
				    url: 'task'
				});
				return false;
			}
			   var _this = this;
			   this.$http.request({
			     url: '/apis/taskMain/detail',
			     params: {
			       id:option.id
			     },
			   }).then(res=>{
					if(res.data.code == 0){
						this.taskMain=res.data.taskMain;
						this.csr = res.data.ccIdList;
						this.replyList = res.data.replyList;
						this.dealList = res.data.dealList;
					}
			   }).catch(err=>{
				  uni.showToast({
				  	title: '获取信息失败',
				  	duration: 	1000,
				  	icon:"none"
				  });
			   });
			
		},
		watch:{
			search_value_user(newv){
				var _this = this;
				this.$http.request({
					url: '/apis/taskMain/reventTurnToSend',
					params: {
						taskId:_this.id,
						userId:newv.userId
					}
				}).then(res=>{
					if(res.data.code == 0) {
						uni.showToast({
						    title: res.data.msg,
						    duration: 2000,
							icon:"none"
						});
						setTimeout( function(){
							uni.redirectTo({
							    url: 'taskDetail?id='+_this.id
							});
						},1000)
					}
					else{
						uni.showToast({
							title: res.data.msg,
							duration: 1000,
							icon:"none"
						});
					}
				}).catch(err => {
					uni.showToast({
						title: '操作失败',
						duration: 1000,
						icon:"none"
					});
				})
			}
		},
		methods:{
			formatCsrName(csr){
				var returnName = '';
				for(var i=0;i<csr.length;i++){
					if(i == 3){
						returnName += csr[i].name+'等等';
						 break;
					}else{
						returnName += csr[i].name+','
					}
				}
				returnName = returnName.substring(0,returnName.length-1);
				return returnName;
			},
			dealDetail(item){
				//查看处理详情。
				uni.navigateTo({
				    url: "dealDetail?id="+item.id
				});
			},
			//回复
			sendMsg(){
				uni.navigateTo({
				    url: "sendMsg?id="+this.id
				});
			},
			//处理
			dealTask(){
				uni.navigateTo({
				    url: "deal?id="+this.id
				});
			},
			//指派
			sendPeople(){
				this.show_search_user=true;
				// uni.navigateTo({
				//     url: "selectPeople?flag=zp&id="+this.id
				// });
			},
			//评价
			avulate(){
				uni.navigateTo({
				    url: "acceptEvaluation?id="+this.id
				});
			},
			changecurrent(num){
				this.current_num=num;
			}
		},
		// onBackPress(options) { //取消默认的返回事件.
		// 	uni.navigateTo({
		// 		url: "task"
		// 	});
		// 	return true;
		// }
	}
</script>

<style scoped>
	
	.btn{
		width: 160upx;
		height:68upx;
		text-align: center;
		line-height: 68upx;
		border-radius: 10upx;
		background-color: #3382FF;
		color: #fff;
		font-size: 28upx;
		float: left;
		margin-right: 30upx;
	}
	
</style>
