<%@ 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">
</head>
<body>

<div class="layui-fluid">
    <div class="layui-card layui-form">
        <div class="layui-tab layui-tab-brief">
            <ul class="layui-tab-title">
                <sfTags:pagePermission authFlag="JXSGL_JXSGL_JXSGLD_T" html='<li class="layui-this"><a href="${ctx}/contract/findContractList">合同管理</a></li>'/>
                <button class="layui-btn f-r mt-10 mr-15 pl-10 pr-10 " id="searchBtn" data-type="reload">
                    <i class="layui-icon fs-12">&#xe615;</i>查询
                </button>
            </ul>
        </div>

        <div class="layui-card-body layuiadmin-card-header-auto">
            <form class="layui-form layui-card" action="" id="searchForm">
                <div class="layui-form-item">
                    <div class="layui-col-md2 layui-col-sm3">
                        <label class="layui-form-label">匹配编号：</label>
                        <div class="layui-input-block">
                            <input type="text" name="number" class="layui-input" id="number">
                        </div>
                    </div>
                    <div class="layui-col-md2 layui-col-sm3">
                        <label class="layui-form-label">业主名称：</label>
                        <div class="layui-input-block">
                            <input type="text" name="customerName" class="layui-input" id="customerName">
                        </div>
                    </div>
                    <div class="layui-col-md2 layui-col-sm3">
                        <label class="layui-form-label">身份证号码：</label>
                        <div class="layui-input-block">
                            <input type="text" name="idCode" class="layui-input" id="idCode">
                        </div>
                    </div>
                    <div class="layui-col-md2 layui-col-sm3">
                        <label class="layui-form-label">匹配状态：</label>
                        <div class="layui-input-block">
                           <select id="status" name="status">
                               <option value="">请选择</option>
                               <option value="1">未匹配</option>
                               <option value="2">已匹配</option>
                           </select>
                        </div>
                    </div>

                </div>
            </form>
        </div>

        <div class="layui-card-body">
            <table class="layui-hide " id="test" lay-filter="test"></table>
        </div>

    </div>
</div>
<div id="toolbarDemo" class="layui-form-item layui-hide">
    <sfTags:pagePermission authFlag="HTGL_HTGL_HTGL_ADD_B" html='<button class="layui-btn layui-btn-sm" id="addBtn" lay-event="add"><i class="layui-icon layui-icon-add-1"></i>导入 </button>'/>
    <sfTags:pagePermission authFlag="HTGL_HTGL_HTGL_DELETE_B" html='<button class="layui-btn layui-btn-sm" id="deleteBtn" lay-event="delete"><i class="layui-icon layui-icon-delete"></i>删除 </button>'/>
