<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/WEB-INF/views/include/taglib.jsp" %>
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
          content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <meta name="decorator" content="base"/>
    <link rel="stylesheet" href="${ctxPlugin}/lib/layuiAdmin/dist/layuiadmin/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="${ctxPlugin}/lib/layuiAdmin/dist/layuiadmin/style/admin.css" media="all">
    <link rel="stylesheet" href="${ctxPlugin}/static/css/reset.css" media="all">
    <style>
        .layui-form-select dl{
            max-height:180px;
            width: 80%;
        }
    </style>
</head>
<body>
<div class="">
    <div class="layui-card">
        <form class="layui-form layui-card-body over pt-20 pb-40 h-160" style="height: 190px" action="" id="detailSet">
           <div class="layui-col-xs12 mb-20 pr-30">
                <label class="layui-form-label " style="width: 200px">CRM客户名称：</label>
                <div class="layui-input-block ml-130">
                    <div class="layui-col-xs8 pr-20">
                        <select class="" id="customerId" name="customerId" lay-filter="customerId" lay-search>
                            <option value="">请选择CRM客户</option>
                            <c:forEach items="${map}" var="cus">
                                <option value="${cus.columns.id}" title="${cus.columns.name}" >${cus.columns.name}</option>
                            </c:forEach>
                        </select>
                    </div>

                </div>
            </div>
            <input type="hidden" id="siteId" name="siteId" value="${siteId}"/>
            <div class="layui-col-xs12 mb-20 pr-30 mt-20">
                <div class="layui-form-item " style="text-align: center;">
                    <input type="button" lay-submit lay-filter="confirm" id="confirm" class="layui-btn " value="确认">
                   <%-- <input type="button"   value="取消" class="layui-btn layui-btn-primary " onclick="closeDiv();" >--%>
                </div>
            </div>
        </form>
    </div>

</div>
<script src="${ctxPlugin}/lib/layuiAdmin/dist/layuiadmin/layui/layui.js"></script>
<script src="${ctxPlugin}/lib/layuiAdmin/dist/layuiadmin/layui/data.js"></script>
<script type="text/javascript">
    //初始数据
    var $form;
    var form;
    var upload;
    var $;
    var customerName="" ;
    layui.use(['form', 'table', 'upload', 'jquery'], function () {
        $ = layui.jquery;
        form = layui.form;
        upload = layui.upload;
        $form = $('form');

        form.on('select(customerId)', function(data){
            customerName= data.elem[data.elem.selectedIndex].text;

            console.log(data.value); //得到被选中的值

        });


        form.on('submit(confirm)', function(data){

            //获取选择的值
            if(isBlank(customerName)){
                layer.msg("保请选择客户信息",{time:1000});
                return
            }


            $.ajax({
                url:'${ctx}/siteInformation/siteBinDingCustomer',
                method:'post',
                data:{
                    siteId:data.field.siteId,
                    cusromerId:data.field.customerId,
                    customerName:customerName
                },
                success:function(res){
                    if(res.code=="200"){
                        layer.msg("保存成功",{time:1000,icon:1});
                        closeDiv();
                        parent.table.reload('test');
                    }else if(res.code=="201") {
                        layer.msg("该登录账号已存在，请重新输入",{time:1500,icon:2});
                    }else if(res.code=="202") {
                        layer.msg(res.errMsg,{time:1500,icon:2});
                    }  else{
                        layer.msg("保存失败",{time:1000,icon:2});
                    }
                },
                error:function (data) {
                }
            }) ;
        });


    });


    function  closeDiv() {
        var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
        parent.layer.close(index);
    }

        function isBlank(val) {
            if (val == null || val == '' || val == undefined) {
                return true;
            }
            return false;
        }

</script>
</body>
</html>
