<template>
	<view class="conent">
		<view class="assignrbitrators">
			<uni-forms ref="form" :modelValue="formData" :rules="rules">
				<uni-forms-item label="案件编号:" name="caseNum" label-width="80px">
					<uni-easyinput v-model="formData.caseNum" type="text" :disabled='true' placeholder="请输入案件编号" />
				</uni-forms-item>
				<!-- <uni-forms-item label="案件标的:" name="caseSubjectAmount" label-width="80px">
					<uni-easyinput v-model="formData.caseSubjectAmount" type="text" :disabled='true' placeholder="请输入案件标的" />
				</uni-forms-item> -->
				<uni-forms-item label="缴费金额:" name="feePayable" label-width="80px">
					<uni-easyinput v-model="formData.feePayable" type="text" :disabled='true' placeholder="请输入缴费金额" />
				</uni-forms-item>
				<uni-forms-item label="申请人缴费:" name="feePayable" label-width="90px" v-if="annexTypeS">
					<view v-for="item in formData.caseAttachList">
						<uni-link v-if="item.annexType==4" :href="item.annexPath" color="#007BFF"
							:text="item.annexName"></uni-link>
					</view>
				</uni-forms-item>	
				<uni-forms-item label="被申请人缴费:" name="feePayable" label-width="100px" v-if="annexTypeB">
					<view v-for="item in formData.caseAttachList">
						<uni-link v-if="item.annexType==9" :href="item.annexPath" color="#007BFF"
							:text="item.annexName"></uni-link>
					</view>
				</uni-forms-item>
				<uni-forms-item label="是否缴费通过" label-width="120px" name="yesOrNo">
					<uni-data-checkbox class='checkbox' 
						:localdata="yesOrNoObject"
						v-model="yesOrNo"
						@change='clearValidate'></uni-data-checkbox>
				</uni-forms-item>
				<uni-forms-item label="驳回原因:" name="reason" label-width="120px" required v-if="refusedisabled"
				:rules="[{required: true,errorMessage: '驳回原因不能为空'}]"
				>
					<uni-easyinput  v-model="formData.reason" type="textarea" placeholder="请输入驳回原因" />
				</uni-forms-item>
			</uni-forms>
			<view class="determine" style="text-align: center;">	
				<button  class="mini-btn" 
				type="primary" size="mini" 
				@tap="confirmPayment">确认</button>
				<button style="margin-left:30rpx;" class="mini-btn" 
				type="default" size="mini" 
				@tap="cencalBut">取消</button>
			</view>
		</view>
	</view>
</template>

<script>
	import {selectPaymentDetail,confirmPaid,resConfirmPaid} from '../../../api/handlecase/index.js'
	export default {
		data() {
			return {
				yesOrNo:1,
				formData:{
					reason:""
				},
				rules:{},
				paymentConfirm:{},
				annexTypeS:false,
				annexTypeB:false,
				yesOrNoObject: [{
					text: '同意',
					value: 1
				}, {
					text: '拒绝',
					value: 0
				}],
				refusedisabled:false
			}
		},
		methods:{
			confirmPayment(){
				this.$refs.form.validate().then(res=>{
						if(this.paymentConfirm.caseFlowId==3){
							this.confirmPaymentApplicant()
						}else if(this.paymentConfirm.caseFlowId==45){
							this.confirmPaymentRespondent()
						}
						console.log(this.paymentConfirm.caseFlowId)
					}).catch(err =>{
						
				})
			},
			// 申请人确认缴费
			confirmPaymentApplicant(){
				let vals = {
					caseId:this.paymentConfirm.id,
					batchNumber:"",
					caseFlowId:this.paymentConfirm.caseFlowId,
					yesOrNo:this.yesOrNo,
					reason:this.formData.reason
				}
				confirmPaid(vals).then(res =>{
					uni.showToast({
						title: '申请人缴费确认成功',
						icon: 'none',
						duration: 1000
					})
					uni.navigateTo({
						url:'/pages/handlecase/index'
					})
				})
			},
			// 被申请人缴费确认
			confirmPaymentRespondent(){
				let vals = {
					caseId:this.paymentConfirm.id,
					batchNumber:"",
					caseFlowId:this.paymentConfirm.caseFlowId,
					yesOrNo:this.yesOrNo,
					reason:this.formData.reason
				}
				resConfirmPaid(vals).then(res =>{
					uni.showToast({
						title: '被申请人缴费确认成功',
						icon: 'none',
						duration: 1000
					})
					uni.navigateTo({
						url:'/pages/handlecase/index'
					})
				})
			},
			// 缴费详情
			paymentDetails(val) {
			    selectPaymentDetail(val).then(res => {
			        this.formData = res.data;
					this.formData.caseAttachList.forEach(res =>{
						if(res.annexType==4){
							this.annexTypeS = true
						}else if(res.annexType==9){
							this.annexTypeB = true
						}
					})
			    })
			}, 
			clearValidate(val){
				 this.yesOrNo=val.detail.value
				if(val.detail.value==0){
					this.refusedisabled = true
				}else{
					this.refusedisabled = false
				}
			}
		},
		onLoad(data) {
			this.paymentConfirm = data
			this.paymentDetails({id:data.id})
		}
	}
</script>

<style lang="scss">
	page {
		background-color: #ffffff;
	}
	.assignrbitrators{
		margin: 30rpx;
	}
</style>