<!DOCTYPE html>
<html>

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0" />
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <title>消息</title>
    <link rel="stylesheet" type="text/css" href="../../css/api.css" />
    <link rel="stylesheet" type="text/css" href="../../css/style.css" />
    <link rel="stylesheet" href="../../css/toast.css">
    <link rel="stylesheet" href="../../css/projeck.css">
    <style>
        body,
        html {
            background: #fff;
        }

        .api_news_item .news_img {
            background: none;
            background-color: #009fe8;
            -webkit-border-radius: 50%;
            -moz-border-radius: 50%;
            border-radius: 50%;
            font-size: 12px;
            line-height: 15px;
            text-align: center;
            padding: 8px 10px;
            box-sizing: border-box;
            color: #fff;
        }

        .api_layout {
            padding-bottom: 30px;
        }
        /*tab*/

        .tab-box {
            padding: 16px;
        }

        .tab-item {
            height: 105px;
            display: flex;
            justify-content: space-around;
            align-items: center;
        }

        .tab-item li {
            text-align: center;
            color: #BDC3C7;
            font-size: 16px;
            cursor: pointer;
            transition: .5s;
            position: relative;
        }

        .tab-item li span {
            font-size: 14px;
            color: #BDC3C7;
            transition: .5s;
        }

        .tab-item img {
            width: 35px;
            height: 35px;
            transition: .5s;
        }

        .tab-item .tab-avtive {
            font-size: 18px;
            color: #2C3E50;
            transition: .5s;
        }

        .tab-item .tab-avtive img {
            width: 45px;
            height: 45px;
            transition: .5s;
        }

        .tab-item .tab-avtive span {
            font-size: 15px;
            transition: .5s;
        }
        /*闭环管理*/

        .close-loop {
            display: none;
        }

        .close-loop-box {
            padding: 8px 10px;
            /*background: */
        }

        .close-loop-box li {
            display: flex;
            justify-content: flex-start;
            align-items: center;
            height: 84px;
            box-shadow: 0 2px 4px 0 #a6a6a6;
            border-radius: 5px;
            margin-bottom: 10px;
            flex-wrap: nowrap;
            position: relative;
        }

        .time-name {
            background: #50A1FF;
            height: 100%;
            flex: 0 0 84px;
            border-radius: 5px;
            padding: 5px 10px;
            box-sizing: border-box;
            width: 84px;
        }

        .time-name span {
            color: #fff;
            font-weight: bold;
        }

        .time-name .lt {
            display: block;
            font-size: 20px;
        }

        .time-name .rt {
            font-size: 16px;
            text-align: right;
            display: block;
        }

        .time-name p {
            width: 100%;
            color: #fff;
            font-size: 17px;
            overflow: hidden;
            text-overflow: clip;
            white-space: nowrap;
            text-align: center;
        }

        .info {
            padding: 5px 10px;
            font-size: 14px;
            color: #2C3E50;
            width: 100%;
            overflow: hidden;
        }

        .info p {
            width: 100%;
            padding-bottom: 5px;
            overflow: hidden;
            text-overflow: ellipsis;
            white-space: nowrap;
            display: flex;
            align-items: center;
        }

        .info span {
            display: inline-block;
            overflow: hidden;
            text-overflow: ellipsis;
            white-space: nowrap;
            width: 40%;
        }

        .loop-ico {
            width: 19px;
            height: 25px;
            background: url(../../icon/loop_ico.png) center no-repeat;
            background-size: contain;
            position: absolute;
            top: 0;
            right: 13px;
        }
        /*自定义加载*/

        .loadings {
            width: 100%;
            height: 100%;
            position: fixed;
            top: 30%;
            left: 0;
            z-index: 9999;
            background: rgba(255, 255, 255, 0.1);
        }

        .loadings img {
            z-index: 9999;
            width: 40px;
            height: 40px;
            position: absolute;
            top: -50%;
            left: 0;
            bottom: 0;
            right: 0;
            margin: auto;
        }
        /*徽章*/

        .badge,
        .loop-Badge {
            position: absolute;
            top: -10px;
            right: 15px;
            width: 20px;
            height: 20px;
            line-height: 20px;
            border-radius: 50%;
            text-align: center;
            background: #E74C3C;
            color: #fff;
            font-size: 11px;
            font-style: normal;
        }
    </style>
</head>

