<%@ 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="FWSGL_EDGL_CZJL_T" html='<li class=""><a href="${ctx}/fittingAmount/recharge">额度充值记录</a></li>'/>
                <sfTags:pagePermission authFlag="FWSGL_EDGL_KKJL_T" html='<li class="layui-this"><a href="${ctx}/fittingAmount/cost">额度扣款记录</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">
                            <select class="" id="siteId" name="siteId" lay-verify="siteId" lay-filter="siteId"  lay-search >
                                <option value="">请选择服务商</option>
                                <c:forEach items="${siteList}" var="site">
                                    <option value="${site.columns.id}" title="${site.columns.name}" >${site.columns.name}</option>
                                </c:forEach>
                            </select>
                        </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="fittingCode" class="layui-input" id="fittingCode" >
                        </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="fittingName" class="layui-input" id="fittingName" >
                        </div>
                    </div>
                    <div class="layui-col-lg4 layui-col-sm6">
                        <label class="layui-form-label">扣款时间：</label>
                        <div class="layui-input-block">
                            <div class="layui-col-xs5">
                                <input type="text" name="createTimeMin" class="layui-input" id="createTimeMin" placeholder="开始日期">
                            </div>
                            <div class="layui-col-xs1 text-c lh-30">
                                —
                            </div>
                            <div class="layui-col-xs5">
                                <input type="text" name="createTimeMax" class="layui-input" id="createTimeMax" placeholder="结束日期">
                            </div>
                        </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="FWSGL_EDGL_KKJL_DC" html='<button class="layui-btn layui-btn-sm" id="exportBtn" lay-event="exports"><i class="layui-icon layui-icon-export"></i>导出 </button>'/>
</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;
        laydate = layui.laydate;
        var excel = layui.excel;

        //开始日期
        var insStart = laydate.render({
            elem: '#createTimeMin'
            ,type: 'datetime'
            ,done: function(value, date){
                //更新结束日期的最小日期
                insEnd.config.min = lay.extend({}, date, {
                    month: date.month - 1
                });
                //自动弹出结束日期的选择器
                insEnd.config.elem[0].focus();
            }
        });
        //结束日期
        var insEnd = laydate.render({
            elem: '#createTimeMax'
            ,type: 'datetime'
            ,done: function(value, date){
                //更新开始日期的最大日期
                insStart.config.max = lay.extend({}, date, {
                    month: date.month - 1
                });
            }
        });
        //服务商信息列表
        tableExt.render({
            elem: '#test'
            , height: 'full-130'
            , id: 'test'
            , defaultToolbar: false
            , url: '${ctx}/fittingAmount/getcostList'
            , layout: ['count', 'prev', 'page', 'next', 'limit', 'refresh', 'skip']
            , page: true
            , method:"post"
            ,toolbar:"#toolbarDemo"
            , limits: [20, 50, 100]
            , limit: 20
            , cols: [[
                {field: 'number', width: 50, title: '序号', align: 'center', type: 'numbers',rowspan:'2', fixed: 'left'}
                , {field: 'siteName', title: '服务商名称', width: 300, align: 'center',exportable:true ,rowspan:'2', fixed: 'left'}
                , {field: 'fittingCode', title: '物料号', width: 250, align: 'center',exportable:true ,rowspan:'2'}
                , {field: 'fittingName', title: '备件名称', width: 200, align: 'center',exportable:true ,rowspan:'2'}
                , {field: 'nums', width: 200, title: '出库数量', align: 'center',exportable:true ,rowspan:'2'}
                , {field: 'site_price', width: 200, title: '服务商价格', align: 'center',exportable:true ,rowspan:'2'}
                , {field: 'amount', width: 200, title: '扣款金额', align: 'center',exportable:true ,rowspan:'2'}
                , {field: 'create_time', width: 250, title: '扣款时间', align: 'center',exportable:true ,rowspan:'2'}
            ],
            ]
            ,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"));
                }
            }
        });

        $('#searchBtn').on('click', function(){
            var type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });

        var active = {
            reload: function(){
                table.reload('test', {
                    where: {
                        fittingCode: $('#fittingCode').val().trim(),
                        fittingName:$("#fittingName").val().trim(),
                        siteId:$("#siteId").val().trim(),
                        createTimeMin:$("#createTimeMin").val().trim(),
                        createTimeMax:$("#createTimeMax").val().trim()
                    }
                });
            }
        };
    });
</script>
</body>
</html>
