/**
 * Created by Administrator on 2021/4/5.
 */
define(['jquery', "template", "Tools", "announApi", "paging", 'swiper'], function ($, template, Tools ) {
    //数据存储
    var module = {
        data: {
            //焦点图数据
            focusListTop: [],
            announcementInformationDetail:'',
        },
    };
    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.doGet(attestationDetail+'/'+getQueryVariable('id'), {}, module.announInformation,true);
        //网站配置信息（网站名称 底部联系方式 公安备案号 网站备案号）
        tools.getWebConfig();
    };

    //焦点图数据
    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.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);
        }
    }

    //项目公告数据
    module.announInformation = function (data) {
        if (data.code == 200) {
            //console.log(data)
            var content = data.data;
            module.data.announcementInformationDetail = content;
            var announcementInformationData = template('announcementInformationData', module.data);
            $("#announcementInformationContent").html(announcementInformationData);
            //公司性质字典
            tools.doGet(Dictionaries+'/company_nature', {}, module.companyDictionaries,true);
            //流转方向字典
            tools.doGet(Dictionaries+'/rollout_type', {}, module.circulationDictionaries,true);
            //交易方式字典
            tools.doGet(Dictionaries+'/deal_type', {}, module.transactionDictionaries,true);
            //面积单位字典
            tools.doGet(Dictionaries+'/area_unit', {}, module.areaDictionaries,true);
            //成交价格字典
            tools.doGet(Dictionaries+'/price_unit', {}, module.unitDictionaries,true);
        }
    }

    //流转方向
    module.circulationDictionaries = function (data) {
        if (data.code == 200) {
            var content = data.data;
            var rollout = content[(module.data.announcementInformationDetail.rollout-1)].dictLabel;
            module.data.announcementInformationDetail.rollout = rollout;
            var announcementInformationData = template('announcementInformationData', module.data);
            $("#announcementInformationContent").html(announcementInformationData);
        }
    }

    //公司性质
    module.companyDictionaries = function (data) {
        if (data.code == 200) {
            var content = data.data;
            var companyNature = content[(module.data.announcementInformationDetail.companyNature-1)].dictLabel;
            module.data.announcementInformationDetail.companyNature = companyNature;
            var announcementInformationData = template('announcementInformationData', module.data);
            $("#announcementInformationContent").html(announcementInformationData);
        }
    }


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

    //面积单位
    module.areaDictionaries = function (data) {
        if (data.code == 200) {
            var content = data.data;
            var allCountUnit = content[(module.data.announcementInformationDetail.allCountUnit-1)].dictLabel;
            module.data.announcementInformationDetail.allCountUnit = allCountUnit;
            var announcementInformationData = template('announcementInformationData', module.data);
            $("#announcementInformationContent").html(announcementInformationData);
        }
    }

    //成交价格单位
    module.unitDictionaries = function (data) {
        if (data.code == 200) {
            var content = data.data;
            var unit = content[(module.data.announcementInformationDetail.unit-1)].dictLabel;
            module.data.announcementInformationDetail.unit = unit;
            var announcementInformationData = template('announcementInformationData', module.data);
            $("#announcementInformationContent").html(announcementInformationData);
        }
    }

    return module;
});