/**
 * 工作台代办页面JS
 *
 * Created by li.kui on 2021/3/11.
 */
'use strict';

/**
 * 文档就绪
 */
$(function () {

    // 初始化待办提醒
    refreshDealtWith();

});


/**
 * 刷新待办提醒
 */
function refreshDealtWith() {
    $.ajax({
        type: 'POST',
        url: g.ctx + 'pc/sys/dealt/info/rest/getUserDealtWith',
        success: function (data) {
            var html = [], dealtDiv = $('.dealt-with');
            if (data.length === 0) {
                dealtDiv.empty();
            } else {
                for (var i = 0; i < data.length; i++) {
                    var item = data[i];
                    if (item.targetTypeCode!=='MHGYSTJ'){
                        html.push('<div class="warning-box">');
                        html.push('<div class="warning-title">');
                        html.push('<span></span>' + item.targetTypeName);
                        html.push('</div>');
                        html.push('<ul class="warning-item">');

                        for (var j = 0; j < item.dwtList.length; j++) {
                            var dwt = item.dwtList[j], dwtTotalNum = dwt.dwtTotalNum;

                            html.push('<li onclick="openMenuPage(this)" data-rid="' + dwt.resId + '" data-rui="' + dwt.resUrl + '" data-rn="' + dwt.resName + '" data-dtn="' + dwtTotalNum + '">');
                            html.push('<div class="title">');
                            html.push('<img src="' + g.ctx + 'static/img/pz_icon.png" alt="">' + dwt.dwtName);
                            html.push('</div>');
                            if (Number(dwtTotalNum) <= 0) {
                                html.push('<div class="date" style="color: grey;font-weight: 600">' + dwtTotalNum + '</div>');
                            } else {
                                // html.push('<div class="date" style="color: #EB5F02;font-weight: 600">' + dwtTotalNum + '</div>');
                                html.push('<span class="layui-badge date">' + dwtTotalNum + '</span>');
                            }
                            html.push('</li>');
                        }

                        html.push('</ul>');
                        html.push('</div>');
                    }

                }
                html.push('<div style="clear: both;"></div>');

                dealtDiv.empty();
                dealtDiv.html(html.join(''));
            }
        }
    });
}


/**
 * 打开菜单页面
 */
function openMenuPage(ele) {
    var rid = $(ele).data('rid'), rui = $(ele).data('rui'), rn = $(ele).data('rn');
    var dwtTotalNum = $(ele).data('dtn');
    if (Number(dwtTotalNum) > 0) {
        parent.tabAdd(rn, rui, rid, true);
    }
}

