layui.config({
    base: '../../js/layuiModules/',   // 第三方模块所在目录
    version: 'v1.6.4' // 插件版本号
}).extend({
    soulTable: 'notice,layNotify',	// 模块
});
let form;
var tree;
var table;
var notice;
var layNotify;
const token = localStorage.getItem("token");
$("#resetBt").click(function(){
    table.reload('menuTable', {
        url: ctxPath + '/proProgress/getBasicDataList'
        , method: 'post' //方式默认是get
        , where: {
            keyWord:  "",
            orgId: "",
            voltageLevel: "",
        } //设定异步数据接口的额外参数
    });
    $("#keyWord").val("");
    getVoltageLevel(form,"");
    getOrgName(form,"");
})
$("#searchBt").click(function(){
    table.reload('menuTable', {
        url: ctxPath + '/proProgress/getBasicDataList'
        , method: 'post' //方式默认是get
        , where: {
            keyWord:  $("#keyWord").val(),
            voltageLevelId: $("#volLevelIds").val(),
            orgId: $("#orgId").val(),
        } //设定异步数据接口的额外参数
    });
})
$("#exportBt").click(function(){
    keyWord = $("#keyWord").val();
    voltageLevelId = $("#volLevelIds").val();
    orgId = $("#orgId").val();
    window.location.href = ctxPath + "/proProgress/exportPhysicalCheckResult?"
        +"keyWord=" + keyWord
        + "&voltageLevelId=" + voltageLevelId
        + "&orgId=" + orgId
        + "&type=" + '1'
        + "&token=" + token; //下载文件
})


layui.use(['table', 'form','notice', 'layNotify','element'], function () {
    table = layui.table;
    form = layui.form;
    tree = layui.tree;
    notice = layui.notice;
    layNotify = layui.layNotify;
    var element = layui.element;
    getVoltageLevel(form,"");
    getOrgName(form,"");
    //渲染表格
    table.render({
        elem: '#demo'
        , url: ctxPath + '/proProgress/getBasicDataList' //数据接口

        , method: 'post' //方式默认是get
        , toolbar: 'default' //开启工具栏，此处显示默认图标，可以自定义模板，详见文档
        , where: {} //post请求必须加where ，post请求需要的参数
        , cellMinWidth: 80
        , cols: [[ //表头
            {
                field: 'number', width:80,title: '序号', align: 'center', type: 'numbers', templet: d => {
                    return '<div style="margin-left: 26px;width: 25px;height: 25px;background-color: rgb(255, 152, 0);border: none;border-radius: 5px;font-family: "Roboto Bold", "Roboto Regular", Roboto, sans-serif;font-weight: 700;font-style: normal;font-size: 12px;color: rgb(255, 255, 255);">d.number</div>';
                }
            }
            , {field: 'orgName', align: 'center', title: '分公司'}
            , {field: 'proName', align: 'center', title: '工程名称'}
            , {field: 'voltageLevel', align: 'center', title: '电压等级'}
            , {
                field: 'progress', title: '项目进度', align: 'center', templet: d => {
                    return '<div class="layui-progress layui-progress-big" lay-showPercent="true"><div class="layui-progress-bar" lay-percent="'+d.progress+'%"></div></div>';
                }
            }
            , {field: 'updateTime',  align: 'center', title: '最后更新时间'}
            , {fixed: 'right', title: '操作', align: 'center', toolbar: '#toolsBar'}
        ]]
        ,done: function (res, curr, count) {
            element.render();
        }
        , id: 'menuTable'
        , page: true //开启分页
        , loading: true //数据加载中。。。
        , limits: [5, 10, 20, 100]  //一页选择显示3,5或10条数据
        , limit: 10  //一页显示5条数据
        , response: {
            statusCode: 200 //规定成功的状态码，默认：0
        }, parseData: function (res) { //将原始数据解析成 table 组件所规定的数据，res为从url中get到的数据
            let result;
            if (res.data !== '' && res.data != null && res.data !== "null") {
                if (this.page.curr) {
                    result = res.data.slice(this.limit * (this.page.curr - 1), this.limit * this.page.curr);
                } else {
                    result = res.data.slice(0, this.limit);
                }
            }
            return {
                "code": res.code, //解析接口状态
                "msg": res.msg, //解析提示文本
                "count": res.count, //解析数据长度
                "data": result, //解析数据列表
            };
        },
        toolbar: "#toolbar"
    });
    //监听工具条
    table.on('tool(test)', function (obj) {
        var data = obj.data; //当前行数据
        var rowIndex = obj.index;
        var layEvent = obj.event; //当前点击的事件名
        if (layEvent === 'view') {
            localStorage.setItem("proId",data.id)
            localStorage.setItem("proName",data.proName)
            localStorage.setItem("orgId",data.orgId)
            localStorage.setItem("orgName",data.orgName)
            layerOpenProgressView("详情","./proScheduleManagemenView.html");
        }
    });
});

function layerOpenProgressView(title,contentUrl){
    var index = layer.open({
        title: [title, 'color:#3B70A1;background-color:#E8ECEB;font-size:20px'],
        type: 2,
        content: contentUrl,
        area: ['90%', '95%'],
        maxmin: false,
        cancel:function (){
            reloadTable()
        }
    });

}

function reloadTable(){
    table.reload('menuTable', {
        url: ctxPath + '/proProgress/getBasicDataList'
        , method: 'post' //方式默认是get
        , where: {
            keyWord:  "",
            orgId: "",
            voltageLevel: "",
        } //设定异步数据接口的额外参数
    });
}