<%@ 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" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no, minimum-sacle=1, maximum-scale=1" >

    <link rel="stylesheet" type="text/css" href="${ctxPlugin}/static/css/reset.css" />
    <link rel="stylesheet" href="${ctxPlugin}/lib/layuiAdmin/dist/layuiadmin/style/formSelects-v4.css" media="all">
    <link rel="stylesheet" type="text/css" href="${ctxPlugin}/lib/font/iconfont.css" />
    <style>
        .xm-select-parent .xm-select {
            min-height: 32px;
        }
    </style>
</head>
<body>

<div class="layui-fluid">
    <div class="layui-form layui-card">
        <div class="layui-tab layui-tab-brief">
            <ul class="layui-tab-title">
                <a href="${ctx}/rele/releOrderPage"><li class="layui-this">投放管理</li></a>
                <button class="layui-btn f-r mt-10 mr-15 pl-10 pr-10 " type="reset"  onclick="reset()" >
                    <i class="layui-icon fs-12">&#xe9aa;</i>
                    重置
                </button>
                <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>
            </ul>
        </div>
        <form class="layui-card-body layuiadmin-card-header-auto" id="searchForm">
            <div class="layui-form-item">
                <div class="layui-col-lg2 layui-col-sm3">
                    <label class="layui-form-label">投放单号：</label>
                    <div class="layui-input-block">
                        <input type="text" name="releCode" id="releCode" class="layui-input" >
                    </div>
                </div>
            </div>
        </form>
    </div>
    <div class="layui-card">
        <div class="layui-card-body">
            <table class="layui-hide" lay-skin="row" id="test" lay-filter="test"></table>
            <script type="text/html" id="toolbarDemo">
                <div class="layui-btn-container">
                    <button class="layui-btn layui-btn-sm" lay-event="export" id="exportBtn"><i class="layui-icon layui-icon-export"></i>导出列表</button>
                </div>
            </script>
        </div>
    </div>
