<template>
	<view>
		<!-- 顶部 -->
		<cu-custom bgColor="bg-blue" :isBack="true">
			<block slot="backText">编辑施工日志</block>
			<block slot="content"></block>
			<block slot="right">
				<view class=" flex justify-center">
				 	<button  @click="save()" class="margin-top-ssm cu-btn line-blue round text-white" style="width: 160rpx;height: 66rpx;padding: 0;">保存</button>
				</view>
			</block>
		</cu-custom>
		<!-- 项目合同段信息 -->
		<view style="background-color: #fff;padding: 22rpx;margin-bottom: 20rpx;"> 
			<view style="font-size: 30rpx;color: #101010;font-weight: bold;">{{project.project_name}}</view>
			<view style="font-size: 28rpx;color: #101010;margin-top: 10rpx;">{{project.contractName}}</view>
		</view>
        <form>
        	<view class="cu-form-group_1">
        		<view class="title">填报日期</view>
        		<input placeholder-style="color:#AEAEAE" placeholder="请输入" disabled="" v-model="data.date"  name="input"></input>
        	</view>
        	<view class="cu-form-group_1">
        		<view class="title">平均气温</view>
        		<input placeholder-style="color:#AEAEAE" placeholder="请输入" v-model="data.averageTemperature" name="input"></input>
        	</view>
			<view class="cu-form-group_1">
				<view class="title">天气</view>
				<input placeholder-style="color:#AEAEAE" placeholder="请输入" v-model="data.weather" name="input"></input>
			</view>
			<view class="cu-form-group_1" @click="modalShow=true">
				<view class="title">开工时间</view>
				<input disabled="true"  placeholder-style="color:#AEAEAE" placeholder="请输入" v-model="data.startTime" name="input"></input>
			</view>
			<view class="cu-form-group_1">
				<view class="title">工程名称</view>
				<input placeholder-style="color:#AEAEAE" placeholder="请输入" v-model="data.itemName" name="input"></input>
			</view>
			<view class="cu-form-group_1">
				<view class="title">施工部位</view>
				<input placeholder-style="color:#AEAEAE" placeholder="请输入" v-model="data.site" name="input"></input>
			</view>
		</form>
	    <form>
			<view class="cu-form-group_2" style="margin-top: 20rpx;">
				<view class="title">施工组织计划</view>
				<view>
					<textarea placeholder-style="color:#AEAEAE" maxlength="-1" v-model="data.orgPlan"  placeholder="请输入"></textarea>
				</view>
			</view>
	    	<view class="cu-form-group_2">
				<view class="title">安全交底</view>
				<view>
					<textarea placeholder-style="color:#AEAEAE" maxlength="-1" v-model="data.safetyDegree"  placeholder="请输入"></textarea>
				</view>
			</view>
			<view class="cu-form-group_2">
				<view class="title">技术交底</view>
				<view>
					<textarea placeholder-style="color:#AEAEAE" maxlength="-1" v-model="data.technologyDegree" placeholder="请输入"></textarea>
				</view>
			</view>
			<view class="cu-form-group_2">
				<view class="title">下达施工任务</view>
				<view>
					<textarea placeholder-style="color:#AEAEAE" maxlength="-1" v-model="data.releaseTask"  placeholder="请输入"></textarea>
				</view>
			</view>
			<view class="cu-form-group_2" style="margin-bottom: 20rpx;">
				<view class="title">重要记事</view>
				<view>
					<textarea placeholder-style="color:#AEAEAE" maxlength="-1" v-model="data.importantNote"  placeholder="请输入"></textarea>
				</view>
			</view>
	    </form>
		<form>
			<view class="cu-form-group_1"  @click="navTo(2)" style="justify-content: space-between;">
				<view class="title">监理员</view>
				<input placeholder-style="color:#AEAEAE" placeholder="请选择" v-model="data.supervisionWorker"  disabled=""  style="width: 520rpx;"></input>
				<text class='cuIcon-right'></text>
			</view>
			<view class="cu-form-group_1" @click="navTo(1)" style="justify-content: space-between;">
				<view class="title">施工员</view>
				<input placeholder-style="color:#AEAEAE" placeholder="请选择" v-model="data.constructionWorker" disabled=""  style="width: 520rpx;"></input>
				<text class='cuIcon-right'></text>
			</view>
		</form>
	    <!-- 时间弹窗 -->
	    <view class="cu-modal bottom-modal" :class="modalShow?'show':''" >
	    	<view class="cu-dialog" style="background-color: white;border-radius: 20rpx 20rpx 0 0;">
	    		<view class="cu-bar bg-white">
	    			<view class="action text-gray"></view>
	    			<view class="action text-black text-bold" style="color: #101010;">选择时间</view>
	    			<view class="action text-gray" @tap="showdialog()">取消</view>
	    		</view>
	    		<view style="padding-bottom: 10rpx;">
	    		      <calendar @selected-change="datechange"   :showBack="false" :dotStyle="dotStyle"></calendar>
	    		</view>
	    	</view>
	    </view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				dotStyle:{color: 'black'},
				project:"",
				time:"",
				constructionList:[],
				supervisionList:[],
				modalShow:false,
				data:{
					id:'',
					averageTemperature:'',
					weather:'',
					date:'',
					startTime:'',
					itemName:'',
					site:'',
					orgPlan:'',
					safetyDegree:'',
					technologyDegree:'',
					releaseTask:'',
					importantNote:'',
					supervisionWorker:'',
					constructionWorker:''
				},
				rules:[
					{name: 'date', required: true, type: 'required', errmsg: '请填写填报日期'},
					{name: 'averageTemperature', required: true, type: 'required', errmsg: '请填写平均气温'},
					{name: 'weather', required: true, type: 'required', errmsg: '请填写天气'},
					{name: 'startTime', required: true, type: 'required', errmsg: '请填写开工时间'},
					{name: 'itemName', required: true, type: 'required', errmsg: '请填写工程名称'},
					{name: 'site', required: true, type: 'required', errmsg: '请填写施工部位'},
					{name: 'orgPlan', required: true, type: 'required', errmsg: '请填写施工组织计划'},
					{name: 'safetyDegree', required: true, type: 'required', errmsg: '请填写安全交底'},
					{name: 'technologyDegree', required: true, type: 'required', errmsg: '请填写技术交底'},
					{name: 'releaseTask', required: true, type: 'required', errmsg: '请填写下达施工任务'},
					{name: 'importantNote', required: true, type: 'required', errmsg: '请填写重记事'},
					{name: 'supervisionWorker', required: true, type: 'required', errmsg: '请选择监理员'},
					{name: 'constructionWorker', required: true, type: 'required', errmsg: '请填写施工员'},
				],
				updateOrInsert:0,//0为新增 ， 1为编辑
				upId:null,
				
				contractId : uni.getStorageSync("porject"+"_"+uni.getStorageSync("userInfo").id).contractId,
				project:uni.getStorageSync("porject"+"_"+uni.getStorageSync("userInfo").id),
			}
		},
		onLoad(e) {
			this.data.date=e.time;
			this.project= uni.getStorageSync("porject"+"_"+uni.getStorageSync("userInfo").id);
			this.updateOrInsert=e.type;
			this.upId = e.id;
			if(this.updateOrInsert==1){//获取日志信息进行绑定
				this.findData(this.upId);
			}else{
				//获取合同段的地址，根据地址获取温度和天气
				var that =this;
				var cityName = uni.getStorageSync("porject"+"_"+uni.getStorageSync("userInfo").id).project_place;
				that.http.request("/app/diary/getWeather",{
						projectId:that.project.id,
						contractId:that.contractId,
						date:e.time
					}).then((res)=>{
					that.data.averageTemperature =res.tempSection;
					that.data.weather = res.weather
				})
			}
		},
		methods: {
			showdialog(){
				this.modalShow= !this.modalShow;
			},
			datechange(e) {
			    this.data.startTime=e.fullDate
				this.showdialog();
			},
			navTo(value){
				uni.navigateTo({
					url:"/pages/constructionLog/personnel/personnel?type="+value
				})
			},
			//获取该日志的数据，编辑
			findData(id){
				var that =this;
				that.http.request('/app/diary/findDiaryById', {diaryId:id}).then((result)=>{
					that.data = result.data;
					that.$delete(that.data,'prefix');				
				})  
			},
			save(){
				var that =this;
			/* 	let result= that.$formValidate.validate(this.data,this.rules)//表单验证
				if(result.isOk){ */
					let param =that.data;
					param.contractId= this.project.contractId;
					param.creator= uni.getStorageSync("userInfo").id;
					param.state= that.data.state==null ? 0 : that.data.state;
					param.deleted= that.data.deleted==null ? 0 : that.data.deleted;
					param.createTime=new Date();
				    that.http.request('/app/diary/addOrUpdate', param).then((result)=>{
				    	if(result.result=="1"){
				    		that.$prompt.none(result.msg);
				    		setTimeout(function(){
				    			uni.navigateBack({
				    				delta:1
				    			})
				    		},500)						   
				    	}else{
				    		 that.$prompt.Error("保存失败");						  
				    	}
				    })
				/* }else{
					that.$prompt.none(result.errmsg)
				} */
				
			}
		},
		onShow(){
			/* 监听选择施工人员页面的handleFun方法 */
		    uni.$on("handleFun", res => {
			   this.data.constructionWorker="";
			   this.constructionList=res;
			   res.forEach((item)=>{
				   this.data.constructionWorker+=item.user_name
			   })
		    })
			/* 监听选择监理人员页面的handleFun方法 */
			uni.$on("handleFunBy", res => {
			   this.data.supervisionWorker="";
			   this.supervisionList=res;
			   res.forEach((item)=>{
				   this.data.supervisionWorker+=item.user_name
			   })
			})
		},
	}
</script>

<style>
    .solid-top-type{
    	   border-top: 0px solid #eee;
    }
	.cu-form-group_1{display: flex;align-items: center;padding:0 22rpx;background-color: #fff;border-bottom: 2rpx solid #EAEAEA;height: 88rpx;}
	.cu-form-group_1 .title{font-size: 30rpx;color: #101010;width: 154rpx;}
	.cu-form-group_1 input{font-size: 30rpx;color: #8a8a8a;}
	.cu-form-group_2{padding: 22rpx;background-color: #fff;border-bottom: 2rpx solid #EAEAEA;}
	.cu-form-group_2 .title{font-size: 30rpx;color: #101010;padding-bottom: 18rpx;}
	.cu-form-group_2 textarea{font-size: 30rpx;color: #8a8a8a;width: 100%;}
	.cu-modal.show {
		overflow-y: auto;
		pointer-events: auto; 
	}
</style>
