<!DOCTYPE html>
<?php
	$delviery_name = "";
	if($third_distribution_type == 'imdada'){
		$delviery_name = "达达配送";
	}else if($third_distribution_type == 'sf'){
		$delviery_name = "顺丰同城";
	}else if($third_distribution_type == 'uupt'){
		$delviery_name = "UU跑腿";
	}else if($third_distribution_type == 'dianwoda'){
		$delviery_name = "点我达";
	}
?>
<head>
	<meta charset="utf-8">
	<meta http-equiv="X-UA-Compatible" content="IE=edge">
	<title><?php $delviery_name;?>配送取消原因</title>
</head>
<body style="width:100%;margin:0 auto;text-align: center;">
<input type="hidden" id="order_id" name="order_id" value="{$order_id}"/>
<input type="hidden" id="third_distribution_type" name="third_distribution_type" value="{$third_distribution_type}"/>
<div class="layui-card-body" style="padding:15px 0 0 15px;">
	<?php if($third_distribution_type == 'imdada'){ ?>
	<div class="layui-form-item">
		<label class="layui-form-label">取消原因</label>
		<div class="layui-input-block">
			<select id="cancel_reason_id_imdada" name="cancel_reason_id">
				<option value="1">没有配送员接单</option>
				<option value="2">配送员没来取货</option>
				<option value="3">配送员态度太差</option>
				<option value="4">顾客取消订单</option>
				<option value="5">订单填写错误</option>
				<option value="34">配送员让我取消此单</option>
				<option value="35">配送员不愿上门取货</option>
				<option value="36">我不需要配送了</option>
				<option value="37">配送员以各种理由表示无法完成订单</option>
				<option value="1000">其他</option>
			</select>
		</div>
	</div>
	<div class="layui-form-item" style="display: none;" id="cancel_reason_div">
		<label class="layui-form-label">取消具体原因</label>
		<div class="layui-input-block">
			<input type="text" name="cancel_reason" id="cancel_reason_imdada" class="form-control" value="" style="width: 80%;">
		</div>
	</div>
	<?php }else if($third_distribution_type == 'sf'){?>
		<div class="layui-form-item">
			<label class="layui-form-label">取消原因</label>
			<div class="layui-input-block">
				<input type="text" name="cancel_reason" id="cancel_reason_sf" class="form-control" value="" style="width: 80%;">
			</div>
		</div>
	<?php }else if($third_distribution_type == 'make'){?>
	<div class="layui-form-item">
		<label class="layui-form-label">取消原因</label>
		<div class="layui-input-block">
			<input type="text" name="cancel_reason" id="cancel_reason_make" class="form-control" value="" style="width: 80%;">
		</div>
	</div>	
	<?php }else if($third_distribution_type == 'ele'){ ?>
		<div class="layui-form-item">
			<label class="layui-form-label">取消原因</label>
			<div class="layui-input-block">
				<select id="cancel_reason_id_ele" name="cancel_reason_id">
					<option value="1">物流原因：订单长时间未分配骑手</option>
					<option value="2">物流原因：分配骑手后，骑手长时间未取件</option>
					<option value="3">物流原因：骑手告知不配送，让取消订单</option>
					<option value="4">商品缺货/无法出货/已售完</option>
					<option value="5">商户联系不上门店/门店关门了</option>
					<option value="6">商户发错单</option>
					<option value="7">商户/顾客自身定位错误</option>
					<option value="8">商户改其他第三方配送</option>
					<option value="9">顾客下错单/临时不想要了</option>
					<option value="10">顾客自取/不在家/要求另改时间配送</option>
				</select>
			</div>
		</div>
		<div class="layui-form-item" style="display: none;" id="cancel_reason_div_ele">
			<label class="layui-form-label">取消原因</label>
			<div class="layui-input-block">
				<input type="text" name="cancel_reason" id="cancel_reason_ele" class="form-control" value="" style="width: 80%;">
			</div>
		</div>
	<?php } ?>
	<div class="layui-form-item">
		<label class="layui-form-label"></label>
		<div class="layui-input-block">
			<a href="javascript:;" class="layui-btn layui-btn-sm cancelBtn">确认取消</a>
		</div>

	</div>
</div>
</body>
<script>
	$(function(){
		$('#cancel_reason_id_imdada').change(function(){
			if($(this).val() == '1000'){
				$('#cancel_reason_div').show();
			}else{
				$('#cancel_reason_div').hide();
			}
		});

		$('.cancelBtn').click(function(){
			cancel_delivery();
		});
	})

	function cancel_delivery(){
		var order_id = $('#order_id').val();
		var third_distribution_type = $('#third_distribution_type').val();
		var cancel_reason_id = "";
		var cancel_reason = "";
		if(third_distribution_type == 'imdada'){
			cancel_reason_id = $('#cancel_reason_id_imdada').val();
			cancel_reason = $('#cancel_reason_imdada').val();
			if(cancel_reason_id == '1000' && cancel_reason == ''){
				layer.msg("取消原因为其他时，取消具体原因必填",{icon: 2,time: 2000});
				return false;
			}
			if(cancel_reason_id != '1000'){
				cancel_reason = $('#cancel_reason_id_imdada').find('option:selected').text();
			}
		}else if(third_distribution_type == 'sf'){
			cancel_reason = $('#cancel_reason_sf').val();
		}else if(third_distribution_type == 'make'){
            cancel_reason = $('#cancel_reason_make').val();
        }else if(third_distribution_type == 'ele'){
			cancel_reason_id = $('#cancel_reason_id_ele').val();
			cancel_reason = $('#cancel_reason_ele').val();
		}
		layer.confirm('订单在“第三方配送平台”处于 待接单 或 待取货 情况下，取消订单可能会产生违约金，确认取消配送订单吗？', function(index){
			$.ajax({
				url:"{:U('order/thirth_cancel_delivery_order')}",
				type:'post',
				dataType:'json',
				data: {order_id:order_id,cancel_reason_id:cancel_reason_id,cancel_reason:cancel_reason},
				success:function(res){
					if(res.status == 0)
					{
						layer.msg(res.result.msg,{icon: 2,time: 2000});
						return false;
					}else if(res.status == 1){
						var go_url = location.href;

						layer.msg('取消配送订单成功',{time: 1000,
							end:function(){
								layer.closeAll();
								location.reload();
							}
						});
					}
				}
			})
		});
	}
</script>
</html>