<template>
<view  :style="'padding-bottom:' + bottom ">
  	  <view class='zhanline'></view>
	  <uni-forms class='inform '  ref="form" :rules="rules"  :value="datainfo" v-show="type==1">
	  			<view class="info_tit">项目信息</view>
	  			<uni-forms-item name="xmmc" style='margin-bottom: 0;'>
	  			 <view class="flexc infolist">
	  			  	<view class="f16 fw c34 flex0 pr pl12"><text class="cir">*</text>项目名称</view>
					<!-- <uni-easyinput v-model="datainfo.xmmc" placeholder="请输入项目名称" /> -->
	  			  	<input  placeholder="请输入项目名称" v-model="datainfo.xmmc"  class="f16  c34 flex1 txr"/>
	  			  </view> 
	  			</uni-forms-item>
	  			<uni-forms-item name="xmdw" style='margin-bottom: 0;'>
	  			 <view class="flexc infolist">
	  			  	<view class="f16 fw c34 flex0 pr pl12"><text class="cir">*</text>项目单位</view>
	  			  	<input  placeholder="请输入项目单位" v-model="datainfo.xmdw"   class="f16  c34 flex1 txr"/>
	  			  </view>
	  			</uni-forms-item>
	  			<uni-forms-item name="qtzrdw" style='margin-bottom: 0;'>
	  			 <view class="flexc infolist">
	  			  	<view class="f16 fw c34 flex0 pr pl12"><text class="cir">*</text>牵头责任单位</view>
	  			  	<input  placeholder="请输入牵头责任单位" v-model="datainfo.qtzrdw"  class="f16  c34 flex1 txr"/>
	  			  </view>
	  			</uni-forms-item>
				<uni-forms-item name="qtsld" style='margin-bottom: 0;'>
				 <view class="flexc infolist">
				  	<view class="f16 fw c34 flex0 pr pl12"><text class="cir">*</text>牵头市领导</view>
				  	<input  placeholder="请输入牵头市领导" v-model="datainfo.qtsld"  class="f16  c34 flex1 txr"/>
				  </view>
				</uni-forms-item>
				<uni-forms-item name="gmnr" style='margin-bottom: 0;'>
				 <view class="flexc infolist">
				  	<view class="f16 fw c34 flex0 pr pl12"><text class="cir">*</text>主要建设规模和内容</view>
				  	<input  placeholder="请输入主要建设规模和内容" v-model="datainfo.gmnr"    class="f16  c34 flex1 txr"/>
				  </view>
				</uni-forms-item>
	  			<uni-forms-item name="jhkgsj" style='margin-bottom: 0;'>
	  			 <view class="flexc infolist">
	  			  	<view class="f16 fw c34 flex0 pr pl12"><text class="cir">*</text>计划开工时间</view>
	  			  	<picker mode="date" :value="datainfo.jhkgsj" class="infolist_a" @change='bindDateChangetimea'>
	  					<view :class="datainfo.jhkgsj?'':'f16 co80'">{{datainfo.jhkgsj||"请选择计划开工时间"}}</view>
	  			  	</picker>
	  			  </view>
	  			</uni-forms-item>
	  			<uni-forms-item name="xmztz" style='margin-bottom: 0;'>
	  			 <view class="flexc infolist">
	  			  	<view class="f16 fw c34 flex0 pr pl12"><text class="cir">*</text>项目总投资(万元)</view>
	  			  	<input  placeholder="请输入项目总投资" type="number" v-model="datainfo.xmztz"    class="f16  c34 flex1 txr"/>
	  			  </view>
	  			</uni-forms-item>
	  			<view class="infobtn flexcc cf f16 f500" @click="getNext">下一步</view>
	  		</uni-forms>
			<!-- 下一步 -->
			<uni-forms class='inform' ref="twoform" :rules="tworules" :value="datainfo" v-show="type==2">
				<view class="info_tit">资金来源</view>
				<uni-forms-item name="sjbz" style='margin-bottom: 0;'>
				 <view class="flexc infolist">
				  	<view class="f16 fw c34 flex0 pr pl12"><text class="cir">*</text>上级补助资金(万元)</view>
				  	<input @input="getHjFn" placeholder="请输入上级补助资金" type="number" v-model="datainfo.sjbz"  class="f16  c34 flex1 txr"/>
				  </view>
				</uni-forms-item>
				<uni-forms-item name="sczbj" style='margin-bottom: 0;'>
				 <view class="flexc infolist">
				  	<view class="f16 fw c34 flex0 pr pl12"><text class="cir">*</text>市政财本资金(万元)</view>
				  	<input @input="getHjFn" placeholder="请输入市政财本资金" v-model="datainfo.sczbj"  type="number"  class="f16  c34 flex1 txr"/>
				  </view>
				</uni-forms-item>
				<uni-forms-item name="zxz" style='margin-bottom: 0;'>
				 <view class="flexc infolist">
				  	<view class="f16 fw c34 flex0 pr pl12"><text class="cir">*</text>专项债(万元)</view>
				  	<input @input="getHjFn" placeholder="请输入专项债" v-model="datainfo.zxz" type="number" class="f16  c34 flex1 txr"/>
				  </view>
				</uni-forms-item>
				<!-- <uni-forms-item name="ppp" style='margin-bottom: 0;'>
				 <view class="flexc infolist">
				  	<view class="f16 fw c34 flex0 pr pl12"><text class="cir">*</text>PPP(万元)</view>
				  	<input @input="getHjFn" placeholder="请输入PPP" v-model="datainfo.ppp"  type="number"  class="f16  c34 flex1 txr"/>
				  </view>
				</uni-forms-item> -->
				<uni-forms-item name="rz" style='margin-bottom: 0;'>
				 <view class="flexc infolist">
				  	<view class="f16 fw c34 flex0 pr pl12"><text class="cir">*</text>融资(万元)</view>
				  	<input @input="getHjFn" placeholder="请输入融资" v-model="datainfo.rz" type="number" class="f16  c34 flex1 txr"/>
				  </view>
				</uni-forms-item>
				<uni-forms-item name="qyzc" style='margin-bottom: 0;'>
				 <view class="flexc infolist">
				  	<view class="f16 fw c34 flex0 pr pl12"><text class="cir">*</text>企业自筹(万元)</view>
				  	<input @input="getHjFn" placeholder="请输入企业自筹" v-model="datainfo.qyzc"  type="number"  class="f16  c34 flex1 txr"/>
				  </view>
				</uni-forms-item>
				<uni-forms-item name="hj" style='margin-bottom: 0;'>
				 <view class="flexc infolist">
				  	<view class="f16 fw c34 flex0 pr pl12">合计(万元)</view>
					<view class="f16  c34 flex1 txr">{{hj}}</view>
				  </view>
				</uni-forms-item>
				<view class="border"></view>
				<uni-forms-item name="ndjh" style='margin-bottom: 0;'>
				 <view class="flexc infolist">
				  	<view class="f16 fw c34 flex0 pr pl12"><text class="cir">*</text>年度计划完成投资(万元)</view>
				  	<input  placeholder="请输入年度计划完成投资" type="number" v-model="datainfo.ndjh" class="f16  c34 flex1 txr"/>
				  </view>
				</uni-forms-item>
				<uni-forms-item name="sjbzzjqd" style='margin-bottom: 0;'>
				 <view class="flexc infolist">
				  	<view class="f16 fw c34 flex0 pr pl12"><text class="cir" v-if="Number(datainfo.sjbz)>0">*</text>上级补助资金渠道</view>
				  	<input  placeholder="请输入上级补助资金渠道" v-model="datainfo.sjbzzjqd" class="f16  c34 flex1 txr"/>
				  </view>
				</uni-forms-item>
				<uni-forms-item name="rzqd" style='margin-bottom: 0;'>
				 <view class="flexc infolist">
				  	<view class="f16 fw c34 flex0 pr pl12"><text class="cir" v-if="Number(datainfo.rz)>0">*</text>融资渠道</view>
				  	<input  placeholder="请输入融资渠道" v-model="datainfo.rzqd" class="f16  c34 flex1 txr"/>
				  </view>
				</uni-forms-item>
				<view class="border"></view>
				<uni-forms-item name="remark" style='margin-bottom: 0;'>
				 <view class="flexc infolist">
				  	<view class="f16 fw c34 flex0 pr pl12">备注</view>
				  	<input  placeholder="请输入备注信息" v-model="datainfo.remark"    class="f16  c34 flex1 txr"/>
				  </view>
				</uni-forms-item>
				<!-- 新增 -->
				<view class="infobtn flexcc cf f16 f500" v-if="(checkPermi(['fgw:xmsb:add'])&&pagetype=='add')||(checkPermi(['fgw:xmsb:edit'])&&pagetype=='update')" @click="getSubmit">提交</view>
			</uni-forms>
  </view>
