<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.afterServiceRecordList[0].refund ? data.afterServiceRecordList[0].refund : data.payMoney}}</text>
				</view>
				<view v-if="!data.isOnlyServ && data.afterServiceRecordList[0].refund && data.payMoney < data.afterServiceRecordList[0].refund" class="padding-top text-red">
					警报：该单关联其它订单，客户申请的退款金额有效，有疑问可先沟通派单公司（详情处电话），如确认同意，最大退款额以本单接单额原路退回，其余需退的或你仍有收益则由派单公司处理，如更改退单额，需先协商一致，余额部分完单后计入你账户。
				</view>
				<view class="text-lg padding-top flex justify-start align-center">
					<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 agreedRefund = this.agreedRefund;
				if (!agreedRefund && this.data.afterServiceRecordList[0].refund != null) {
					agreedRefund = this.data.afterServiceRecordList[0].refund;
				} else if (!agreedRefund) {
					agreedRefund = this.data.payMoney;
				}
				let res = await this.$request.editAfterServiceRecord({
					id: this.data.afterServiceRecordList[0].id,
					workerFeedbackReasonType: this.reasonType,
					agreedRefund: agreedRefund,
					workerFeedbackReason: this.remark,
					workerFeedbackResult: 1,
					updateBy: 2
				});
				if (res && res.code === 0) {
					uni.showToast({
						icon: 'success',
						title: '提交成功',
						duration: 1000
					})
					this.hideModal(e);
					this.$emit('confirmFeedback');
					return;
				}
				uni.showToast({
					icon: 'error',
					duration: 1000,
					title: '提交失败',
				})
			}
		},
	}
</script>

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