<%@ 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"%>
<style>
.layui-input,.layui-input-inline{
	width:600px
}
.layui-form-select .layui-edge{
	right:-150px;
}
.layui-input-block{
	margin-top:50px;
}
</style>
</head>
<body>
	<div class="layui-input-block layui-form"
		style="margin-top: 30px">
		<form class="layui-form " action="">
			<input type="hidden" name="id" id="id">
			<div class="layui-form-item">
				<label class="layui-form-label">客户旺旺</label>
				<div class="layui-input-inline">
					<input type="text" name="wangwang" id="wangwang" placeholder="请输入客户的旺旺名" class="layui-input"
					autocomplete="off" lay-verify="required">
				</div>
			</div>
			<div class="layui-form-item">
				<input type="hidden" class="layui-input" id="ROLE">
				<label class="layui-form-label">所属店铺</label>
				<div class="layui-input-inline edge">
					<select name="role" id="role"></select>
				</div>	
			</div>
			<div class="layui-form-item">
				<label class="layui-form-label">产品说明</label>
				<div class="layui-input-inline">
					<input type="text" name="productExplain" id="productExplain" placeholder="请输入产品说明" class="layui-input"
					autocomplete="off" lay-verify="required">
				</div>
			</div>

			<div class="layui-form-item">
				<div class="layui-inline">
					<label class="layui-form-label">金额</label>
					<div class="layui-input-inline">
						<input type="text" name="price" id="price" placeholder="请输入报价金额" class="layui-input"
						autocomplete="off" lay-verify="number">
					</div>
				</div>
			</div>	
			<div class="layui-form-item">
				<label class="layui-form-label">未成交原因</label>
				<div class="layui-input-inline">
					<input type="text" name="commentSelf" id="commentSelf" placeholder="请输入未成交原因" class="layui-input"
						autocomplete="off">
				</div>
			</div>
			<!-- <div class="layui-form-item">
				<div class="layui-form-item">
					<label class="layui-form-label">是否成交</label>
					<div class="layui-input-inline">
						<input type="radio" name="isBuy" value="1" title="是">
						<input type="radio" name="isBuy" value="0" title="否">
					</div>
				</div>
			</div> -->
			<div class="layui-form-item">
				<div class="layui-input-block">
					<button class="layui-btn" lay-submit="" lay-filter="enadd">确认修改</button>
				</div>
			</div>
		</form>
	</div>
	<script type="text/javascript">
		layui.use([ 'table', 'laydate', 'form','layer'], function() {
			var $ = layui.jquery;
			var table = layui.table;
			var laydate = layui.laydate;
			var form = layui.form;
			var layer = layui.layer;
			
			//获取用户的角色
			$.ajax({
				url : '${path}/getUserRoles',
				dataType : 'json',
				data : {}, 
				type : 'get',
				success : function(data) {
					var datas = data.data.userRoleList
					$.each(datas, function(index, item) {
						$('#role').append(
								new Option(item.roleName, item.roleId));// 下拉菜单里添加元素
						});
					//把input的值给下拉框，再渲染。做到动态下拉框回显
					$("#role").val($("#ROLE").val());
					form.render("select");
				}
			});
			
			form.on('submit(enadd)',function(data){
				$.ajax({
					url:'${path}/updateCustomerData',
					dataType : 'json',
					data:$(data.form).serialize(),
					type : 'post',
					success:function(data){
						if (data.code == 200) {
							layer.msg('修改成功！',{icon:6,offset:"auto",time:2000});//提示框
						}else  {
							layer.msg('修改失败！',{icon:5,offset:"auto",time:2000});//提示框
						}
						setTimeout(function(){
							var index = parent.layer.getFrameIndex(window.name);//获取窗口索引
							parent.layer.close(index);//关闭弹出层
							parent.layui.table.reload("dataTableAll"); //重新加载页面表格
						}, 1100);
					}
				})
				return false;
			});
		})
	</script>
</body>
</html>