<%--    <sfTags:pagePermission authFlag="HTGL_HTGL_HTGL_DELETE_B" html='<button class="layui-btn layui-btn-sm" id="testHSGBtn" lay-event="testHSG"><i class="layui-icon layui-icon-delete"></i>测试是 </button>'/>--%>
</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 saveMark = false;
    //初始数据
    var $form;
    var form;
    var upload;
    var $;
    var table;
    layui.config({
        base: '${ctxPlugin}/lib/layuiAdmin/dist/layuiadmin/' //静态资源所在路径
    }).extend({
        index: 'lib/index' //主入口模块
    }).use(['index', 'tableExt', 'jquery', 'layer','laypage','laydate','form','excel'], function(){
        $ = layui.$
            ,form = layui.form
            ,tableExt = layui.tableExt;
        table = layui.table;
        var excel = layui.excel;
        var detail = '${fns:checkPagePermission(request, "FAGL_FAGL_FAGL_DETAIL_B")}';
        var download = '${fns:checkPagePermission(request, "FAGL_FAGL_FAGL_DOWNLOAD_B")}';
        //方案信息列表
        tableExt.render({
            elem: '#test'
            , height: 'full-130'
            , id: 'test'
            , defaultToolbar: false
            , url: '${ctx}/contract/list'
            , layout: ['count', 'prev', 'page', 'next', 'limit', 'refresh', 'skip']
            , page: true
            , toolbar: "#toolbarDemo"
            , method: "post"
            , limits: [20, 50, 100]
            , limit: 20
            , cols: [[
                {field: 'number', minWidth: 50, title: '序号', align: 'center', type: 'numbers', fixed: 'left'}
                , {field: 'id', minWidth: '4%', checkbox: true, align: 'center', fixed: 'left'}
                , {field: 'number', title: '匹配编号', minWidth: 150, align: 'center', exportable: true, fixed: 'left'}
                , {field: 'customer_name', title: '业主姓名', minWidth: 200, align: 'center', exportable: true}
                , {field: 'id_code', minWidth: 200, title: '身份证号码', align: 'center', exportable: true}
                , {field: 'assembly_specs', minWidth: 150, title: '安装组件规格（W）', align: 'center', exportable: true}
                , {field: 'assembly_num', minWidth: 150, title: '安装组件块数（块）', align: 'center', exportable: true}
                , {
                    field: 'status', minWidth: 150, title: '匹配状态', align: 'center', exportable: true,
                    templet: function (d) {
                        if (d.status == '1') {
                            return "未匹配";
                        }
                        return "已匹配";
                    }
                }
                , {field: 'create_time', minWidth: 150, title: '创建时间', align: 'center',exportable:true }
            ],
            ]
            ,exportOpt:{                           //导出选项配置
                ele:'#exportBtn',                   //导出的Dom元素
                headerTitle: '合同信息',             //excel表格的标题
                pageData:false,                     //true:导出的数据为页面数据，false:最大导出maxAmount条数据
                maxAmount: 1000,                    //当pageData为false生效
                fileName: '合同信息',
                where: function (){
                    console.log(_serializeJson($("#searchForm")));//当pageData为false时生效，过滤的条件
                    return _serializeJson($("#searchForm"));
                }
            }
        });

        table.on('toolbar(test)',function(obj) {
            var checkStatus = table.checkStatus(obj.config.id);
            if (obj.event === 'add') {
                layer.open({
                    title: '导入物料',
                    type: 2,
                    area: ['550px', '300px'],
                    content: '${ctx}/contract/toImportMaterial'
                });
            }  else if (obj.event === 'delete') {
                var data = checkStatus.data;
                if (data.length < 1) {
                    layer.msg("请先选择数据",{icon:5,anim:6});
                    return;
                }
                var ids="";
                for(var i=0;i<data.length;i++){
                    ids+=data[i].id+",";
                }
                var indexla = layer.confirm('已匹配的项目信息会清除，您确定要删除合同吗？', {
                    icon: 3,
                    btn: ['确定', '取消'] //按钮
                }, function () {
                    $.ajax({
                        type: "POST",
                        url: "${ctx}/contract/delete",
                        data: {
                            ids: ids
                        },
                        success: function (result) {
                            if(result.code=='200'){
                                layer.msg('删除成功！', {icon: 1, time: 1000}, function () {
                                    window.location.reload();
                                });
                            }else {
                                layer.msg('删除失败!', {icon: 2});
                            }
                        },
                        error:{
                        }
                    })
                }, function () {
                    layer.close(indexla);
                });
            } else if (obj.event === 'testHSG'){
                $.ajax({
                    type: "POST",
                    url: "${ctx}/customerEntry/uploadAttachment?id=2c90807880a8406d01829187ba5b4703",
                    success: function (result) {
                      console.log("浙银返回数据 ："+ result);
                    },
                    error:{
                    }
                })
            }
        });

        //监听事件
        table.on('tool(test)', function (obj) {

        });

        function isBlank(val) {
            if (val == null || val == '' || val == undefined) {
                return true;
            }
            return false;
        }
        $('#searchBtn').on('click', function(){
            var type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });

        var active = {
            reload: function(){
                reload();
            }
        };
    });

    function reload(){
        table.reload('test', {
            where: {
                number: $('#number').val().trim(),
                customerName:$("#customerName").val().trim(),
                idCode:$("#idCode").val().trim(),
                status:$("#status").val().trim(),
            }
        });
    }

    window.importMaterial = function(materials){
        childWin.importMaterial(materials);
    }


    function  denglsj(id,userId) {
        console.log("siteInfo" + id +" userId : "+ userId)
        parent.denglusdj(id,userId);
    }

    /*方案详情*/
    function siteDetail(id) {
        layer.open({
            type: 2,
            title: '查看',
            content: '${ctx}/contract/toAdd?mode=view&id=' + id,
            area: ['80%','80%']
        });
    }

    function downloadAttach(attach){
        var name = attach.substring(0, attach.lastIndexOf(".") - 1);
        var suffix = attach.substring(attach.lastIndexOf("."));
        attach=decodeURI(attach);
        attach = attach.replace(/\+/g,"%2B"); //
        window.open('${commonStaticImgPath}'+attach)
       // location.href = '${ctx}/technical/imgDownload?path=' + '${commonStaticImgPath}' + attach + "&fileGS=" + suffix + "&name=" + name;
    }


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