<template>
	<div class="page-cont">
		<p class="page-title">请确认驳回当前业务到上一环节</p>
		<div class="page-select">
			<div class="select-item">
				<span>业务驳回到</span>
				<view class="select-unit" >
					<picker mode="selector" @change="pickerChange" :value="pickerIndex" range-key="ActDef_Name" :range="NextActDefList">
						<view class="uni-ellipsis">{{NextActDefList[pickerIndex].ActDef_Name}}</view>
					</picker>
					<i class="uni-icon uni-icon-arrowright"></i>
				</view>
				
			</div>
			
			<div class="text-area-box">
				<textarea value="" placeholder="驳回原因" v-model="postData.APPROVED_INFO"/>
			</div>
		</div>
		
		<button @click="postFn()" :loading="isSubmit">驳回</button>
		
	</div>
</template>

<script>
	import {mapState,mapMutations,mapActions} from 'vuex'
	export default {
		data() {
		
			return {
				postData: {
					PROINST_ID:'',
					FINANCEPROINST_ID:'',
					NOWACTINST_ID:'',
					PROINST_NEXTID: 3000,
					APPROVED_INFO:''
				},
				
				NextActDefList: [] ,// 可选环节列表
		
				isSubmit:false,
			
				pickerIndex: 0
			};
		},
		computed:{
			...mapState({
				'userId': state => state.userData.UserId
			}),
			// ...mapGetters({'users':'getUser'})
		},
		methods: {
			...mapMutations(['shouldReLoadingList']),
			...mapActions(['getTodoList']),
			pickerChange(e){
				
				this.pickerIndex = e.mp.detail.value

			},
		
			getHighNextActDef() { // 获取下一环节
				let _this = this
				let _data = _data = {
						
						businessType: _this.postData.businessType,
						PROINST_ID: _this.postData.PROINST_ID,
						PROINST_NEXTID: _this.postData.PROINST_NEXTID
						
					}
				
				this.$request.$get('GetNextStep',_data).then((res)=> {
					uni.hideLoading()
					_this.NextActDefList= res.Data.List
			
				})
			},
			
			postFn () {
				
				let _this = this
				if(_this.isSubmit) {
					return
				}
				if(!_this.NextActDefList[_this.pickerIndex]) {
					uni.showToast({
						title: '请选择回退环节后提交。',
						icon: 'none'
					})
					return false
				}
				if(!_this.postData.APPROVED_INFO) {
					uni.showToast({
						title: '请填写驳回原因。',
						icon: 'none'
					})
					return false
				}
		
				let arr = {
						
						businessType: _this.postData.businessType,
						PROINST_ID: _this.postData.PROINST_ID,
						PROINST_NEXTID: _this.postData.PROINST_NEXTID,
						NOWACTINST_IDS: _this.postData.NOWACTINST_ID,
						NextACTDEF_IDS: _this.NextActDefList[_this.pickerIndex].ActInst_ID,
						APPROVED_INFO: _this.postData.APPROVED_INFO,
						NextSTAFF_ID: "",
				
					}
				this.isSubmit = true
				this.$request.$post('ProcessApproval',arr).then((_data)=> {
					_this.isSubmit = false
					
					if (_data.ResultCode==='100') {
						uni.$emit(_this.postData.businessType,true);
						_this.getTodoList();
						_this.shouldReLoadingList(true);
						uni.showToast({
							title: _data.ResultDesc,
							icon: 'none',
							success () {
								setTimeout(()=> {
									uni.navigateBack({ delta: 1})
								},200)
								
							}
						})
					}else {
						uni.showToast({
							title: _data.ResultDesc || '操作错误',
							icon: 'none'
						})
						
					}
				})
			},
		},
		onLoad(option) {
			
			this.postData = option
			this.postData.PROINST_NEXTID = 3000
			this.postData.APPROVED_INFO = '' // 审核意见
			uni.showLoading({
				title:'正在加载'
			})
			this.getHighNextActDef()
		},
		onUnload() {
			this.$util.addUserBehavior()
		}
	}
</script>

<style scoped>
	@import url("../../common/css/auditingPop.css");
	@import url("../../common/css/picker.css");
</style>
