<template>
	<view :style="'padding-top:'+nvaHeight+'px;'">
		<view class="navbox">
			<uni-nav-bar color="#ffffff" left-icon="left" title="就餐预订" :background-color="backgroundColor"
				:border="false" statusBar='true' fixed="true" @clickLeft='getBack'>
			</uni-nav-bar>
		</view>
		<image :src="navbg" class="navbg"></image>
		<view class="zxmain">
			<view class="ytbox">
				<uni-forms ref="form" class="ytforms"  :modelValue="datainfo">
					<view class="ytsbox">
						<view class="yttit flexcj">预订信息
							<view class="cook flexcc" @click="getCookFn">
								<image :src="cookimg"></image>
								本周食谱
							</view>
						</view>
						<view class="pt5">
							<uni-forms-item label="就餐日期" name="orderFoodTime">
								<picker mode="date" class="pickbox" 
									 @change="bindTimeChangea">
									<view class="flexc flex1">
										<view class="flex1 " :class="datainfo.orderFoodTime?'co16 fw5 f14':'coa f14'">
											{{datainfo.orderFoodTime||'请选择'}}</view>
											<image :src="hupimg" class="hupimg"></image>
									</view>
								</picker>
								
							</uni-forms-item>
							<uni-forms-item label="就餐类型"  name="orderFoodType">
								<picker  class="pickbox"  range-key='label' :value="jclxidx"
									:range="jclxlist"  @change="bindTimeChangeb">
									<view class="flexc flex1">
										<!-- <view class="flex1 " :class="orderFoodType?'co16 fw5 f14':'coa f14'">
											{{orderFoodType||'请选择'}}</view> -->
										<view class="flex1 f14" v-if="datainfo.orderFoodType&&!jclx">{{statusFormat(datainfo.orderFoodType,jclxlist,'jclx')}}</view>
										<view class="flex1 f14" v-else :class="jclx?'':'coa'">{{jclx||"请选择就餐类型"}}</view>
											<image :src="hupimg" class="hupimg"></image>
									</view>
								</picker>
							</uni-forms-item>
							<uni-forms-item label="姓名" class="disable"  name="orderFoodUser">
								<view class="intit">{{datainfo.orderFoodUser}}</view>
								<!-- <uni-easyinput :inputBorder="false" disabled v-model="datainfo.visitName" placeholder="请输入姓名">
								</uni-easyinput> -->
							</uni-forms-item>
							<uni-forms-item label="部 门" class="disable"  name="orderFoodDept">
								<view class="intit">{{datainfo.orderFoodDept}}</view>
								<!-- <uni-easyinput :inputBorder="false" disabled type="number" v-model="datainfo.visitPhone"
									placeholder="请输入手机号码">
								</uni-easyinput> -->
							</uni-forms-item>
						</view>
						<view class="ybtn flexcc" @click="getSubmit">确认提交</view>
						<view class="tips">* 为响应国家号召，请您视真实情况填写，珍惜粮食，适量定 餐，避免剩餐，减少浪费。</view>
					</view>	
				</uni-forms>
			</view>
		</view>
	</view>
</template>

