<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/WEB-INF/views/include/taglib.jsp" %>
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>代理商准入申请</title>
    <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" type="text/css" href="${ctxPlugin}/static/css/reset.css"/>
    <link rel="stylesheet" type="text/css" href="${ctxPlugin}/lib/font/iconfont.css" />
</head>
<body>

<div class="layui-fluid">
    <div class="layui-form layui-card">
        <div class="layui-tab layui-tab-brief">

        </div>
        <div class="layui-card-body layuiadmin-card-header-auto" id="searchForm">
            <div class="layui-form-item" style="position: relative">
                <div class="layui-col-md3 layui-col-sm3">
                    <label class="layui-form-label"><c:if test="${type eq '1'}">产品名称：</c:if>
                        <c:if test="${type eq '2'}">代理商名称：</c:if> </label>
                    <div class="layui-input-block">
                        <input type="text" name="name" class="layui-input" id="traderName" >
                    </div>
                </div>
                <button class="layui-btn f-r mt-10 mr-15 pl-10 pr-10" id="searchBtn" lay-submit
                        lay-filter="LAY-user-back-search"><i class="layui-icon fs-12">&#xe615;</i>查询
                </button>
            </div>
        </div>
    </div>
    <div class="layui-card">
        <div class="layui-card-body">
            <table class="layui-hide" lay-skin="row" id="test" lay-filter="test"></table>
        </div>
    </div>
</div>
<div class="operate-footer">
    <input type="button" class="layui-btn approve" value="确定">
    <input type="button"  value="取消" class="layui-btn layui-btn-primary " onclick="closeSelf();" >
</div>
<script src="${ctxPlugin}/lib/layuiAdmin/dist/layuiadmin/layui/layui.js"></script>
<script type="text/javascript">
    var saveMark = false;
    //初始数据
    var $form;
    var form;
    var upload;
    var $;
    var table;
    var laydate;
    layui.config({
        base: '${ctxPlugin}/lib/layuiAdmin/dist/layuiadmin/' //静态资源所在路径
    }).extend({
        index: 'lib/index' //主入口模块
    }).use(['index', 'tableExt', 'jquery', 'layer','laypage','laydate','form'], function(){
        $ = layui.$
            ,form = layui.form
            ,tableExt = layui.tableExt;
        table = tableExt.getLayTable();
        tableExt.render({
            elem: '#test'
            , height: 'full-150'
            , id: 'test'
            , defaultToolbar: false
            , url: '${ctx}/apply/standardPrice/projectOrTraderData?setType=${type}&ids=${ids}'
            , layout: ['count', 'prev', 'page', 'next', 'limit', 'refresh', 'skip']
            , page: true
            , method:"post"
            , limit: 20
            , cols: [[
                {type: 'numbers', title: '序号'}
                , {field: 'id', hide: true}
                <c:if test="${type eq '1'}">
                , {field: 'code', title: '产品编号', align: 'center', minWidth: 150}
                , {field: 'name', title: '产品名称', align: 'center', minWidth: 90}
                , {field: 'productLineName', title: '产品线', align: 'center', minWidth: 100}
                , {field: 'filing_type', title: '备案类型', align: 'center', minWidth: 100, templet: function (d) {
                        var add = '';
                        if (d.filing_type == '1') {
                            add = '农户备案';
                        } else {
                            add = '项目公司备案';
                        }
                        return add;
                    }
                }
                </c:if>
                <c:if test="${type eq '2'}">
                , {field: 'name', title: '代理商名称', align: 'center', minWidth: 90}
                </c:if>
                , {field: 'id', type: 'checkbox', title: '操作'}
            ]], done: function (res, cuss, count) {
                console.log(res)
            }
        });

        var checkBu = false;
        $(".approve").click(function(){
            if(checkBu){
                return
            }
            var checkstatus = table.checkStatus('test');
            var materials=[];

            if("${type}" == '2'){
                $.each(checkstatus.data, function (idx, item) {
                    var obData={
                        id:item.id
                        ,name:item.name
                    }
                    materials.push(obData);
                })
                if(isBlank(materials)){
                    layer.msg("请选择数据！");
                    return;
                }
                parent.getMerchTrader(materials);
            }else{
                $.each(checkstatus.data, function (idx, item) {
                    var obData={
                        id:item.id
                        ,code:item.code
                        ,name:item.name
                        ,filingType:item.filing_type
                        ,productLineName:item.productLineName
                    }
                    materials.push(obData);
                })
                if(isBlank(materials)){
                    layer.msg("请选择数据！");
                    return;
                }
                parent.getMerchProject(materials);

            }
            closeSelf();
        })

        //监听搜索
        form.on('submit(LAY-user-back-search)', function(data){
            var field = data.field;
            //执行重载
            table.reload('test', {
                where: field,
                page:{
                    curr:1
                }
            });
        });

        $('input').on('keydown', function(event){
            if(event.keyCode == 13){
                //执行相关操作
                $("#searchBtn").click();
            }
        });


        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 closeSelf(){
        var index = parent.layer.getFrameIndex(window.name);
        parent.layer.close(index);
    }
    function reload(){
        table.reload('test', {
            where: {
                name: $('#name').val().trim(),
                telephone:$("#mobile").val().trim()
            }
        });
    }


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