
<template>
	<view>
		<uni-forms ref="form" labelPosition="left" labelAlign="left" @submit="submitForm">
			<view class="uni-form-item uni-column" v-show="isShowHand">
				<view class="title"><text class="uni-form-item__title">手送资料：</text></view>
				<radio-group @change="radioChange">
				<view style="background-color: #fff;">
					  <label class="radio"><radio value="有"  />有</label>
					   <label class="radio"><radio value="无" />无</label>
				</view>
				</radio-group>
			</view>
			
			<view class="uni-form-item uni-column" v-show="isShowUnit">
				<view class="title"><text class="uni-form-item__title">经办人部门</text></view>
				<view class="uni-input-wrapper" style="justify-content: left;">
					<picker mode="selector" :value="unitCode" :range="array" range-key="fullName" @change="bindPickerChange" v-model="unitCode"  style="width: 100%;"  >
						<view class="uni-input">{{array.length>0?array[index].fullName:'--请选择--'}}</view>
					</picker>
				</view>
			</view>
			 <view style="margin-bottom: 120px;">
			 
			 </view>
			<view class="uni-btn-v uni-column">
				<button type="primary" form-type="submit" style="border-radius: 15px;" >保存</button>
			</view>
			
		</uni-forms>
		 
		 
		 
	</view>
</template>

<script> 
	import {WorkFlowAudit,WorkFlowSave} from "@/common/api/commonApi.js"; 
	import {Decimal} from 'decimal.js';     //decimal计算 
	export default {
		 
		data() {			
			return {
				array:[],
				radioValue:'',
				unitCode:'',
				index:0 ,
				isShowHand:false,   //是否显示手送资料
				isShowUnit:false    //是否显示经办人部门
			}
		},
		onLoad(){
			//console.info(page.path);
			console.info(uni.getStorageSync('storage_state'));
			//console.info(this);
			this.$util.persistLogin(this);
			//console.info(this.$store.state.user);
			
		},
		onUnload() {
			
		},
		created: function() {
			this.GetDropDown();
				
			
		},
		updated:function(){
			
		},
		methods: {
			/**
			 * 手动提交
			 * @param {Object} form
			 */
			submitForm(e) {				
				console.info('submitForm');
				let _this=this;
				if(_this.isShowHand){
					if(this.$util.isEmpty(this.radioValue))
					{
						uni.showToast({
							icon:"none",
							title:"请选择手送资料",
							duration:3000
						});
						return;
					}
				}
				if(_this.isShowUnit){
					if(this.$util.isEmpty(this.unitCode))
					{
						uni.showToast({
							icon:"none",
							title:"请选择经办人部门",
							duration:3000
						});
						return;
					} 
				}
				
				//return;
				let hand=this.radioValue;
				let unitCode=this.unitCode;				
				let procedureName=this.$util.getQuery("procedureName");        //流程名
				let applicationCode=this.$util.getQuery("applicationCode");   //流程审核项的主键ID
				let procedureCode=this.$util.getQuery("procedureCode");      //流程编码
				let projectCode=this.$util.getState(this,'projectCode');
				let userCode=this.$util.getState(this,'userCode'); 
				 
				
				var data={procedureName:procedureName,applicationCode:applicationCode,procedureCode:procedureCode,projectCode:projectCode,unitCode:unitCode,hand:hand,userCode:userCode};
				console.info('data:',data); 
				//return;
				WorkFlowSave(data).then((res)=>{
					console.info("提交应答");
					console.info(res);
					if(!res.isSuccess){
						uni.showToast({
							title:res.errMsg,
							duration:4000,
							icon:'none'
						})
					}
					else{
						let usercode=_this.$util.getState(_this,'userCode');
						let userid=_this.$store.state.user.userID;
						let un=this.$store.state.name;
						let url="http://1.193.162.246:18403/reception?type=gcy&usercode="+usercode+"&userid="+userid+"&actCode="+res.data+"&un="+encodeURIComponent(un);
						console.info("workflow url",url);
						//return;
						location.href=url;
						 
						 
					}
					 
					
				});
			}, 
			GetDropDown:function(){
				let that=this;
				let userCode=this.$util.getState(this,'userCode');
				let procedureCode=this.$util.getQuery("procedureCode");
				WorkFlowAudit(userCode,procedureCode).then((res)=>{
					console.info('WorkFlowAudit:',res);
					that.isShowHand=res.isShowHand;
					that.isShowUnit=res.isShowUnit;
					res.list.forEach(function(item,index,array){
						that.$set(that.array,index,item);
					});
					that.array.unshift({unitCode:'',funllCode:'',fullName:'--请选择--'});
					//赋默认值
					//that.viseType=that.array[0];	
					//console.info(that.viseType);
					if(that.isShowHand==false&&that.isShowUnit==false){
						that.submitForm();
					}
				});
			},
			/* 经办人部门选择 */
			bindPickerChange: function(e) {
				//console.log('picker发送选择改变，携带值为：' + e.detail.value);
				console.info('bindPickerChange',e.detail.value);
				this.index = e.detail.value;
				this.unitCode=this.array[this.index].unitCode;
				console.info(this.unitCode);
			},
			/* 单选按钮选择 */
			radioChange: function(evt) {
				console.info('radioChange',evt.target.value);
				 this.radioValue = evt.target.value;
			},
			
		}
	}