</template>

<script>
import { getDictionaryFn} from '@/api/work/index.js'
import {selectDictLabel} from "@/utils/common.js"
import {getxmsbDetail,getxmsbAddFn,getxmsbPutFn} from '@/api/zdwork/addclue.js'
import { checkPermi, checkRole } from "@/utils/permission"; // 权限判断函数
 import config from '@/config'
  const baseUrl = config.baseUrl
  import { getToken } from '@/utils/auth'
  export default {

    data() {
      return {
		selectDate: '',
		defaultPhoneHeight: '', //屏幕默认高度
		nowPhoneHeight: '', //屏幕现在的高度
		bottom:0,
		type:1,
		datainfo:{
			"xmbh":"",//项目编号
			"xmmc":"",//项目名称
			"xmdw":"",//项目单位
			"qtzrdw":"",//牵头责任单位
			"qtsld":"",//牵头市领导
			"gmnr":"",//主要建设规模和内容
			"jhkgsj":"",//计划开工时间）
			"xmztz":"",//项目总投资
			"sjbz":"",//上级补助
			"sczbj":"",//市财政补助
			"zxz":"",//专项债
			"ppp":"",//ppp
			"qyzc":"",//qyzc
			"rz":"",//融资
			"ndjh":"",//年度计划完成投资
			"sjbzzjqd":"",//上级补助资金渠道
			"rzqd":"",//融资渠道
			"remark":""//备注
		},
		tanfalg:false,
		addimg:require("@/static/images/mine/add.png"),
		delimg:require("@/static/images/mine/del.png"),
		checknimg:require("@/static/images/mine/jnicon.png"),
		gcheckimg:require("@/static/images/mine/jicon.png"),
		closeimg:require('@/static/images/close.png'),
		wimg:require('@/static/images/index/wicon.png'),
		downimg:require('@/static/images/index/down.png'),
		rules: {
		  xmmc: {rules: [{required: true,errorMessage: '请输入项目名称'}]},
		  xmdw: {rules: [{required: true,errorMessage: '请输入项目单位',}]},
		  qtzrdw: {rules: [{required: true,errorMessage: '请输入牵头责任单位' } ]},
		  qtsld: {rules: [{required: true,errorMessage: '请输入牵头市领导'} ]},
		  gmnr: {rules: [{required: true,errorMessage: '请输入主要建设规模和内容'} ]},
		  jhkgsj: {rules: [{required: true,errorMessage: '请选择计划开工时间'} ]},
		  xmztz: {rules: [{required: true,errorMessage: '请输入项目总投资'} ]},
		},
		tworules:{
			sjbz: {rules: [{required: true,errorMessage: '请输入上级补助'} ]},
			sczbj: {rules: [{required: true,errorMessage: '请输入市政财本级'} ]},
			zxz: {rules: [{required: true,errorMessage: '请输入专项债'} ]},
			// ppp: {rules: [{required: true,errorMessage: '请输入PPP'} ]},
			rz: {rules: [{required: true,errorMessage: '请输入融资'}]},
			ndjh: {rules: [{required: true,errorMessage: '请输入年度计划完成投资'} ]},
			qyzc: {rules: [{required: true,errorMessage: '请输入企业自筹'} ]},
			// sjbzzjqd: {rules: [{required: true,errorMessage: '请输入上级补助资金渠道'} ]},
			// rzqd: {rules: [{required: true,errorMessage: '请输入融资渠道'} ]},
		},
		lhindex:0,
		cyindex:0,
		cylist:[{dictLabel:'是',dictValue:'Y'},{dictLabel:'否',dictValue:'N'}],//宜商
		currentdate:'',//当天日期
		pagetype:'add',
		hj:'',//合计
		}
    },
	onLoad(e) {
		// this.currentdate = this.getNowFormatDate();
		if(e.data){
			var newObj=JSON.parse(decodeURIComponent(e.data))
			this.pagetype=newObj.pagetype||'add';
		}
		if(this.pagetype=='update'){
			this.id=newObj.id;
			// 获取详情 修改
			this.getDataFn()
		}else{
		}
	// #ifdef APP
		uni.onKeyboardHeightChange(res=> { //监听键盘高度变化
		    const res_keyboard = uni.getSystemInfoSync();
		    let key_height = res.height - (res_keyboard.screenHeight - res_keyboard.windowHeight)
		    // let key_height = res.height - (res_keyboard.screenHeight - res_keyboard.windowHeight + res_keyboard.safeAreaInsets.bottom)
		     this.bottom = `${ key_height>0 ? key_height : 0}px`; 
			 // console.log( this.bottom,1)
		})
		// #endif
	},
	onHide() {
	    // #ifdef APP-PLUS
	    uni.offKeyboardHeightChange();  // 取消监听键盘高度变化事件，避免内存消耗
	    // #endif
	},
    onReady() {
      // this.$refs.form.setRules(this.rules)
    },
    methods: {
		checkPermi, checkRole,
		// 项目详情
		// that.diff_amount = parseFloat(that.order.amount - that.money).toFixed(2);
		getDataFn(){
			var that=this;
			getxmsbDetail(this.id).then(res=>{
				if(res.code==200){
					this.datainfo=res.data;
					var strnum=Number(this.datainfo.sjbz) + Number(this.datainfo.sczbj) + Number(this.datainfo.zxz)  + Number(this.datainfo.rz) + Number(this.datainfo.qyzc)
					this.hj=strnum.toFixed(2);
				}else{
					this.$toast(res.msg)
				}
			})
		},
		getHjFn(){
			var strnum=Number(this.datainfo.sjbz) + Number(this.datainfo.sczbj) + Number(this.datainfo.zxz) + Number(this.datainfo.rz)+ Number(this.datainfo.qyzc)
			this.hj=strnum.toFixed(2);
		},
		// 字典值
		getinvestmentarea(){
			// 所属行业
			getDictionaryFn('industry').then(res=>{
				if(res.code==200){
					this.industry=res.data
				}
			})
		},
		getNowFormatDate(){
			let date = new Date();
			let y = date.getFullYear();
			let m = date.getMonth() + 1;
			m = m < 10 ? "0" + m : m;
			let d = date.getDate();
			d = d < 10 ? "0" + d : d;
			const timeday = y + "-" + m + "-" + d;
			return timeday;
		},
		
		bindDateChangetimea(e){//计划开工时间
			this.datainfo.jhkgsj=e.detail.value
		},
		getNext(){
			this.$refs.form.validate().then(res => {
				this.type=2;
			})
		},
      getSubmit() {
			var that=this;
			this.$refs.twoform.validate().then(res => {
				var params=this.datainfo;
				// 判断渠道必填
				if(Number(params.sjbz)>0){
					if(!params.sjbzzjqd){
						this.$toast('请输入上级补助资金渠道')	
						return
					}
				}
				if(Number(params.rz)>0){
					if(!params.rzqd){
						this.$toast('请输入融资渠道')	
						return
					}
				}
				if(this.pagetype=='add'){
					getxmsbAddFn(params).then(res=>{
						if(res.code==200){
							this.$toast('新增申报成功')	
							setTimeout(function() {
								uni.$emit('refreshdatalistzd');
								uni.navigateBack({delta: 1});
							},1500);
						}else{
							this.$toast(res.msg)
						}
					})
				}else{
					getxmsbPutFn(params).then(res=>{
						if(res.code==200){
							this.$toast('修改申报信息成功')	
							setTimeout(function() {
								uni.$emit('refreshdatazd');
								uni.$emit('refreshdatalistzd');
								uni.navigateBack({delta: 1});
							},1500);
						}else{
							this.$toast(res.msg)
						}
						
					})
				}
			})
      },
    }
  }
