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

<div class="layui-fluid">
    <div class="layui-form layui-card">
        <div class="layui-tab layui-tab-brief " >
            <ul class="layui-tab-title">
                <li class="layui-this">结算明细</li>
                <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>
        <div class=" layui-card-body layuiadmin-card-header-auto" id="searchForm">
            <div class="layui-form-item">
                <input class="layui-hide" name="site_billing_id"  id="site_billing_id" value="${site_billing_id}">
                <div class="layui-col-lg2 layui-col-sm3">
                    <label class="layui-form-label">工单编号：</label>
                    <div class="layui-input-block">
                        <input type="text" name="number" 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="warrantyType"  id="warrantyType" >
                            <option value="">请选择</option>
                            <option value="1">保内</option>
                            <option value="2">保外</option>
                        </select>
                    </div>
                </div>
                <div class="layui-col-lg2 layui-col-sm5">
                    <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>
                            <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">
                        <select name="applianceBrand" lay-search>
                            <option value="">请选择</option>
                            <c:forEach var="brand" items="${brandList}">
                                <option value="${brand.columns.brand}">${brand.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="applianceCategory" lay-search>
                            <option value="">请选择</option>
                            <c:forEach var="cate" items="${cateList}">
                                <option value="${cate.columns.category}">${cate.columns.category}</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">
                        <input type="text" name="applianceModel" 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="type"  id="type" >
                            <option value="">请选择</option>
                            <option value="1">新增结算</option>
                            <option value="0">工单结算</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="jzFlag"  >
                            <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">
                        <input type="text" name="customerName" 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" class="layui-input">
                    </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="pubStart" class="layui-input" id="startTime"
                                   placeholder="开始日期">
                        </div>
                        <div class="layui-col-xs2 text-c lh-30">
                            —
                        </div>
                        <div class="layui-col-xs5">
                            <input type="text" name="pubEnd" class="layui-input" id="endTime" placeholder="结束日期">
                        </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" name="endStart" class="layui-input" id="shipStart"
                                   placeholder="开始日期">
                        </div>
                        <div class="layui-col-xs2 text-c lh-30">
                            —
                        </div>
                        <div class="layui-col-xs5">
                            <input type="text" name="end" class="layui-input" id="shipEnd" placeholder="结束日期">
                        </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" name="settlementStart" class="layui-input" id="jsStart"
                                   placeholder="开始日期">
                        </div>
                        <div class="layui-col-xs2 text-c lh-30">
                            —
                        </div>
                        <div class="layui-col-xs5">
                            <input type="text" name="settlementEnd" class="layui-input" id="jsEnd" placeholder="结束日期">
                        </div>
                    </div>
                </div>
            </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>
            <script type="text/html" id="toolbarDemo">
                <div class="layui-btn-container">
                    <button class="layui-btn layui-btn-sm" id="exportBtn" lay-event="exports"><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>

    layui.config({
        base: '${ctxPlugin}/lib/layuiAdmin/dist/layuiadmin/' //静态资源所在路径
    }).extend({
        index: 'lib/index' //主入口模块
    }).use(['index', 'tableExt', 'jquery', 'layer','laypage','laydate','form'], 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;
        var table = tableExt.getLayTable();


        var site_billing_id=$("#site_billing_id").val();

        tableExt.render({
            elem: '#test'
            , height: 'full-300'
            , toolbar: '#toolbarDemo'
            , defaultToolbar: false
            , limits: [20, 50, 100]
            , limit: 20
            , page: true //开启分页
            , url: '${ctx}/site/financialManagement/billingDetailList'
                ,where:{
                    site_billing_id:site_billing_id
                }
            ,totalRow: true
            ,totalRowText: '合计'
            , cols: [[
                {type: 'numbers',fixed:'left',title:'序号'}
                , {field: 'id', type: 'checkbox',fixed: 'left'}
                /*, {field: 'logistics_names',hide:true}*/
                , {
                    field: 'type', title: '结算类型',minWidth:'100', sort: false, align: 'center',fixed: 'left', exportable:true, templet: function (d) {
                      if(d.type=='0'){
                        return "工单结算";
                      }else{
                          return "新增结算"
                      }
                    },expFormat:function (d){
                        if(d.type=='0'){
                            return "工单结算";
                        }else{
                            return "新增结算"
                        }
                    }
                }
                , {field: 'jz_flag', title: '是否结账', minWidth: '150', sort: false, align: 'center', exportable:true,
                    templet: function (d){
                    if(d.jz_flag=='0'){
                         return "未结账";
                    }else{
                        return "已结账";
                    }
                    },expFormat:function (d){
                        if(d.jz_flag=='0'){
                            return "未结账";
                        }else{
                            return "已结账";
                        }
                    }

                }
                , {field: 'number', title: '工单编号',minWidth:'180', sort: false, align: 'center', exportable:true}
               /* , {
                    field: 'order_number',
                    title: '工单编号',
                    minWidth: '180',
                    sort: false,
                    align: 'center',
                    templet: function (d) {
                      /!*  return '<a href="javascript:orderDetail(\'' + d.id + '\');">' + d.order_number + '</a>'*!/
                    }
                }*/
                , {field: 'employe_name', title: '服务工程师',minWidth:'150', sort: false, align: 'center',exportable:true}
                , {field: 'service_costs', title: '服务费用',minWidth: '120', sort: false, align: 'center', exportable:true}
                , {field: 'reward_costs', title: '奖励费用',minWidth:'120', sort: false, align: 'center', exportable:true}
                , {field: 'other_cost', title: '其他费用',minWidth: '120', sort: false, align: 'center', exportable:true,}
                , {field: 'mileage_cost', title: '里程费',minWidth: '120', sort: false, align: 'center', exportable:true}
                , {field: 'exigency_costs', title: '加急费', minWidth: '120', sort: false, align: 'center', exportable:true,}
                , {field: 'total_costs', title: '结算总额',minWidth:'150', sort: false, align: 'center', exportable:true}
                , {field: 'warranty_type', title: '保修类型',minWidth:'100', sort: false, align: 'center', exportable:true,
                    templet: function (d){
                        if(d.warranty_type=='1'){
                            return "保内";
                        }else{
                            return "保外";
                        }
                    },expFormat:function (d){
                        if(d.warranty_type=='1'){
                            return "保内";
                        }else{
                            return "保外";
                        }
                    }

                }
                , {field: 'repair_time', title: '报修时间', minWidth: '200', sort: false, align: 'center', exportable:true}
                , {field: 'end_time', title: '完工时间', minWidth: '180', sort: false, align: 'center'}
            ]]
            ,done:function(res){
                $.ajax({
                    type:"post",
                    url:"${ctx}/site/financialManagement/summaryData",
                    data:{
                        site_billing_id:site_billing_id
                    },
                    success:function(data){
                        var obj = $(".layui-table-total").find("table").find("tbody").find("td");
                        obj.eq(2).find("div").html("<span>合计：</span>");
                        obj.eq(6).find("div").html("<span style='color:#ff5151'>"+data.columns.service_costs+"</span>");
                        obj.eq(7).find("div").html("<span style='color:#ff5151'>"+data.columns.reward_costs+"</span>");
                        obj.eq(8).find("div").html("<span style='color:#ff5151'>"+data.columns.other_cost+"</span>");
                        obj.eq(9).find("div").html("<span style='color:#ff5151'>"+data.columns.mileage_cost+"</span>");
                        obj.eq(10).find("div").html("<span style='color:#ff5151'>"+data.columns.exigency_costs+"</span>");
                        obj.eq(11).find("div").html("<span style='color:#ff5151'>"+data.columns.total_costs+"</span>");
                        site_billing_id="";
                        $("#site_billing_id").val("");
                    }
                });
            }
            ,exportOpt:{                           //导出选项配置
                ele:'#exportBtn',                   //导出的Dom元素
                headerTitle: '备件申请-备件在途',             //excel表格的标题
                pageData:false,                     //true:导出的数据为页面数据，false:最大导出maxAmount条数据
                maxAmount: 1000,                    //当pageData为false生效
                fileName: '备件申请-备件在途',
                where: function (){                 //当pageData为false时生效，过滤的条件
                    return _serializeJson($("#searchForm"));
                }
            }
        });

        //监听搜索
        form.on('submit(LAY-user-back-search)', function (data) {
            var field = data.field;
            //执行重载
            tableExt.reload('test', {
                where: field,
                page: {
                    curr: 1
                }
                ,done:function(res){
                    $.ajax({
                        type:"post",
                        url:"${ctx}/site/financialManagement/summaryData",
                        data:field,
                        success:function(data){
                            var obj = $(".layui-table-total").find("table").find("tbody").find("td");
                            obj.eq(2).find("div").html("<span>合计：</span>");
                            obj.eq(6).find("div").html("<span style='color:#ff5151'>"+data.columns.service_costs+"</span>");
                            obj.eq(7).find("div").html("<span style='color:#ff5151'>"+data.columns.reward_costs+"</span>");
                            obj.eq(8).find("div").html("<span style='color:#ff5151'>"+data.columns.other_cost+"</span>");
                            obj.eq(9).find("div").html("<span style='color:#ff5151'>"+data.columns.mileage_cost+"</span>");
                            obj.eq(10).find("div").html("<span style='color:#ff5151'>"+data.columns.exigency_costs+"</span>");
                            obj.eq(11).find("div").html("<span style='color:#ff5151'>"+data.columns.total_costs+"</span>");
                        }
                    });
                }
            });
        });

        //发布开始日期
        var insStart = laydate.render({
            elem: '#startTime'
            , done: function (value, date) {
                //更新结束日期的最小日期
                insEnd.config.min = lay.extend({}, date, {
                    month: date.month - 1
                });

                //自动弹出结束日期的选择器
                insEnd.config.elem[0].focus();
            }
        });

        //发布结束日期
        var insEnd = laydate.render({
            elem: '#endTime'
            , done: function (value, date) {
                //更新开始日期的最大日期
                insStart.config.max = lay.extend({}, date, {
                    month: date.month - 1
                });
            }
        });

        //完工开始日期
        var insShipS = laydate.render({
            elem: '#shipStart'
            , done: function (value, date) {
                //更新结束日期的最小日期
                insShipE.config.min = lay.extend({}, date, {
                    month: date.month - 1
                });

                //自动弹出结束日期的选择器
                insShipE.config.elem[0].focus();
            }
        });

        //完工结束日期
        var insShipE = laydate.render({
            elem: '#shipEnd'
            , done: function (value, date) {
                //更新结束日期的最小日期
                insShipS.config.min = lay.extend({}, date, {
                    month: date.month - 1
                });
            }
        });

        //结束开始日期
        var endStart = laydate.render({
            elem: '#jsStart'
            , done: function (value, date) {
                //更新结束日期的最小日期
                insShipE.config.min = lay.extend({}, date, {
                    month: date.month - 1
                });

                //自动弹出结束日期的选择器
                endEnd.config.elem[0].focus();
            }
        });

        //结束结束日期
        var endEnd = laydate.render({
            elem: '#jsEnd'
            , done: function (value, date) {
                //更新结束日期的最小日期
                endStart.config.min = lay.extend({}, date, {
                    month: date.month - 1
                });
            }
        });

    });


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

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


