/**
 * Created by Administrator on 2021/4/5.
 */
define(['jquery', "template", "Tools", "user", "paging"], function ($, template, Tools) {
    //数据存储
    var module = {
        data: {
            userInformationDetail:[],
            userSupplyInformationList:'',
            consultingInformationList:'',
            biddingInformationList:'',
            //页码
            pageNum: 1,
            //页码集合
            pageList: [],
            //每页数量
            pageSize: 1,
            //总页数
            pageCount:0,
            //用户ID
            memberId:0,
            //用户资料form
            form:{

            }
        },
    };
    var tools = new Tools();

    module.init = function (page) {

        //用户资料
        tools.doGet(userData, {}, module.userData);

        //用户资料
        //tools.doPut(userData, {id:}, module.userData,true);

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

        //个人中心选项卡鼠标悬浮
        module.userListHover();
    };

    //个人中心用户信息
    module.userData = function(data){
        if (data.code == 200) {
            var content = data.user;
            console.log(content)
            tools.doGet(userMember+'/'+content.userId, {}, module.userMember);//memberType 1个人 2单位
        }
    }

    //个人中心用户资料
    module.userMember = function(data){
        if (data.code == 200) {
            var content = data.data;
            console.log(data)
            module.data.userInformationDetail = content;
            module.data.memberType = content.memberType;
            if(content.memberType == '1'){
                document.getElementById('companyInformationContent').style.display = 'none';
                document.getElementById('userInformationContent').style.display = 'block';
                var userInformationData = template('userInformationData', module.data);
                $("#userInformationContent").html(userInformationData);
            }else{
                document.getElementById('companyInformationContent').style.display = 'block';
                document.getElementById('userInformationContent').style.display = 'none';
                var companyInformationData = template('companyInformationData', module.data);
                $("#companyInformationContent").html(companyInformationData);
            }
            document.getElementById('bankAddress').value = content.bankAddress;
            document.getElementById('bankCardName').value = content.bankCardName;
            document.getElementById('bankCardNum').value = content.bankCardNum;
            document.getElementById('phone').innerHTML = content.phone;
            module.data.memberId = content.id;
            console.log(content.memberType)

            //我的供求
            tools.doGet(userSupply, {memberId:content.id,pageNum:module.data.pageNum,pageSize:module.data.pageSize}, module.userSupply);
            //我的咨询
            tools.doGet(userConsulting, {memberId:content.id,pageNum:module.data.pageNum,pageSize:module.data.pageSize}, module.consulting);
            //我的竞价
            tools.doGet(userBidding, {memberId:content.id,pageNum:module.data.pageNum,pageSize:module.data.pageSize}, module.bidding);
        }
    }

    //个人中心我的供求
    module.userSupply = function(data){
        console.log(data)
        if (data.code == 200) {
            var content = data.rows;
            console.log(data)
            var pageCount = (data.total/module.data.pageSize).toFixed(0);
            if (pageCount < 1){
                pageCount = 1;
            }
            if(module.data.userSupplyInformationList == '') {
                // 初始化 分页器
                var page_s1 = createPage('.page_s1');
                // 设置分页
                setPage(page_s1, {
                    pageTotal: data.total, // 数据总条数
                    pageSize: module.data.pageSize,    // 每页显示条数
                    pageCurrent: 1,  //  当前页
                    maxBtnNum: 5,   // 最多按钮个数  （最少5个）
                })
                $('#page_s1').html('共' + pageCount + '页')
            }
            module.data.userSupplyInformationList = content;
            var userSupplyInformationData = template('userSupplyInformationData', module.data);
            $("#userSupplyInformationContent").html(userSupplyInformationData);
        }
    }

    //个人中心我的咨询
    module.consulting = function(data){
        if (data.code == 200) {
            var content = data.rows;
            var pageCount = (data.total/module.data.pageSize).toFixed(0);
            if (pageCount < 1){
                pageCount = 1;
            }
            if(module.data.consultingInformationList == '') {
                // 初始化 分页器
                var page_s1 = createPage('.page_s2');
                // 设置分页
                setPage(page_s1, {
                    pageTotal: data.total, // 数据总条数
                    pageSize: module.data.pageSize,    // 每页显示条数
                    pageCurrent: 1,  //  当前页
                    maxBtnNum: 5,   // 最多按钮个数  （最少5个）
                })
            }
            module.data.consultingInformationList = content;
            $('#page_s2').html('共'+pageCount+'页')
            var consultingInformationData = template('consultingInformationData', module.data);
            $("#consultingInformationContent").html(consultingInformationData);
        }
    }

    //个人中心我的竞价
    module.bidding = function(data){
        if (data.code == 200) {
            var content = data.rows;
            console.log(content)
            var pageCount = (data.total/module.data.pageSize).toFixed(0);
            if (pageCount < 1){
                pageCount = 1;
            }
            if(module.data.biddingInformationList == '') {
                // 初始化 分页器
                var page_s1=createPage('.page_s3');
                // 设置分页
                setPage(page_s1, {
                    pageTotal: data.total, // 数据总条数
                    pageSize: module.data.pageSize,    // 每页显示条数
                    pageCurrent: 1,  //  当前页
                    maxBtnNum: 5,   // 最多按钮个数  （最少5个）
                })
                $('#page_s3').html('共' + pageCount + '页')
            }
            module.data.biddingInformationList = content;
            var biddingInformationData = template('biddingInformationData', module.data);
            $("#biddingInformationContent").html(biddingInformationData);
        }
    }

    tabCheck = function(type){
        document.getElementById('user').className = '';
        document.getElementById('bank').className = '';
        document.getElementById(type).className = 'active';

        console.log(type)
        document.getElementById('userInformationContent').style.display = 'none';
        document.getElementById('companyInformationContent').style.display = 'none';
        document.getElementById('bankInformationContent').style.display = 'none';
        document.getElementById('phoneInformationContent').style.display = 'none';
        if (module.data.memberType == '2' && type == 'user'){
            document.getElementById('companyInformationContent').style.display = 'block';
        }else if (module.data.memberType == '1' && type == 'user'){
            document.getElementById('userInformationContent').style.display = 'block';
        }else{
            document.getElementById(type+'InformationContent').style.display = 'block';
        }

    }

    phoneUpdate = function(type){
        document.getElementById(type+'InformationContent').style.display = 'none';
        document.getElementById('phoneInformationContent').style.display = 'block';
    }

    tabLeftCheck = function(type){
        for (var i = 1 ; i < 5 ; i++){
            document.getElementById('icon-list'+i).className = '';
        }
        document.getElementById(type).className = 'active';
        document.getElementById('userInformation').style.display = 'none';
        document.getElementById('supplyInformation').style.display = 'none';
        document.getElementById('consultingInformation').style.display = 'none';
        document.getElementById('biddingInformation').style.display = 'none';
        if(type == 'icon-list1'){
            document.getElementById('userInformation').style.display = 'block';
        }
        if(type == 'icon-list2'){
            document.getElementById('supplyInformation').style.display = 'block';
            module.data.clickType = 'supply';
        }
        if(type == 'icon-list3'){
            document.getElementById('consultingInformation').style.display = 'block';
            module.data.clickType = 'consulting';
        }
        if(type == 'icon-list4'){
            document.getElementById('biddingInformation').style.display = 'block';
            module.data.clickType = 'bidding';
        }
        module.data.pageNum = 1 ;
    }

    //翻页
    turnThePage = function (pageNum) {
        module.data.pageNum = pageNum ;
        if(module.data.clickType == 'supply'){
            tools.doGet(userSupply, {memberId:module.data.memberId,pageNum:pageNum,pageSize:module.data.pageSize}, module.userSupply);
        }
        if(module.data.clickType == 'consulting'){
            tools.doGet(userConsulting, {memberId:module.data.memberId,pageNum:pageNum,pageSize:module.data.pageSize}, module.consulting);
        }
        if(module.data.clickType == 'bidding'){
            tools.doGet(userBidding, {memberId:module.data.memberId,pageNum:pageNum,pageSize:module.data.pageSize}, module.bidding);
        }
    }

    //个人用户资料修改
    formAction = function (name,value){
        console.log(name+'-------'+value)
        return;
        module.data.form.name = value ;
        console.log(module.data.form)
    }

    //个人中心选项卡鼠标悬浮
    module.userListHover = function(){
        document.getElementById('icon-list1').onmouseout = function(){
            document.getElementById('icon1').src = '../../static/images/user_index_icon1.png'
        }
        document.getElementById('icon-list1').onmouseover = function(){
            document.getElementById('icon1').src = '../../static/images/user_index_icon5.png'
        }

        document.getElementById('icon-list2').onmouseout = function(){
            document.getElementById('icon2').src = '../../static/images/user_index_icon2.png'
        }
        document.getElementById('icon-list2').onmouseover = function(){
            document.getElementById('icon2').src = '../../static/images/user_index_icon6.png'
        }

        document.getElementById('icon-list3').onmouseout = function(){
            document.getElementById('icon3').src = '../../static/images/user_index_icon3.png'
        }
        document.getElementById('icon-list3').onmouseover = function(){
            document.getElementById('icon3').src = '../../static/images/user_index_icon7.png'
        }

        document.getElementById('icon-list4').onmouseout = function(){
            document.getElementById('icon4').src = '../../static/images/user_index_icon4.png'
        }
        document.getElementById('icon-list4').onmouseover = function(){
            document.getElementById('icon4').src = '../../static/images/user_index_icon8.png'
        }


    }

    //用户资料鼠标悬浮
    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;
});