<%@ page contentType="text/html;charset=UTF-8"%>
<%@ include file="/WEB-INF/views/include/taglib.jsp"%>
<!DOCTYPE HTML>
<html>
<head>
    <meta name="decorator" content="base" />
    <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">
    <title>平台财务管理结算明细</title>
    <link rel="stylesheet" href="${ctxPlugin}/static/css/reset.css" media="all">
    <style>
    </style>
</head>
<body>
<div class="layui-fluid">
    <form class="layui-form layui-card" action="" id="searchForm" lay-filter="searchForm">

        <div class="layui-tab layui-tab-brief">
            <ul class="layui-tab-title">
                    <sfTags:pagePermission authFlag="SIT_CWGL_JSMX_JSMX_T" html='<a href="${ctx}/financialManage/financialManageList"><li class="layui-this">结算明细</li></a>'/>
                <div class="f-r layadmin-form-right mb-10">
                    <button class="layui-btn f-r mt-10 mr-15 pl-10 pr-10" lay-submit lay-filter="btnSubmit" id="btnSubmit">
                        <i class="layui-icon fs-12">&#xe615;</i>查询
                    </button>
                </div>

            </ul>
        </div>

        <div class="layui-card-body">
            <div class="layui-form-item">
                <div class="layui-col-lg2 layui-col-sm3">
                    <label class="layui-form-label">服务工程师：</label>
                    <div class="layui-input-block">
                        <select name="employeId" lay-search>
                            <option value="">请选择</option>
                            <c:forEach var="emp" items="${empList}">
                                <option value="${emp.columns.id}">${emp.columns.name}</option>
                            </c:forEach>
                        </select>
                    </div>
                </div>
                <div class="layui-col-lg2 layui-col-sm3">
                    <label class="layui-form-label">保修类型：</label>
                    <div class="layui-input-block">
                        <select name="warrantyType">
                            <option value="">请选择</option>
                            <option value="1">保内</option>
                            <option value="2">保外</option>
                        </select>
                    </div>
                </div>

                <div class="layui-col-lg2 layui-col-sm3">
                    <label class="layui-form-label">服务类型：</label>
                    <div class="layui-input-block">
                        <select name="serviceType">
                            <option value="">请选择</option>
                            <option value="安装">安装</option>
                            <option value="维修">维修</option>
                            <option value="咨询" >咨询</option>
                        </select>
                    </div>
                </div>

                <div class="layui-col-lg2 layui-col-sm3">
                    <label class="layui-form-label">电站名称：</label>
                    <div class="layui-input-block">
                        <input type="text" name="powerStationName" autocomplete="off" class="layui-input">
                    </div>
                </div>
                <div class="layui-col-lg2 layui-col-sm3">
                    <label class="layui-form-label">工单编号：</label>
                    <div class="layui-input-block">
                        <input type="text" name="number" autocomplete="off" class="layui-input">
                    </div>
                </div>

                <div class="layui-col-lg2 layui-col-sm3">
                    <label class="layui-form-label">结账编号：</label>
                    <div class="layui-input-block">
                        <input type="text" name="withdrawalNumber" autocomplete="off" class="layui-input">
                    </div>
                </div>

                <div class="layui-col-lg2 layui-col-sm3">
                    <label class="layui-form-label">结账状态：</label>
                    <div class="layui-input-block">
                        <select name="jzFlag">
                            <option value="">请选择</option>
                            <option value="3">未结账</option>
                            <option value="2">处理中</option>
                            <option value="1">已结账</option>
                            <option value="4">已登记</option>
                        </select>
                    </div>
                </div>
                <div class="layui-col-lg2 layui-col-sm3">
                    <label class="layui-form-label">用户姓名：</label>
                    <div class="layui-input-block">
                        <input type="text" name="customerName" autocomplete="off" class="layui-input">
                    </div>
                </div>

                <div class="layui-col-lg2 layui-col-sm3">
                    <label class="layui-form-label">用户电话：</label>
                    <div class="layui-input-block">
                        <input type="text" name="mobile" autocomplete="off" class="layui-input">
                    </div>
                </div>
                <div class="layui-col-lg2 layui-col-sm3">
                    <label class="layui-form-label">结账类型：</label>
                    <div class="layui-input-block">
                        <select name="checkoutType">
                            <option value="">请选择</option>
                            <option value="1">开票</option>
                            <option value="2">转货款</option>
                        </select>
                    </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" id="pubStart" name="pubStart" autocomplete="off" class="layui-input" placeholder="开始日期" readonly>
                        </div>
                        <div class="layui-col-xs2 text-c lh-30">
                            —
                        </div>
                        <div class="layui-col-xs5">
                            <input type="text" id="pubEnd" name="pubEnd" autocomplete="off" class="layui-input" placeholder="结束日期" readonly>
                        </div>
                    </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" id="endStart" name="endStart"  autocomplete="off" class="layui-input" placeholder="开始日期" readonly>
                        </div>
                        <div class="layui-col-xs2 text-c lh-30">
                            —
                        </div>
                        <div class="layui-col-xs5">
                            <input type="text" id="end" name="end" autocomplete="off" class="layui-input"  placeholder="结束日期" readonly>
                        </div>
                    </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" id="settlementStart" name="settlementStart"  autocomplete="off" class="layui-input" placeholder="开始日期" readonly>
                        </div>
                        <div class="layui-col-xs2 text-c lh-30">
                            —
                        </div>
                        <div class="layui-col-xs5">
                            <input type="text" id="settlementEnd" name="settlementEnd" autocomplete="off" class="layui-input"  placeholder="结束日期" readonly>
                        </div>
                    </div>
                </div>

            </div>
        </div>
    </form>
