<{import file="common.html" title="售后详情"}> 
<link rel="stylesheet" type="text/css" href="<{$__APP__}>public/css/member_refund.css">
<div class="cnav">
	<a class="back" href="javascript:;">&nbsp;</a> 售后详情 <a class="thome" href="javascript:;">主页</a>
</div> 
<{uqcms m="refund" v="row" c="get_one:service_id=smarty.get.service_id"}> 
<{uqcms m="refund" v="goods" c="refund_goods:service_id=smarty.get.service_id"}>  
<div class="abox">
	<!--产品信息-->
	<div class="ginfo">
		<div class="img"><a href=""><img src="<{$__IMG__}><{$goods.images|img_size:120x120}>"></a></div>
		<div class="ttl">
			<div class="sttl"><a href=""><{$goods.title}></a></div>
			<div class="spr">￥<{$goods.price}></div>
		</div>
	</div>
	
	<!--操作信息-->
	<div class="do">
		<{if $row.id}>
			<{if $row.status == '1'}>			
				<div class="submit_msg">已经提交申请，请等待卖家处理</div> 
			<{elseif $row.status == '2'}>
				<form id="kd_form" method="post"> 
					<input type="hidden" name="service_id" value="<{$row.service_id}>"/>
					<div class="fhuo">
						<dl>
							<dt>快递名称</dt>
							<dd>
								<{uqcms m="express" v="exp" c="get_config"}> 
								<select name="kd_code">
									<option value="0">--选择快递--</option>
									<{foreach item=i from=$exp}>		
										<option value="<{$i.code}>"><{$i.name}></option>
									<{/foreach}>			 
								</select>
							</dd>
						</dl>
						<dl>
							<dt>快递单号</dt>
							<dd><input type="text" name="kd_number" class="rmk"/></dd>
						</dl>
						<dl>
							<dt>退款说明</dt>
							<dd><input type="text" name="kd_remark" class="rmk"></dd>
						</dl>
					</div> 
					<div class="img_up">
						<div class="img_name"><span>上传凭证</span></div>
						<div class="img_box">
							<{if $i.comment_status}>
								<{foreach item=ci from=$i.comment_img}>
									<img src="<{$__IMG__}><{$ci.images|img_size:120x120}>" width="60" height="60"/>
								<{/foreach}>
							<{else}> 
								<div class="upload_box"></div>
								<div class="upload_button"> 
									<a class="file" href="javascript:;">选择文件<input type="file" name="imgFile" class="img_file" id="imgFile"/></a>									
								</div>
							<{/if}>
						</div>
					</div> 
					<div class="sbutton"><p><input type="submit" id="submit"  name="kd_submit" class="submit" value="发送快递"/></p></div>
				</form> 
			<{elseif $row.status == '3'}>
				 <div class="submit_msg">已经发货,等待买家确认收货</div>
			<{elseif $row.status == '4'}>
				<div class="submit_msg">平台介入</div>
			<{elseif $row.status == '5'}>
				<div class="submit_msg">退款成功</div>
			<{elseif $row.status == '6'}>
				<div class="submit_msg">退款失败</div>
			<{/if}>
		<{else}>
			<!--不存在，则申请-->
			<{if $row.error == '0'}>
				<form id="form" method="post">
					<input type="hidden" name="service_id" value="<{$smarty.get.service_id}>"/>
					<div class="fhuo">
						<dl>
							<dt>退货原因</dt>
							<dd>
								<{uqcms m="refund" v="reason" c="refund_reason"}>	
								<select name="reason">
									<option value="0">请选择退款原因</option>
									<{foreach item=i key=k from=$reason}>			
										<option value="<{$k}>"><{$i}></option>
									<{/foreach}>
								</select>
							</dd>
						</dl>
						<dl>
							<dt>退款金额</dt>
							<dd><input type="number" name="price" size="15" value="<{$goods.refund_price}>" max="<{$goods.refund_price}>">
								<span>不能高于<{$goods.refund_price}>元</span>
							</dd>
						</dl>
						<dl>
							<dt>退款说明</dt>
							<dd><input type="text" name="remarks" class="rmk"></dd>
						</dl>
					</div>
					
					<div class="img_up">
						<div class="img_name"><span>上传凭证</span></div>
						<div class="img_box">
							<div class="upload_box"></div>
							<div class="upload_button" data-gid="<{$i.id}>"> 
								<a class="file" href="javascript:;">选择文件<input type="file" name="imgFile" class="img_file" id="imgFile"/></a>									
							</div>
						</div>
					</div>
					<div class="sbutton"><p><input type="submit" id="submit"  name="apply_submit" class="submit" value="提交申请"/></p></div>
				</form>
			<{else}>
				<div class="submit_msg"><{$row.msg}></div>
			<{/if}>
				
		<{/if}> 
	</div>
</div> 
<{include file="default/footer.html"}> 
<script type="text/javascript" src="<{$__PUBLIC__}>js/ajaxfileupload.js"></script>
<script type="text/javascript"> 
$(function(){  
	// 申请订单
	$("form#form").submit(function(){ 
		$.ajax({
			type:'POST',
			url:'member.php?m=buy&a=refund_apply',
			data: $("#form").serialize(),
			success:function(result){ 
				var data = jQuery.parseJSON(result); 
				if(data.error == 0){
					$.alert('申请成功', function(){
						location.reload();
					}); 
				}else{ 
					$.alert(data.msg);
				}
			},
			error:function(){
				$.alert('系统错误');
			}
		}); 
		return false;
	});  
	// 发货 
	$("form#kd_form").submit(function(){
		$.ajax({
			type:'POST',
			url:'member.php?m=buy&a=refund_kd_submit',
			data:$("form#kd_form").serialize(),
			success:function(result){ 
				var data = jQuery.parseJSON(result); 
				if(data.error == 0){
					$.alert('发货成功', function(){
						location.reload();
					}); 
				}else{ 
					$.alert(data.msg);
				}
			},
			error:function(){
				$.alert('系统错误');
			}
		}); 
		return false;
	});
	
	
	$(document).on('click','.upload_box .img i',function(){
		$(this).parent('.img').remove();
	});
	$(document).on('change','.upload_button',function(){ 
		var $this=$(this); 
		$("#upload_msg").ajaxStart(function(){ 
			$(this).show();
		});
		img_num = $('.upload_box .img').length;
		if(img_num < 3){ 
			$.ajaxFileUpload({ 
				url:'member.php?m=user&a=upload&path=refund',
				secureuri:false, 
				fileElementId:'imgFile',
				dataType: 'text',		//text json
				success: function(result){ 
					var data = jQuery.parseJSON(result); 
					if(data.error == '0'){
						html = 		'<div class="img">'+
									'	<img src="'+data.url+'"><i>删除</i>'+
									'	<input type="hidden" name="refund_img[]" value="'+data.name+'"/>'+
									'</div>';
						if(img_num == 0){
							$('.upload_box').html(html); 
						}else{
							$('.upload_box .img:last').after(html); 
						}
					}else{
						$.alert(data.msg);
					}
				}
			});	
		}else{
			$.alert('最多能上传3张图片');
		} 
	});
});
</script>
