layui.extend({
    common: 'js/common'
}).use(['jquery', 'layer', 'common', 'table', 'util', 'form'], function () {
    //  Jquery插件
    var $ = layui.jquery;
    //  引入公共模块
    var common = layui.common;
    //  引入表单
    var form = layui.form;
    //设备id
    var deviceIds = $('#deviceId').val();
    //  初始化表单
    var layuiTable = common.layuiTable.render(layui.table,{
        elem: '#data_entity_table'
        ,url: '/permissions/appPackage/deviceUpgradeAppPackage?deviceId='
        ,cellMinWidth: 80 //全局定义常规单元格的最小宽度，
        , cols: [[
            { field: 'version', title: '版本号',align:'center',width:200 }
            , { field: 'packageName',title: '版本名称',align:'center',width:200}
            , { field: 'description',title: '版本说明',align:'center'}
            , { field: 'deviceFactory',title: '设备厂商',align:'center',width:200}
            , { field: 'deviceModelNumber',title: '设备型号',align:'center',width:200}
            , { field: 'isEnable',title: '启用状态',align:'center',templet:"#switch_is_enable"}
        ]],page : true
        // , parseDate: function (res) {
        //     debugger
        // }
    });
    //  页面元素
    var $node = {
        //  取消按钮
        resetBtn: $('button[type="reset"]'),
        subBtn: $('button[type="sub"]'),
        // deviceIdInput: $('#deviceId'),
    };
    var pageData = {
        id: "",
        version: '',
        deviceFactory: '',
        deviceModelNumber: '',
        deviceId: $('#deviceId').val()
    }

    //单选框选中事件

    $(document).on('click', '.packageRadio', function () {
        var $td = $(this).parent().parent().find('td');
        pageData.version = $td[1].textContent;
        pageData.deviceFactory = $td[5].textContent;
        pageData.deviceModelNumber = $td[6].textContent;
    })

    //  点击取消事件
    $node.resetBtn.on('click', function () {
        var index = parent.layer.getFrameIndex(window.name);
        parent.layer.close(index);
    });

    //  点击提交事件
    $node.subBtn.on('click', function () {
        if (pageData.version == "" || pageData.deviceFactory == "" || pageData.deviceModelNumber == ""){
            layer.msg("请选择升级的版本");
            return;
        }
        // var ids = Number.parseInt($node.deviceIdInput.val());
        // pageData.deviceIds.push(ids);
        $.ajax({
            url: '/permissions/appPackage/deviceUpgradeByAppPackage',
            data: pageData,
            type: 'POST',
            success: function () {
                $node.resetBtn.click();
            }
        });
    })
});
