/**
 * Created by Administrator on 2021/4/5.
 */
define(['jquery', "template", "Tools", 'swiper', 'itemsApi',"cupload"], function ($, template, Tools, swiper) {
    //数据存储
    var module = {
        data: {
            showImgInformationDetail:''
        },
    };
    var tools = new Tools();

    module.init = function (page) {//底部友情链接
        tools.doGet(friendsLinks, {}, module.bottomFriendsLinks, true);
        document.getElementById('realName').value = tools.getCookie('userName');
        document.getElementById('userNum').value = tools.getCookie('phone');
        document.getElementById('userBank').value = tools.getCookie('bankAddress');
        document.getElementById('bankId').value = tools.getCookie('bankCardNum');
        document.getElementById('idCard').value = tools.getCookie('idCardNum');
        //项目基本信息
        tools.doGet(outProject + '/id/'+getQueryVariable('id'), {}, module.outProjectInformation,true);
        //网站配置信息（网站名称 底部联系方式 公安备案号 网站备案号）
        tools.getWebConfig();
    };
    //底部友情链接
    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);
        }
    }

    //获取地址栏参数
    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);
    }

    //获取上传图片list
    module.upLoadAction = function(data){
        console.log(data)
        if (data.msg != '操作成功'){
            tools.initError(data.msg);
            return;
        }else{
            var upLoadList = [];
            var dataList = {};
            $('#cupload-3').find('input').each(function() {
                if($(this).val()!=''){
                    upLoadList.push($(this).val())
                }
            });
            dataList["files"] = upLoadList;
            dataList["tableId"] = data.data;
            dataList["fileType"] = '';
            dataList["bizPath"] = 'transaction';
            dataList["tableName"] = 't_transaction_signup';
            console.log(dataList)
            tools.doPostImg(base64Upload, dataList, module.upLoadOver);
        }
    }

    module.upLoadOver = function(data){
        tools.initError('提交申请，等待审核')
        setTimeout(function () {
            tools.skip('itemsDetail.html?id='+getQueryVariable('id'))
        },2000)
    }

    module.outProjectInformation = function (data) {
        if (data.code == 200) {
            console.log(data)
            var content = data.data;
            $("#projectTitle").html('项目名称：'+content.projectName);
            $("#projectNum").html('需缴纳保证新：'+content.deposit+'元');
            var cupload2 = new Cupload ({
                ele: '#cupload-3',
                num: 5,
            });
        }
    }

    submit  = function(){

        var data = {};
        var realName = $('#realName').val();
        var userNum = $('#userNum').val();
        var userBank = $('#userBank').val();
        var bankId = $('#bankId').val();
        var idCard = $('#idCard').val();

        data['projectId'] = getQueryVariable('id');
        data['memberId'] = tools.getCookie('memberId');
        data['realname'] = realName;
        data['idCardNum'] = idCard;
        data['phone'] = userNum;
        data['address'] = tools.getCookie('address');
        data['bankAddress'] = userBank;
        data['bankCardName'] = tools.getCookie('userName');
        data['bankCardNum'] = bankId;
        data['status'] = 'Y';

        tools.doPost(signupSubmit, data, module.upLoadAction);


    }

    module.toTips = function(data){
        console.log(data)
        if(data.msg != '操作成功'){
            tools.initError(data.msg)
        }else{
            tools.initError('提交申请，等待审核')
        }
    }
    return module;
});