<{import file="common.html" title="售后详情"}> 
<link rel="stylesheet" type="text/css" href="<{$__APP__}>public/css/member_refund.css?v=<{$js_version}>"> 
<div class="cnav"><a class="back" href="javascript:;">&nbsp;</a> 售后详情 <a class="thome" href="javascript:;">主页</a></div> 
<div class="abox"> 
	<{uqcms m="refund" v="goods" c="refund_goods:service_id=smarty.get.service_id"}>
	<!--产品信息-->
	<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="javascript:;"><{$goods.title}></a></div>
			<div class="spr">￥<{$goods.price}></div> 
		</div>
	</div>
	<!--操作信息-->
	<{uqcms m="refund" v="row" c="get_one:service_id=smarty.get.service_id"}>
	<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="<{$smarty.get.service_id}>"/>
					<div class="fhuo">
						<dl>
							<dt>快递名称</dt>
							<dd>
								<{uqcms m="express" v="exp" c="api_config"}> 
								<select name="kd_code">
									<option value="0">--选择快递--</option>
									<{foreach item=i from=$exp}>		
										<option value="<{$i.id}>"><{$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>
			<{/if}>
			<div class="submit_msg" style="border-top:1px solid #efefef;">
				<a href="<{$__WAP__}>order/refund_process?service_id=<{$smarty.get.service_id}>">查看记录</a> 
			</div>
		<{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> 
								<select name="reason">
									<option value="0">请选择退款原因</option> 
									<{uqcms m="common" v="cancel_reason" c="category:name=user_cancel_order"}> 
									<{if $cancel_reason}>
										<{foreach item=i key=k from=$cancel_reason}>
											<option value="<{$k}>"><{$i}></option>
										<{/foreach}>
									<{/if}> 
								</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="<{$row.id}>"> 
								<a class="file" href="javascript:;">选择文件<input type="file" name="imgFile" class="img_file" id="imgFile"/></a>									
							</div>
						</div>
					</div>
					<div class="sbutton"><input type="submit" id="submit"  name="apply_submit" class="submit" value="提交申请"/></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:URI+'buy/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:URI+'buy/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:URI+'user/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>
