<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" range-key="USER_NAME" :range="TransferUserList">
						<view class="uni-ellipsis">{{TransferUserList[pickerIndex].USER_NAME}}</view>
					</picker>
					<i class="uni-icon uni-icon-arrowright"></i>

				</view>

			</div>
		</div>
		<button class="mt80" @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: 4000
				},

				TransferUserList: [] ,// 待移交人员列表

				isSubmit:false, // 是否在提交

				pickerIndex: 0
			};
		},
		computed:{
			...mapState({
				'userId': state => state.userData.UserId
			}),
		},
		methods: {
			...mapMutations(['shouldReLoadingList']),
			...mapActions(['getTodoList']),
			pickerChange(e){
				this.pickerIndex = e.mp.detail.value
			},
			getTransferUser() { // 是否是请求移交人员
				let _this = this
				let _data = {

						businessType: _this.postData.businessType,
						PROINST_ID: _this.postData.PROINST_ID,
						NextStepId: _this.postData.NOWACTINST_ID,
						IsTransfer: 1,
						USER_ID : _this.userId
					}

				this.$request.$get('GetNextStepUser',_data).then((res)=> {
					uni.hideLoading()
					_this.TransferUserList= res.Data.List

				})
			},

			postFn () {
				let _this = this
				if(_this.isSubmit) {
					return
				}
				if(!_this.TransferUserList[_this.pickerIndex]) {
					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,
						NextSTAFF_ID: _this.TransferUserList[_this.pickerIndex].USER_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,
							success () {
								setTimeout(()=> {
									uni.navigateBack({ delta: 1})
								},200)

							}
						})
					}else {
						uni.showToast({
							title: _data.ResultDesc || '操作错误',
							icon: 'none'
						})

					}
				})
			},
		},
		onUnload() {
			this.$util.addUserBehaviorNew()
		},
		onLoad(option) {

			uni.showLoading({
				title:'正在加载'
			})
			this.postData = option
			this.postData.PROINST_NEXTID = 4000
			this.getTransferUser()
		}
	}
</script>

<style scoped>
	@import url("../../common/css/auditingPop.css");
	@import url("../../common/css/picker.css");
	.page-select {
		padding: 8upx 30upx;
	}
	.select-item {
		border-bottom: none;
	}
	.mt80 {
		margin-top: 200upx;
	}

</style>
