<template>
	<view>
		<z-navbar title="取消订单" back></z-navbar>

		<z-card class="mt-30 ptb-10">
			<z-form :model="info" :rules="rules" ref="info">
				<z-form-item height="100rpx" label="退款金额" prop="confirmMoney" showline >
					<z-input v-model="info.confirmMoney"  type="number"  placeholder="¥"></z-input>
				</z-form-item>
				<z-form-item label="备注信息" prop="remark" labelPos="top">
					<textarea class="textarea" v-model="info.remark" placeholder="请输入备注信息" maxlength="512" auto-height></textarea>
				</z-form-item>
			</z-form>
		</z-card>
		<view class="common_btn" @click="submit">
			确认取消
		</view>
		<u-toast ref="uToast"></u-toast>
	</view>
</template>

<script>
	export default {
		data() {
			// var validateConfirmMoney = (rule, value, callback) => {
			// 	if (this.info.confirmMoney=='') {
			// 		return {
			// 			state: false,
			// 			message: '请输入退款金额'
			// 		};
			// 	} else
			// 		return true;
			// };
			return {
				id: '',
				type: 0,

				info: {
					confirmMoney: 0,
					remark: ''
				},
				rules: {
					// confirmMoney: [{
					// 	validator: validateConfirmMoney
					// }]
				},
				switchAlert: false
			};
		},
		onLoad(option) {
			this.id = option.id;
			this.type = option.type;
		},
		methods: {
			submit() {
				this.$refs.info.validate(val => {
					console.log(val)
					if(this.info.confirmMoney==''&&this.info.confirmMoney!=0){
						this.$refs.uToast.error('请输入退款金额');
					}else{
						if (this.type == 0) {
							this.submitData();
						} else {
							this.submitWedData();
						}
					}
					
				})
			},
			submitData() {
				this.$axios.post('app/orderFinanceConfirm/preOrderCancel', {
					"confirmMoney": this.info.confirmMoney,
					"orderId": this.id,
					"remark": this.info.remark
				}).then(res => {
					this.$refs.uToast.success('订单取消成功！');
					uni.navigateBack({
						delta: 1
					});
				}).catch(err => {
					this.$refs.uToast.error(err.msg);
				})
			},
			submitWedData() {
				this.$axios.post('app/weddingFinanceConfirm/preOrderCancel', {
					"confirmMoney": this.info.confirmMoney,
					"weddingOrderId": this.id,
					"remark": this.info.remark
				}).then(res => {
					this.$refs.uToast.success('婚庆订单取消成功！');
					uni.navigateBack({
						delta: 1
					});
				}).catch(err => {
					this.$refs.uToast.error(err.msg);
				})
			}
		}
	}
</script>

<style scoped lang="scss">
	.textarea {
		font-size: 28rpx;
		min-height: 180rpx;
		padding-bottom: 20rpx;
		width: 100%;
	}

	.common_btn {
		margin: 0 auto;
		width: 690rpx;
		line-height: 88rpx;
		background: #2481EE;
		border-radius: 6rpx;
		margin-top: 50rpx;
		color: white;
		font-size: 32rpx;
		text-align: center;
	}
</style>
