@page 
@model Waste.Web.Entry.Pages.Role.EditModel
@{
    ViewData["Title"] = "角色编辑";
}
<div class="layui-card">
    <div class="layui-card-body">
        <div class="form-horizontal layui-form">

            <div class="layui-tab layui-tab-brief" lay-filter="docDemoTabBrief">
                <ul class="layui-tab-title">
                    <li class="layui-this">基本信息</li>
                    <li>菜单设置</li>
                </ul>
                <div class="layui-tab-content">
                    <div class="layui-tab-item layui-show" style="width:80%;">
                        <div class="layui-form-item layui-row">
                            <label class="layui-form-label" for="Name">角色名称</label>
                            <div class="layui-input-block">
                                <input type="text" class="layui-input" id="Name" name="Name" value="@Model.role.Name" placeholder="请输入角色名称" lay-verify="required" />
                            </div>
                        </div>
                        <div class="layui-form-item layui-row">
                            <label class="layui-form-label" for="EnCode">角色编码</label>
                            <div class="layui-input-block">
                                <input type="text" class="layui-input" id="EnCode" name="EnCode" value="@Model.role.EnCode" placeholder="请输入角色编码" lay-verify="required" />
                            </div>
                        </div>
                        <div class="layui-form-item layui-row">
                            <label class="layui-form-label" for="remark">描述</label>
                            <div class="layui-input-block">
                                <textarea type="text" class="layui-textarea" id="Remark"
                                          name="Remark" placeholder="请输入描述" lay-verify="required">@Model.role.Remark</textarea>
                            </div>
                        </div>
                    </div>
                    <div class="layui-tab-item">
                        <table class="layui-table" id="list" lay-filter="list"></table>
                    </div>
                </div>
            </div>
            <div class="layui-row text-center">
                <button class="layui-btn js-submit" lay-submit lay-filter="submit" type="button">提交</button>
            </div>
        </div>
    </div>
</div>
@section Scripts{
    <script type="text/javascript">
        layui.use(['common', 'form','element','table'], function () {
            var common = layui.common,table=layui.table,
                element = layui.element,
            form = layui.form;
            common.initTable({
                url: '/api/system/GetMenuTreeJson'
                , method: "post"
                , id: 'mlist'
                , parseData: function (res) {
                    var data = JSON.parse(res.data);
                    if ('@Model.role.Id' != null && '@Model.role.Id' != '') {
                        common.ajax({
                            url: "/api/role/detail/" + '@Model.role.Id',
                            async: false,
                            success: function (ress) {
                                if (ress.statuscode == 200 && ress.data != null) {
                                    $.each(data, function () {
                                        var that = this;
                                        $.each(ress.data.permissionid, function () {
                                            if (that.id == this.toString()) {
                                                that["LAY_CHECKED"] = true;
                                            }
                                        });
                                    });
                                }
                            }
                        });
                    }
                    return {
                        "statuscode": res.statuscode,
                        "message": "success",
                        "data": data,
                        "TotalNum": 0
                    };
                }
                , page: false
                 , cellMinWidth: 80
                , initSort: false
                , cols: [[
                {
                    checkbox: true
                },
                  {
                      field: 'Name', title: '名称', templet: function (d) {
                          return d.text;
                      }
                  }
                  , {
                      field: 'UrlAddress', title: '链接', templet: function (d) {
                          return d.data.UrlAddress;
                      }
                  }
                  , {
                      field: 'Icon', title: '图标', templet: function (d) {
                          return d.data.Icon;
                      }
                  }
                  , {
                      field: 'SortCode', title: '排序', templet: function (d) {
                          return d.data.SortCode;
                      }
                  }
                  , {
                      field: 'Status', title: '是否可用', templet: function (d) {
                          if (d.data.Status == 1) {
                              return '<input type="checkbox" name="close" lay-skin="switch" lay-text="是|否" checked>';
                          } else {
                              return '<input type="checkbox" name="close" lay-skin="switch" lay-text="是|否">';
                          }
                      }
                  }
                ]]
            });
            form.on("submit(submit)", function (data) {
                var $this = this;
                data.field["Id"] = '@Model.role.Id';
                var datas = table.checkStatus('mlist');
                var ids =[];
                $.each(datas.data, function () {
                    ids.push(this.id);
                });
                data.field["permissionId"] = ids;
                common.ajax({
                    url: "/api/role/submitform",
                    type: "post",
                    data: data.field
                });
            });
        });
    </script>
}