<template>
	<view>
		<view class="textarea-wrap white-wrap">
			<textarea :placeholder="`请输入${type === 'del' ? '删除' : '拒绝'}理由`" v-model="reason" maxlength="-1" @input="formatSpace"></textarea>
		</view>
		<view class="btns-wrap flex">
			<button class="cancel-btn" @click="handleCancel">取消</button>
			<button class="confirm-btn" @click="handleSubmit">提交</button>
		</view>
	</view>
</template>

<script>
	import {apiRoadShowReject} from '@/api/approve/activity.js'
	import { delActivity } from '@/api/roadshow/index.js';
	export default {
		data() {
			return {
				type: '',
				reason: '',
				RsCalendarId:null,
				RsCalendarResearcherId:null,
			}
		},
		onLoad(options) {
			const { RsCalendarId,RsCalendarResearcherId,type } = options;
			this.type = type;
			this.RsCalendarId=RsCalendarId;
			this.RsCalendarResearcherId=RsCalendarResearcherId;
			uni.setNavigationBarTitle({
				title: type==='del' ? '删除理由' : '拒绝理由'
			})
		},
		methods: {
			async handleSubmit() {
				if(!this.reason){
					uni.showToast({
						title:'请填写理由',
						icon:"none"
					})
					return
				}
				
				const res = this.type==='del' ? await delActivity({
					DeleteReason: this.reason,
					RsCalendarId:Number(this.RsCalendarId),
					RsCalendarResearcherId:Number(this.RsCalendarResearcherId),
				}) : await apiRoadShowReject({
					RsCalendarId:Number(this.RsCalendarId),
					RsCalendarResearcherId:Number(this.RsCalendarResearcherId),
					RefuseReason:this.reason
				})
				if(res.code===200){
					uni.showToast({
						title:"审批成功",
						icon:'success'
					})
					uni.$emit('activityApproveListUpdate',{
						RsCalendarId:this.RsCalendarId,
						RsCalendarResearcherId:this.RsCalendarResearcherId
					})
					setTimeout(()=>{
						this.handleCancel()
					},1000)
				}
			},
			
			handleCancel(){
				uni.navigateBack({
					delta:1
				})
			},
			
			/* 过滤空格 */
			formatSpace({detail}) {
				this.reason = detail.value.replace(/\s+/g,'');
			}
			
		},
	}
</script>

<style lang="scss">
	.textarea-wrap {
		padding: 17px;

		textarea {
			resize: none;
			display: block;
			box-sizing: border-box;
			width: 100%;
			height: 200px;
			border: none;
			font-size: 14px;
			/* no */
		}
	}

	.btns-wrap {
		justify-content: center;
		padding-top: 50px;
		padding-bottom: 50px;

		button {
			width: 90px;
			height: 28px;
			border-radius: 28px;
			border: none;
			margin: 0 10px;
			font-size: 14px;
			/* no */
			color: #fff;
			line-height: 28px;
		}

		.confirm-btn {
			background-color: #5890fb;
		}

		.cancel-btn {
			border: 1px solid #5890fb;
			color: #5890fb;
			background-color: #fff;
		}
	}
</style>
