/**
 * Created by Administrator on 2021/4/5.
 */
define(['jquery', "template", "Tools"], function ($, template, Tools) {
    //数据存储
    var module = {
        data: {
            //服务器地址
            serverApi:'',
            //焦点图数据
            focusList: [],
            communicateList: [],
        },
    };
    var tools = new Tools();

    module.init = function (page) {
        //新闻详情
        tools.doGet(contractionList, {
            code:getQueryVariable('id'),
            translate_dict: '1',
            bookId: JSON.parse(tools.getCookie('user')).bookId,
            deptId: JSON.parse(tools.getCookie('user')).deptId
        }, module.newsDetail , true);
        //新闻列表
        tools.doGet(contractionList, {
            pageNum:1,
            pageSize:10,
            orderByColumn: 'buildingTime',
            isAsc: 'desc',
            translate_dict: '1',
            bookId: JSON.parse(tools.getCookie('user')).bookId,
            deptId: JSON.parse(tools.getCookie('user')).deptId
        }, module.newsList , true);
        tools.doGet(webList, {}, module.webList , 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.webList = function (data) {
        if (data.code == 200) {
            var content = data.data;
            module.data.webList = content;
            var webData = template('webData', module.data);
            $("#webContent").html(webData);
            $('#ewm').attr('src', 'static/images/'+content.top.bz);
        }
    }

    module.newsDetail = function (data) {
        if (data.code == 200) {
            var content = data.rows[0];
            $('#name').html(content.name);
            $('#code').html('合同编码：' + content.code);
            $('#biddingType').html('合同类型：'+(content.assetType || ''));
            $('#secondParty').html('合同乙方：'+(content.secondParty || ''));
            $('#settleType').html('结款方式：'+(content.settleType || ''));
            $('#totalAmount').html('合同金额：'+(content.totalAmount || '') + '元');
            $('#settledAmount').html('已结款：'+(content.settledAmount || '') + '元');
            $('#receivedAmount').html('下次应结：'+(content.receivedAmount || '') + '元');
            $('#num').html('数量：'+(content.num || ''));
            $('#unit').html('单位：'+(content.unit || ''));
            $('#buildingTime').html('签订日期：'+(content.buildingTime || ''));
            $('#startTime').html('开始日期：'+(content.startTime || ''));
            $('#endTime').html('结束日期：'+(content.endTime || ''));
            //新闻列表
            tools.doGet(attachmentList, {
                tableId: content.id,
                tableName: 't_contraction_info',
                bizPath: 'contraction',
            }, module.NewsInformation , true);
        }
    }
    module.NewsInformation = function (data) {
        console.log(data)
        if (data.code == 200) {
            var content = data.rows;
            let list = [];
            content.map(rr=>{
                list.push({
                    fileUrl:rr.fileUrl,
                    fileName:rr.fileName
                })
            })
            module.data.attachmentList = list;
            var attachmentListData = template('attachmentListData', module.data);
            $("#attachmentListContent").html(attachmentListData);
        }
    }

    module.newsList = function (data) {
        if (data.code == 200) {
            var content = data.rows;
            module.data.newList = content;
            var newListData = template('newListData', module.data);
            $("#newListContent").html(newListData);
        }
    }

    return module;
});