</div>
<script src="${ctxPlugin}/lib/layuiAdmin/dist/layuiadmin/layui/layui.js"></script>
<script src="${ctxPlugin}/lib/layuiAdmin/dist/layuiadmin/lib/formSelects-v4.js"></script>
<script>
    var formSelects;
    var entrycount=0;
    layui.config({
        base: '${ctxPlugin}/lib/layuiAdmin/dist/layuiadmin/' //静态资源所在路径
    }).extend({
        index: 'lib/index' //主入口模块
    }).use(['index', 'tableExt', 'jquery', 'layer','laypage','laydate','form','formSelects'], function(){
        //layui.use(['table','layer','laypage','laydate','form'], function(){
        $ = layui.$;
        tableExt = layui.tableExt;
        layer = layui.layer;
        laypage = layui.laypage;
        laydate = layui.laydate;
        form = layui.form;
        table = tableExt.getLayTable();
        formSelects = layui.formSelects;

        var invoice = '${fns:checkPagePermission(request, "XMGL_TFGL_INVOICE_B")}';

        tableExt.render({
            elem: '#test'
            , title:'投放管理查询'
            , height: 'full-270'
            , toolbar: '#toolbarDemo'
            , defaultToolbar: false
            , limits : [ 20, 50, 100 ]
            , limit:20
            , page : true //开启分页
            , url: '${ctx}/rele/getReleOrderList'
            , where: _serializeJson($("#searchForm"))
            , method:"post"
            , cols: [[
                {type: 'numbers',fixed:'left',title:'序号'}
                ,{field : 'id', minWidth : '4%',checkbox : true,align : 'center',fixed: 'left'}
                , {field: 'id', minWidth: 100, title: '操作', align: 'center', rowspan: '2', fixed: 'left', templet: function (d) {
                        var html = '';
                        if(invoice =='0'){
                            if(d.invoice_status === '2' || d.invoice_status === '4'){
                                return html + '<a href="#" class="layui-table-link" onclick="invoiceUpload(\'' + d.rele_code + '\')">发票上传</a>';
                            }else{
                                return "";
                            }
                        }else{
                            return "";
                        }
                    }}
                , {field: 'rele_code',title: '投放单号',minWidth: '220',sort: false,align: 'center',exportable: true,
                    templet: function (d) {
                        var html = '';
                        return html + '<a href="#" class="layui-table-link" onclick="psDetail(\'' + d.rele_code + '\')">' + d.rele_code + '</a>';
                    }}
                , {field: 'putin_amount_total',title: '投放金额合计',minWidth: '220',sort: false,align: 'center',exportable: true}
                , {field: 'actual_payment_amount',title: '实付金额合计',minWidth: '220',sort: false,align: 'center',exportable: true}
                , {field: 'rele_order_status',title: '投放单状态',minWidth: '220',sort: false,align: 'center',exportable: true
                    , templet:function(d){
                        return releStatusStr(d.rele_order_status);
                    }
                    , expFormat: function(d){
                        return releStatusStr(d.rele_order_status);
                    }
                }
                , {field: 'invoice_status',title: '开票状态',minWidth: '220',sort: false,align: 'center',exportable: true
                    , templet:function(d){
                        return invoiceStatusStr(d.invoice_status);
                    }
                    , expFormat: function(d){
                        return invoiceStatusStr(d.invoice_status);
                    }
                }
                , {field: 'rele_order_date',title: '投放日期',minWidth: '220',sort: false,align: 'center',exportable: true}
                , {field: 'create_time', title: '投放单创建时间', minWidth: 150, sort: false, align: 'center', exportable: true}

            ]]
            ,exportOpt:{                           //导出选项配置
                ele:'#exportBtn',                   //导出的Dom元素
                headerTitle: '投放管理查询',             //excel表格的标题
                pageData:false,                     //true:导出的数据为页面数据，false:最大导出maxAmount条数据
                maxAmount: 5000,                    //当pageData为false生效
                fileName: '投放管理查询',
                where: function (){                 //当pageData为false时生效，过滤的条件
                    return _serializeJson($("#searchForm"));
                }
            },done: function(res, curr, count){
                //得到数据总量
                entrycount = count;
            }
        });

        function  releStatusStr(releStatus) {
            if (releStatus == '0') {
                return "业务员审核中";
            }else if (releStatus == '1') {
                return "业务员已提交";
            }else if (releStatus == '2') {
                return "财务出纳审核中";
            }else if (releStatus == '3') {
                return "已投放";
            }else{
                return "--";
            }
        }

        function  invoiceStatusStr(invoiceStatus) {
            if (invoiceStatus == '1') {
                return "已开票";
            } else if (invoiceStatus == '2') {
                return "未开票";
            } else if (invoiceStatus == '3') {
                return "待确认";
            } else if (invoiceStatus == '4') {
                return "待重新开票";
            }else{
                return "--";
            }
        }


        table.on('toolbar(test)',function(obj) {
            if(obj.event==='invoiceUpload'){
                alert(11)

            }

        });

        //监听搜索
        form.on('submit(LAY-user-back-search)', function(data){
            var field = data.field;
            //执行重载
            tableExt.reload('test', {
                where: field,
                page:{
                    curr:1
                }
            });
        });
        $('input').on('keydown', function (event) {
            if (event.keyCode == 13) {
                //执行相关操作
                $("#searchBtn").click();
            }
        });
    })

    function downloadAttach(attach) {
        attach = decodeURI(attach);
        attach = attach.replace(/\+/g, "%2B"); //
        window.location.href = '${commonStaticImgPath}' + attach;
    }

    function searchOrder() {
        layer.closeAll();
        //执行重载
        var wherobj = _serializeJson($("#searchForm"));
        tableExt.reload('test', {
            where: wherobj
        });
    }

    function deliver() {

    }

    //查看详情
    function psDetail(releCode) {
        layer.open({
            type: 2
            , title: '投放详情'
            , content: '${ctx}/rele/releOrderDetail?releCode=' + releCode
            , area: ['100%', '100%']
            , yes: function(index, layero){

            }
        });
    }

    function invoiceUpload(releCode){
        layer.open({
            type: 2
            , title: '发票信息上传'
            , content: '${ctx}/rele/invoiceUpload?releCode=' + releCode
            , area: ['100%', '100%']
            , yes: function(index, layero){

            }
        });
    }

    function downloadImg(attach) {
        var name = attach.substring(0, attach.lastIndexOf(".") - 1);
        var suffix = attach.substring(attach.lastIndexOf("."));
        window.open('${commonStaticImgPath}'+attach)
        // location.href = '${ctx}/technical/imgDownload?path=' + '${commonStaticImgPath}' + attach + "&fileGS=" + suffix + "&name=" + name;
    }

    function inDoc(id){

    }

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

    function reset(){
        layui.form.render();
        $("#searchForm").find("select").val("");
        $("#searchForm").find("input").val("");
    }
</script>
</body>
</html>