</script>

<style scoped>
	/* 头条小程序组件内不能引入字体 */
	/* #ifdef MP-TOUTIAO */
	@font-face {
		font-family: uniicons;
		font-weight: normal;
		font-style: normal;
		src: url("~@/static/uni.ttf") format("truetype");
	}

	/* #endif */
	 
	page {
		display: flex;
		flex-direction: column;
		box-sizing: border-box;
		background-color: #efeff4;
		min-height: 100%;
		height: auto;
	}

	view {
		font-size: 14px;
		line-height: inherit;
	}

	.uni-form-item__title {
	    font-size: 16px;
	    line-height: 24px;
	}
	
	.uni-input-wrapper {
	    /* #ifndef APP-NVUE */
	    display: flex;
	    /* #endif */
	    padding: 8px 13px;
	    flex-direction: row;
	    flex-wrap: nowrap;
	    background-color: #FFFFFF;
	}
	.title{
		background-color: #efefef;
	}
	.uni-input {
	    height: 28px;
	    line-height: 28px;
	    font-size: 15px;
	    padding: 0px;
	    flex: 1;
	    background-color: #FFFFFF;
	}
	
	.uni-icon {
	    font-family: uniicons;
	    font-size: 24px;
	    font-weight: normal;
	    font-style: normal;
	    width: 24px;
	    height: 24px;
	    line-height: 24px;
		margin-left:15px;
	    color: #999999;
	}
	
	.uni-eye-active {
	    color: #007AFF;
	}
	.uni-btn-v{
		position: fixed;
		bottom: 0;
		width:100%;
		
	}
	.header-slot-box {
		font-size:15px;
		margin: 5px 5px;
		width:20%;
		justify-content: center;
	}
	.body-slot-box {
		font-size:15px;
		margin: 5px 5px;
		width:40%;
		justify-content: center;
	}
	.footer-slot-box {
		font-size:15px;
		margin: 5px 5px;
		width:40%;
		justify-content: center;
	}
	.uni-textarea textarea{
		font-size:15px;
	}
	.content {
		padding: 40rpx;
		background-color: #fff;
	}
	
	/* 上传控件 */
	.uploadControl {
		border: 1rpx solid #eee;
		border-radius: 10rpx;
		width: 130rpx;
		display: block;
		height: 130rpx;
		text-align: center;
		line-height: 130rpx;
		font-size: 30rpx;
		color: #888;
		background-color: #eeeeee;
	}
	 
	 .topicon >>> .icon{
	        border: #4CD964 2upx solid;
	    }
</style>
