/**
 * Created by Administrator on 2021/4/5.
 */
define(['jquery', "template", "Tools", 'swiper', 'itemsApi', 'swiper'], function ($, template, Tools ,Swiper) {
    //数据存储
    var module = {
        data: {
            //焦点图数据
            focusListTop: [],
            showImgInformationDetail:'',
            loginNow:'',
            isFirst:'',
            timer:null,
            timer2:null,
            biddinglistInformationDetailLength:-1,
            biddingTimeType:0,
            biddinglistInformationDetail:[],
            timeConfig:0.00
        },
    };
    var tools = new Tools();

    module.init = function (page) {
        //获取焦点图信息
        tools.doGet(websitePicture, {picType:1,status:0,orderByColumn:'picSort',isAsc:'desc'}, module.focusNewsTop , true);
        //底部友情链接
        tools.doGet(friendsLinks, {}, module.bottomFriendsLinks, true);

        //网站配置信息（网站名称 底部联系方式 公安备案号 网站备案号）
        tools.getWebConfig();

        module.data.loginNow = tools.getCookie('Admin-Token');

        //浏览次数
        tools.doGet(outProject, {id:getQueryVariable('id')}, module.projectNum,true);

        setTimeout(function(){//项目基本信息
            tools.doGet(outProject + '/id/'+getQueryVariable('id'), {}, module.outProjectInformation,true);
        },100)

        //焦点图
        setTimeout(function () {
            module.swiperBanner();
        },5000)

        setTimeout(function(){//项目基本信息
            tools.doGet(showImg + '/'+getQueryVariable('id'), {}, module.showImgInformation,true);
        },100)

        tools.doGet(webConfig, {}, module.webConfigInformation, true)
    };

    openChangeImg = function (data) {
        $('#changeBox').css('display','block')
        $('#changeBoxBg').css('display','block')
    }

    closeChangeImg = function (data) {
        $('#changeBox').css('display','none')
        $('#changeBoxBg').css('display','none')
    }

    //焦点图数据
    module.focusNewsTop = function (data) {
        if (data.code == 200) {

            let focusArray = [];

            if(data.data.length<1){
                focusArray.push({
                    picUrl:'../../../static/images/banner1.png'
                },{
                    picUrl:'../../../static/images/banner2.png'
                },{
                    picUrl:'../../../static/images/banner3.png'
                })
            }else{
                data.data.forEach(res=>{
                    focusArray.push({
                        picUrl:'/api'+res.picUrl
                    })
                })
            }

            module.data.focusListTop = focusArray;
            var bannerFocusDataTop = template('bannerFocusDataTop', module.data);
            $("#bannerFocusTopContent").html(bannerFocusDataTop);

            new Swiper('#bannerFocusWrapTop', {
                paginationClickable: true,
                autoplay : 4000,
                loop:true
            })

        }
    }

    //获取地址栏参数
    function getQueryVariable(variable){
        var query = window.location.search.substring(1);
        var vars = query.split("&");
        for (var i=0;i<vars.length;i++) {
            var pair = vars[i].split("=");
            if(pair[0] == variable){return pair[1];}
        }
        return(false);
    }
    //网站配置信息
    module.webConfigInformation = function (data) {
        if (data.code == 200) {
            var content = data.data;
            //console.log(content)
            //document.getElementById('time').innerHTML = '延时周期：'+content[8].configValue+content[8].remark+'<i class="wh">?</i>'
            module.data.timeConfig = parseFloat(content[8].configValue);
            module.data.titleConfig = content[9].configValue;
            module.data.importantTitle = content[7].configName+':'+ content[7].configValue.substr(3).substr(0,(content[7].configValue.substr(3).length-4));
            module.data.know = content[6].configValue;
            $("#know").html(content[6].configValue);
            // + '<span style="margin-left: 10px;"></span>' + content[6].configValue
        }
    }
    //底部友情链接
    module.bottomFriendsLinks = function (data) {
        if (data.code == 200) {
            var content = data.data;
            //console.log(content)
            module.data.friendsLinksList = content;
            var friendsLinksData = template('friendsLinksData', module.data);
            $("#friendsLinksContent").html(friendsLinksData);
        }
    }

    var t = 3;
    module.dataCompare = function(signupStartTime,signupStopTime,biddingStartTime,biddingStopTime){
        //console.log('aaaaaaaaaaa')
        var signupStartTime = signupStartTime;
        var signupStopTime = signupStopTime;
        var biddingStartTime = biddingStartTime;
        var biddingStopTime = biddingStopTime;
        var nowTime = Date.parse(new Date($.ajax({type:'HEAD',async:false,data:{i: Date.parse(new Date())}}).getResponseHeader("Date")));
        // console.log(new Date($.ajax({type:'HEAD',async:false,data:{i: Date.parse(new Date())}}).getResponseHeader("Date")))
        var beginTimes=signupStartTime.substring(0,10).split('-');
        var endTimes=signupStopTime.substring(0,10).split('-');

        var biddingBeginTimes=biddingStartTime.substring(0,10).split('-');
        var biddingEndTimes=biddingStopTime.substring(0,10).split('-');

        signupStartTime=beginTimes[1]+'/'+beginTimes[2]+'/'+beginTimes[0]+' '+signupStartTime.substring(10,19);
        signupStopTime=endTimes[1]+'/'+endTimes[2]+'/'+endTimes[0]+' '+signupStopTime.substring(10,19);

        biddingStartTime=biddingBeginTimes[1]+'/'+biddingBeginTimes[2]+'/'+biddingBeginTimes[0]+' '+biddingStartTime.substring(10,19);
        biddingStopTime=biddingEndTimes[1]+'/'+biddingEndTimes[2]+'/'+biddingEndTimes[0]+' '+biddingStopTime.substring(10,19);

        //时间差
        var leftTime = Date.parse(biddingStopTime)-nowTime;
        //报名开始时间差
        var signupLeftTime = Date.parse(signupStartTime)-nowTime;
        //报名结束时间差
        var signDownLeftTime = Date.parse(signupStopTime)-nowTime;
        //定义变量 d,h,m,s保存倒计时的时间
        var d,h,m,s;

        if(Date.parse(biddingStartTime)<nowTime&&nowTime<Date.parse(biddingStopTime)){
            //正在竞价
            // console.log('正在竞价')
            module.data.biddingTimeType = 1;
            module.data.outProjectInformationDetail.projectShowStatus = '正在竞价';
            // if(module.data.outProjectInformationDetail.biddingType == '自由竞价'){
            //     document.getElementById('biddingTable').style.display = 'none';
            //     document.getElementById('biddingTitle').style.display = 'block';
            //     document.getElementById('biddingTitle').innerHTML = '竞价进行中...';
            // }
            // document.getElementById('swiperType').style.display = 'block';
            d = Math.floor(leftTime/1000/60/60/24);
            h = Math.floor(leftTime/1000/60/60%24);
            m = Math.floor(leftTime/1000/60%60);
            s = Math.floor(leftTime/1000%60);
            // console.log('<span>距竞价结束还有：'+d+'</span>天<span>'+h+'</span>时<span>'+m+'</span>分<span>'+s+'</span>秒')
            $('#countType').html('竞价中')
            $('#countDown').html('<span>距竞价结束还有：'+d+'</span>天<span>'+h+'</span>时<span>'+m+'</span>分<span>'+s+'</span>秒')
            if (module.data.outProjectInformationDetail.biddingType == '自由竞价'){
                document.getElementById('biddingTitle').innerHTML = '自由竞价方式下，项目成交前不显示竞价记录！';
            }
            if(module.data.outProjectInformationDetail.biddingType != '自由竞价' && module.data.biddingTimeType != 2){
                document.getElementById('showNowMoney').style.display = 'table-row';
                var timName = document.getElementById('timeDown');
                if(timName) {
                    document.getElementById('timeDown').style.display = 'inline-block';
                    timName.innerHTML = t + '<b style="color: #666666">秒后自动刷新</b>';
                }
                t--;
                if (t < 0) {
                    t = 3;
                    tools.doGet(biddinglist, {projectId: getQueryVariable('id')}, module.biddinglistInformation, true);
                }
            }

        }else if (nowTime>Date.parse(biddingStopTime)){
            //竞价结束
            $('#countType').html('')
            $('#countDown').html('竞价结束')
            module.data.outProjectInformationDetail.projectShowStatus = '等待成交';
            // document.getElementById('swiperType').style.display = 'none';
            // document.getElementById('biddingTable').style.display = 'table';
            // document.getElementById('biddingTitle').style.display = 'none';
            module.data.biddingTimeType = 2;
        }else if (nowTime<Date.parse(biddingStartTime)){
            leftTime = Date.parse(biddingStartTime)-nowTime;
            module.data.outProjectInformationDetail.projectShowStatus = '等待竞价';
            d = Math.floor(leftTime/1000/60/60/24);
            h = Math.floor(leftTime/1000/60/60%24);
            m = Math.floor(leftTime/1000/60%60);
            s = Math.floor(leftTime/1000%60);
            $('#countType').html('未开始')
            $('#countDown').html('<span>距竞价开始还有：'+d+'</span>天<span>'+h+'</span>时<span>'+m+'</span>分<span>'+s+'</span>秒')
            //竞价暂未开始
            // document.getElementById('biddingTitle').innerHTML = '竞价暂未开始...';
            module.data.biddingTimeType = 3;
        }

        if(Date.parse(signupStartTime)<nowTime&&nowTime<Date.parse(signupStopTime)){
            //正在报名
            module.data.signupTimeType = 1;
            // document.getElementById('swiperType').style.display = 'block';
            d = Math.floor(signDownLeftTime/1000/60/60/24);
            h = Math.floor(signDownLeftTime/1000/60/60%24);
            m = Math.floor(signDownLeftTime/1000/60%60);
            s = Math.floor(signDownLeftTime/1000%60);
            $('#countType').html('报名中')
            $('#countDown').html('<span>距报名结束还有：'+d+'</span>天<span>'+h+'</span>时<span>'+m+'</span>分<span>'+s+'</span>秒')
        }else if (nowTime>Date.parse(signupStopTime)){
            //报名结束
            module.data.signupTimeType = 2;
        }else if (nowTime<Date.parse(signupStartTime)){
            //报名暂未开始
            module.data.signupTimeType = 3;
            d = Math.floor(signupLeftTime/1000/60/60/24);
            h = Math.floor(signupLeftTime/1000/60/60%24);
            m = Math.floor(signupLeftTime/1000/60%60);
            s = Math.floor(signupLeftTime/1000%60);
            $('#countType').html('未开始')
            $('#countDown').html('<span>距报名开始还有：'+d+'</span>天<span>'+h+'</span>时<span>'+m+'</span>分<span>'+s+'</span>秒')
        }

        //moneyText：出价输入框
        //moneyBtn：出价按钮
        //signYes：已报名显示文字
        //signNo：未报名显示文字
        //signBtn：已登录但未报名跳转报名按钮
        //signBtn2：未登录跳转登录按钮
        //noAction：未开始显示文字

        if(module.data.loginNow){ //判断是否登录（已登录）
            if(module.data.signup == 1){ //判断是否报名（已报名）
                if( module.data.biddingTimeType == 1 ){ //判断当前竞价状态（竞价中）
                    document.getElementById('signYes').style.display = 'none';
                    document.getElementById('signNo').style.display = 'none';
                    document.getElementById('signBtn').style.display = 'none';
                    document.getElementById('signBtn2').style.display = 'none';
                    document.getElementById('noAction').style.display = 'none';

                    document.getElementById('moneyText').style.display = 'table-row';
                    document.getElementById('moneyBtn').style.display = 'flex';
                }else if( module.data.biddingTimeType == 3 ){ //判断当前竞价状态（竞价未开始）
                    document.getElementById('moneyText').style.display = 'none';
                    document.getElementById('moneyBtn').style.display = 'none';
                    document.getElementById('signNo').style.display = 'none';
                    document.getElementById('signBtn').style.display = 'none';
                    document.getElementById('signBtn2').style.display = 'none';
                    document.getElementById('noAction').style.display = 'none';

                    document.getElementById('signYes').style.display = 'block';
                }else{ //判断当前竞价状态（竞价结束）
                    $('.swiperInput').css('display','none');
                    $('#timeDown').css('display','none');
                    clearInterval(module.data.timeDown)
                }
            }else{ //判断是否报名（未报名）
                if( module.data.signupTimeType == 1 ){ //判断当前报名状态（正在报名）
                    document.getElementById('moneyText').style.display = 'none';
                    document.getElementById('moneyBtn').style.display = 'none';
                    document.getElementById('signNo').style.display = 'none';
                    document.getElementById('signBtn2').style.display = 'none';
                    document.getElementById('noAction').style.display = 'none';
                    document.getElementById('signYes').style.display = 'none';

                    document.getElementById('signBtn').style.display = 'block';
                }else if( module.data.signupTimeType == 3 ){ //判断当前报名状态（报名未开始）
                    document.getElementById('moneyText').style.display = 'none';
                    document.getElementById('moneyBtn').style.display = 'none';
                    document.getElementById('signBtn2').style.display = 'none';
                    document.getElementById('signYes').style.display = 'none';
                    document.getElementById('signBtn').style.display = 'none';
                    document.getElementById('signNo').style.display = 'none';

                    document.getElementById('noAction').style.display = 'block';
                }else{ //判断当前报名状态（报名结束）
                    document.getElementById('moneyText').style.display = 'none';
                    document.getElementById('moneyBtn').style.display = 'none';
                    document.getElementById('signBtn2').style.display = 'none';
                    document.getElementById('noAction').style.display = 'none';
                    document.getElementById('signYes').style.display = 'none';
                    document.getElementById('signBtn').style.display = 'none';

                    document.getElementById('signNo').style.display = 'block';
                }
            }
        }else{ //判断是否登录（未登录）
            if( module.data.biddingTimeType == 2 ){//判断当前竞价状态（竞价结束）
                $('.swiperInput').css('display','none')
            }else{
                document.getElementById('signBtn2').style.display = 'block';
            }
        }

        // if(module.data.outProjectInformationDetail.biddingType != '自由竞价' && module.data.biddingTimeType != 2){
        //     document.getElementById('biddingTable').style.display = 'table';
        //     document.getElementById('biddingTitle').style.display = 'none';
        // }
    }

    module.projectNum = function(data){
        console.log(data)
    }

    module.signup = function(data){
        console.log(data)
        module.data.signup = data.data;
        module.data.isFirst = data.signup.isFirst;
        var outProjectInformationData = template('outProjectInformationData', module.data);
        $("#outProjectInformationContent").html(outProjectInformationData);
    }

    goBond = function(){
        var nowTime = Date.parse(new Date());
        var signupStopTime = Date.parse(module.data.outProjectInformationDetail.signupStopTime)
        if (nowTime>signupStopTime){
            tools.initError('报名已结束！');
            return;
        }
        if (module.data.signHistory == 1){
            tools.initError('已报名，请耐心等待审核结果！');
            return;
        }

        tools.doGet(userData, {}, module.userData);

    }
    module.userData = function(data){
        if (data.code == 200) {
            var content = data.user;
            //console.log(content)
            module.data.userId = content.userId;
            tools.doGet(userMember + '/' + content.userId, {}, module.userMember);//memberType 1个人 2单位
        }
    }
    module.userMember = function(data){
        if (data.code == 200) {
            var content = data.data;
            if (content.auditStatus == 'Y'){
                tools.skip('bond.html?id='+getQueryVariable('id'))
            }else{
                tools.initError("交易中心审核注册信息后方可进行报名！");
            }
        }
    }

    //项目基本信息
    module.outProjectInformation = function (data) {
        if (data.code == 200) {
            var content = data.data;
            module.data.biddingStopTime = content.biddingStopTime;

            for(var i = 0 ; i < content.fileUrlList.length ; i++){
                content.fileUrlList[i].fileUrl = serverApi+content.fileUrlList[i].fileUrl;
            }

            module.data.outProjectInformationDetail = content;
            setTimeout(function(){
                var outProjectInformationData = template('outProjectInformationData', module.data);
                $("#outProjectInformationContent").html(outProjectInformationData);
                // var timName = document.getElementById('timeDown');
                // if(timName){
                //     var t = 3;
                //
                //     module.data.timeDown = setInterval(function(){
                //         // console.log($('#countType').html())
                //         // if ($('#countType').html()!='竞价中'){
                //         //     clearInterval(module.data.timeDown)
                //         //     document.getElementById('timeDown').style.display = 'none';
                //         //     return;
                //         // }
                //         timName.innerHTML = t+'<b style="color: #666666">秒后自动刷新</b>';
                //         t--;
                //         document.getElementById('timeDown').style.display = 'inline-block';
                //         if(t<0){
                //             t = 3;
                //             let biddingStartTime = content.biddingStartTime;
                //             let biddingStopTime = content.biddingStopTime;
                //             var nowTime = Date.parse(new Date());
                //             if(Date.parse(biddingStartTime)<nowTime&&nowTime<Date.parse(biddingStopTime)){
                //                 //正在竞价
                //                 //交易项目竞价记录
                //                 tools.doGet(biddinglist, {projectId:getQueryVariable('id')}, module.biddinglistInformation,true);
                //             }
                //         }
                //     }, 1000)
                // }
            },2000)

            $("#know").html(module.data.know);


            //挂牌价格字典
            tools.doGet(Dictionaries+'/price_unit', {}, module.unitDictionaries,true);

            //经济类型字典
            tools.doGet(Dictionaries+'/economic_type', {}, module.economicTypeDictionaries,true);

            //项目类型字典
            tools.doGet(Dictionaries+'/project_type', {}, module.projectNumberDictionaries,true);

            //农地性质字典
            // tools.doGet(Dictionaries+'/sub_object_type', {}, module.projectTypeDictionaries,true);

            //前次转出方式
            tools.doGet(Dictionaries+'/rollout_type', {}, module.oneoutDictionaries,true);

            //面积单位字典
            tools.doGet(Dictionaries+'/area_unit', {}, module.areaDictionaries,true);

            //支付方式字典
            tools.doGet(Dictionaries+'/payment_type', {}, module.paymentTypeDictionaries,true);

            //缴纳形式字典
            tools.doGet(Dictionaries+'/deposit_payment_type', {}, module.depositPaymentTypeDictionaries,true);

            //交易方式字典
            tools.doGet(Dictionaries+'/deal_type', {}, module.transactionDictionaries,true);

            //竞价方式字典
            tools.doGet(Dictionaries+'/bidding_type', {}, module.biddingTypeDictionaries,true);

            //期满处理字典
            tools.doGet(Dictionaries+'/expire_type', {}, module.expireTypeDictionaries,true);

            //期满处理字典
            tools.doGet(Dictionaries+'/bidding_direct', {}, module.biddingDirectDictionaries,true);

            //交易项目竞价记录
            tools.doGet(biddinglist, {projectId:getQueryVariable('id')}, module.biddinglistInformation,true);


            //倒计时
            module.data.timer = setInterval(function(){
                // '2023-05-17 14:56:00'
                let signupStartTime = module.data.outProjectInformationDetail.signupStartTime;
                let signupStopTime = module.data.outProjectInformationDetail.signupStopTime;
                let biddingStartTime = module.data.outProjectInformationDetail.biddingStartTime;
                let biddingStopTime = module.data.outProjectInformationDetail.biddingStopTime;//延时后结束时间
                let biddingStopSetime = module.data.outProjectInformationDetail.biddingStopSetime;//原始结束时间

                var nowTime = Date.parse(new Date($.ajax({type:'HEAD',async:false,data:{i: Date.parse(new Date())}}).getResponseHeader("Date")));
                var difference = Date.parse(biddingStopTime)-nowTime;//延时后时间差
                var differenceSetime = Date.parse(biddingStopSetime)-nowTime;//原始时间差
                // var centerTime = module.data.timeConfig * 60 * 1000
                var centerTime = content.delayPeriod * 1000//延时周期

                var m,s;
                m = Math.floor(difference/1000/60%60);
                s = Math.floor(difference/1000%60);
                if(s%2 == 0&&centerTime!=0){
                    tools.doGet(getBiddingStopTime+getQueryVariable('id'), {}, module.getBiddingStopTime,true);
                }

                if ( differenceSetime <= 0 && difference >= 0 && difference <= centerTime){
                    console.log("竞价最后两分钟")
                    //正在竞价
                    // if(module.data.outProjectInformationDetail.biddingType == '自由竞价'){
                    //     document.getElementById('biddingTable').style.display = 'none';
                    //     document.getElementById('biddingTitle').style.display = 'block';
                    //     document.getElementById('biddingTitle').innerHTML = '竞价进行中...';
                    // }
                    // document.getElementById('swiperType').style.display = 'block';
                    module.data.biddingTimeType = 1;
                    module.data.outProjectInformationDetail.projectShowStatus = '正在竞价';
                    $('#countType').html('竞价中')
                    $('#countDown').html('<span>距竞价结束还有：0</span>天<span>0</span>时<span>'+m+'</span>分<span>'+s+'</span>秒')
                    if(module.data.outProjectInformationDetail.biddingType != '自由竞价' && module.data.biddingTimeType != 2){
                        document.getElementById('showNowMoney').style.display = 'table-row';
                        var timName = document.getElementById('timeDown');
                        if(timName) {
                            document.getElementById('timeDown').style.display = 'inline-block';
                            timName.innerHTML = t + '<b style="color: #666666">秒后自动刷新</b>';
                        }
                        t--;
                        if (t < 0) {
                            t = 3;
                            tools.doGet(biddinglist, {projectId: getQueryVariable('id')}, module.biddinglistInformation, true);
                        }
                    }
                    if(module.data.loginNow){ //判断是否登录（已登录）
                        if(module.data.signup == 1){ //判断是否报名（已报名）
                            if( module.data.biddingTimeType == 1 ){ //判断当前竞价状态（竞价中）
                                document.getElementById('signYes').style.display = 'none';
                                document.getElementById('signNo').style.display = 'none';
                                document.getElementById('signBtn').style.display = 'none';
                                document.getElementById('signBtn2').style.display = 'none';
                                document.getElementById('noAction').style.display = 'none';

                                document.getElementById('moneyText').style.display = 'table-row';
                                document.getElementById('moneyBtn').style.display = 'flex';
                                $('.swiperInput').css('display','block')
                            }else if( module.data.biddingTimeType == 3 ){ //判断当前竞价状态（竞价未开始）
                                document.getElementById('moneyText').style.display = 'none';
                                document.getElementById('moneyBtn').style.display = 'none';
                                document.getElementById('signNo').style.display = 'none';
                                document.getElementById('signBtn').style.display = 'none';
                                document.getElementById('signBtn2').style.display = 'none';
                                document.getElementById('noAction').style.display = 'none';

                                document.getElementById('signYes').style.display = 'block';
                            }else{ //判断当前竞价状态（竞价结束）
                                $('.swiperInput').css('display','none');
                                $('#timeDown').css('display','none');
                                clearInterval(module.data.timeDown)
                            }
                        }else{ //判断是否报名（未报名）
                            if( module.data.signupTimeType == 1 ){ //判断当前报名状态（正在报名）
                                document.getElementById('moneyText').style.display = 'none';
                                document.getElementById('moneyBtn').style.display = 'none';
                                document.getElementById('signNo').style.display = 'none';
                                document.getElementById('signBtn2').style.display = 'none';
                                document.getElementById('noAction').style.display = 'none';
                                document.getElementById('signYes').style.display = 'none';

                                document.getElementById('signBtn').style.display = 'block';
                            }else if( module.data.signupTimeType == 3 ){ //判断当前报名状态（报名未开始）
                                document.getElementById('moneyText').style.display = 'none';
                                document.getElementById('moneyBtn').style.display = 'none';
                                document.getElementById('signBtn2').style.display = 'none';
                                document.getElementById('signYes').style.display = 'none';
                                document.getElementById('signBtn').style.display = 'none';
                                document.getElementById('signNo').style.display = 'none';

                                document.getElementById('noAction').style.display = 'block';
                            }else{ //判断当前报名状态（报名结束）
                                document.getElementById('moneyText').style.display = 'none';
                                document.getElementById('moneyBtn').style.display = 'none';
                                document.getElementById('signBtn2').style.display = 'none';
                                document.getElementById('noAction').style.display = 'none';
                                document.getElementById('signYes').style.display = 'none';
                                document.getElementById('signBtn').style.display = 'none';

                                document.getElementById('signNo').style.display = 'block';
                            }
                        }
                    }else{ //判断是否登录（未登录）
                        if( module.data.biddingTimeType == 2 ){//判断当前竞价状态（竞价结束）
                            $('.swiperInput').css('display','none')
                        }else{
                            document.getElementById('signBtn2').style.display = 'block';
                        }
                    }
                    //console.log(s+'-------------'+m)
                    if (s < 1 && m < 1){
                        console.log("竞价结束22222222222")
                        tools.doGet(getBiddingStopTime+getQueryVariable('id'), {}, function(data){
                            if (data.code == 200) {
                                var nowDate = Date.parse(new Date($.ajax({type:'HEAD',async:false,data:{i: Date.parse(new Date())}}).getResponseHeader("Date")));
                                module.data.outProjectInformationDetail.biddingStopTime = data.data

                                let timeNew = Date.parse(data.data) + 0 - nowDate;
                                if (timeNew > 0) {
                                    module.data.outProjectInformationDetail.biddingStopTime = data.data;
                                    $('.swiperInput').css('display','block')
                                    // module.data.biddingTimeType = 1;
                                }else{
                                    $('#countType').html('')
                                    $('#countDown').html('竞价结束')
                                    $('#timeDown').css('display','none');
                                    $('.swiperInput').css('display','none');
                                    // document.getElementById('swiperType').style.display = 'none';
                                    // document.getElementById('biddingTable').style.display = 'table';
                                    // document.getElementById('biddingTitle').style.display = 'none';
                                    module.data.biddingTimeType = 2;
                                    module.data.outProjectInformationDetail.projectShowStatus = '等待成交';

                                    tools.doGet(biddinglist, {projectId: getQueryVariable('id')}, (data1)=>{
                                        let content1 = data1.rows;
                                        module.data.biddinglistInformationDetail = content1;
                                        module.data.biddinglistInformationDetailLength = content1.length;
                                        var biddinglistInformationData = template('biddinglistInformationData', module.data);
                                        $("#tabDetail4").html(biddinglistInformationData);
                                    }, true);
                                    return;
                                }
                            }
                        },true);

                    }else if(s%2 == 0&&centerTime!=0){
                        tools.doGet(getBiddingStopTime+getQueryVariable('id'), {}, module.getBiddingStopTime,true);
                    }
                }else{
                    if (!signupStartTime){console.log('缺失报名开始时间');return;}
                    if (!signupStopTime){console.log('缺失报名结束时间');return;}
                    if (!biddingStartTime){console.log('缺失竞价开始时间');return;}
                    if (!biddingStopTime){console.log('缺失竞价结束时间');return;}
                    module.dataCompare(signupStartTime,signupStopTime,biddingStartTime,biddingStopSetime);
                }
                // if(module.data.outProjectInformationDetail.biddingType == '自由竞价' && module.data.biddingTimeType != 2){
                //     document.getElementById('biddingTable').style.display = 'none';
                //     document.getElementById('biddingTitle').style.display = 'block';
                // }
            },1000)


            //倒计时
            // module.data.timer2 = setInterval(function(){
            //     //交易项目竞价记录
            //     tools.doGet(biddinglist, {projectId:getQueryVariable('id')}, module.biddinglistInformationNew,true);
            //
            // },10000)

            if(module.data.loginNow){
                //判断是否报名
                tools.doGet(signup, {projectId:getQueryVariable('id'),depositStatus:'1',memberId:tools.getCookie('memberId')}, module.signup);
                tools.doGet(signup, {projectId:getQueryVariable('id'),memberId:tools.getCookie('memberId')}, module.signup2);
            }
        }
    }

    module.getBiddingStopTime = function(data){
        if (data.code == 200) {
            // $('#stopTime').html(data.data)
            module.data.outProjectInformationDetail.biddingStopTime = data.data
        }
    }

    module.signup2 = function(data){
        if (data.code == 200) {
            module.data.signHistory = data.data
        }
    }

    //标的物图片
    module.showImgInformation = function (data) {
        if (data.code == 200) {
            var content = data.data;
            console.log(content)
            var contentList = [];
            for(var i = 0 ; i < content.length ; i++){
                contentList[i] = serverApi+content[i].fileUrl;
            }
            module.data.showImgInformationDetail = contentList;
            console.log(contentList)
            var showImgInformationData = template('showImgInformationData', module.data);
            $("#tabDetail2").html(showImgInformationData);
        }
    }

    //竞价记录
    module.biddinglistInformation = function (data) {
        if (data.code == 200) {
            var content = data.rows;
            if (content.length>0){
                //console.log('abccba')
                $("#nowMoneyBlock").html('<span id="nowMoney">'+content[0].money+'</span>'+module.data.outProjectInformationDetail.unit);
            }else{
                $("#nowMoneyBlock").html('暂无出价');
            }
            if(module.data.biddinglistInformationDetailLength == content.length){
                return;
            }
            //console.log(module.data.outProjectInformationDetail.biddingDirect)
            //console.log(module.data.outProjectInformationDetail.biddingType)
            setTimeout(function(){

                if(module.data.outProjectInformationDetail.biddingType == '阶梯竞价'||module.data.outProjectInformationDetail.biddingType == '2'){

                    if (module.data.outProjectInformationDetail.biddingDirect == '反向竞价'||module.data.outProjectInformationDetail.biddingDirect == '2'){
                        if (content.length>0){
                            let money = $('#money').val()?$('#money').val():content[0].money
                            if(content[0].money<=money) {
                                document.getElementById('money').value = parseFloat(parseFloat(content[0].money) - parseFloat(module.data.outProjectInformationDetail.ladderPrice)).toFixed(2);
                            }
                        }else{
                            document.getElementById('money').value = parseFloat(parseFloat(module.data.outProjectInformationDetail.price)).toFixed(2);
                            // + parseFloat(module.data.outProjectInformationDetail.ladderPrice)
                        }
                    }else{
                        if (content.length>0){
                            let money = $('#money').val()?$('#money').val():content[0].money
                            if(content[0].money>=money){
                                document.getElementById('money').value = parseFloat(parseFloat(content[0].money) + parseFloat(module.data.outProjectInformationDetail.ladderPrice)).toFixed(2);
                            }
                        }else{
                            document.getElementById('money').value = parseFloat(parseFloat(module.data.outProjectInformationDetail.price)).toFixed(2);
                            // + parseFloat(module.data.outProjectInformationDetail.ladderPrice)
                        }
                    }
                }

            },2000)

            module.data.biddinglistInformationDetail = content;
            module.data.biddinglistInformationDetailLength = content.length;
            var biddinglistInformationData = template('biddinglistInformationData', module.data);
            $("#tabDetail4").html(biddinglistInformationData);
            $('#unit').html('出价价格【'+module.data.outProjectInformationDetail.unit+'】')
            if (content.length>0){
                //console.log('abccba')
                $("#nowMoneyBlock").html('<span id="nowMoney">'+content[0].money+'</span>'+module.data.outProjectInformationDetail.unit);}
        }
    }

    //竞价记录
    module.biddinglistInformationNew = function (data) {
        if (data.code == 200) {
            var content = data.rows;
            //console.log(module.data.biddinglistInformationDetail.length+'----------------------'+content.length)
            if (module.data.biddinglistInformationDetailLength<content.length){
                let time = new Date(Date.parse(new Date())+(2 * 60 * 1000));
                const Y = time.getFullYear()
                const M = time.getMonth() + 1 < 10 ? '0'+(time.getMonth()+1) : time.getMonth()+1
                const D = time.getDate()
                const H = time.getHours() // 小时
                const m = time.getMinutes() // 分钟
                const S = time.getSeconds() // 秒
                module.data.biddingStopTime = Y+'-'+M+'-'+D+' '+H+':'+m+':'+S;
                module.data.biddinglistInformationDetailLength = content.length;

            }
        }
    }

    //焦点图滚动
    module.swiperBanner = function (type) {
        //console.log('aaaa')
        var viewSwiper = new Swiper('.view .swiper-container', {
            onSlideChangeStart: function() {
                updateNavPosition()
            }
        })

        $('.view .arrow-left,.preview .arrow-left').on('click', function(e) {
            //console.log('abc')
            e.preventDefault()
            if (viewSwiper.activeIndex == 0) {
                viewSwiper.swipeTo(viewSwiper.slides.length - 1, 1000);
                return
            }
            viewSwiper.swipePrev()
        })

        $('.view .arrow-right,.preview .arrow-right').on('click', function(e) {
            //console.log('abc')
            e.preventDefault()
            if (viewSwiper.activeIndex == viewSwiper.slides.length - 1) {
                viewSwiper.swipeTo(0, 1000);
                return
            }
            viewSwiper.swipeNext()
        })

        var previewSwiper = new Swiper('.preview .swiper-container', {
            visibilityFullFit: true,
            slidesPerView: 'auto',
            onlyExternal: true,
            onSlideClick: function() {
                viewSwiper.swipeTo(previewSwiper.clickedSlideIndex)
            }
        })

        function updateNavPosition() {
            $('.preview .active-nav').removeClass('active-nav')
            var activeNav = $('.preview .swiper-slide').eq(viewSwiper.activeIndex).addClass('active-nav')
            if (!activeNav.hasClass('swiper-slide-visible')) {
                if (activeNav.index() > previewSwiper.activeIndex) {
                    var thumbsPerNav = Math.floor(previewSwiper.width / activeNav.width()) - 1
                    previewSwiper.swipeTo(activeNav.index() - thumbsPerNav)
                } else {
                    previewSwiper.swipeTo(activeNav.index())
                }
            }
        }
    }

    //切换
    tabClick = function(type){
        //标的物介绍
        for (var i = 0 ; i < 4 ; i++){
            document.getElementById('tabDetail'+(i+1)).style.display = 'none';
            document.getElementById('tab'+(i+1)).classList = '';
        }
        document.getElementById('tabDetail'+type).style.display = 'block';
        document.getElementById('tab'+type).classList = 'active';
    }

    //挂牌价格
    module.unitDictionaries = function (data) {
        if (data.code == 200) {
            var content = data.data;
            var unit = content[(module.data.outProjectInformationDetail.unit-1)].dictLabel;
            module.data.outProjectInformationDetail.unit = unit;
            var outProjectInformationData = template('outProjectInformationData', module.data);
            $("#outProjectInformationContent").html(outProjectInformationData);
        }
    }

    //出价
    module.biddingSubmitMethod = function (data2) {
        let newMoney;
        if (data2.data&&data2.code==200){
            //console.log(data2)
            newMoney = data2.data;
        }else{
            newMoney = module.data.outProjectInformationDetail.price;
        }

        if ($('#money').val()<=0){
            tools.initError('请正常出价！');
            return;
        }
        if (module.data.outProjectInformationDetail.biddingDirect == '反向竞价'){
            //判断用户出价不能高于挂牌价
            if(module.data.outProjectInformationDetail.price<$('#money').val()){
                tools.initError('出价不能高于挂牌价');
                return;
            }else{
                //判断当前竞价方式
                if (module.data.outProjectInformationDetail.biddingType=='阶梯竞价' || module.data.outProjectInformationDetail.biddingType=='公开竞价'){
                    //判断当前是否有人出价
                    if (data2.data){
                        //判断用户出价不能高于当前出价最低价格
                        if(newMoney <= $('#money').val()){
                            tools.initError('不能高于当前最低价格！');
                            return;
                        }
                    }
                }
            }
        }else{
            if(module.data.outProjectInformationDetail.price>$('#money').val()){
                tools.initError('出价不能低于挂牌价');
                return;
            }else{
                //判断当前竞价方式
                if (module.data.outProjectInformationDetail.biddingType=='阶梯竞价' || module.data.outProjectInformationDetail.biddingType=='公开竞价'){
                    //判断当前是否有人出价
                    if (data2.data){
                        //判断用户出价不能低于当前出价最高价格
                        if(newMoney >= $('#money').val()){
                            tools.initError('不能低于当前最高价格！');
                            return;
                        }
                    }
                }
            }
        }
        var data = {};
        var projectId = getQueryVariable('id');
        var memberId = tools.getCookie('memberId');
        var userId = tools.getCookie('userId');
        var userAccount = tools.getCookie('phone');
        var userName = tools.getCookie('userName');
        var money = parseFloat($('#money').val());
        var loginTime = Date.now($.ajax({type:'HEAD',async:false,data:{i: Date.parse(new Date())}}).getResponseHeader("Date"));
        data['projectId'] = projectId;
        data['memberId'] = memberId;
        data['userId'] = userId;
        data['userAccount'] = userAccount;
        data['userName'] = userName;
        data['money'] = money;
        data['loginTime'] = loginTime;
        tools.doPost(biddingSubmit, data, module.biddingSubmitOpen);
    }

    module.biddingSubmitOpen = function(data1){
        if (data1.code == 200) {
            tools.initError('出价成功');
        }
        tools.doGet(getBiddingStopTime+getQueryVariable('id'), {}, function(data){
            if (data.code == 200) {
                var nowDate = Date.parse(new Date($.ajax({type:'HEAD',async:false,data:{i: Date.parse(new Date())}}).getResponseHeader("Date")));
                module.data.outProjectInformationDetail.biddingStopTime = data.data
                let timeNew = Date.parse(data.data) + 0 - nowDate;
                if (timeNew > 0) {
                    module.data.outProjectInformationDetail.biddingStopTime = data.data;
                    // module.dataCompare(
                    //     module.data.outProjectInformationDetail.signupStartTime,
                    //     module.data.outProjectInformationDetail.signupStopTime,
                    //     module.data.outProjectInformationDetail.biddingStartTime,data.data);
                }else{
                    $('#countType').html('')
                    $('#countDown').html('竞价结束')
                    // document.getElementById('swiperType').style.display = 'none';
                    // document.getElementById('biddingTable').style.display = 'table';
                    // document.getElementById('biddingTitle').style.display = 'none';
                    module.data.biddingTimeType = 2;
                    return;
                }
            }
        },true);
        // $('#money').val(0)
    }

    //经济类型
    module.economicTypeDictionaries = function (data) {
        if (data.code == 200 && module.data.outProjectInformationDetail.economicType!='') {
            var content = data.data;
            if(content[(module.data.outProjectInformationDetail.economicType-1)] != undefined){
                var economicType = content[(module.data.outProjectInformationDetail.economicType-1)].dictLabel;
                module.data.outProjectInformationDetail.economicType = economicType;
                var outProjectInformationData = template('outProjectInformationData', module.data);
                $("#outProjectInformationContent").html(outProjectInformationData);
            }
        }
    }

    //项目类型
    module.projectNumberDictionaries = function (data) {
        if (data.code == 200 && module.data.outProjectInformationDetail.projectNumber!='') {
            module.data.outProjectInformationDetail.projectNumberOriginal = module.data.outProjectInformationDetail.projectNumber;
            var content = data.data;
            var projectNumber = content.filter(function (e) { return e.dictValue == module.data.outProjectInformationDetail.projectNumber; })[0].dictLabel;
            module.data.outProjectInformationDetail.projectNumber = projectNumber;
            var outProjectInformationData = template('outProjectInformationData', module.data);
            $("#outProjectInformationContent").html(outProjectInformationData);
        }
    }

    //农地性质
    module.projectTypeDictionaries = function (data) {
        if (data.code == 200 && module.data.outProjectInformationDetail.projectType!='') {
            var content = data.data;
            //console.log(content)
            //console.log((module.data.outProjectInformationDetail.projectType-1))
            var projectType = content[(module.data.outProjectInformationDetail.projectType-1)].dictLabel;
            module.data.outProjectInformationDetail.projectType = projectType;
            var outProjectInformationData = template('outProjectInformationData', module.data);
            $("#outProjectInformationContent").html(outProjectInformationData);
        }
    }

    //前次转出方式
    module.oneoutDictionaries = function (data) {
        if (data.code == 200 && module.data.outProjectInformationDetail.oneout!='') {
            var content = data.data;
            if(module.data.outProjectInformationDetail.oneout == 0){
                module.data.outProjectInformationDetail.oneout = '无';
            }else{
                var oneout = content[(module.data.outProjectInformationDetail.oneout-1)].dictLabel;
                module.data.outProjectInformationDetail.oneout = oneout;
            }
            var rollout = content[(module.data.outProjectInformationDetail.rollout-1)].dictLabel;
            module.data.outProjectInformationDetail.rollout = rollout;

            var outProjectInformationData = template('outProjectInformationData', module.data);
            $("#outProjectInformationContent").html(outProjectInformationData);
        }
    }

    //面积单位
    module.areaDictionaries = function (data) {
        if (data.code == 200 && module.data.outProjectInformationDetail.allCountUnit!='') {
            var content = data.data;
            var allCountUnit = content[(module.data.outProjectInformationDetail.allCountUnit-1)].dictLabel;
            module.data.outProjectInformationDetail.allCountUnit = allCountUnit;
            if(module.data.outProjectInformationDetail.subjectList.length>0){
                for(var i = 0 ; i < module.data.outProjectInformationDetail.subjectList.length ; i++){
                    module.data.outProjectInformationDetail.subjectList[i].areaUnit = content[(module.data.outProjectInformationDetail.subjectList[i].areaUnit-1)].dictLabel;
                }
            }
            var outProjectInformationData = template('outProjectInformationData', module.data);
            $("#outProjectInformationContent").html(outProjectInformationData);
        }
    }

    //支付方式
    module.paymentTypeDictionaries = function (data) {
        if (data.code == 200 && module.data.outProjectInformationDetail.paymentType!='') {
            module.data.outProjectInformationDetail.paymentTypeOriginal = module.data.outProjectInformationDetail.paymentType;
            var content = data.data;
            var paymentType = content[(module.data.outProjectInformationDetail.paymentType-1)].dictLabel;
            module.data.outProjectInformationDetail.paymentType = paymentType;
            var outProjectInformationData = template('outProjectInformationData', module.data);
            $("#outProjectInformationContent").html(outProjectInformationData);
        }
    }

    //缴纳形式
    module.depositPaymentTypeDictionaries = function (data) {
        if (data.code == 200 && module.data.outProjectInformationDetail.depositPaymentType!='') {
            var content = data.data;
            var depositPaymentType = content[(module.data.outProjectInformationDetail.depositPaymentType-1)].dictLabel;
            module.data.outProjectInformationDetail.depositPaymentType = depositPaymentType;
            var outProjectInformationData = template('outProjectInformationData', module.data);
            $("#outProjectInformationContent").html(outProjectInformationData);
        }
    }

    //交易方式
    module.transactionDictionaries = function (data) {
        if (data.code == 200 && module.data.outProjectInformationDetail.dealType!='') {
            var content = data.data;
            var dealType = content[(module.data.outProjectInformationDetail.dealType-1)].dictLabel;
            module.data.outProjectInformationDetail.dealType = dealType;
            var outProjectInformationData = template('outProjectInformationData', module.data);
            $("#outProjectInformationContent").html(outProjectInformationData);
        }
    }

    //竞价方式
    module.biddingTypeDictionaries = function (data) {
        if (data.code == 200 && module.data.outProjectInformationDetail.biddingType!='') {
            var content = data.data;
            var biddingType = content[(module.data.outProjectInformationDetail.biddingType-1)].dictLabel;
            module.data.outProjectInformationDetail.biddingType = biddingType;
            var outProjectInformationData = template('outProjectInformationData', module.data);
            $("#outProjectInformationContent").html(outProjectInformationData);
        }
    }

    //系统是否
    module.expireTypeDictionaries = function (data) {
        if (data.code == 200 && module.data.outProjectInformationDetail.expire!='') {
            var content = data.data;
            var expire = content[(module.data.outProjectInformationDetail.expire-1)].dictLabel;
            module.data.outProjectInformationDetail.expire = expire;
            var outProjectInformationData = template('outProjectInformationData', module.data);
            $("#outProjectInformationContent").html(outProjectInformationData);
        }
    }

    //系统是否
    module.biddingDirectDictionaries = function (data) {
        if (data.code == 200 && module.data.outProjectInformationDetail.biddingDirect!='') {
            var content = data.data;
            var biddingDirect = content[(module.data.outProjectInformationDetail.biddingDirect-1)].dictLabel;
            module.data.outProjectInformationDetail.biddingDirect = biddingDirect;
            var outProjectInformationData = template('outProjectInformationData', module.data);
            $("#outProjectInformationContent").html(outProjectInformationData);
        }
    }

    changeProMoney = function(){
        tools.doGet(projectNewBidMoney+getQueryVariable('id'), {}, module.biddingSubmitMethod);
    }

    changeProMoneyFirst = function(){
        tools.doGet(projectNewBidMoney+getQueryVariable('id'), {}, module.biddingSubmitMethodFirst);
    }

    module.biddingSubmitMethodFirst = function (data) {
        if (data.code == 200) {
            let newMoney;
            if (data.data){
                newMoney = data.data;
            }else{
                newMoney = module.data.outProjectInformationDetail.price;
            }

            //console.log(newMoney);
            var data = {};
            var projectId = getQueryVariable('id');
            var memberId = tools.getCookie('memberId');
            var userId = tools.getCookie('userId');
            var userAccount = tools.getCookie('phone');
            var userName = tools.getCookie('userName');
            var money = parseFloat(newMoney);
            // var loginTime = tools.getNowFormatDate();
            var loginTime = Date.now($.ajax({type:'HEAD',async:false,data:{i: Date.parse(new Date())}}).getResponseHeader("Date"));
            data['projectId'] = projectId;
            data['memberId'] = memberId;
            data['userId'] = userId;
            data['userAccount'] = userAccount;
            data['userName'] = userName;
            data['money'] = money;
            data['loginTime'] = loginTime;
            tools.doPost(biddingSubmit, data, module.biddingSubmitOpen);

        }
    }

    //向上加价
    upMoney = function(){
        if (module.data.outProjectInformationDetail.biddingDirect == '反向竞价'){
            if (module.data.biddinglistInformationDetail.length<1){
                if(module.data.outProjectInformationDetail.price <= $('#money').val()){
                    tools.initError('出价不能高于挂牌价格');
                    return;
                }
            }else{
                if(module.data.biddinglistInformationDetail[0].money <= (parseFloat($('#money').val())+parseFloat(module.data.outProjectInformationDetail.ladderPrice)).toFixed(2)){
                    tools.initError('出价不能高于当前出价最低价格');
                    return;
                }
            }
        }else{
            if (module.data.biddinglistInformationDetail.length<1){
                if(module.data.outProjectInformationDetail.price>$('#money').val()){
                    tools.initError('出价不能低于挂牌价格');
                    return;
                }
            }else{
                if(module.data.biddinglistInformationDetail[0].money>=$('#money').val()){
                    tools.initError('出价不能低于当前出价最高价格');
                    return;
                }
            }
        }

        $('#money').val() == null||$('#money').val() == ''?$('#money').val(0):'';

        //console.log($('#money').val())

        module.data.outProjectInformationDetail.ladderPrice?$('#money').val((parseFloat($('#money').val())+parseFloat(module.data.outProjectInformationDetail.ladderPrice)).toFixed(2)):document.getElementById('money').value += 1

    }

    //向下降价
    downMoney = function(){
        if (module.data.outProjectInformationDetail.biddingDirect == '反向竞价'){
            if (module.data.biddinglistInformationDetail.length<1){
                if(module.data.outProjectInformationDetail.price<$('#money').val()){
                    tools.initError('出价不能高于挂牌价格');
                    return;
                }
            }else{
                if(module.data.biddinglistInformationDetail[0].money<$('#money').val()){
                    tools.initError('出价不能高于当前出价最低价格');
                    return;
                }
            }
        }else{
            if (module.data.biddinglistInformationDetail.length<1){
                if(module.data.outProjectInformationDetail.price>=$('#money').val()){
                    tools.initError('出价不能低于挂牌价格');
                    return;
                }
            }else{
                if(module.data.biddinglistInformationDetail[0].money>=(parseFloat($('#money').val())-parseFloat(module.data.outProjectInformationDetail.ladderPrice)).toFixed(2)){
                    tools.initError('出价不能低于当前出价最高价格');
                    return;
                }
            }
        }

        $('#money').val() == null?$('#money').val(0):'';
        if ($('#money').val() == 0)return;
        module.data.outProjectInformationDetail.ladderPrice?$('#money').val((parseFloat($('#money').val())-parseFloat(module.data.outProjectInformationDetail.ladderPrice)).toFixed(2)):document.getElementById('money').value -= 1

    }

    moneyChange = function(){
        if (module.data.outProjectInformationDetail.biddingDirect == '反向竞价'){
            if(module.data.outProjectInformationDetail.price<$('#money').val()){
                $('#money').val(module.data.outProjectInformationDetail.price-1);
            }
        }
    }

    //登录跳转
    goLogin = function(){
        tools.initDialog('登录提示', '登录后可参与竞价，是否登录？', function () {
            tools.skip('../login/login.html')
        }, '登录', function () { }, "取消")
    }
    return module;
});