<body>
    <div class="api_layout">
        <div class="tab-box">
            <ul class="tab-item">
                <li class="only-li tab-avtive" id="closedLoopManagement">
                    <img src="../../icon/bihuan.png" alt="">
                    <p>闭环管理</p>
                    <span>PDCA循环管控</span>
                    <i class="loop-Badge hide"></i>
                </li>
                <li>
                    <img src="../../icon/recodeJ.png" alt="">
                    <p>记录合集</p>
                    <span>全部消息一览</span>
                    <i class="badge hide"></i>
                </li>
                <li>
                    <img src="../../icon/myrecode.png" alt="">
                    <p>我的记录</p>
                    <span>记录日志一览</span>
                </li>
            </ul>
        </div>
        <!-- 闭环管理 -->
        <div class="close-loop close-loop-admin">
            <p class="api_title_text" style="height:15px"></p>
            <ul class="close-loop-box" id="close_loop"></ul>
        </div>
        <!-- 我的记录 -->
        <div class="close-loop my-close-loop">
            <p class="api_title_text" style="height:15px"></p>
            <ul class="close-loop-box" id="my_close_loop"></ul>
        </div>
        <!-- 记录合集 -->
        <div id="depList"></div>
    </div>
    <div class="noText hide">
        <img src="../../image/noText.png" alt="">
    </div>
    <!-- 自定义加载效果 -->
    <div class="loadings hide">
        <img src="../../icon/loading.gif" alt="">
    </div>
</body>

</html>
<!-- 记录合集列表 -->
<script type="text/template" id="templatePublic">
    <div class="api_news_items api_news_public">
        <p class="api_title_text">公共：</p>
        <ul class="api_news_item">
            {{~it:value:index}} {{?value.departmentId == 'root'}}
            <li onclick="openQRcodeInfo('{{=value.departmentId}}','{{=value.departmentName}}')">
                <span class="news_img">{{=value.departmentName.substring(0,4)}}</span>
                <div class="api_titles">
                    <span class="api_news_title">{{=value.departmentName}}</span>
                    <p>
                        <i class="api_ico"></i> {{=value.desc}}
                    </p>
                </div>
                <span class="api_date">{{=value.time}}</span> {{?value.messageCount != 0}}
                <span class="api_news_num">{{=value.messageCount}}</span> {{?}}
                <span class="api_ceil"></span>
            </li>
            {{?}} {{~}}
        </ul>
    </div>
    <div class="api_news_items api_news_office">
        <p class="api_title_text">机关部室：</p>
        <ul class="api_news_item">
            {{~it:value:index}} {{?value.departmentId != 'root'}}
            <li onclick="openQRcodeInfo('{{=value.departmentId}}','{{=value.departmentName}}')">
                <span class="news_img">{{=value.departmentName.substring(0,4)}}</span>
                <div class="api_titles">
                    <span class="api_news_title">{{=value.departmentName}}</span>
                    <p>
                        <i class="api_ico"></i> {{=value.desc}}
                    </p>
                </div>
                <span class="api_date">{{=value.time}}</span> {{?value.messageCount != 0}}
                <span class="api_news_num">{{=value.messageCount}}</span> {{?}}
                <span class="api_ceil"></span>
            </li>
            {{?}} {{~}}
        </ul>
    </div>

</script>
<!-- 闭环管理 -->
<script type="text/template" id="templateCloseLoop">
    {{~it:value:index}}
    <li onclick="openRecordDe('{{=value.recordParentId}}')" style="{{=value.colorStatus?'border:1px solid #E74C3C':''}}">
        <div class="time-name" style="background:{{=value.colorStatus?'#E74C3C':'#50A1FF'}}">
            <span class="lt">{{=value.createDate.substring(5,7)}}月</span>
            <span class="rt">{{=value.createDate.substring(8,10)}}</span>
            <p class="name">{{=value.createName}}</p>
        </div>
        <div class="info">
            <p class="templateName">名称：{{=value.templateName}}</p>
            {{?value.recordStatusInstanceList !== ''}} {{ for(var i= 0;i
            <value.recordStatusInstanceList.length;i++) { }} {{?i<2}} <p> {{=value.recordStatusInstanceList[i].statusName}}：
                <span style="color:#E74C3C">{{=value.recordStatusInstanceList[i].recordStatusInstanceValue}}</span>
                </p>
                {{?}} {{ } }} {{?}}
        </div>
        <i class="loop-ico"></i>
    </li>
    {{~}}
