<template>
	<view class='page'>
		<view class="top_container" style="padding-right: 30upx;clear: both;overflow: auto;">
			<view class="report_status" style="float: left;">
				<text class="magtext">{{purchaseContract.statusName}}</text>
			</view>
			<view style="float: right;" v-if="num==2 && purchaseContract.approveState=='1'">  <!-- 待审批和 审批中 -->
				<view class="btn"   @click="approval()">审批</view>
				<!-- <view class="btn"   @click="sendMsg()">回复</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">{{purchaseContract.contractCode||''}}</view>
				</view>
				<view class="list_item">
					<view class="list_item_name">合同日期</view>
					<view class="list_item_content content_right">{{purchaseContract.contractDate||''}}</view>
				</view>
				<view class="list_item">
					<view class="list_item_name">供应商</view>
					<view class="list_item_content content_right">{{purchaseContract.supplierIdName||''}}</view>
				</view>
				<view class="list_item">
					<view class="list_item_name">采购员</view>
					<view class="list_item_content content_right">{{purchaseContract.buyerName||''}}</view>
				</view>
				<view class="list_item">
					<view class="list_item_name">采购部门</view>
					<view class="list_item_content content_right">{{purchaseContract.deptName||''}}</view>
				</view>
				<view class="list_item">
					<view class="list_item_name">合同有效期</view>
					<view class="list_item_content content_right">{{purchaseContract.contractEffectiveDate||''}}</view>
				</view><view class="list_item">
					<view class="list_item_name">供应商合同编号</view>
					<view class="list_item_content content_right">{{purchaseContract.supplierContractCode||''}}</view>
				</view>
				
			</view>
			<view class="myCon myContentBox">
				<view class="top_container">物料明细</view>
				<view class="mybox" v-if="detailList.length>0">
					<view v-for="(item,index) in detailList" :key="index">
						<view class="list_item">
							<view class="list_item_name">物料代码：{{item.materielSerialNo}}</view>
						</view>
						<view class="list_item">
							<view class="list_item_name">物料名称：{{item.materielName}}</view>
						</view>
						<view class="list_item">
							<view class="list_item_name">规格型号：{{item.specification}}</view>
							
						</view>
						<view class="list_item">
							<view class="list_item_name">主计量单位：{{item.unitUomName}}</view>
							
						</view>
						<view class="list_item">
							<view class="list_item_name">数量（主单位）：{{item.count}}</view>
							
						</view><view class="list_item">
							<view class="list_item_name">辅助单位：{{item.supportUomName}}</view>
							
						</view>
						<view class="list_item">
							<view class="list_item_name">采购数量（辅助单位）：{{item.subQuoteCount}}</view>
						</view><view class="list_item">
							<view class="list_item_name">含税单价：{{item.taxUnitPrice}}</view>
						</view><view class="list_item">
							<view class="list_item_name">含税金额：{{item.taxAmount}}</view>
						</view><view class="list_item">
							<view class="list_item_name">不含税单价：{{item.unitPrice}}</view>
						</view><view class="list_item">
							<view class="list_item_name">不含税金额：{{item.amount}}</view>
						</view>
						<view class="list_item">
							<view style="border: solid 0.5px #f2f2f2;margin-top:10px;"></view>
						</view>
					</view>
					<!-- <uni-load-more  :status="loading_status" ></uni-load-more> -->
				</view>
			</view>
		</view>
		<view v-else-if="current_num==2">
			<view class="myContainer myContentBox">
				<view class="top_container">付款条件</view>
				<view class="mybox" v-if="extraList.length>0">
					<view v-for="(item,index) in extraList" :key="index">
						<view class="list_item">
							<view class="list_item_name">应付日期：{{item.dueDate}}</view>
						</view><view class="list_item">
							<view class="list_item_name">应付金额：{{item.payAmount}}元</view>
						</view><view class="list_item">
							<view class="list_item_name">已付金额：{{item.amountPaid}}元</view>
						</view><view class="list_item">
							<view class="list_item_name">未付金额：{{item.unpayAmount}}元</view>
						</view><view class="list_item">
							<view class="list_item_name">付款方式：{{item.paymentTerm}}</view>
						</view><view class="list_item">
							<view class="list_item_name">备注：{{item.remarks}}</view>
						</view>
						<view class="list_item">
							<view style="border: solid 0.5px #f2f2f2;margin-top:10px;"></view>
						</view>
						<uni-load-more  :status="loading_status" v-if="extraList.length<total"></uni-load-more>
					</view>
					
				</view>
				<view class="top_container">附件</view>
				
			</view>
		</view>
		<view v-else-if="current_num==3">
			<view class="myCon myContentBox" v-if="approvalList.length>0">
				<uni-steps :options="approvalList" :active="active" direction="column" />
			</view>
		</view> 
		<view class="goHome" @click='goMain("purchaseInfo")'>
			<img src="../../static/img/gohome.png">
		</view>
	</view>
