const $ = require('jquery');
require("../css/messageNoti.less");
require('jquery-templates');
require('./modal.js');
const { api } = require('./api.js')
const { post, getCookie, emptyBox, listenScroll } = require('./utils.js')
require('./../resource/jquery-ui/jquery-ui.min.js');
require('./../resource/jquery-ui/jquery-ui.min.css');
const iconDown = require("./../images/arrow_down.png")
const iconUp = require("./../images/arrow_up.png")
const arrowLeft = require("./../images/arrow_left.png")
const arrowRight = require("./../images/arrow_right.png")
listenScroll()
$(".selectType").append(`
`)
$(".qcSelectCheck").append(`
`)
let status = "", type = "", page = 1, showNum = 0, newsNumber;
$(".menu .page", parent.document).removeClass("active")
$(parent.document).find(".menu .page[code=YH-XXTZ]").addClass("active")
function getTabData(activePage) {
const param = {
current: activePage,
size: 15,
desc: ['gmtCreate'],
type: type,
status: status
}
$('.pagination').html("")
$('.tbody').html(emptyBox('努力加载中...', '',))
return post(api.newsNoticePage, param).then(res => {
if (res.data.code == '0') {
tabList = res.data.data.records
const totalPage = res.data.data.pages
const totalNum = res.data.data.total
renderTab(tabList)
renderPagination(totalPage, Number(activePage), totalNum)
if (totalPage > 1) {
renderPagination(totalPage, Number(activePage), totalNum)
} else {
$('.pagination').html("")
}
} else {
const token = localStorage.getItem('accessToken');
if (!token && window.location.href.indexOf('login') == -1) {
//alert('无token判断,跳回登录')
} else {
$.alerModal({ "message": res.data.msg, type: "tip", time: '1000', isFather: true, fatherWrapper: $("#mainBox", parent.document) });
}
}
}).catch((e) => {
})
}
function renderTab(data) {
let str = ``
if (data.length === 0) {
$('.tbody').html(emptyBox(null, showNum + 12))
return;
}
for (let i = 0; i < data.length; i++) {
const item = data[i]
str += `
${item.title || "-"} |
${item.type == 1 ? '质控任务' : '-'} |
${item.senderName || '-'} |
${item.gmtCreate || '-'} |
${item.status == 0 ? '未读' : '已读'} |
查看
|
`
}
$('.tbody').html(str)
$(".goHomeDetail1").click(function () {
let id = $(this).parent().attr("data-id")
let status = $(this).parent().attr("data-status")
getNewsNoticeInfoById(id, status)
})
}
function getNewsNoticeInfoById(id, status) {
return post(api.getNewsNoticeInfoById, { id: id, status: status }).then(res => {
if (res.data.code == '0') {
const data = res.data.data
$("#delModal").show();
$(".modal-body").html('');
$("#editTmpl").tmpl(data).appendTo("#delModal .modal-body");
$("#delModal .confirm").unbind("click").click(function () {
$("#delModal").hide();
getTabData(page)
getNewsCount()
});
} else {
const token = localStorage.getItem('accessToken');
if (!token && window.location.href.indexOf('login') == -1) {
//alert('无token判断,跳回登录')
} else {
$.alerModal({ "message": res.data.msg, type: "tip", time: '1000', isFather: true, fatherWrapper: $("#mainBox", parent.document) });
}
}
}).catch((e) => {
})
}
getNewsCount()
//获取待审核数量
function getNewsCount() {
return post(api.getNewsCount).then(res => {
if (res.data.code == '0') {
newsNumber = res.data.data.count > 99 ? '99+' : res.data.data.count
if (newsNumber == 0) {
$(".menu .page", parent.document).children('.redNews').hide()
} else {
$(".menu .page", parent.document).children('.redNews').html(newsNumber)
}
} else {
const token = localStorage.getItem('accessToken');
if (!token && window.location.href.indexOf('login') == -1) {
//alert('无token判断,跳回登录')
} else {
$.alerModal({ "message": res.data.msg, type: "tip", time: '1000', isFather: true, fatherWrapper: $("#mainBox", parent.document) });
}
}
}).catch((e) => {
})
}
$(".filter").on("click", function (e) {
getTabData(1)
})
$(".abnormalClear").on("click", function (e) {
status = ""
type = ""
$('.selectType').html('全部')
$(".typeList ").css("display", "none")
$(".selectType").append(`
`)
$('.qcSelectCheck').html('全部')
$(".qcCheckList").css("display", "none")
$(".qcSelectCheck").append(`
`)
$("th[code]").removeClass("asc desc")
getTabData(1)
})
//操作类型
$('.selectType').on("click", function (e) {
e.stopPropagation()
$(".qcSelectCheck .arrow").attr("src", iconDown)
$(".qcCheckList").css("display", "none")
const showList = $(".typeList ").css("display")
if (showList == "none" || !showList) {
$(".typeList ").css("display", "block")
$(".selectType .arrow").attr("src", iconUp)
} else {
$(".typeList ").css("display", "none")
$(".selectType .arrow").attr("src", iconDown)
}
})
//选择状态
$('.qcSelectCheck').on("click", function (e) {
e.stopPropagation()
$(".selectType .arrow").attr("src", iconDown)
$(".typeList").css("display", "none")
const showList = $(".qcCheckList ").css("display")
if (showList == "none" || !showList) {
$(".qcCheckList ").css("display", "block")
$(".qcSelectCheck .arrow").attr("src", iconUp)
} else {
$(".qcCheckList ").css("display", "none")
$(".qcSelectCheck .arrow").attr("src", iconDown)
}
})
getNewsDropDownBox()
//获取操作类型
function getNewsDropDownBox() {
post(api.getNewsDropDownBox).then(res => {
if (res.data.code == '0') {
const typeList = res.data.data.newsType
const statusList = res.data.data.newsStatus
renderTypeList(typeList)
renderStatusList(statusList)
} else { }
}).catch((e) => {
})
}
function renderTypeList(data) {
let str = ``
for (var i in data) {
console.log(i);
str += ` ${data[i].name}`
}
$('.typeList').html(str)
bindTypedSelect()
}
//通知类型选择
function bindTypedSelect() {
$('.typeItem').on("click", function () {
const typeItemName = $(this).attr("data-name")
const typeItemItemId = $(this).attr("data-id")
type = typeItemItemId
$('.selectType').html(typeItemName)
$(".typeList").css("display", "none")
$(".selectType").append(`
`)
$('.selectType').removeClass('unSelect')
})
}
function renderStatusList(data) {
let str = ``
for (var i in data) {
str += ` ${data[i].name}`
}
$('.qcCheckList').html(str)
bindCheckedSelectQc()
}
//状态
function bindCheckedSelectQc() {
$('.qcCheckItem').on("click", function () {
const qcCheckItemName = $(this).attr("data-name")
const qcCheckItemItemId = $(this).attr("data-id") || ""
status = qcCheckItemItemId
$('.qcSelectCheck').html(qcCheckItemName)
$(".qcCheckList").css("display", "none")
$(".qcSelectCheck").append(`
`)
$('.qcSelectCheck').removeClass('unSelect')
})
}
$(function () {
getTabData(page)
});
//分页渲染
function renderPagination(totalPage, activePage, totalNum) {
let str = `共${totalPage}页/${totalNum}条数据
`
if (totalPage <= 6) {
for (let i = 1; i <= totalPage; i++) {
str += `${i}`
}
} else {
if (activePage <= 3) { //选中页数小于4
for (let i = 1; i <= 4; i++) {
str += `${i}`
}
str += `...`
str += `${totalPage}`
} else if (activePage > totalPage - 3) {
str += `1`
str += `...`
str += `${totalPage - 3}`
str += `${totalPage - 2}`
str += `${totalPage - 1}`
str += `${totalPage}`
} else {
str += `1`
str += `...`
str += `${activePage - 1}`
str += `${activePage}`
str += `${activePage + 1}`
str += `...`
str += `${totalPage}`
}
}
str += `
`
$('.pagination').html(str)
$('.page' + activePage).addClass('activePage')
$(".pageNum").on("click", function (e) {
const activePageNow = Number($(this).attr('data-page'))
page = activePageNow
getTabData(activePageNow)
// renderPagination(totalPage,activePageNow,totalNum)
})
$(".prePage").on("click", function (e) {
let activePageNow = Number($(".activePage").attr('data-page'))
page = activePageNow
if (activePageNow > 1) {
activePageNow--
getTabData(activePageNow)
// renderPagination(totalPage,activePageNow,totalNum)
}
})
$(".nextPage").on("click", function (e) {
let activePageNow = Number($(".activePage").attr('data-page'))
page = activePageNow
if (activePageNow < totalPage) {
activePageNow++
getTabData(activePageNow)
// renderPagination(totalPage,activePageNow,totalNum)
}
})
}
$(document).on("click", function () {
$(".selectType .arrow").attr("src", iconDown)
$(".typeList").css("display", "none")
$(".qcSelectCheck .arrow").attr("src", iconDown)
$(".qcCheckList").css("display", "none")
})