@{
    ViewBag.Title = "设备管理";
    Layout = "~/Views/Shared/_Layout.cshtml";
}
@using MES.Production.Service;
@using Central.Control.Domain;
@using Ant.Service.Common;
@using Ant.Service.Common.Enums;
@using CommonToolHelper;

@model PageInfo
<!-- table star -->
<div class="row col-lg-12">
    <div class="wrapper wrapper-content animated fadeInUp">
        <div class="ibox">
            <div class="ibox-title">
                <h5>设备管理</h5>
                <div class="ibox-tools rboor">
                    <a class="btn btn-primary btn-xs p310" id="insert" action="add"><i class="im-plus"></i> 创建新设备</a>
                    <a class="btn btn-primary btn-xs p310" id="modify" action="edit"><i class="im-pencil2"></i> 编辑</a>
                    <a class="btn btn-primary btn-xs p310" id="delete" action="remove"><i class="im-remove4"></i> 删除</a>
                    <a class="btn btn-primary btn-xs p310" id="showPassword" action="showPassword"><i class="im-vcard"></i> 查看密码</a>
                </div>
            </div>
            <div class="ibox-content">
                <!-- search star -->
                @using (Ajax.BeginForm("Index", null, new AjaxOptions() { }, new { @id = "form1", @class = "form-horizontal", @method = "get" }))
                {
                    <div class="form-horizontal clearfix">
                        <div class="col-lg-4 col-sm-3 pl0" style="width:55%;">
                            <div class="form-group">
                               
                            </div>
                        </div>
                        <div class="col-lg-4 col-sm-4" style="float:right;">
                            <div class="form-group">
                                <div class="col-lg-12 col-sm-12 input-group">
                                    @Html.TextBox("Search", null, new { @class = "input-sm form-control", @placeholder = "请输入查询关键词" })
                                    <span class="input-group-btn">
                                        <button type="button" onclick="submit()" class="btn btn-sm btn-primary"> 搜索</button>
                                    </span>
                                </div>
                            </div>
                        </div>
                    </div>
                <!-- search end -->
                                            <div id="example_wrapper" class="dataTables_wrapper form-inline dt-bootstrap no-footer">
                                                <table id="example" class="table table-striped table-bordered table-hover dataTables-example dataTable" cellspacing="0" width="100%">
                                                    <thead>
                                                        <tr>
                                                            <th class="tn" style="width: 40px !important"><input name="checkall" id="checkall" type="checkbox" value=""></th>
                                                            <th>设备名称</th>
                                                            <th>设备编码</th>
                                                            <th>设备地址</th>
                                                            <th style="width: 170px !important">创建时间</th>
                                                        </tr>
                                                    </thead>
                                                    <tbody>
                                                        @{foreach (var item in Model.List)
                                                            {
                                                                <tr>
                                                                    <td class="tn"><input name="checkbox_name" type="checkbox" value="@item.Id"></td>
                                                                    <td>
                                                                        <a href="javascript:modify('@item.Id')" listaction="detail">  @item.Name</a>
                                                                    </td>
                                                                    <td>@item.Name</td>
                                                                    <td>@item.Code</td>
                                                                    <td>@item.Address</td>
                                                                    <td>@item.CreateDT</td>
                                                                </tr>
                                                            }
                                                        }
                                                    </tbody>
                                                </table>
                                                <!-- page -->
                                                <div class="bottom">
                                                    <div class="dataTables_info" id="example_info" Post="status" aria-live="polite">显示第 @Model.BeginPage 至 @Model.EndPage 项结果,共 @Model.Count 项</div>
                                                    <div class="dataTables_length" id="example_length">
                                                        <label>
                                                            显示
                                                            <select name="example_length" onchange="submit()" aria-controls="example" class="form-control input-sm">
                                                                <option value="10" @(Model.PageSize == 10 ? "selected" : "")>10</option>
                                                                <option value="25" @(Model.PageSize == 25 ? "selected" : "")>25</option>
                                                                <option value="50" @(Model.PageSize == 50 ? "selected" : "")>50</option>
                                                                <option value="100" @(Model.PageSize == 100 ? "selected" : "")>100</option>
                                                            </select> 项结果
                                                        </label>
                                                    </div>
                                                    @CommonHtmlHelper.PaginationPager(Model.Index, Model.PageSize, Model.Count, 7, Model.Url)
                                                    <div class="clear"></div>
                                                </div>
                                                <!-- page -->
                                            </div>
                                                            }
            </div>
        </div>
    </div>
</div>
<!-- table end -->
@section scripts{
    <script type="text/javascript">
        //点击修改
        function modify(n) {
            dig.addModel('添加/编辑设备', '/Sys/DeviceSet/Detail/' + n, 600, 280, function () {
                if (this.returnValue == 'yes') {
                    location.reload();
                }
            });
        }
        $(function () {
            $('.select2').select2();
            //添加
            $('#insert').click(function () {
                dig.addModel('添加/编辑设备', '/Sys/DeviceSet/Detail', 600, 280, function () {
                    if (this.returnValue == 'yes') {
                        location.reload();
                    }
                });
            });
            //修改
            $('#modify').click(function () {
                var vals = '';
                var num = 0;
                $('input[name="checkbox_name"]:checked').each(function () {
                    vals = $(this).val();
                    num++;
                });
                if (!vals) {
                    dig.alertError("提示", "对不起,请选中您要操作的记录!");
                    return;
                }
                if (num > 1) {
                    dig.alertError("提示", "对不起,每次只能修改一条记录!");
                    return;
                }
                dig.addModel('添加/编辑设备', '/Sys/DeviceSet/Detail/' + vals, 600, 280, function () {
                    if (this.returnValue == 'yes') {
                        location.reload();
                    }
                });
            });
            //查看密码
            $('#showPassword').click(function () {
                var vals = '';
                var num = 0;
                $('input[name="checkbox_name"]:checked').each(function () {
                    vals = $(this).val();
                    num++;
                });
                if (!vals) {
                    dig.alertError("提示", "对不起,请选中您要查看的记录!");
                    return;
                }
                if (num > 1) {
                    dig.alertError("提示", "对不起,每次只能查看一条记录!");
                    return;
                }
                dig.addModel('查看密码', '/Sys/DeviceSet/ShowPassword/' + vals, 600, 180, function () {

                });
            });


        });
    </script>
}