</template>

<script>
	import uniSteps from '@/components/uni-steps/uni-steps.vue'
	import {
		config
	} from '../../request/js/config.js'
	export default{
		components: {
			uniSteps
		},
		data(){
			return {
				config:config,
				current_num:1,
				total:0,
				id:'',
				taskId:'',
				instanceId:'',
				purchaseContract:{},
				initFileList:[],
				detailList:[],
				extraList:[],
				active: 1,
				approvalList:[],
				num:1
			}
		},
		onLoad(option) {
			  this.id=option.id;
			  this.taskId = option.taskId;
			  this.num =option.num;
			  this.instanceId =option.instanceId;
			if(this.id==undefined){
				uni.reLaunch({
				    url: 'purchaseContract'
				});
				return false;
			}
			   var _this = this;
			   this.$http.request({
			     url: '/apis/scm/purchaseContract/detail',
				 method:'GET',
			     params: {
			       id:option.id
			     },
			   }).then(res=>{
				   console.log(res.data)
					if(res.data.code == 0){
						console.log("++++++++++++++++")
						if(res.data.data.detailOfHead.approveState==0){
							res.data.data.detailOfHead.statusName = "暂存"
						  } else if(res.data.data.detailOfHead.approveState==1){
							res.data.data.detailOfHead.statusName = "待审批"
						  }else if(res.data.data.detailOfHead.approveState==2){
							res.data.data.detailOfHead.statusName = "已驳回"
						  }else if(res.data.data.detailOfHead.approveState==3){
							res.data.data.detailOfHead.statusName = "审批通过"
						  }
						this.purchaseContract=res.data.data.detailOfHead;
						this.detailList = res.data.data.detailOfBody
						this.extraList = res.data.data.detailOfTail
						console.log("++++++++++++++++")
						// this.initFileList = res.data.initFileList;
						if(res.data.data.progressList){
							res.data.data.progressList.forEach(function(val,index){
								var myjson = {
									title: val.approveName+(val.approveState?val.approveState:'')+(val.reason?('~不通过，原因：'+val.reason):''),
									desc: val.approveTime?('时间：'+val.approveTime):'时间：-'
								}
								if(val.isDealed){
									_this.active = index;
								}
								_this.approvalList.push(myjson);
							})
						}
						
					}
			   }).catch(err=>{
				  uni.showToast({
				  	title: '获取信息失败',
				  	duration: 	1000,
				  	icon:"none"
				  });
			   });
			
		},
		methods:{
			//点击审批
			approval(){
				console.log("__________________")
				uni.navigateTo({
				    url: "approval?id="+this.id + "&taskId=" + this.taskId + "&type=" + 2 + "&instanceId=" + this.instanceId
				});
			},
			//回复
			sendMsg(){
				uni.navigateTo({
				    url: "sendMsg?id="+this.id
				});
			},
			changecurrent(num){
				this.current_num=num;
			}
		},
		onBackPress(options) { //取消默认的返回事件.
			uni.navigateTo({
				url: "purchaseContract"
			});
			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>