</script>
<!-- 我的记录 -->
<script type="text/template" id="templateMyCloseLoop">
    {{~it:value:index}}
    <li onclick="openRecordDe('{{=value.recordParentId}}')">
        <div class="time-name">
            <span class="lt">{{=value.createDate.substring(8,10)}}</span>
            <span class="rt">{{=value.createDate.substring(5,7)}}月</span>
            <p class="name">{{=value.createName}}</p>
        </div>
        <div class="info">
            <p class="templateName">名称：{{=value.templateName}}</p>
            {{?value.recordStatusInstanceList !== ''}} {{ for(var i= 0;i
            <value.recordStatusInstanceList.length;i++) { }} {{?i<2}} <p>{{=value.recordStatusInstanceList[i].statusName}}：<span style="color:#E74C3C">{{=value.recordStatusInstanceList[i].recordStatusInstanceValue}}</span></p>
                {{?}} {{ } }} {{?}}
        </div>
        <i class="loop-ico"></i>
    </li>
    {{~}}
</script>
<script type="text/javascript" src="../../script/api.js"></script>
<script type="text/javascript" src="../../script/doT.min.js"></script>
<script type="text/javascript" src="../../script/zepto.js"></script>
<script src="../../script/config.js" charset="utf-8"></script>
<script type="text/javascript">
    var skip = 1,
        jobNum = "",
        isLoadding = false,
        isLoaddingMy = false,
        closeLoopNumber = 0;
        departmentId = ''
    var skipCloseLoop = 1
    apiready = function() {
            var info = $api.getStorage('data');
            jobNum = JSON.parse(info).data.user.staff_num;
            departmentId = JSON.parse(info).data.user.section_id
            getCloseLoop()
            newsBadge(jobNum)
            // 闭环管理的UI列表渲染
            $('.close-loop-admin').show()
            api.addEventListener({
                name: 'myEvent'
            }, function(ret, err) {
                $('#closedLoopManagement').addClass('tab-avtive').siblings().removeClass('tab-avtive')
                isLoadding = true
                isLoaddingMy = true
                $('.close-loop-admin').show()
                $('.my-close-loop').hide()
                $('#depList').hide()
                getCloseLoop()
                newsBadge(jobNum)
            });
            api.addEventListener({
                name: 'scrolltobottom',
                extra: {
                    threshold: 0 //设置距离底部多少距离时触发，默认值为0，数字类型
                }
            }, function(ret, err) {
                if (!isLoadding) {
                    getCloseLoop(true);
                }
                if (!isLoaddingMy) {
                    getMyCloseLoop()
                }
            })
        }
        // 记录合集列表
    function getNewsDatas() {
        $api.removeCls($api.dom('.loadings'), 'hide');
        $http.requestData(UrlRouter.findMessageApi + jobNum, 'get', '')
            .then(ret => {
                api.refreshHeaderLoadDone();
                $api.addCls($api.dom('.noText'), 'hide');
                if (ret.code === '200') {
                    // getChangMessageList(); //已读二维码和记录
                    $apis.html(depList, '#templatePublic', ret.data);
                    $api.addCls($api.dom('.noText'), 'hide');
                } else {
                    $api.removeCls($api.dom('.noText'), 'hide');
                }
                $api.addCls($api.dom('.loadings'), 'hide');
            })
            .catch(err => {
                $api.addCls($api.dom('.loadings'), 'hide');
                // $api.addCls($api.dom('.noText'), 'hide');
            })
    }

    // 不同部门消息数量变化
    function differentMsgCount(departmentId) {
      $http.requestData(UrlRouter.getChangMessageDepartmentIdList+`?userId=${jobNum}&departmentId=${departmentId}`, 'get', '')
          .then(ret => {
            // console.log(JSON.stringify(ret));
          })
          .catch(err => {

          })
    }

    // 详情
    function openQRcodeInfo(id, title) {
        differentMsgCount(id);
        newsBadge(jobNum)
        api.openWin({
            slidBackEnabled: 'false',
            reload: true,
            name: 'QrcodeRecodeList',
            url: '../Qrcode/QrcodeRecodeList.html',
            pageParam: {
                depID: id,
                title: title
            },
            animation: {
                type: 'fade',
                duration: 450
            }
        });
    }
    // 已读消息 二维码
    function getChangMessageList() {
        $http.requestData(UrlRouter.getChangMessageList + jobNum, 'get', '')
            .then(ret => {})
            .catch(err => {})
    }
    // 点击tab切换
    $('.tab-item').on('click', 'li', function() {
            $(this).addClass('tab-avtive').siblings().removeClass('tab-avtive')
            if ($(this).index() === 0) {
                isLoaddingMy = true
                isLoadding = false
                $api.addCls($api.dom('.noText'), 'hide');
                $('.close-loop-admin').show()
                $('#depList').hide()
                $('.my-close-loop').hide()
                skipCloseLoop = 1
                    // 闭环管理
                getCloseLoop()
            } else if ($(this).index() === 1) {
                isLoadding = true
                isLoaddingMy = true
                $api.addCls($api.dom('.noText'), 'hide');
                $('.close-loop-admin').hide()
                $('.my-close-loop').hide()
                $('#depList').show()
                    // 记录合集
                // $("#close_loop li").remove()
                // getCloseLoop()
                // 解决append 方法由于数据过慢 或者渲染慢 造成的重复渲染
                getNewsDatas()
            } else {
                isLoadding = true
                isLoaddingMy = false
                $api.addCls($api.dom('.noText'), 'hide');
                $('.close-loop-admin').hide()
                $('#depList').hide()
                $('.my-close-loop').show()
                skip = 1
                    // 我的记录
                // $("#close_loop li").remove()
                // getCloseLoop()
                getMyCloseLoop()
            }
        })
        // 闭环记录列表
    function getCloseLoop() {
        $api.removeCls($api.dom('.loadings'), 'hide');
        var param = {
            pageNumber: skipCloseLoop,
            pageSize: 20
        }
        $http.requestData(UrlRouter.getPageRecordInstaneClosedLoop, 'get', param)
            .then(ret => {
                $api.addCls($api.dom('.loadings'), 'hide');
                if (ret.data.length == 0 && skipCloseLoop == 1) {
                    $api.removeCls($api.dom('.noText'), 'hide');
                    return false;
                } else {
                    $api.addCls($api.dom('.noText'), 'hide');
                }
                if (ret.data.length > 0) {
                    skipCloseLoop += 1;
                    $apis.html(close_loop, '#templateCloseLoop', ret.data);
                    $api.addCls($api.dom('.noText'), 'hide');
                    // 闭环列表的消息总数
                    closeLoopNumber = ret.count
                    closeLoopBadge()
                } else {
                    isLoadding = true;
                    $api.addCls($api.dom('.noText'), 'hide');
                    api.toast({
                        msg: '没有更多数据',
                        duration: 2000,
                        location: 'bottom'
                    });
                }
            })
            .catch(err => {
                $api.addCls($api.dom('.loadings'), 'hide');
                $api.removeCls($api.dom('.noText'), 'hide');
            })
    }
    // 我的记录列表
    function getMyCloseLoop() {
        $api.removeCls($api.dom('.loadings'), 'hide');
        var param = {
            pageNumber: skip,
            pageSize: 20,
            createBy: jobNum
        }
        $http.requestData(UrlRouter.getPageRecordInstanCreateBy, 'get', param)
            .then(ret => {
                $api.addCls($api.dom('.loadings'), 'hide');
                if (ret.data.length == 0 && skip == 1) {
                    $api.removeCls($api.dom('.noText'), 'hide');
                    return false;
                } else {
                    $api.addCls($api.dom('.noText'), 'hide');
                }
                if (ret.data.length > 0) {
                    skip += 1;
                    $apis.append(my_close_loop, '#templateMyCloseLoop', ret.data);
                } else {
                    isLoaddingMy = true;
                    api.toast({
                        msg: '没有更多数据',
                        duration: 2000,
                        location: 'bottom'
                    });
                }
            })
            .catch(err => {
                $api.addCls($api.dom('.loadings'), 'hide');
                $api.removeCls($api.dom('.noText'), 'hide');
            })
    }
    // 记录详情
    function openRecordDe(id) {
        $event.openTabLayout('recodeDetails' + Math.random(), '../browseQrcode/recodeDetails', '记录详情', {
            recordParentId: id
        });
    }
    // 消息徽章
    function newsBadge(id) {
        var NVTabBar = api.require('NVTabBar');
        $http.fnReuestDataNologing(UrlRouter.findMessageCount + id, '', 'get', '', function(ret, err) {
            if (ret.data && ret.data > 99) {
                $('.badge').show()
                $('.badge').html(ret.data > 99 ? '99' : ret.data)
            }
            if (ret.data && ret.data < 99 && ret.data != 0) {
                $('.badge').show()
                $('.badge').html(ret.data)
            }
            if (ret.data === 0) {
                $('.badge').hide()
            }
        })
    }
    // 闭环管理消息徽章
    function closeLoopBadge() {
        if (closeLoopNumber && closeLoopNumber > 99) {
            $('.loop-Badge').show()
            $('.loop-Badge').html(closeLoopNumber > 99 ? '99' : closeLoopNumber)
        }
        if (closeLoopNumber && closeLoopNumber < 99 && closeLoopNumber != 0) {
            $('.loop-Badge').show()
            $('.loop-Badge').html(closeLoopNumber)
        }
        if (closeLoopNumber === 0) {
            $('.loop-Badge').hide()
        }
    }
</script>