<script>
	import {checkPermi,checkRole} from "@/utils/permission"; // 权限判断函数
	import {getFoodAdd,getFoodPut,getFoodDetail} from "@/api/mine/work.js"
	import {getDictionaryFn} from "@/api/mine/register.js"
	import {selectValueKey} from "@/utils/common.js"
	export default {
		components: {},
		data() {
			return {
				hupimg:require("@/static/images/order/hup.png"),
				cookimg:require("@/work/static/yuy/cook.png"),
				navbg:require("@/static/images/navbg.png"),
				backgroundColor: "transparent",
				nvaHeight: 44,
				marTop: 0, //距离顶部的距离
				stubarHeight: 0, //
				datainfo:{
					"orderFoodTime": "",//就餐时间
					"orderFoodType": "",//1:午餐 2：晚餐
					"orderFoodUser":"",//就餐人员名称
					"orderFoodUserId":"",//就餐人员id（用户id）
					"orderFoodDept":"",//就餐人员部门
					"orderFoodDeptId":"",//就餐人员部门id
				},
				jclx:'',
				jclxidx:'',
				jclxlist:[],
				ptype:'add',
				id:'',
				name:this.$store.state.user.nickName,
				userId:this.$store.state.user.userId,
				deptId:this.$store.state.user.deptId,
				deptName:this.$store.state.user.deptName,
			}
		},
		onPageScroll(e) {
			var scrollTop = Number(e.scrollTop);
			if (scrollTop > 0) {
				this.backgroundColor = '#0491FD'
			} else {
				this.backgroundColor = 'transparent'
			}
		},
		onLoad: function(e) {
			if(e.data){
				var data=JSON.parse(decodeURIComponent(e.data))
				if(data.type){
					this.ptype=data.type;
					this.id=data.id;
					this.getDetail()
				}
			}else{
				this.datainfo.orderFoodUser=this.name;
				this.datainfo.orderFoodUserId=this.userId;
				this.datainfo.orderFoodDept=this.deptName;
				this.datainfo.orderFoodDeptId=this.deptId;
				this.time()
			}
			
			this.init()
			// this.getDataFn()
			uni.getSystemInfo({
				success: (e) => {
					this.stubarHeight = Number(e.statusBarHeight);
					this.nvaHeight = Number(e.statusBarHeight) + 44;
				}
			})
		},
		onShow() {},
		methods: {
			checkPermi,
			checkRole,
			getBack() {
				uni.navigateBack({
					delta: 1
				})
			},
			statusFormat(ite,list,type) {
				var aite=selectValueKey(list, ite);
				if(type=='jclx'){
					this.jclxidx=aite.key
					this.jclx=aite.actions
				}
				return aite.actions;
			},
			init() {
				// 就餐类型
				getDictionaryFn('jiucan').then(res=>{
					if(res.code==200){
						this.jclxlist = res.data.map(v => {
							return {
								label: v.dictLabel,
								value: v.dictValue
							}
						})
					}
				})
			},
			time() {
				var date = new Date();
				var y = date.getFullYear();
				var m = date.getMonth() + 1;
				var d = date.getDate();
				var yearStr = y + '-' + (m < 10 ? ('0' + m) : m) + '-' + (d < 10 ? ('0' + d) : d)
				// var timeStr = (h < 10 ? ('0' + h) : h) + ':' + (min < 10 ? ('0' + min) : min) + ':' + (s < 10 ? (
				// 	'0' + s) : s);
				this.datainfo.orderFoodTime= yearStr
			},
			getCookFn(){
				this.$tab.navigateTo("/work/pages/yyorder/menu")
			},
			bindTimeChangea(e){
				var val=e.detail.value;
				this.datainfo.orderFoodTime=val
			},
			bindTimeChangeb(e){
				var val=e.detail.value;
				this.datainfo.orderFoodType=this.jclxlist[val].value
				this.jclx=this.jclxlist[val].label
			},
			getSubmit() {
				var that=this;
				var params = JSON.parse(JSON.stringify(this.datainfo))
				if(!params.orderFoodTime){
					this.$toast("请选择就餐日期")
					return
				}
				if(!this.jclx){
					this.$toast("请选择就餐类型")
					return
				}
				uni.showLoading({
					title:"加载中"
				})
				if(this.ptype=='add'){
					getFoodAdd(params).then(res => {
						uni.hideLoading()
						if (res.code == 200) {
							this.$toast("预约成功")
							setTimeout(function(){
								uni.$emit('refreshfoodlist')
								uni.navigateBack({
									delta:1
								})
							},1200)
						} else {
							this.$toast(res.msg)
						}
					})
				}else{
					getFoodPut(params).then(res => {
						uni.hideLoading()
						if (res.code == 200) {
							this.$toast("修改成功")
							setTimeout(function(){
								uni.$emit('refreshfoodlist')
								uni.navigateBack({
									delta:1
								})
							},1200)
						} else {
							this.$toast(res.msg)
						}
					})
				}
			},
			getDetail(){
				getFoodDetail(this.id).then(res=>{
					if(res.code==200){
						this.datainfo=JSON.parse(JSON.stringify(res.data))
					}
				})
			}
		},

	}
