<template>
	<view class="cu-modal" :class="show?'show':''">
		<view class="cu-dialog bg-white">
			<view class="cu-bar">
				<view class="content">同意售后</view>
				<view class="action" data-modal="agreeAfterSale" @click="hideModal">
					<text class="cuIcon-close text-red"></text>
				</view>
			</view>
			<view class="padding text-left">
				<view class="text-lg">
					<text>本单售后到帐额：</text>
					<text class="text-price text-red">{{data.explainRefund}}</text>
				</view>
				<view class="text-lg padding-top">
					<text>更改到帐额：</text>
					<input class="radius-input inline-input" v-model="agreedRefund"></input>
					<text class="margin-left-xs">元</text>
				</view>
				<view class="padding-top">
					<view class="flex justify-start">
						<view>原因选择：</view>
						<radio-group @change="changeReasonRadio">
							<label class="radio margin-right-sm">
								<radio style="transform:scale(0.7)" class="main-color" value="1" :checked="data.reasonType === 1"/>
								<text>客户原因</text>
							</label>
							<label class="radio">
								<radio style="transform:scale(0.7)" class="main-color" value="2" :checked="data.reasonType === 2"/>
								<text>师傅原因</text>
							</label>
							<label class="radio">
								<radio style="transform:scale(0.7)" class="main-color" value="3" :checked="data.reasonType === 3"/>
								<text>其他</text>
							</label>
						</radio-group>
					</view>
					<view class="margin-top">
						<textarea style="width: 100%; height: 200rpx;" class="solid radius text-left padding-sm"
							v-model="remark" maxlength="-1"
							placeholder="请输入具体原因或直接同意，更改到帐金额需与客户协商一致，否则可能被拒绝或引起客诉升级"></textarea>
					</view>
				</view>
			</view>
			<view class="cu-bar solid-top">
				<view class="action margin-0 flex-sub text-black" data-modal="agreeAfterSale" @click="hideModal">取消</view>
				<view class="action margin-0 flex-sub text-main-color solid-left" data-modal="agreeAfterSale"
					@click="submit">确认</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		name: 'agreeAfterSale',
		props: {
			show: {
				type: Boolean,
				default: false
			},
			data: {
				type: Object,
				default: {}
			}
		},
		data() {
			return {
				agreedRefund: null,
				reasonType: null,
				remark: null
			}
		},
		methods: {
			hideModal(e) {
				this.resetData();
				uni.$emit(this.$globalFun.HIDE_MODAL, e);
			},
			resetData() {
				this.data = null;
				this.agreedRefund = null;
				this.reasonType = null;
				this.remark = null;
			},
			changeReasonRadio(e) {
				this.reasonType = e.detail.value;
			},
			async submit(e) {
				let res = await this.$request.editAfterServiceRecord({
					id: this.data.afterServiceRecordList[0].id,
					workerFeedbackReasonType: this.reasonType,
					agreedRefund: this.agreedRefund,
					workerFeedbackReason: this.remark,
					updateBy: 2
				});
				if (res && res.code === 0) {
					uni.showToast({
						icon: 'success',
						duration: 1000
					})
					this.hideModal(e);
					this.$emit('confirmFeedback');
					return;
				}
				uni.showToast({
					icon: 'error',
					duration: 1000
				})
			}
		},
	}
</script>

<style scoped>
	.inline-input {
		flex-basis: 25%;
	}
</style>
