layui.use(['layer', 'form','laydate','util', 'table', 'admin', 'ax', 'element'], function () {
    var $ = layui.$;
    var layer = layui.layer;
    var form = layui.form;
    var laydate = layui.laydate;
    var table = layui.table;
    var $ax = layui.ax;
    var admin = layui.admin;

    var element = layui.element;
    press();
    //一些事件监听
    element.on('tab(demo)', function(data){
        console.log(data);
        if (data.index === 0){
            press();
        }


        if (data.index === 1){
            var spo2His = {
                tableId: "spo2Table",    //表格id
                condition: {
                    name: "",
                    timeLimit: ""
                }
            };

            /**
             * 初始化表格的列
             */
            spo2His.initColumn = function () {
                return [[
                    // {type: 'checkbox'},
                    {field: 'id', hide: true, sort: true, title: 'id'},
                    {field: 'spo2Value', sort: true, title: '血氧饱和度',width:200},
                    {field: 'rateValue', sort: true, title: '血氧脉搏值'},
                    {field: 'perfValue', sort: true, title: '血流灌注指数'},
                    {field: 'createTime', sort: true, title: '时间'}
                ]];
            };



            // 渲染表格
            var tableResult = table.render({
                elem: '#' + spo2His.tableId,
                url: Feng.ctxPath + '/spo2/pageList?userId='+Feng.getUrlParam("id"),
                page: true,
                height: "full-158",
                cellMinWidth: 100,
                cols: spo2His.initColumn()
            });
        }

        if (data.index === 2){
            var ecgHis = {
                tableId: "ecgTable",    //表格id
                condition: {
                    name: "",
                    timeLimit: ""
                }
            };

            /**
             * 初始化表格的列
             */
            ecgHis.initColumn = function () {
                return [[
                    // {type: 'checkbox'},
                    {field: 'id', hide: true, sort: true, title: 'id'},
                    {field: 'heartValue', sort: true, title: '心跳',width:200},
                    {field: 'respValue', sort: true, title: '呼吸'},
                    {field: 'vpcValue', sort: true, title: '心室收缩次数'},
                    {field: 'vpbValue', sort: true, title: '室性过早搏动'},
                    {field: 'beatsValue', sort: true, title: '漏搏'},
                    {field: 'createTime', sort: true, title: '时间'}
                ]];
            };



            // 渲染表格
            var tableResult = table.render({
                elem: '#' + ecgHis.tableId,
                url: Feng.ctxPath + '/ecg/pageList?userId='+Feng.getUrlParam("id"),
                page: true,
                height: "full-158",
                cellMinWidth: 100,
                cols: ecgHis.initColumn()
            });
        }
        if (data.index === 3){
            var ypHis = {
                tableId: "ypTable",    //表格id
                condition: {
                    name: "",
                    timeLimit: ""
                }
            };

            /**
             * 初始化表格的列
             */
            ypHis.initColumn = function () {
                return [[
                    // {type: 'checkbox'},
                    {field: 'id', hide: true, sort: true, title: 'id'},
                    {field: 'na', sort: true, title: 'na',width:200},
                    {field: 'cl', sort: true, title: 'cl'},
                    {field: 'k', sort: true, title: 'k'},
                    {field: 'bun', sort: true, title: 'bun'},
                    {field: 'urea', sort: true, title: 'urea'},
                    {field: 'crea', sort: true, title: 'crea'},
                    {field: 'glu', sort: true, title: 'glu'},
                    {field: 'lac', sort: true, title: 'lac'},
                    {field: 'an_gap', sort: true, title: 'an_gap'},
                    {field: 'hct', sort: true, title: 'hct'},
                    {field: 'hb', sort: true, title: 'hb'},
                    {field: 'ph', sort: true, title: 'ph'},
                    {field: 'pco2', sort: true, title: 'pco2'},
                    {field: 'po2', sort: true, title: 'po2'},
                    {field: 'hco3', sort: true, title: 'hco3'},
                    {field: 'tco2', sort: true, title: 'tco2'},
                    {field: 'be', sort: true, title: 'be'},
                    {field: 'so2', sort: true, title: 'so2'},
                    {field: 'c_tnl', sort: true, title: 'c_tnl'},
                    {field: 'h_cg', sort: true, title: 'h_cg'},
                    {field: 'create_time', sort: true, title: '时间'}
                ]];
            };



            // 渲染表格
            var tableResult = table.render({
                elem: '#' + ypHis.tableId,
                url: Feng.ctxPath + '/ypStat/pageList?userId='+Feng.getUrlParam("id"),
                page: true,
                height: "full-158",
                cellMinWidth: 100,
                cols: ypHis.initColumn()
            });
        }

        if (data.index === 4){
            var ratioHis = {
                tableId: "ratioTable",    //表格id
                condition: {
                    name: "",
                    timeLimit: ""
                }
            };

            /**
             * 初始化表格的列
             */
            ratioHis.initColumn = function () {
                return [[
                    // {type: 'checkbox'},
                    {field: 'name', sort: true, title: '名称',width:200},
                    {field: 'value2', sort: true, title: '2分'},
                    {field: 'value4', sort: true, title: '4分'},
                    {field: 'value8', sort: true, title: '8分'},
                    {field: 'value16', sort: true, title: '16分'},
                    {field: 'value32', sort: true, title: '32分'},
                ]];
            };



            // 渲染表格
            var tableResult = table.render({
                elem: '#' + ratioHis.tableId,
                url: Feng.ctxPath + '/grade/getLevel?id='+Feng.getUrlParam("id"),
                page: true,
                height: "full-158",
                cellMinWidth: 100,
                cols: ratioHis.initColumn()
            });
        }
    });

    function press() {
        var presslHis = {
            tableId: "pressTable",    //表格id
            condition: {
                name: "",
                timeLimit: ""
            }
        };

        /**
         * 初始化表格的列
         */
        presslHis.initColumn = function () {
            return [[
                // {type: 'checkbox'},
                {field: 'id', hide: true, sort: true, title: 'id'},
                {field: 'systValue', sort: true, title: ' 收缩压',width:200},
                {field: 'diasValue', sort: true, title: '舒张压'},
                {field: '', sort: true, title: '平均动脉压', templet  : function (d) {
                        var s = d.systValue;
                        var a = d.diasValue;
                        var avg = (a-s)/3 + a;
                        return Math.round(avg);
                    }},
                {field: '', sort: true, title: '脑灌注压', templet  : function (d) {
                        var s = d.systValue;
                        var a = d.diasValue;
                        var avg = (a-s)/3 + a;
                        return Math.round(avg - d.icpValue);
                    }},
                {field: 'pulseValue', sort: true, title: '脉率'},
                {field: 'icpValue', sort: true, title: '颅内压'},
                {field: 'createTime', sort: true, title: '时间'}
            ]];
        };



        // 渲染表格
        var tableResult = table.render({
            elem: '#' + presslHis.tableId,
            url: Feng.ctxPath + '/press/pageList?userId='+Feng.getUrlParam("id"),
            page: true,
            height: "full-158",
            cellMinWidth: 100,
            cols: presslHis.initColumn()
        });
    }
});