</script>

<style lang="scss" scoped>
 .inform{padding-top: 30rpx; padding-bottom: 160rpx;}
  .infolist{padding: 30rpx 32rpx 30rpx 24rpx;position: relative;
	.cir{position: absolute;font-size: 36rpx;font-weight: bold;color: #FE5706;left: 0rpx;}
  }
  .delimg{width: 40rpx;height:40rpx;margin-left: 16rpx;display: flex;align-items: center;justify-content: center;
  	image{width: 30rpx;height: 30rpx;}
  }
  .infobtn{width: 100%;height: 88rpx;background: #FA5F03;line-height: 88rpx;position: fixed;left: 0;right: 0;bottom: 0;z-index: 3;}
  .input_ye image{width: 34rpx;height: 18rpx;}
.info_tit{font-size: 32rpx;color: #FE5706;padding: 30rpx 26rpx;font-weight: bold;}
.infolist_a{height: 44rpx;flex: 1;text-align: right;font-size: 32rpx;color: #343434;}


 .inform /deep/ .uni-forms-item__error{margin-top: -30rpx;margin-left: 24rpx;}
.inform .pl12{margin-right: 10rpx;}
.fixedbox .pl12{margin-right: 10rpx;}

// 计算合计
.infohjbtn{font-size: 30rpx;margin-left: 20rpx;color: #3C9BCD;}
</style>
