/**
 * Created by Administrator on 2021/4/5.
 */
define(['jquery', "template", "Tools", "announApi", "paging"], function ($, template, Tools ) {
    //数据存储
    var module = {
        data: {
            //公告列表
            announcementInformationList:'',
            //鉴证列表
            attestationInformationList:'',
            //页码
            pageNum: 1,
            //页码集合
            pageList: [],
            //每页数量
            pageSize: 1,
            //总页数
            pageCount:0,
            //选中卡ID
            clickType:'announcement'
        },
    };
    var tools = new Tools();

    module.init = function (page) {

        //成交公告
        tools.doGet(announList, {deptId:100,pageNum:module.data.pageNum,pageSize:module.data.pageSize}, module.announInformation,true);

        //鉴证公告
        tools.doGet(attestationList, {deptId:100,pageNum:module.data.pageNum,pageSize:module.data.pageSize}, module.attestationInformation,true);


    };

    //项目公告数据
    module.announInformation = function (data) {
        if (data.code == 200) {
            var content = data.rows;
            var pageCount = (data.total/module.data.pageSize).toFixed(0);
            if (pageCount < 1){
                pageCount = 1;
            }
            if(module.data.announcementInformationList == ''){
                // 初始化 分页器
                var page_s1=createPage('.page_s1');
                // 设置分页
                setPage(page_s1,{
                    pageTotal: data.total, // 数据总条数
                    pageSize: module.data.pageSize,    // 每页显示条数
                    pageCurrent: 1,  //  当前页
                    maxBtnNum: 5,   // 最多按钮个数  （最少5个）
                })
                $('#page_s1').html('共'+pageCount+'页')
            }
            module.data.pageCount = pageCount;
            module.data.announcementInformationList = content;
            var announcementInformationData = template('announcementInformationData', module.data);
            $("#announcementInformationContent").html(announcementInformationData);
        }
    }

    //鉴证公告数据
    module.attestationInformation = function (data) {
        if (data.code == 200) {
            var content = data.rows;
            var pageCount = (data.total/module.data.pageSize).toFixed(0);
            if (pageCount < 1){
                pageCount = 1;
            }
            if(module.data.announcementInformationList == ''){
                // 初始化 分页器
                var page_s1=createPage('.page_s2');
                // 设置分页
                setPage(page_s1,{
                    pageTotal: data.total, // 数据总条数
                    pageSize: module.data.pageSize,    // 每页显示条数
                    pageCurrent: 1,  //  当前页
                    maxBtnNum: 5,   // 最多按钮个数  （最少5个）
                })
                $('#page_s2').html('共'+pageCount+'页')
            }
            module.data.pageCount = pageCount;
            module.data.attestationInformationList = content;
            var attestationInformationData = template('attestationInformationData', module.data);
            $("#attestationInformationContent").html(attestationInformationData);
        }
    }

    tabList = function(type){
        console.log(type)
        document.getElementById('attestationInformationContent').style.display = 'none';
        document.getElementById('announcementInformationContent').style.display = 'none';
        document.getElementById(type+'InformationContent').style.display = 'block';

        document.getElementById('attestation').className = '';
        document.getElementById('announcement').className = '';
        document.getElementById(type).className = 'active';

        document.getElementById('attestationNum').style.display = 'none';
        document.getElementById('announcementNum').style.display = 'none';
        document.getElementById(type+'Num').style.display = 'block';

        module.data.clickType = type;
        module.data.pageNum = 1 ;
    }

    turnThePage = function (pageNum) {
        module.data.pageNum = pageNum ;
        if(module.data.clickType == 'attestation'){
            tools.doGet(attestationList, {deptId:100,pageNum:pageNum,pageSize:module.data.pageSize}, module.attestationInformation,true);
        }
        if(module.data.clickType == 'announcement'){
            tools.doGet(announList, {deptId:100,pageNum:pageNum,pageSize:module.data.pageSize}, module.announInformation,true);
        }
    }
    return module;
});