<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>填写成交订单号</title>
<%@include file="/views/common.jsp"%>
<link rel="stylesheet" href="${path}/static/css/formSelects-v4.css">
<style>
.layui-input,.layui-input-inline{
	width:350px
}
</style>
</head>
<body>
	<div class="layui-input-block layui-form" style="margin-top: 30px">
		<form class="layui-form " action="">
			<div class="layui-form-item">
				<input type="hidden" id="TYPE" class="layui-input">
				<input type="hidden" id="ID" class="layui-input">
				<input type="hidden" id="USERNAME" class="layui-input">
				<label class="layui-form-label">订单号</label>
				<div class="layui-input-inline">
					<input type="text" name="orderNumber" placeholder="请输入成交的订单号" class="layui-input" id="orderNumber"
					autocomplete="off">
				</div>
			</div>
			<div class="layui-form-item">
				<div class="layui-input-block">
					<button class="layui-btn" lay-submit="" lay-filter="enadd">确认添加</button>
					<button type="reset" class="layui-btn layui-btn-primary">重置</button>
				</div>
			</div>
		</form>
	</div>
<script>
	layui.use([ 'form', 'layer'],function() {
		var $ = layui.$,
		 form = layui.form, 
		layer = layui.layer;
		
		//监听提交
		form.on('submit(enadd)', function(data) {
			$.ajax({
				url : '${path}/addOrderNumber',
				dataType : 'json',
				data : {
					id 			: $("#ID").val(),
					orderNumber	:$("#orderNumber").val()
				},
				type : 'post',
				success : function(data) {
					//填写订单号后
					if (data.code == 200) {
						// 改变状态
						//当天成交
						if($("#TYPE").val() == 0){
							$.ajax({
								url : "${path}/changeIsBuyToDayStatus",
								dataType : 'json',
								data : {
									'id'		:	$("#ID").val(),
									'username'	:	$("#USERNAME").val()
								}, 
								type : 'post',
								success : function(data) {
									if (data.code == 200) {
										layer.msg('状态修改成功！',{icon:6,offset:"auto",time:1000});//提示框
								  	}else{
								  		layer.msg(data.msg,{icon:5,offset:"auto",time:2000});//提示框
								  	}
								}		
							})	
						}else if($("#TYPE").val() == 1){ // 跟单成交
							$.ajax({
								url : "${path}/changeIsBuyStatus",
								dataType : 'json',
								data : {
									'id':$("#ID").val()
								}, 
								type : 'post',
								success : function(data) {
									if (data.code == 200) {
										layer.msg('状态修改成功！',{icon:6,offset:"auto",time:1000});//提示框
								  	}else{
								  		layer.msg('只允许店长修改！',{icon:5,offset:"auto",time:2000});//提示框
								  	}
								}		
							})
						}
						//关闭弹出层
						setTimeout(function(){
							var index = parent.layer.getFrameIndex(window.name);//获取窗口索引
							parent.layer.close(index); //关闭弹出层
						}, 2100);
					} else {
						layer.msg(data.msg, {
							icon : 5,
							offset : "auto",
							time : 2000
						});//提示框
					}
				}
			})
			return false;
		});
	});
</script>
</body>
</html>