</script>
<style>
/* 	page {
		background: #ffffff;
	} */
</style>
<style lang="scss" scoped>
.ytbox /deep/ .uni-forms .uni-forms-item{padding: 10rpx 26rpx 10rpx;border: 2rpx solid #0391FD;margin-bottom: 24rpx;border-radius: 12rpx;}
.ytbox /deep/ .uni-forms-item__label{flex: 0 0 auto;width: 144rpx !important;font-size: 28rpx;font-weight: bold;position: relative;color: #161616;text-align-last: justify;}
.ytbox /deep/ .uni-forms-item__label text{flex: 1;}
.ytbox /deep/ .uni-forms-item__label .is-required{position: absolute;right: 0;color: #F10C31;margin-top: 16rpx;}
.ytbox /deep/ uni-textarea{flex: 1;width: auto;text-align: right;}
.ytbox /deep/ .uni-textarea-placeholder{font-size: 28rpx;color: #DDDDDD !important;}
.ytbox /deep/ .uni-easyinput__placeholder-class{font-size: 28rpx;color: #DDDDDD;}
.ytbox /deep/ .uni-forms-item__content{display: flex;align-items: center;flex-direction: row;}
.ytbox /deep/ .uni-easyinput{flex: 1;text-align: right;}
.ytbox /deep/ .uni-easyinput__content-input{font-size: 28rpx;}
 .ytbox /deep/ .uni-forms-item__error{margin-top:20rpx;left: auto;right: 0;}
 .disable{background: #EFF0F2;border: none !important;}
 .ytbox{width: 684rpx;margin: 0 auto;padding-top: 10rpx;position: relative;flex: 1;overflow: auto;background-color: #ffffff;padding-bottom: 4rpx;border-radius: 14rpx;}
.ytforms{
	.yttit{font-size: 28rpx;font-weight: bold;margin-bottom: 40rpx;
color: #161616;display: flex;align-items: center;padding: 0rpx 26rpx;box-sizing: border-box;position: relative;
		&::before{content: '';width: 6rpx;height: 34rpx;background: $com-cd3;border-radius: 4rpx;position: absolute;top: 50%;transform: translateY(-50%);left: 0rpx;}
	}
	.ytsbox{background-color: #ffffff;padding: 32rpx 28rpx 0;border-radius: 14rpx;margin-bottom: 24rpx;
		.intit{font-weight: 500;flex: 1;font-size: 26rpx;text-align: right;color: #666666;}
		.pickbox{flex: 1;text-align: right;font-weight: 500;font-size: 28rpx;color: #161616;
			.hupimg{width: 18rpx;height: 14rpx;margin-left: 12rpx;flex: 0 0 auto;}
		}
		
	}
	.cook{background: #FFEAC8;
border-radius: 26rpx;width: 186rpx;height: 52rpx;font-weight: 500;
font-size: 26rpx;
color: #FE5A0E;
		image{margin-right: 6rpx;width: 28rpx;height: 26rpx;}
	}
}
// 按钮
	.ybtn{width: 100%;height: 90rpx;background: $com-cd3;border-radius: 14rpx;margin: 100rpx auto 0;font-size: 28rpx;font-weight: 500;color: #FFFFFF;
		&.btn1{background-color: #9a9c9e;}
	}
	.tips{font-weight: bold;margin-top: 28rpx;
font-size: 22rpx;line-height: 34rpx;
color: #FF0000;}

.navbox{position: fixed;left: 0;right: 0;top: 0;z-index: 4;	}
.navbg{width: 100%;height: 692rpx;position: absolute;left: 0;right: 0;top: 0;z-index: -1;}	
.zxmain{position: relative;padding: 20rpx 32rpx 40rpx;box-sizing: border-box;display: flex;
		min-height: calc(100vh - 44px);		
}

</style>
