<template>
	<view class="hzIndex">
		<hzHeader title="留餐受理详情"></hzHeader>
		<view class="hzContent" style="padding-top: 200upx;">
		
		<view class="details">
			<view class="detail_msg">
				<view class="info-item">
					<text class="label">申请人： </text>
					<text class="infoSpan">{{item.USER_NAME}}</text>
				</view> 
				<view class="info-item">
					<text class="label">食堂： </text>
					<text class="infoSpan">{{item.LOCATION}}</text>
				</view> 
				<view class="info-item">
					<text class="label">留餐类别： </text>
					<text class="infoSpan">{{formatFoodType(item.NEA_TYPE)}}</text>
				</view> 
				<view class="info-item">
					<text class="label">就餐人数： </text>
					<text class="infoSpan">{{ item.NEAL_NUM }}</text>
				</view>
				
				<view class="info-item">
					<text class="label">就餐时间： </text>
					<text class="infoSpan">{{item.NEAL_TIME}}</text>
				</view>
				<view class="info-item status">
					<text class="label">服务状态： </text>
					<text v-if="item.EXAMINE_STATE =='0'" class="infoSpan2" style="color: green;" >待处理</text><!-- statusred -->
					<text v-if="item.EXAMINE_STATE =='1'" class="infoSpan" style="color: green;">已同意</text>
					<text v-if="item.EXAMINE_STATE =='2'" class="infoSpan" >已拒绝</text>
				</view>
				
				<!-- <view class="info-item">
					<text class="label">申请人： </text>
					<text class="infoSpan">{{ item.USER_NAME }}</text>
				</view> -->
				<view class="info-item" v-if="item.EXAMINE_NAME">
					<text class="label">办理人:</text>
					<text class="infoSpan">{{ item.EXAMINE_NAME }}</text>
				</view>
			</view> 
		</view>
		
		<view class="footer-btn footer-btn-two batchBtn" v-if="item.EXAMINE_STATE =='0'">
			<view class="btn btn1" style="" @click="submit(2)">拒绝</view>
			<view class="btn btn2" style="background: linear-gradient( 90deg, #50CBA1 0%, #06AEA6 100%), #C1EFEA;color: #fff;width: 40%;" @click="submit(1)">同意</view>
		</view>
		
		<view class="occupied"></view>
		<view class="footer-btn" v-if="item.STATE =='1' && item.APPROVAL_ID ==userId">
			<view class="btn" style="background: #00C277;color: #f2f2f2;" @click="submit()">已完成</view>
		</view>
		
		</view>
	</view>
</template>

<script>
	import {
		getWeekMeal,updateStateWeekMeal
	} from '@/common/api.js';
	import {
		callbackRequest,
		getStorage,
		alertTip,
		formatDate,
		sureAlterTip,
		vbPicture,
		formatImgUrl
	} from '@/common/util.js';
	export default {
		data() {
			return {
				vbPicture:vbPicture,
				formatImgUrl:formatImgUrl,
				userInfo:getStorage('userInfo'),
				userId:getStorage('userInfo').userId,
				formatDate:formatDate,
				item: {},
				foodTypes:[{ id: '0', name: '早餐' }, { id: '1', name: '午餐' },{ id: '2', name: '晚餐' }],
				id:0,
				feedback:'',
				submitFlag:true,
			}
		},
		onLoad(option) {
			this.id = option.id||0;
			this.getWeekMeal();
		},
		methods: {
			getWeekMeal(){
				let params =  {
						method: getWeekMeal,
						data: {
							USER_ID:this.userId,
							ID:this.id
						}
					};
				callbackRequest(params).then(res => {
					res = res.data;
					console.log(res)
					if (res.returnCode == 1) {
						this.item = res.returnData[0];
					} else {
						alertTip(res.returnMsg);
					}
				});
			},
			submit(state){
				console.log(state)
				let params = {
					"method": updateStateWeekMeal,
					"data":{
						ID: this.id,
						USER_ID:getStorage('userInfo').id,
						USER_NAME:getStorage('userInfo').userName,
						EXAMINE_STATE:state,
					}
				};
				callbackRequest(params).then(res => {
					res = res.data;
					if (res.returnCode == 1) {
						alertTip(res.returnMsg);
						this.getWeekMeal();
						// uni.navigateTo({
						// 	url: '/pages/malfunc-repair/service-record'
						// });
					} else {
						alertTip(res.returnMsg);
					}
				})
			},
			formatFoodType(NEA_TYPE){
				for(let i=0;i<this.foodTypes.length;i++){
					let obj = this.foodTypes[i];
					if(obj.id == NEA_TYPE){
						return obj.name;
					}
				}
			},
		}
	}
</script>

<style lang="scss">
	@import '@/static/css/common.scss';
	.batchBtn{
		display: flex;
		justify-content: space-between;
		padding: 10upx 40upx;
		.btn1{
			background: #C1EFEA;
			color: #09AFA5;
			width: 40%;
			border-radius: 50upx;
		}
		.btn2{
			background: linear-gradient( 90deg, #50CBA1 0%, #06AEA6 100%), #C1EFEA;
			color: #fff;
			width: 40%;
			border-radius: 50upx;
		}
	}
 
	.details{
		position: relative;
		// height: 550upx;
		background: white;
		margin: 20upx;
		border-radius: 20upx;
		padding-bottom:60upx;
		font-size: 26upx;
		.detail_header {
			border-bottom: #f8f8f8 5upx solid;
			height: 90upx;
			line-height: 90upx;
			margin: 15upx;
			border-radius: 10upx;
			.blueSign {
				height: 28upx;
				width: 5upx;
				background: #00c277;
				display: inline-block;
				margin-left: 20upx;
			}
			.font-tilte {
				font-weight:bold;
				margin-left: 20upx;
			}
		}
		.form-box {
			background: #fff;
			.form-item {
				overflow: hidden;
				border-bottom: 1px solid #eee;
				padding: 30upx 20upx;
				.label {
					float: left;
					width: 180upx;
					font-size: 28upx;
					color: #333;
					font-weight: bold;
					line-height: 50upx;
				}
				.ipt-box {
					margin-left: 160upx;
					input {
						width: 90%;
						height: 50upx;
						line-height: 50upx;
						font-size: 26upx;
						color: #666;
					}
				}
				.select {
					.arrow {
						float: right;
						width: 16upx;
						height: 29upx;
						margin-top: 10upx;
					}
					.picker {
						height: 50upx;
						line-height: 50upx;
						font-size: 26upx;
						color: #666;
						margin-left: 10upx;
					}
				}
			}
		}
		.detail_msg {
			margin-left: 20upx;
			border-radius: 10upx;
			.info-item{
				border-bottom:1px solid #f8f8f8;
				padding:20upx 10upx;
				line-height: 50upx;
				.label{
					float: left;
					width: 180upx;
					font-size: 28upx;
					color: #333;
					font-weight: bold;
					line-height: 50upx;
				}
			}
			.status {
				.infoSpan{
					color: #00c277;
				}
				.infoSpan2{
					color: red;
				}
			}
			.img-box {
				// background: #fff;
				image{
					width: 200upx;
					height: 200upx;
					margin:20upx 20upx 0 0;
				}
			}
		}
	}

</style>
