/**
 * Created by Administrator on 2021/4/5.
 */
define(['jquery', "template", "Tools", "demandApi", "paging","user", 'swiper'], function ($, template, Tools ) {
    //数据存储
    var module = {
        data: {
            //焦点图数据
            focusListTop: [],
            //公告列表
            demandInformationList:'',
            //鉴证列表
            supplyInformationList:'',
            //页码
            pageNum: 1,
            //页码集合
            pageList: [],
            //每页数量
            pageSize: 50,
            //总页数
            pageCount:0,
            //选中卡ID
            clickType:'supply',
            //供求类型    1:供应  2:求购  （不传值获取两种类型混合数据）
            demandType:1
        },
    };
    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();

        tools.doGet(userDemandUpdate+'/'+getQueryVariable('id'), {}, module.demandDetail,true);
    };


    //焦点图数据
    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.demandDetail = function(data){
        if (data.code == 200) {
            var content = data.data;
            //console.log(content)
            module.data.demandInformationDetail = content;
            tools.doGet(demandImageList+'/'+getQueryVariable('id'), {}, module.demandImageDetail,true);
        }
    }
    //底部友情链接
    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.demandImageDetail = function(data){
        //console.log(data)
        if (data.code == 200){
            var content = data.data;
            var fileUrlList = [];
            for (var i = 0 ; i < content.length ; i++){
                fileUrlList[i] = serverApi+content[i].fileUrl;
            }
            module.data.demandInformationDetail.fileUrlList = fileUrlList;
            var demandInformationData = template('demandInformationData', module.data);
            $("#demandInformationContent").html(demandInformationData);
            $("#projectContent").html(module.data.demandInformationDetail.projectContent);
        }
    }
    return module;
});