<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="padding-top">
					<view class="flex justify-start flex-direction">
						<view>本单商品已设置包安装/包施工类服务</view>
						<view>请预置分配安装或服务费/工时费：</view>
					</view>
					<view class="margin-top solid radius text-left padding-sm">
						<input type="digit" style="width: 100%;" placeholder="请输入本单服务费，工时费可撤回或修改" v-model="serviceMoney">
					</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="noticeConfirm">继续接单</view>
			</view>
		</view>
		
		<confirm-modal ref="notice" :content="'本单款项银联确认已发起支付，款项已到达或即将到达您所绑定帐户，需退款的同意后您线下与客户操作退款，系统无法提供原路返回退款!'" :confirmMsg="'同意'" @confirm="noticeConfirm" @cancel="noticeCancel"></confirm-modal>
	</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,
				serviceMoney: null
			}
		},
		methods: {
			hideModal(e) {
				this.resetData();
				this.$emit('close', e);
			},
			resetData() {
				this.serviceMoney = null;
			},
			showNotice(e) {
				if (this.data.drawCashStatus != null && this.data.drawCashStatus >= 1) {
					this.$refs.notice.showModal();
				} else {
					this.submit(e);
				}
			},
			noticeConfirm() {
				this.submit({
					currentTarget: {
						dataset: {
							modal: 'agreeAfterSale'
						}
					}
				});
			},
			noticeCancel() {
				this.hideModal({
					currentTarget: {
						dataset: {
							modal: 'agreeAfterSale'
						}
					}
				});
			},
			async submit(e) {
				if (!this.serviceMoney) {
					uni.showToast({
						title: '请输入本单服务费',
						icon: 'none'
					});
					return;
				}
				if(parseFloat(this.serviceMoney) > this.data.serverMoney) {
					uni.showToast({
						title: '本单服务费不能大于订单服务金额',
						icon: 'none'
					});
					return;
				}
				let res = await this.$request.allocateServiceMoney({
					id: this.data.orderMasterId,
					serverGoodsMoney: this.serviceMoney
				});
				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>