</div>
<div class="layui-card">
    <div class="layui-card-body">
        <table class="layui-hide"  id="test" lay-filter="test"></table>
    </div>
</div>
    <div id="toolbarDemo" class="layui-form-item layui-hide">
        <sfTags:pagePermission authFlag="BJD_ZP_B" html=' <button class="layui-btn layui-btn-sm" lay-event="cashOut"><i class="layui-icon layui-icon-export"></i>开票</button>'/>
        <button class="layui-btn layui-btn-sm" lay-event="transCashOut"><i class="layui-icon layui-icon-export"></i>转货款</button>
        <sfTags:pagePermission authFlag="BJD_DC_B" html=' <button class="layui-btn layui-btn-sm" lay-event="export" id="exportBtn"><i class="layui-icon layui-icon-export"></i>导出</button>'/>
    </div>
<script src="${ctxPlugin}/lib/layuiAdmin/dist/layuiadmin/layui/layui.js"></script>
<script type="text/javascript">
    function resetForm() {
        $("#searchForm")[0].reset();
        $("#btnSubmit").click();
    }

    var adjustLayer = -1;
    layui.config({
        base: '${ctxPlugin}/lib/layuiAdmin/dist/layuiadmin/' //静态资源所在路径
    }).extend({
        index: 'lib/index' //主入口模块
    }).use(['index','tableExt', 'form','layer','laydate'], function() {
        var $ = layui.$, form = layui.form;

        var tableExt = layui.tableExt;
        var table = tableExt.getLayTable();
        var date = layui.laydate;

        date.render({
            elem: '#pubStart' //指定元素
        });
        date.render({
            elem: '#pubEnd' //指定元素
        });
        date.render({
            elem: '#endStart' //指定元素
        });
        date.render({
            elem: '#end' //指定元素
        });
        date.render({
            elem: '#settlementStart' //指定元素
        });
        date.render({
            elem: '#settlementEnd' //指定元素
        });


        //初始化table表格，事件处理在初始化之后
        tableExt.render({
            elem : '#test',
            height : 'full-220',
            url : '${ctx}/financialManage/listData', //数据接口
            page : true, //开启分页
            toolbar : "#toolbarDemo",
            defaultToolbar : [],
            limits : [ 20, 50, 100 ],
            limit : 20,
            cols : [[
                {type: 'numbers',fixed:'left',title:'序号'}
                ,{field: 'id',fixed:'left', type: 'checkbox'}
                ,{field: 'jz_flag',fixed:'left', title: '结账状态', width: 150,align: 'center', exportable: true, templet:function(d){

                        if(d.jz_flag=='0'){
                            return "未结账";
                        }else if(d.outStatus=='1'  ){
                          return "处理中";
                        }else if(d.outStatus =='4'){
                                return "已登记";
                        }else{
                            return "已结账";
                        }
                    },expFormat:function (d) {

                        if(d.jz_flag=='0'){
                            return "未结账";
                        }else if(d.outStatus=='1'  ){
                            return "处理中";
                        }else if(d.outStatus =='4'){
                            return "已登记";
                        }else{
                            return "已结账";
                        }
                    }}
                ,{field: 'number',fixed:'left', title: '工单编号', width: 200,align: 'center', exportable: true}
                ,{field: 'checkout_type', title: '结账类型', width: 150,align: 'center', exportable: true,
                   templet:function(d){
                    if(d.checkout_type=='1'){
                       return "开票";
                    }else if(d.checkout_type=='2'){
                        return "转货款";
                    }else{
                        return "";
                    }
                   },expFormat:function (d) {
                        if(d.checkout_type=='1'){
                            return "开票";
                        }else if(d.checkout_type=='2'){
                            return "转货款";
                        }else{
                            return "";
                        }
                    }
                }
                ,{field: 'employe_name', title: '服务工程师',align: 'center', width: 150, exportable: true}
                ,{field: 'power_station_name', title: '电站名称', align: 'center',width: 150, exportable: true}
                ,{field: 'service_type', title: '服务类型', width: 150, align: 'center',exportable: true}
                ,{field: 'service_measures', title: '服务措施', width: 150,align: 'center', exportable: true}
                ,{field: '_warranty_type', title: '保修类型', width: 150, align: 'center',exportable: true}
                ,{field: 'withdrawal_number', title: '结账编号', width: 200, align: 'center',exportable: true}
                ,{field: 'appliance_model', title: '设备型号', width: 150, align: 'center',exportable: true}
                ,{field: 'appliance_category', title: '设备类型', width: 150, align: 'center',exportable: true}
                ,{field: 'appliance_machine_code', title: '设备序列号', width: 150,align: 'center', exportable: true}
                ,{field: 'orderRemarks', title: '工单描述', width: 150,align: 'center', exportable: true}
                ,{field: 'level', title: '重要程度', width: 150,align: 'center', exportable: true,
                    templet:function(d){
                        if(d.level =='1'){
                            return "紧急";
                        } else if (d.level == '2') {
                            return "一般";
                        }
                        return "";
                }
                    , expFormat: function (d) {
                        if(d.level =='1'){
                            return "紧急";
                        } else if (d.level == '2') {
                            return "一般";
                        }
                        return "";
                    }}
                ,{field: 'order_type', title: '信息来源',align: 'center', width: 150, exportable: true,
                    templet:function(d){
                    console.log()
                        if(d.order_type =='1'){
                            return "用户在线报修";
                        }else  if(d.order_type =='2'){
                            return "平台录入";
                        }else if (d.order_type == 4) {
                            return "电子商务";
                        } else{
                            return "其他";
                        }
                    }
                    , expFormat: function (d) {
                        if(d.order_type =='1'){
                            return "用户在线报修";
                        }else  if(d.order_type =='2'){
                            return "平台录入";
                        }else if (d.order_type == 4) {
                            return "电子商务";
                        } else{
                            return "其他";
                        }
                    }}
                , {
                    field: 'total_costs', title: '结算总额', width: 150, align: 'center',exportable: true, templet: function (d) {
                        return "&nbsp;&nbsp;<a href=\"#\" class=\"layui-table-link\" onclick=\"costDetail('" + d.id + "','" + d.total_costs + "')\">" + d.total_costs + "</a>";
                    }
                }
                ,{field: 'remarks', title: '结算备注', width: 150,align: 'center', exportable: true}
                ,{field: 'customer_name', title: '用户姓名', width: 150,align: 'center', exportable: true}
                ,{field: 'customer_mobile', title: '用户电话', width: 150, align: 'center',exportable: true}
                ,{field: 'customer_address', title: '用户地址', width: 150,align: 'center', exportable: true,
                    templet:function(d){
                        return d.province+d.city+d.area+d.customer_address;
                    }
                    , expFormat: function (d) {
                        return d.province+d.city+d.area+d.customer_address;
                    }
                }
                ,{field: 'repair_time', title: '报单时间', width: 180,align: 'center', exportable: true}
                ,{field: 'end_time', title: '完工时间', width: 180,align: 'center', exportable: true}
                ,{field: 'settlement_time', title: '结算时间', width: 180,align: 'center', exportable: true}
            ]]

            ,exportOpt: {
                ele: '#exportBtn',                   //导出的Dom元素
                headerTitle: '结算明细列表',             //excel表格的标题
                pageData: false,                     //true:导出的数据为页面数据，false:最大导出maxAmount条数据
                maxAmount: 10000,                    //当pageData为false生效
                fileName: '结算明细列表',
                where: function () {                 //当pageData为false时生效，过滤的条件
                    return _serializeJson(layui.$("#searchForm"), layui.$);
                }
            }
        });

        /*条件查询*/
        layui.form.on('submit(btnSubmit)', function(data) {
            var params = data.field; //获取提交的字段
            table.reload('test', {
                where : params,
                page : {
                    curr : 1
                }

            }); //数据刷新

            return false;
        });

        //头工具栏事件
        table.on('toolbar(test)', function(obj){
            var checkStatus = table.checkStatus(obj.config.id);
            var data = checkStatus.data;
            switch(obj.event){
                case 'cashOut':  //开票
                    if (data.length < 1) {
                        layer.msg("请选择一条数据",{icon:5,anim:6});
                        return;
                    }
                    var checkjz_flag = false;
                    var number ;
                    var ids="";
                    var len=data.length;
                    for(var i=0;i<data.length;i++){
                        var jz_flag = data[i].jz_flag;
                        if(jz_flag != 0){
                            number = data[i].number;
                            checkjz_flag = true;
                            layer.msg("工单编号为"+ number +" 不能进行开票处理",{icon:5,anim:6});
                            return false;
                        }
                        ids+=data[i].order_id+",";
                    }
                    if(checkjz_flag){
                        layer.msg("工单编号为"+ number +" 不能进行开票处理",{icon:5,anim:6});
                        return false;
                    }

                    settleAccounts(ids,1,len);
                break;
                case 'transCashOut':
                    if (data.length < 1) {
                        layer.msg("请选择一条数据",{icon:5,anim:6});
                        return;
                    }
                    var checkjz_flag = false;
                    var number ;
                    var ids="";
                    var len=data.length;
                    for(var i=0;i<data.length;i++){
                        var jz_flag = data[i].jz_flag;
                        if(jz_flag != 0){
                            number = data[i].number;
                            checkjz_flag = true;
                            layer.msg("工单编号为"+ number +" 不能进行转货款处理",{icon:5,anim:6});
                            return false;
                        }
                        ids+=data[i].order_id+",";
                    }
                    if(checkjz_flag){
                        layer.msg("工单编号为"+ number +" 不能进行转货款处理",{icon:5,anim:6});
                        return false;
                    }
                    settleAccounts(ids,2,len);
                    break;
            }
        });

    });
    function settleAccounts(ids,type,len) {
        var str="";
        if(type==1){
          str="开票";
        }else if(type="2"){
          str="转货款";
        }
        layer.open({
            type : 2,
            title :str,
            content : '${ctx}/siteReceipt/toUplodeImage?ids=' + ids+'&&type='+type +'&&len='+len,
            area : [ '450px', '287px' ],
            end:function(){
                //刷新表格

            }
        })
    }
    function costDetail(id,total_costs) {
        layer.open({
            type: 2,
            title:" 结算总额",
            area: ['600px', '300px'],
            resize:false,
            content: "${ctx}/settlement/site/stat/costDetail?id="+id+"&total_costs="+total_costs
        });
    }

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