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

            },
            modifyUrl:'',
            detailUrl:'',
            sheng:[],
            shi:[],
            sfzList:[],
            yhkList:[],
            sfz:'',
            yhk:'',
            khzm:'',
            companyLicense:'',
            activitiStatus:'',
            upType1:false,
            upType2:false,
            upType5:false,
        },
    };
    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(userData, {}, module.userData);

        if(!tools.getCookie('Admin-Token')){
            tools.skip('../../index.html')
        }
        //用户资料
        //tools.doPut(userData, {id:}, module.userData,true);

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

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

        //所属银行
        tools.doGet(dictionaries+"/bank_type_all", {}, module.bankType, true);

        //所属银行
        tools.doGet(dictionaries+"/deposit_status", {}, module.depositStatus, true);

        //账户类型
        tools.doGet(dictionaries+"/bank_account_type", {}, module.accountType, true);

        window.KindEditor.create('#editor_id')

        //console.log(tools.getParam('type'))

        var type = tools.getParam('type');

        module.getType(type);

        setTimeout(function(){
            //主题图片切换
            module.switchTheme();
        },2000)

        module.data.sheng = options;
        module.data.shi = options[0].children;
        var shengData = template('shengData', module.data);
        $("#sheng").html(shengData);
        var shiData = template('shiData', module.data);
        $("#shi").html(shiData);

    };

    getShi = function () {
        console.log($('#bankTypeData').val())
        // if (!$('#bankTypeData').val()){
        //     return;
        // }
        module.data.shi = module.data.sheng.filter(function (e) { return e.label == $('#sheng').val(); })[0].children;
        var shiData = template('shiData', module.data);
        $("#shi").html(shiData);

        // tools.doGet(depositList, {sheng:$('#sheng').val(),shi:$('#shi').val()}, module.depositList, true);
    }
    getDeposit = function () {
        let data = {
            sheng:$('#sheng').val(),
            shi:$('#shi').val(),
            bankType:$('#bankType').val(),
            bankDeposit:$('#bankDeposit').val(),
        }
        console.log(data)
        tools.doGet(depositListYN, data,module.depositListYN);
    }
    changeBankAddress = function () {
        console.log($('#bankAddress').val())
        console.log(module.data.bankAddress.filter(function (e) { return e.bankDeposit == $('#bankAddress').val(); }))

        document.getElementById('payeePaymentLines').value =
        module.data.bankAddress.filter(function (e) { return e.bankDeposit == $('#bankAddress').val(); })[0].payeePaymentLines;
    }

    module.depositListYN = function (data) {
        var content = data.rows;
        if (content.length<1){
            let dataHtt = {
                sheng:$('#sheng').val(),
                shi:$('#shi').val(),
                bankType:$('#bankType').val(),
                bankDeposit:$('#bankDeposit').val(),
            }
            tools.doPost(depositListPub, dataHtt,module.depositList);
        }else{
            module.data.bankAddress = content;
            var bankAddressData = template('bankAddressData', module.data);
            $("#bankAddress").html(bankAddressData);
            if (content.length>0){
                changeBankAddress();
            }else{
                document.getElementById('payeePaymentLines').value = '';
            }
        }
    }

    module.depositList = function (data) {
        var content = data.data;
        module.data.bankAddress = content;
        var bankAddressData = template('bankAddressData', module.data);
        $("#bankAddress").html(bankAddressData);
        if (content.length>0){
            // changeBankAddress();
        }else{
            document.getElementById('payeePaymentLines').value = '';
        }
    }

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

    //底部友情链接
    module.depositStatus = function (data) {
        if (data.code == 200) {
            var content = data.data;
            module.data.depositStatusOption = content;
        }
    }

    //账户类型
    module.accountType = function (data) {
        if (data.code == 200) {
            var content = data.data;
            module.data.accountTypeOption = content;
            var accountTypeData = template('accountTypeData', module.data);
            $("#accountType").html(accountTypeData);
        }
    }

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

        }
    }

    //主题图片切换
    module.switchTheme = function(){
        if(themeColor == 'red'){
            module.data.modifyUrl = '../../static/images/modify_red.png';
            module.data.detailUrl = '../../static/images/detail_red.png';
        }else if(themeColor == 'green'){
            module.data.modifyUrl = '../../static/images/modify.png';
            module.data.detailUrl = '../../static/images/detail.png';
        }
    }
    //底部友情链接
    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.getType = function(type){
        if (type == 'info'){
            document.getElementById("icon-list1").click();
        }
        if (type == 'demand'){
            document.getElementById("icon-list2").click();
        }
        if (type == 'interact'){
            document.getElementById("icon-list3").click();
        }
        if (type == 'bidding'){
            document.getElementById("icon-list4").click();
        }
        if (type == 'goDemand'){
            document.getElementById("icon-list2").click();
            document.getElementById("goSupply").click();
        }
        if (type == 'goInteract'){
            document.getElementById("icon-list3").click();
            document.getElementById("goRelease").click();
        }
        if (type == 'application'){
            document.getElementById("icon-list5").click();
        }
    }

    //个人中心用户信息
    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;
            console.log(data)
            module.data.userInformationDetail = content;
            module.data.memberType = content.memberType;
            module.data.activitiStatus = content.activitiStatus;
            var bankTypeData = template('bankTypeData', module.data);
            $("#bankType").html(bankTypeData);
            var bankAddressData = template('bankAddressData', module.data);
            $("#bankAddress").html(bankAddressData);
            document.getElementById('bankSubmitBtn').style.display = content.activitiStatus == '1'?'none':'block';
            if(content.memberType == '1'){
                document.getElementById('companyInformationContent').style.display = 'none';
                document.getElementById('userInformationContent').style.display = 'table';
                var userInformationData = template('userInformationData', module.data);
                $("#userInformationContent").html(userInformationData);
            }else{
                document.getElementById('companyInformationContent').style.display = 'table';
                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('bankType').value = content.bankType;
            document.getElementById('accountType').value = content.accountType;
            document.getElementById('payeePaymentLines').value = content.payeePaymentLines;
            document.getElementById('phone').innerHTML = content.phone;

            module.data.memberId = content.id;
            //console.log(module.data.userId)

            //用户图片
            module.showUserImage(content);
            //我的供求
            tools.doGet(userSupply, {memberId:content.id,pageNum:module.data.pageNum,pageSize:10}, 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);
            //我的报名
            tools.doGet(getSignupByMemberId, {memberId:content.id,pageNum:module.data.pageNum,pageSize:module.data.pageSize}, module.application);

            // tools.doPost(listHistory, {processInstanceId:content.instanceId}, module.listHistory);
            tools.doGet(listHistory, {auditbatchNo: content.auditbatchNo}, module.listHistory);
            //个人资料提交
            $('#supplyAction').on('click', module.supplyAction)
            $('#releaseAction').on('click', module.releaseAction)

            //获取附件的值
            //$('#upLoadBtn').on('click',module.upLoadAction)

            //document.getElementById('userAction').addEventListener('click',module.formAction);
        }
    }

    module.listHistory = function(data){
        if (data.code == 200) {
            var content = data.rows;
            /* content.forEach((row) => {
                row.startTime = tools.format(row.startTime, "yyyy-MM-dd HH:mm:ss");
                row.endTime = tools.format(row.endTime, "yyyy-MM-dd HH:mm:ss");
                row.durationInMillis = tools.formatTotalDateSub(
                    row.durationInMillis / 1000
                );
            }); */
            module.data.listHistory = content;
            var listHistoryData = template('listHistoryData', module.data);
            $("#listHistoryContent").html(listHistoryData);
        }
    }

    module.showUserImage = function(data){
        console.log(data)
            var accountOpenCert = data.accountOpenCert==null||data.accountOpenCert == ''?null:['/api'+data.accountOpenCert];
            var idCardPic = data.idCardPic==null||data.idCardPic == ''?null:['/api'+data.idCardPic];
            var companyLicense = data.companyLicense==null||data.companyLicense == ''?null:['/api'+data.companyLicense];

            console.log(accountOpenCert)
            console.log(idCardPic)
            if(module.data.memberType == '1'){
                var cupload2 = new Cupload ({
                    ele: '#cupload-3',
                    num: 1,
                    data:idCardPic
                });
                var cupload4 = new Cupload ({
                    ele: '#cupload-4',
                    num: 1,
                    data:accountOpenCert
                });
                module.data.sfz = data.idCardPic
                module.data.yhk = data.accountOpenCert
            }else{
                var cupload5 = new Cupload ({
                    ele: '#cupload-5',
                    num: 1,
                    data:accountOpenCert
                });
                var cupload6 = new Cupload ({
                    ele: '#cupload-6',
                    num: 1,
                    data:idCardPic
                });
                var cupload7 = new Cupload ({
                    ele: '#cupload-7',
                    num: 1,
                    data:companyLicense
                });
                module.data.khzm = data.accountOpenCert
                module.data.frzjz = data.idCardPic
                module.data.companyLicense = data.companyLicense
            }
    }

    module.showSupplyImage = function(data){
        //console.log(data)
        if (data.code == 200) {
            var content = data.data;
            var fileUrlList = [];
            var fileNum = [];
            for (var i = 0 ; i < content.length ; i++){
                fileUrlList[i] = serverApi + content[i].fileUrl ;
                fileNum[i] = content[i].id;
            }
            if (fileUrlList.length == 0){
                fileUrlList = '';
            }
            //console.log(fileUrlList)
            document.getElementById('cupload-1').innerHTML = '';
            module.data.fileNum = fileNum;
            var cupload1 = new Cupload ({
                ele: '#cupload-1',
                num: 5,
                data:fileUrlList
            });
        }
    }

    deleteList = function(){
         //console.log(module.data.fileNum[deleteNum])
        // tools.doGet(deleteUserImg+'/'+module.data.fileNum[deleteNum], {}, module.Tips);
    }

    module.getData = function(data){
        upLoadAction(data.data)
    }

     //获取上传图片list
    upLoadAction = function(type){
        //console.log(type)
        var upLoadList = [];
        var data = {};
        if(type == 'user'||type == 'company'){
            if(module.data.memberType == '1'){
                $('#cupload-3').find('input').each(function() {
                    if($(this).val()!=''&&$(this).val().indexOf('http') == -1){
                        upLoadList.push($(this).val())
                    }
                })
            }else{
                $('#cupload-5').find('input').each(function() {
                    if($(this).val()!=''&&$(this).val().indexOf('http') == -1){
                        upLoadList.push($(this).val())
                    }
                })
                data["files"] = upLoadList;
            }
            // tools.doPostImg(base64Upload, data, module.submitInfo());//memberType 1个人 2单位

        }else{
            $('#cupload-1').find('input').each(function() {
                if($(this).val()!=''&&$(this).val().indexOf('http') == -1){
                    upLoadList.push($(this).val())
                }
            })
            data["tableName"] = 't_transaction_supply_demand';
            data["tableId"] = type?type:module.data.supplyId;
            data["files"] = upLoadList;
            data["fileType"] = '';
            data["bizPath"] = 'transaction';
            tools.doPostImg(base64Attach, data, module.upLoadOver);//memberType 1个人 2单位
            setTimeout(function(){
                tools.doGet(userSupply, {memberId:module.data.memberId,pageNum:module.data.pageNum,pageSize:module.data.pageSize}, module.userSupply)
                document.getElementById('supplyInformation').style.display = "block";
                document.getElementById('releaseSupply').style.display = "none";
                $('#demandType').val('');
                $('#projectName').val('');
                $('#location').val('');
                $('#projectRealName').val('');
                $('#projectPhone').val('');
                $('#projectContent').val('');
            },2000)
        }
        // tools.initError('发布成功');
    }

    module.upLoadOver = function(type){

    }

    module.upLoadOverInfo1 = function(data){
        if (data.code == 200)
        module.data.sfz = data.fileName;
    }

    module.upLoadOverInfo2 = function(data){
        if (data.code == 200)
        module.data.yhk = data.fileName;
    }

    module.upLoadOverInfo5 = function(data){
        if (data.code == 200)
        module.data.khzm = data.fileName;
    }

    module.upLoadOverInfo6 = function(data){
        if (data.code == 200)
        module.data.frzjz = data.fileName;
    }

    module.upLoadOverInfo7 = function(data){
        if (data.code == 200)
        module.data.companyLicense = data.fileName;
    }

    submitInfo = function(type){
        var upLoadList = [];
        var data = {};
        console.log(type)
            console.log(module.data.memberType)
            if(module.data.memberType == '1'){
                $('#cupload-3').find('input').each(function() {
                    if($(this).val()!=''&&$(this).val().indexOf('/api') == -1){
                        module.data.upType1 = true;
                        tools.doPostImg(base64Upload, {file:$(this).val()}, module.upLoadOverInfo1);
                    }
                })
                $('#cupload-4').find('input').each(function() {
                    if($(this).val()!=''&&$(this).val().indexOf('/api') == -1){
                        module.data.upType2 = true;
                        tools.doPostImg(base64Upload, {file:$(this).val()}, module.upLoadOverInfo2);
                    }
                })
                console.log(type);
                setTimeout(function(){
                    formAction(type)
                },1000);

            }else{
                $('#cupload-5').find('input').each(function() {
                    if($(this).val()!=''&&$(this).val().indexOf('/api') == -1){
                        module.data.upType5 = true;
                        console.log('5')
                        tools.doPostImg(base64Upload, {file:$(this).val()}, module.upLoadOverInfo5);
                    }
                })
                $('#cupload-6').find('input').each(function() {
                    if($(this).val()!=''&&$(this).val().indexOf('/api') == -1){
                        module.data.upType6 = true;
                        console.log('6')
                        tools.doPostImg(base64Upload, {file:$(this).val()}, module.upLoadOverInfo6);
                    }
                })
                $('#cupload-7').find('input').each(function() {
                    if($(this).val()!=''&&$(this).val().indexOf('/api') == -1){
                        module.data.upType7 = true;
                        console.log('7')
                        tools.doPostImg(base64Upload, {file:$(this).val()}, module.upLoadOverInfo7);
                    }
                })
                setTimeout(function(){
                    formAction()
                },1000);
            }
            //memberType 1个人 2单位
    }

    //删除供求
    deleteUserSupply = function(ids){
        tools.doGet(deleteSupply+'/'+ids, {}, module.Tips);
    }

    //个人中心我的供求
    module.userSupply = function(data){
        //console.log(data)
        if (data.code == 200) {
            var content = data.rows;
            //console.log(data)
            var pageCount = (data.total/10).toFixed(0);
            if (pageCount < 1){
                pageCount = 1;
            }
            if(module.data.userSupplyInformationList == ''){
                $('.page_s1').html('');
                // 初始化 分页器
                var page_s1 = createPage('.page_s1');
                // 设置分页
                setPage(page_s1, {
                    pageTotal: data.total, // 数据总条数
                    pageSize: 10,    // 每页显示条数
                    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;
            //console.log(data )
            var pageCount = (data.total/module.data.pageSize).toFixed(0);
            if (pageCount < 1){
                pageCount = 1;
            }
            $('.page_s2').html('');
            // 初始化 分页器
            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);
        }
    }

    //个人中心我的报名
    module.application = 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.applicationInformationList == '') {
                console.log('aaaaaa')
                // 初始化 分页器
                var page_s1=createPage('.page_s4');
                // 设置分页
                setPage(page_s1, {
                    pageTotal: data.total, // 数据总条数
                    pageSize: module.data.pageSize,    // 每页显示条数
                    pageCurrent: 1,  //  当前页
                    maxBtnNum: 5,   // 最多按钮个数（最少5个）
                })
                $('#page_s4').html('共' + pageCount + '页')
            }
            content.forEach((res,index)=>{
                res.depositStatus = module.data.depositStatusOption.filter(function (e) { return e.dictValue == res.depositStatus; })[0].dictLabel;

                // setInterval(()=>{
                //     res.endTime = new Date(res.biddingStopTime) - new Date();
                //     if (res.endTime <= 0){
                //         document.getElementById('endTime'+res.id).innerHTML = '已结束'
                //         return;
                //     }
                //     document.getElementById('endTime'+res.id).innerHTML = TimeInterval(res.endTime)
                // },1000)
            })

            module.data.applicationInformationList = content;
            var applicationInformationData = template('applicationInformationData', module.data);
            $("#applicationInformationContent").html(applicationInformationData);
        }
    }


    TimeInterval = function(timestamp) {
        //时间戳转化为天时分秒
        // 总秒数
        var second = Math.floor(timestamp/ 1000);
        // 天数
        var day = Math.floor(second / 3600 / 24);
        // 小时
        var hr = Math.floor(second / 3600 % 24);
        // 分钟
        var min = Math.floor(second / 60 % 60);
        // 秒
        var sec = Math.floor(second % 60);
        return (day?day + "天":'') + (hr?hr+ "小时":'') + ( min?min + "分钟":'') + sec + "秒";

    }

    tabCheck = function(type){
        document.getElementById('user').className = '';
        // document.getElementById('bank').className = '';
        document.getElementById('passWord').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';
        document.getElementById('passWordInformationContent').style.display = 'none';
        if (module.data.memberType == '2' && type == 'user'){
            document.getElementById('companyInformationContent').style.display = 'table';
            document.getElementById('bankInformationContent').style.display = 'table';
        }else if (module.data.memberType == '1' && type == 'user'){
            document.getElementById('userInformationContent').style.display = 'table';
            document.getElementById('bankInformationContent').style.display = 'table';
        }else{
            document.getElementById(type+'InformationContent').style.display = 'table';
        }

    }

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

    tabLeftCheck = function(type){
        for (var i = 1 ; i < 6 ; 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';
        document.getElementById('applicationInformation').style.display = 'none';

        document.getElementById('releaseSupply').style.display = 'none';
        document.getElementById('release').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';
            $('#demandType').val('');
            $('#projectName').val('');
            $('#location').val('');
            $('#projectRealName').val('');
            $('#projectPhone').val('');
            $('#projectContent').val('');
        }
        if(type == 'icon-list3'){
            document.getElementById('consultingInformation').style.display = 'block';
            module.data.clickType = 'consulting';
            $('#title').val('');
            $('#releaseContent').val('');
            $('#releaseRealName').val('');
            $('#releasePhone').val('');
        }
        if(type == 'icon-list4'){
            document.getElementById('biddingInformation').style.display = 'block';
            module.data.clickType = 'bidding';
        }
        if(type == 'icon-list5'){
            document.getElementById('applicationInformation').style.display = 'block';
            module.data.clickType = 'application';
        }
        module.data.pageNum = 1 ;
    }

    goSupply = function(){
        document.getElementById('supplyInformation').style.display = "none";
        document.getElementById('releaseSupply').style.display = "block";
        document.getElementById('cupload-1').innerHTML = '';
        module.data.supplyType = 'add'
        var cupload1 = new Cupload ({
            ele: '#cupload-1',
            num: 5,
        });
    }

    gosupplyTable = function(){
        document.getElementById('supplyInformation').style.display = "block";
        document.getElementById('releaseSupply').style.display = "none";
        $('#demandType').val('');
        $('#projectName').val('');
        $('#location').val('');
        $('#projectRealName').val('');
        $('#projectPhone').val('');
        $('#projectContent').val('');
    }

    goRelease = function(){
        document.getElementById('consultingInformation').style.display = "none";
        document.getElementById('release').style.display = "block";
    }

    goReleaseTable = function(){
        document.getElementById('consultingInformation').style.display = "block";
        document.getElementById('release').style.display = "none";
        $('#title').val('');
        $('#releaseContent').val('');
        $('#releaseRealName').val('');
        $('#releasePhone').val('');
    }

    //翻页
    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);
        }
        if(module.data.clickType == 'application'){
            tools.doGet(getSignupByMemberId, {memberId:module.data.memberId,pageNum:module.data.pageNum,pageSize:module.data.pageSize}, module.application);
        }
    }

    //个人用户资料修改
    formAction = function (type){
        var data = {};
        //var password = $('#password').val();
        console.log(module.data.memberType == '2');
        // module.data.userFormType = type ;
        if(module.data.memberType == '2'){
            console.log('qqqqqqqqqqqqq')
            //公司用户信息
            var companyName = $('#companyName').val();
            var idCardNum = $('#idCardNum').val();
            var realname = $('#realname').val();
            var companyCode = $('#companyCode').val();
            var companyNature = $('#companyNature').val();
            var companyScope = $('#companyScope').val();
            var companyTimeLimit = $('#companyTimeLimit').val();
            var companySetupTime = $('#companySetupTime').val();
            var companyCapital = $('#companyCapital').val();
            var companyLicense = module.data.companyLicense;
            var address = $('#address').val();
            var accountOpenCert = module.data.khzm;
            var idCardPic = module.data.frzjz;


            //银行卡信息
            var bankCardName = $('#bankCardName').val();
            var bankCardNum = $('#bankCardNum').val();
            var bankAddress = $('#bankAddress').val();
            var bankType = $('#bankType').val();
            var accountType = $('#accountType').val();
            var payeePaymentLines = $('#payeePaymentLines').val();

            if (companyName == '') {
                $('#companyName')[0].focus()
                tools.initTips('请输入公司名称', 'right', $('#companyName')[0], 2000)
                return false;
            }

            if (idCardNum == '') {
                $('#idCardNum')[0].focus()
                tools.initTips('请输入身份证号', 'right', $('#idCardNum')[0], 2000)
                return false;
            }

            if (realname == '') {
                $('#realname')[0].focus()
                tools.initTips('请输入负责人姓名', 'right', $('#realname')[0], 2000)
                return false;
            }

            let array = []
            $('#cupload-5').find('input').each(function() {
                if($(this).val()!=''){
                    array.push($(this).val())
                }
            });
            if(array.length<1){
                $('#cupload-5')[0].focus()
                tools.initTips('请上传相关附件', 'right', $('#cupload-5')[0], 2000)
                return false;
            }

            let array6 = []
            $('#cupload-6').find('input').each(function() {
                if($(this).val()!=''){
                    array6.push($(this).val())
                }
            });
            if(array6.length<1){
                $('#cupload-6')[0].focus()
                tools.initTips('请上传法人证件照', 'right', $('#cupload-6')[0], 2000)
                return false;
            }

            if (bankCardName == '') {
                $('#bankCardName')[0].focus()
                tools.initTips('请输入开户姓名', 'right', $('#bankCardName')[0], 2000)
                return false;
            }

            if (bankCardNum == '') {
                $('#bankCardNum')[0].focus()
                tools.initTips('请输入开户账号', 'right', $('#bankCardNum')[0], 2000)
                return false;
            }

            if (bankType == '') {
                $('#bankType')[0].focus()
                tools.initTips('请选择所属银行', 'right', $('#bankType')[0], 2000)
                return false;
            }

            if (bankAddress == '') {
                $('#bankAddress')[0].focus()
                tools.initTips('请选择开户银行', 'right', $('#bankAddress')[0], 2000)
                return false;
            }

            if (payeePaymentLines == '') {
                $('#payeePaymentLines')[0].focus()
                tools.initTips('请输入联行号', 'right', $('#payeePaymentLines')[0], 2000)
                return false;
            }
            data['bankCardName'] = bankCardName;
            data['bankCardNum'] = bankCardNum;
            data['bankAddress'] = bankAddress;
            data['bankType'] = bankType;
            data['accountType'] = accountType;
            data['payeePaymentLines'] = payeePaymentLines;
            data['activitiStatus'] = module.data.activitiStatus;
            tools.setCookie('bankCardName',bankCardName,24 * 60 * 60)
            tools.setCookie('bankCardNum',bankCardNum,24 * 60 * 60)
            tools.setCookie('bankAddress',bankAddress,24 * 60 * 60)
            tools.setCookie('bankType',bankType,24 * 60 * 60)
            tools.setCookie('accountType',accountType,24 * 60 * 60)
            tools.setCookie('payeePaymentLines',payeePaymentLines,24 * 60 * 60)

            data['accountOpenCert'] = accountOpenCert;
            data['companyName'] = companyName;
            data['idCardNum'] = idCardNum;
            data['realname'] = realname;
            data['companyCode'] = companyCode;
            data['companyName'] = companyName;
            data['companyNature'] = companyNature;
            data['companyScope'] = companyScope;
            data['companyTimeLimit'] = companyTimeLimit;
            data['companySetupTime'] = companySetupTime;
            data['companyCapital'] = companyCapital;
            data['companyLicense'] = companyLicense;
            data['address'] = address;
            data['idCardPic'] = idCardPic;

            tools.setCookie('userName',realname,24 * 60 * 60)
            tools.setCookie('idCardNum',idCardNum,24 * 60 * 60)
            tools.setCookie('address',address,24 * 60 * 60)
            // upLoadAction('user');
        }
        if(module.data.memberType == '1'){
            //个人用户信息
            var userFormRealName = $('#userFormRealName').val();
            var userFormIdCard = $('#userFormIdCard').val();
            var userFormAddress = $('#userFormAddress').val();
            var idCardPic = module.data.sfz;
            var accountOpenCert = module.data.yhk;

            //银行卡信息
            var bankCardName = $('#bankCardName').val();
            var bankCardNum = $('#bankCardNum').val();
            var bankAddress = $('#bankAddress').val();
            var bankType = $('#bankType').val();
            var accountType = $('#accountType').val();
            var payeePaymentLines = $('#payeePaymentLines').val();

            if (userFormRealName == '') {
                $('#userFormRealName')[0].focus()
                tools.initTips('请输入姓名', 'right', $('#userFormRealName')[0], 2000)
                return false;
            }

            if (userFormIdCard == '') {
                $('#userFormIdCard')[0].focus()
                tools.initTips('请输入身份证号码', 'right', $('#userFormIdCard')[0], 2000)
                return false;
            }

            let array = []
            $('#cupload-3').find('input').each(function() {
                if($(this).val()!=''){
                    array.push($(this).val())
                }
            });
            if(array.length<1){
                $('#cupload-3')[0].focus()
                tools.initTips('请上传身份证', 'right', $('#cupload-3')[0], 2000)
                return false;
            }

            let array2 = []
            $('#cupload-4').find('input').each(function() {
                if($(this).val()!=''){
                    array2.push($(this).val())
                }
            });
            if(array2.length<1){
                $('#cupload-4')[0].focus()
                tools.initTips('请上传银行卡', 'right', $('#cupload-4')[0], 2000)
                return false;
            }


            if (bankCardName == '') {
                $('#bankCardName')[0].focus()
                tools.initTips('请输入开户姓名', 'right', $('#bankCardName')[0], 2000)
                return false;
            }

            if (bankCardNum == '') {
                $('#bankCardNum')[0].focus()
                tools.initTips('请输入开户账号', 'right', $('#bankCardNum')[0], 2000)
                return false;
            }

            if (bankType == '') {
                $('#bankType')[0].focus()
                tools.initTips('请选择所属银行', 'right', $('#bankType')[0], 2000)
                return false;
            }

            if (bankAddress == '') {
                $('#bankAddress')[0].focus()
                tools.initTips('请选择开户银行', 'right', $('#bankAddress')[0], 2000)
                return false;
            }

            if (payeePaymentLines == '') {
                $('#payeePaymentLines')[0].focus()
                tools.initTips('请输入联行号', 'right', $('#payeePaymentLines')[0], 2000)
                return false;
            }
            data['bankCardName'] = bankCardName;
            data['bankCardNum'] = bankCardNum;
            data['bankAddress'] = bankAddress;
            data['bankType'] = bankType;
            data['accountType'] = accountType;
            data['payeePaymentLines'] = payeePaymentLines;
            data['activitiStatus'] = module.data.activitiStatus;
            tools.setCookie('bankCardName',bankCardName,24 * 60 * 60)
            tools.setCookie('bankCardNum',bankCardNum,24 * 60 * 60)
            tools.setCookie('bankAddress',bankAddress,24 * 60 * 60)
            tools.setCookie('bankType',bankType,24 * 60 * 60)
            tools.setCookie('accountType',accountType,24 * 60 * 60)
            tools.setCookie('payeePaymentLines',payeePaymentLines,24 * 60 * 60)


            data['idCardPic'] = idCardPic;
            data['accountOpenCert'] = accountOpenCert;
            data['idCardNum'] = userFormIdCard;
            data['realname'] = userFormRealName;
            data['address'] = userFormAddress;

            tools.setCookie('userName',userFormRealName,24 * 60 * 60)
            tools.setCookie('idCardNum',userFormIdCard,24 * 60 * 60)
            tools.setCookie('address',userFormAddress,24 * 60 * 60)
            // upLoadAction('user');
        }

        //data['password'] = password;
        data['id'] = module.data.memberId;
        data['taskId'] = module.data.userInformationDetail.taskId;
        // data['taskName'] = module.data.userInformationDetail.taskName;

        tools.doPost(userUpdate, data, module.userTips)
    }

    module.userTips = function(data){
        tools.initError(data.msg);
        //用户资料
        tools.doGet(userData, {}, module.userData);
    }

    editPassword = function(){
        var data = {};
        if(module.passWordCompare()){
            var oldPassWord = $('#originalPassWord').val();
            var newPassWord = $('#newPassWord').val();
            data['oldPassword'] = oldPassWord;
            data['newPassword'] = newPassWord;
            tools.doPost(updatePwd, data, module.Tips)
        }
    }

    //手动验证密码是否一致
    module.passWordCompare = function(){
        var newPassword = $('#newPassWord').val();
        var determinePassWord = $('#determinePassWord').val();
        var originalPassWord = $('#originalPassWord').val();
        /*原密码*/
        if (originalPassWord == '') {
            $('#originalPassWord')[0].focus()
            tools.initTips('请输入原密码', 'right', $('#originalPassWord')[0], 2000)
            return false;
        }
        /* 新密码 */
        if (newPassword == '') {
            $('#newPassWord')[0].focus()
            tools.initTips('请输入新密码', 'right', $('#newPassWord')[0], 2000)
            return false;
        }
        /* 确认密码 */
        if (determinePassWord == '') {
            $('#determinePassWord')[0].focus()
            tools.initTips('请确认密码', 'right', $('#determinePassWord')[0], 2000)
            return false;
        }
        return true;
    }

    //发布供求
    module.supplyAction = function (){
        var data = {};
        if(module.supplyCheck()){
            //供求信息
            var demandType = $('#demandType').val();
            var projectName = $('#projectName').val();
            var location = $('#location').val();
            var projectRealName = $('#projectRealName').val();
            var projectPhone = $('#projectPhone').val();
            var projectContent = $('#projectContent').val();
            var logintime = tools.getNowFormatDate();

            //console.log(demandType);
            data['projectName'] = projectName;
            data['location'] = location;
            data['realname'] = projectRealName;
            data['phone'] = projectPhone;
            data['projectContent'] = projectContent;
            data['logintime'] = logintime;
            data['supplyDemandType'] = demandType;
            data['deptId'] = 100;

            data['memberId'] = module.data.memberId;

            if(module.data.supplyType == 'edit'){
                data['id'] = module.data.supplyId;
                tools.doPost(userEdit, data, module.getData)
            }else{
                tools.doPost(userDemand, data, module.getData)
            }

        }
    }

    //发布咨询
    module.releaseAction = function (){
        var data = {};
        if(module.releaseCheck()){
            //供求信息
            var title = $('#title').val();
            var releaseContent = $('#releaseContent').val();
            var releaseRealName = $('#releaseRealName').val();
            var releasePhone = $('#releasePhone').val();
            var logintime = tools.getNowFormatDate();

            data['title'] = title;
            data['content'] = releaseContent;
            data['realname'] = releaseRealName;
            data['phone'] = releasePhone;
            data['logintime'] = logintime;
            data['deptId'] = 100;
            data['memberId'] = module.data.memberId;

            tools.doPost(userCommunicate, data, module.releaseActionYes)
        }
    }
    module.releaseActionYes = function(data){
        tools.initError(data.msg);
        setTimeout(function(){
            tools.doGet(userConsulting, {memberId:module.data.memberId,pageNum:module.data.pageNum,pageSize:module.data.pageSize}, module.consulting);
            document.getElementById('consultingInformation').style.display = "block";
            document.getElementById('release').style.display = "none";
            $('#title').val('');
            $('#releaseContent').val('');
            $('#releaseRealName').val('');
            $('#releasePhone').val('');
        },2000)

    }
    module.Tips = function(data){

        tools.initError(data.msg);
    }

    //手动验证表单
    module.check = function () {
        var usernameVal = $('#username').val();
        var passwordVal = $('#password').val();
        var codeVal = $('#code').val();
        /* 手机号 */
        if (usernameVal == '') {
            $('#username')[0].focus()
            tools.initTips('请输入用户名', 'right', $('#username')[0], 2000)
            return false;
        }
        /* 密码 */
        if (passwordVal == '') {
            $('#password')[0].focus()
            tools.initTips('请输入密码', 'right', $('#password')[0], 2000)
            return false;
        } else if (parseInt(passwordVal.length) < 6 || parseInt(passwordVal.length) > 18) {
            $('#password')[0].focus()
            tools.initTips('请输入正确格式密码', 'right', $('#password')[0], 2000)
            return false;
        }
        /*图形验证码*/
        if (module.uuid == '' || codeVal == '') {
            $('#code')[0].focus()
            tools.initTips('请输入图形验证码', 'right', $('#code')[0], 2000)
            return false;
        }
        return true;
    }

    module.supplyCheck = function () {
        var projectName = $('#projectName').val();
        var location = $('#location').val();
        var projectRealName = $('#projectRealName').val();
        var projectPhone = $('#projectPhone').val();
        var projectContent = $('#projectContent').val();
        if (projectName == '') {
            $('#projectName')[0].focus()
            tools.initTips('请输入项目名称', 'right', $('#projectName')[0], 2000)
            return false;
        }
        if (location == '') {
            $('#location')[0].focus()
            tools.initTips('请输入项目地址', 'right', $('#location')[0], 2000)
            return false;
        }
        if (projectRealName == '') {
            $('#projectRealName')[0].focus()
            tools.initTips('请输入姓名', 'right', $('#projectRealName')[0], 2000)
            return false;
        }
        if (projectPhone == '') {
            $('#projectPhone')[0].focus()
            tools.initTips('请输入联系电话', 'right', $('#projectPhone')[0], 2000)
            return false;
        }
        if (projectContent == '') {
            $('#projectContent')[0].focus()
            tools.initTips('请输入项目详情', 'right', $('#projectContent')[0], 2000)
            return false;
        }
        return true;
    }

    module.releaseCheck = function () {
        var title = $('#title').val();
        var releaseContent = $('#releaseContent').val();
        var releaseRealName = $('#releaseRealName').val();
        var releasePhone = $('#releasePhone').val();
        if (title == '') {
            $('#title')[0].focus()
            tools.initTips('请输入标题', 'right', $('#title')[0], 2000)
            return false;
        }
        if (releaseContent == '') {
            $('#releaseContent')[0].focus()
            tools.initTips('请输入咨询内容', 'right', $('#releaseContent')[0], 2000)
            return false;
        }
        if (releaseRealName == '') {
            $('#releaseRealName')[0].focus()
            tools.initTips('请输入姓名', 'right', $('#releaseRealName')[0], 2000)
            return false;
        }
        if (releasePhone == '') {
            $('#releasePhone')[0].focus()
            tools.initTips('请输入联系电话', 'right', $('#releasePhone')[0], 2000)
            return false;
        }
        return true;
    }

    //个人中心选项卡鼠标悬浮
    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(){
            if(themeColor == 'red'){
                document.getElementById('icon1').src = '../../static/images/user_index_icon5_red.png'
            }else if(themeColor == 'green'){
                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(){
            if(themeColor == 'red'){
                document.getElementById('icon2').src = '../../static/images/user_index_icon6_red.png'
            }else if(themeColor == 'green') {
                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(){
            if(themeColor == 'red'){
                document.getElementById('icon3').src = '../../static/images/user_index_icon7_red.png'
            }else if(themeColor == 'green') {
                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(){
            if(themeColor == 'red'){
                document.getElementById('icon4').src = '../../static/images/user_index_icon8_red.png'
            }else if(themeColor == 'green') {
                document.getElementById('icon4').src = '../../static/images/user_index_icon8.png'
            }
        }

        document.getElementById('icon-list5').onmouseout = function(){
            document.getElementById('icon5').src = '../../static/images/user_index_icon9.png'
        }
        document.getElementById('icon-list5').onmouseover = function(){
            if(themeColor == 'red'){
                document.getElementById('icon5').src = '../../static/images/user_index_icon9_red.png'
            }else if(themeColor == 'green') {
                document.getElementById('icon5').src = '../../static/images/user_index_icon10.png'
            }
        }


    }

    goSearch = function () {
        var searchTitle = $('#searchTitle').val();
        var searchContent = $('#searchContent').val();
        //console.log(searchTitle)
        module.data.searchType = 'YES';
        tools.doGet(userConsulting,{title:searchTitle,content:searchContent,memberId:module.data.memberId,pageNum:module.data.pageNum,pageSize:module.data.pageSize},module.consulting);
    }

    selectUserSupply = function(ids) {
        module.data.supplyType = 'edit';
        module.data.supplyId = ids;

        //console.log('点击修改')
        tools.doGet(selectSupply + '/' + ids, {}, module.selectSupplyDetail);//memberType 1个人 2单位
    }
    module.selectSupplyDetail = function(data){
        console.log('进入修改供求')
        document.getElementById('supplyInformation').style.display = "none";
        document.getElementById('releaseSupply').style.display = "block";

        var content = data.data

        $('#demandType').val(content.supplyDemandType);
        $('#projectName').val(content.projectName);
        $('#location').val(content.location);
        $('#projectRealName').val(content.realname);
        $('#projectPhone').val(content.phone);
        $('#projectContent').val(content.projectContent);

        tools.doGet(supplyDemandImg+'/'+content.id, {}, module.showSupplyImage);
    }

    goProject = function(id){
        tools.skip('../listingItems/itemsDetail.html?id='+id)
    }

    openBiddingList = function(id){
        tools.doGet(userBiddingList, {projectId:id,memberId:module.data.memberId}, module.openBidding);
    }

    module.openBidding = function(data){
        $('#dialog-01').css('display','block')

        if (data.code == 200) {
            var content = data.rows;
            module.data.moneyList = content;
            var biddingMoneyData = template('biddingMoneyData', module.data);
            $("#biddingMoneyContent").html(biddingMoneyData);
        }

    }

    return module;
});
