/**
 * Created by Administrator on 2021/4/5.
 */
define(['jquery', "template", "Tools", "biddingApi", "itemsApi"], function ($, template, Tools ) {
    //数据存储
    var module = {
        data: {
            projectShowStatus:'',
            form:{
                deptId:100,
                projectNumber:'',
                projectShowStatus:'',
            }
        },
    };
    var tools = new Tools();

    module.init = function (page) {
        //查询交易项目浏览总次数
        // tools.doGet(biddingHallList + '/0/10', {}, module.biddingHallList, true);
        tools.doGet(biddingList, {deptId:100,projectShowStatus:'等待竞价'}, module.biddingHallList,true);
        //竞价大厅-滚动
        // module.hallRolling();

        //标的物类型
        //tools.doGet(webDeptType+"/project_type", {}, module.deptType,true);

        //标的物所在地
        //tools.doGet(webDept, {deptId:''}, module.deptLocation, true);

        $("#nowDateNYR").html(new Date().getFullYear()+'.'+(new Date().getMonth()+1)+'.'+new Date().getDate())

        setInterval(function () {
            $("#nowDateSFM").html(new Date().toLocaleTimeString());
        },1000)

    };

    //竞价大厅列表
    module.biddingHallList = function (data) {
        if (data.code == 200) {
            var content = data.rows;
            //console.log(content)

            for(var i = 0 ; i < content.length ; i++){
                if(content[i].biddingStopTime == null || content[i].biddingStartTime == null){continue;}
                var endTimes=content[i].biddingStopTime.substring(0,10).split('-');
                var biddingStopTime=endTimes[1]+'/'+endTimes[2]+'/'+endTimes[0]+' '+content[i].biddingStopTime.substring(10,19);

                var startTimes=content[i].biddingStartTime.substring(0,10).split('-');
                var biddingStartTime=startTimes[1]+'/'+startTimes[2]+'/'+startTimes[0]+' '+content[i].biddingStartTime.substring(10,19);

                var nowTime = Date.parse(new Date());
                var leftTime = Date.parse(biddingStopTime)-nowTime;
                var rightTime = Date.parse(biddingStartTime)-nowTime;
                //console.log(biddingStopTime)
                //console.log(leftTime)

                if(leftTime>0){
                    //console.log('进行中')
                    content[i].timeType = '进行中'
                }
                if(leftTime<0){
                    //console.log('已结束')
                    content[i].timeType = '已结束'
                }
                if(rightTime>0){
                    //console.log('未开始')
                    content[i].timeType = '未开始'
                }
            }
            module.data.biddingHallListList = content;
            //console.log(content)
            var biddingHallListData = template('biddingHallListData', module.data);
            $("#biddingHallListContent").html(biddingHallListData);
        }
    }

    ///竞价大厅-滚动
    module.hallRolling = function () {
        var divScroll = document.getElementById('tableList');
        window.onmousewheel = divScroll.onmousewheel = function () { return false }
        module.timeInter(divScroll);
        divScroll.onmouseover = function () {
            clearInterval(time);
        }
        divScroll.onmouseout = function () {
            module.timeInter(divScroll);
        }

    }

    module.timeInter = function (divScroll) {
        time = setInterval(function () {
            var oldTop = divScroll.scrollTop;
            var newTop = oldTop + 1;
            divScroll.scrollTop = newTop;
            var counst = divScroll.scrollHeight - divScroll.scrollTop - divScroll.clientHeight;
            if (1 > counst) {
                divScroll.scrollTop = 0;
            }
        }, 30)
    }

    selectedStatus = function(id,projectShowStatus){
        module.data.projectShowStatus = projectShowStatus;
        $('#statusall').removeClass('active');
        $('#status1').removeClass('active');
        $('#status2').removeClass('active');
        $('#status3').removeClass('active');
        $('#status4').removeClass('active');
        $('#status5').removeClass('active');
        $('#status'+id).addClass('active');
        goSearch();
    }

    //标的物类型
    module.deptType = function (data) {
        console.log(data)
        if (data.code == 200) {
            var content = data.data ;
            module.data.deptTypeList = content;
            var deptTypeData = template('deptTypeData', module.data);
            $("#deptTypeContent").html(deptTypeData);
        }
    }

    //标的物所在地
    module.deptLocation = function (data) {
        if (data.code == 200) {
            var content = data.data ;
            module.data.deptLocationList = content;
            var deptLocationData = template('deptLocationData', module.data);
            $("#deptLocationContent").html(deptLocationData);
        }
    }

    //标的物所在地(二级)
    module.deptSecondLocation = function (data) {
        if (data.data.length == 0) {
            document.getElementById('secondDept').style.display = 'none';
            return;
        } else {
            document.getElementById('secondDept').style.display = 'inline-block';
        }
        if (data.code == 200) {
            //console.log(data)
            var content = data.data;
            module.data.deptSecondLocationList = content;
            var deptSecondLocationData = template('deptSecondLocationData', module.data);
            $("#secondDept").html(deptSecondLocationData);
            //console.log(module.data.deptId)
        }
    }

    goSearch = function(type){
        // if (type == 'dept'){
        //     if ($('#deptLocationContent').val() == '100') {
        //         document.getElementById('secondDept').style.display = 'none';
        //     } else {
        //         tools.doGet(webDept, { deptId: $('#deptLocationContent').val() }, module.deptSecondLocation, true);
        //     }
        // }

        // console.log($('#secondDept').val() == '')
        // module.data.form.deptId = $('#secondDept').val() == '' || $('#secondDept').val() == null ? $('#deptLocationContent').val() : $('#secondDept').val();
        // module.data.form.projectNumber = $('#deptTypeContent').val();
        module.data.form.projectShowStatus= module.data.projectShowStatus;

        tools.doGet(biddingList, module.data.form, module.biddingHallList, true);
    }

    goDetail = function(id,type){
        console.log(type)
        tools.skip('biddingBigDataDetail.html?id='+id);
    }

    return module;
});
