/**
 * Created by Administrator on 2021/4/5.
 */
define(['jquery', "template", "Tools", "echarts", 'swiper'], function ($, template, Tools, echarts, swiper) {
    //数据存储
    var module = {
        data: {
            //服务器地址
            serverApi:'http://192.168.31.107:8080',
            //焦点图数据
            focusList: [],
            //新闻资讯数据
            newsInformationList: [],
            //政策法规数据
            policiesRegulationsList: [],
            //交易规则数据
            tradingRulesList: [],
            //资料下载数据
            dataDownloadList: [],
            //标的物所在地
            deptLocationList:[],
            //标的物类型
            deptTypeList:[],
            //网站配置信息
            webConfigInformationList:[],
            //底部友情链接
            friendsLinksList:[],
            //土地林地四荒地数据
            landListList:[],
            //集体资产数据
            collectiveAssetsList:[],
            //小型水利设施数据
            waterConservancyFacilitiesList:[],
            //农业生产设备数据
            productionEquipmentList:[],
            //挂牌项目总浏览次数
            allViewCountList:[],
            //成交公示数据
            announcementListList:[]
        },
        //柱状图参数
        option: {
            xAxis: {
                type: 'category',
                axisLine: {
                    show: true,
                    lineStyle: {
                        width: 1,
                        type: "solid"
                    }
                },
                axisLabel: { //设置x轴的字
                    show: true,
                    interval: 0,//使x轴横坐标全部显示
                    textStyle: {//x轴字体样式
                        margin: 15
                    }
                },
                data: ['2014', '2015', '2016', '2017', '2018', '2019', '2020', '2021']
            },
            yAxis: {
                type: 'value',
                min: 400,
                max: 1000,
                splitNumber: 7,
                splitLine: {
                    lineStyle: {
                        type: 'dashed'
                    }
                },
                axisLine: {
                    show: true,
                    lineStyle: {
                        width: 1,
                        type: "solid"
                    }
                },

            },
            series: [{
                data: [490, 520, 650, 600, 700, 640, 680, 600, 660],//实际值减300
                type: 'bar',
                itemStyle: {
                    color: '#007b76'
                }
            }],
            grid: {
                height: 200,
                width: 280,
                top: '-5px'
            },
        }
    };
    var tools = new Tools();

    module.init = function (page) {
        //获取焦点图信息
        tools.doGet(websiteNew + '/1/0/4', {}, module.focusNews);

        //新闻资讯
        tools.doGet(websiteNew + '/2/0/6', {}, module.NewsInformation);

        //政策法规
        tools.doGet(websiteNew + '/3/0/6', {}, module.policiesRegulations);

        //交易规则
        tools.doGet(websiteNew + '/4/0/6', {}, module.tradingRules);

        //资料下载
        tools.doGet(websiteNew + '/5/0/6', {}, module.dataDownload);

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

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

        //网站配置信息（网站名称 底部联系方式 公安备案号 网站备案号）
        tools.doGet(webConfig, {}, module.webConfigInformation);

        //底部友情链接
        tools.doGet(friendsLinks, {}, module.bottomFriendsLinks);

        //土地
        tools.doGet(webListing + '/1,2,3/0/3', {}, module.landList);

        //集体资产
        tools.doGet(webListing + '/4/0/3', {}, module.collectiveAssets);

        //农业生产设备
        tools.doGet(webListing + '/5/0/3', {}, module.productionEquipment);

        //小型水利设施
        tools.doGet(webListing + '/6/0/3', {}, module.waterConservancyFacilities);

        //查询挂牌项目浏览总次数
        tools.doGet(allViewCount + '/100', {}, module.allViewCount);

        //查询挂牌项目浏览总次数
        tools.doGet(announcementList + '/0/4', {}, module.announcementList);

        //查询挂牌项目浏览总次数
        tools.doGet(biddingHallList + '/0/10', {}, module.biddingHallList);

        //竞价大厅-滚动
        module.hallRolling();

        //用户资料鼠标悬浮
        // module.userHover();

        //  柱状图绘制
        var chartDom = document.getElementById('chart');
        var myChart = echarts.init(chartDom);
        module.option && myChart.setOption(module.option);

    };

    //焦点图数据
    module.focusNews = function (data) {
        if (data.code == 200) {
            var content = data.data;
            var focusList = [];
            for (var i = 0; i < content.length; i++) {
                var imgStrs = content[i].content.match(/<img.*?>/g)
                var title = content[i].title
                if (imgStrs != null && imgStrs != '') {
                    focusList.push({img:imgStrs[0],title:title})
                }
            }
            module.data.focusList = focusList;
            var bannerFocusData = template('bannerFocusData', module.data);
            $("#bannerFocusContent").html(bannerFocusData);
            new Swiper('#bannerFocusWrap', {
                pagination: '.page-pagination',
                paginationClickable: true
            })

        }
    }

    //新闻资讯数据
    module.NewsInformation = function (data) {
        if (data.code == 200) {
            var content = data.data;
            module.data.newsInformationList = content;
            var NewsInformationData = template('NewsInformationData', module.data);
            $("#NewsInformationContent").html(NewsInformationData);
        }
    }

    //政策法规
    module.policiesRegulations = function (data) {
        if (data.code == 200) {
            var content = data.data;
            module.data.policiesRegulationsList = content;
            var policiesRegulationsData = template('policiesRegulationsData', module.data);
            $("#policiesRegulationsContent").html(policiesRegulationsData);
        }
    }

    //交易规则
    module.tradingRules = function (data) {
        if (data.code == 200) {
            var content = data.data;
            module.data.tradingRulesList = content;
            var tradingRulesData = template('tradingRulesData', module.data);
            $("#tradingRulesContent").html(tradingRulesData);
        }
    }

    //资料下载
    module.dataDownload = function (data) {
        if (data.code == 200) {
            var content = data.data;
            module.data.dataDownloadList = content;
            var dataDownloadData = template('dataDownloadData', module.data);
            $("#dataDownloadContent").html(dataDownloadData);
        }
    }

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

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

    //网站配置信息
    module.webConfigInformation = function (data) {
        if (data.code == 200) {
            var content = data.data;
            $("#webConfigName").html(content[0].configValue);
            $("#webConfigRecord").html(content[1].configValue + content[2].configValue);
            $("#webConfigAddress").html(content[0].configValue+'&nbsp;'+content[3].configValue);
        }
    }

    //查询挂牌项目浏览总次数
    module.allViewCount = function (data) {
        if (data.code == 200) {
            var content = data.data;
            console.log(content)
            module.data.allViewCountList = content.toString().split("");
            var allViewCountData = template('allViewCountData', module.data);
            $("#allViewCount").html(allViewCountData);
        }
    }

    //底部友情链接
    module.bottomFriendsLinks = function (data) {
        if (data.code == 200) {
            var content = data.data;
            module.data.friendsLinksList = content;
            var friendsLinksData = template('friendsLinksData', module.data);
            $("#friendsLinksContent").html(friendsLinksData);
        }
    }

    //土地林地四荒地
    module.landList = function (data) {
        if (data.code == 200) {
            var content = data.data;
            console.log(content)
            module.data.landListList = content;
            var landListData = template('landListData', module.data);
            $("#landListContent").html(landListData);
        }
    }

    //集体资产
    module.collectiveAssets = function (data) {
        if (data.code == 200) {
            var content = data.data;
            console.log(content)
            module.data.collectiveAssetsList = content;
            var collectiveAssetsData = template('collectiveAssetsData', module.data);
            $("#collectiveAssetsContent").html(collectiveAssetsData);
        }
    }

    //小型水利设施
    module.waterConservancyFacilities = function (data) {
        if (data.code == 200) {
            var content = data.data;
            console.log(content)
            module.data.waterConservancyFacilitiesList = content;
            var waterConservancyFacilitiesData = template('waterConservancyFacilitiesData', module.data);
            $("#waterConservancyFacilitiesContent").html(waterConservancyFacilitiesData);
        }
    }

    //农业生产设备
    module.productionEquipment = function (data) {
        if (data.code == 200) {
            var content = data.data;
            console.log(content)
            module.data.productionEquipmentList = content;
            var productionEquipmentData = template('productionEquipmentData', module.data);
            $("#productionEquipmentContent").html(productionEquipmentData);
        }
    }

    //成交公示列表
    module.announcementList = function (data) {
        if (data.code == 200) {
            var content = data.data;
            console.log(content)
            module.data.announcementListList = content;
            var announcementListData = template('announcementListData', module.data);
            $("#announcementListContent").html(announcementListData);
        }
    }

    //竞价大厅列表
    module.biddingHallList = function (data) {
        if (data.code == 200) {
            var content = data.data;
            console.log(content)
            module.data.biddingHallListList = 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.tabCheck('supply');
    }

    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)
    }

    //切换
    module.tabCheck = function (type) {
        document.getElementById('supply').style.display = 'none';
        document.getElementById('demand').style.display = 'none';
        document.getElementById(type).style.display = 'inline-table';
    }

    //用户资料鼠标悬浮
    module.userHover = function () {
        document.getElementById('userName').onmouseover = function(){
          document.getElementById('headHover').style.display = 'block';
        };
        document.getElementById('headHover').onmouseover = function(){
            document.getElementById('headHover').style.display = 'block';
        };
        document.getElementById('userName').onmouseout = function(){
            document.getElementById('headHover').style.display = 'none';
        };
        document.getElementById('headHover').onmouseout = function(){
            document.getElementById('headHover').style.display = 'none';
        };
    }
    return module;
});