extends /apps/include/layout.pug
include /mixins/client.mixin.pug

block content
    .layui-side.layui-bg-black
        .layui-side-scroll
            include /apps/service/include/left.pug
    .layui-body
        .layui-side-scroll
            .row
                .col-lg-12
                    h1.site-h1(style='border-top:1px solid #e6e6e6;')
                        | 服务小结列表 #{summaryList.totalElements ?"（" + summaryList.totalElements + "）" : "（0）"}
                        span(style='float:right;')
                            .ukefu-bt-text-content(style='position: absolute;right: 5px;top: 0px;')
                                form.layui-form#search(name='search', action='/apps/agent/summary/index.html', method='get', style='float: left;margin-right:5px;')
                                    .layui-form-item
                                        .layui-inline(style='margin-right:5px;')
                                            .layui-input-inline(style='width: auto;margin-right:0px;')
                                                label.layui-form-label(style='width: auto;') 服务时间：
                                                .layui-input-inline(style='width: auto;margin-right:0px;')
                                                    input#begin.layui-input.ukefu-input(name='begin', placeholder='开始时间', value= begin)
                                                label.layui-form-label(style='width: auto;') ~
                                                .layui-input-inline(style='width: auto;margin-right:0px;')
                                                    input#end.layui-input.ukefu-input(name='end', placeholder='结束时间', value= end)
                                        .layui-inline(style='margin-right:0px;')
                                            .layui-input-inline(style='width: auto;margin-right:0px;')
                                                .layui-input-inline(style='width: auto;margin-right:0px;')
                                                    button.layui-btn.layui-btn-small.layui-btn-original(style='color:#ffffff;')
                                                        i.layui-icon 
                                .layui-btn-group.ukefu-btn-group(style='margin-top:2px;')
                                    button.layui-btn.layui-btn-small.dropdown-menu
                                        i.kfont 
                                        |  导出

                                        i.layui-icon 
                                    ul.ukefu-dropdown-menu.layui-anim.layui-anim-upbit
                                        li
                                            a#batexp(href='javascript:void(0)', title='导出联系人', target='_blank')
                                                i.kfont 
                                                | 导出选中结果
                                        li
                                            a(href='/apps/agent/summary/expsearch.html?1=1&begin=' + begin + '&end=' + end + '&subtype=' + subtype, title='导出联系人', target='_blank')
                                                i.kfont 
                                                | 导出当前搜索结果
                                        li
                                            a(href='/apps/agent/summary/expall.html', title='导出联系人', target='_blank')
                                                i.kfont 
                                                | 导出全部数据
                    table.layui-table(lay-skin='line', style='table-layout: fixed;')
                        thead
                            tr.design-sortable-tr
                                th(width='10px')
                                    input#all(type='checkbox', onclick='$(\'.ids\').prop(\'checked\' , $(this).prop(\'checked\'));')
                                th 访客
                                th 服务坐席
                                th 渠道
                                th(style='min-width: 80px') 服务时间
                                th 服务类型
                                th 是否预约
                                th 预约方式
                                th(style='min-width: 80px') 预约时间
                                th 操作
                        tbody(style='table-layout: fixed; word-break: break-all;')
                            if summaryList && summaryList.content
                                for summary in summaryList.content
                                    tr.tdHasContorllor.design-dropable-td
                                        td(style="width:1%;")
                                            input(type="checkbox" class="ids" name="ids" value= summary.id)
                                        td.ukefu-online-client(title= summary.username, style="text-overflow: ellipsis;white-space: nowrap;overflow: hidden;")
                                            a(href="/service/online/index.html?userid=" + summary.userid + "&agentservice=" + summary.agentserviceid + "&id=" + summary.id) #{summary.username}
                                        td(title= summary.agentusername, style="text-overflow: ellipsis;white-space: nowrap;overflow: hidden;") #{summary.agentusername}
                                        td #{summary.channel}
                                        td #{pugHelper.formatDate('yyyy-MM-dd HH:mm:ss', summary.createtime)}
                                        td
                                            if summary.servicetype
                                                for st,index in summary.servicetype.split(",")
                                                    if tags
                                                        for tag in tags
                                                            if st == tag.id
                                                                if index > 0
                                                                    | ，
                                                                | #{tag.tag}
                                        td
                                            if summary.reservation
                                                i.layui-icon(style="color:#19a55d;") &#xe618;
                                        td.minSize #{summary.reservtype ? uKeFuDic[summary.reservtype].name : ""}
                                        td.minSize #{pugHelper.formatDate('yyyy-MM-dd HH:mm:ss', summary.reservtime)}
                                        td.minSize
                                            a(href="/apps/agent/summary/process.pug?id=" + summary.id, data-toggle="ajax", data-width="950", data-height="450", title="服务小结处理")
                                                i.layui-icon &#xe642; 处理
            .row(style='padding:5px;')
                .col-lg-12#page(style='text-align:center;')

    script.
        $(document).ready(function(){
                $('#batexp').click(function(){
                    var ids = "";
                    var num = 0 ;
                    $('.ids').each(function(){
                        if($(this).prop("checked")){
                            if(ids!=""){
                                ids += "&" ;
                            }
                            ids += "ids=" + $(this).val();
                            num++;
                        }
                    });
                    if(num>0){
                        $('#batexp').attr('href' , '/apps/agent/summary/expids.html?'+ids)	;
                    }else{
                        top.layer.alert("请先选择需要导出的服务小结");
                        $('#batexp').attr("href" , "javascript:void(0)");
                    }
                });
            });
            var searchData = $("#search :input").serializeArray()
            var searchCondition = "";
            $.each(searchData, function() {
                searchCondition += '&'+this.name+'='+this.value
            });

            layui.use(['laypage', 'layer'], function(){
                  var laypage = layui.laypage
                  ,layer = layui.layer;
                  var laydate = layui.laydate;
                laypage({
                    cont: 'page'
                        , pages: #{summaryList ? summaryList.totalPages : 0} //总页数
                        , curr: #{summaryList ? summaryList.number + 1 : 0}
                        ,groups: 5 //连续显示分页数
                        ,jump:function(data , first){
                            if(!first){
                                location.href = "/apps/agent/summary/index.html?p="+data.curr+searchCondition;
                            }
                        }
                });
            });

            layui.use('laydate', function() {
                var laydate = layui.laydate;
            });
            function getNowFormatDate() {
                var date = new Date();
                var seperator = "-";
                var year = date.getFullYear();
                var month = date.getMonth() + 1;
                var strDate = date.getDate();
                if (month >= 1 && month <= 9) {
                    month = "0" + month;
                }
                if (strDate >= 0 && strDate <= 9) {
                    strDate = "0" + strDate;
                }
                var currentdate = year + seperator + month + seperator + strDate;
                return currentdate;
            }
            var start = {
                format: 'YYYY-MM-DD',
                max:getNowFormatDate(),//默认最大值为当前日期
                istoday: true,
                choose: function (datas) {
                    end.min = datas; //开始日选好后，重置结束日的最小日期
                }
            };
            var end = {
                format: 'YYYY-MM-DD',
                max:getNowFormatDate(),//默认最大值为当前日期
                istoday: true,
                choose: function (datas) {
                    start.max = datas; //结束日选好后，重置开始日的最大日期
                }
            };
            document.getElementById('begin').onclick = function () {
                start.elem = this;
                laydate(start);
            };
            document.getElementById('end').onclick = function () {
                end.elem = this;
                laydate(end);
            };
            
