<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('涉密人员培训列表')" />
</head>
<body class="gray-bg">
     <div class="container-div" id="app">
        <div class="row">
            <div class="col-sm-12 search-collapse">
                <form id="formId">
                    <div class="select-list">
                        <ul>
                            <li>
                                <label>人员名称：</label>
                                <input type="text" name="trainName"/>
                            </li>
                             <li>
                                 <label>所属地区：</label>
                                 <select id="City" name="AREAID" @change="getAreaList()" v-model="City">
                                     <option value="">请选择</option>
                                     <option v-for="option in CityList" :value="option.id" :key="option.id">
                                         {{ option.name }}
                                     </option>
                                 </select>
                             </li>
                            <li>
                                <label>培训日期：</label>
                                <input type="text" class="time-input" placeholder="请选择培训日期" name="trainDate"/>
                            </li>

                            <li>
                                <label>培训状态：</label>
                                <select name="trainState" th:with="type=${@dict.getType('sys_examine_state')}">
                                    <option value="">所有</option>
                                    <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                                </select>
                            </li>
                            <li>
                                <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                                <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                            </li>
                        </ul>
                    </div>
                </form>
            </div>

            <div class="btn-group-sm" id="toolbar" role="group">
                <a class="btn btn-success" onclick="$.operate.add()" shiro:hasPermission="system:train:add">
                    <i class="fa fa-plus"></i> 记录
                </a>
                <a class="btn btn-primary single disabled" onclick="$.operate.edit()" shiro:hasPermission="system:train:edit">
                    <i class="fa fa-edit"></i> 修改
                </a>
                <a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()" shiro:hasPermission="system:train:remove">
                    <i class="fa fa-remove"></i> 删除
                </a>
                <a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="system:train:export">
                    <i class="fa fa-download"></i> 导出
                </a>
            </div>
            <div class="col-sm-12 select-table table-striped">
                <table id="bootstrap-table"></table>
            </div>
        </div>
    </div>
    <th:block th:include="include :: footer" />
    <script th:inline="javascript">
        var detailFlag = [[${@permission.hasPermi('system:train:detail')}]];
        var editFlag = [[${@permission.hasPermi('system:train:edit')}]];
        var examineFlag = [[${@permission.hasPermi('system:train:examine')}]];
        var removeFlag = [[${@permission.hasPermi('system:train:remove')}]];
        var trainTypeDatas = [[${@dict.getType('sys_usertrain_typer')}]];
        var trainSubjectDatas = [[${@dict.getType('sys_usertrain_obj')}]];
        var trainStateDatas = [[${@dict.getType('sys_examine_state')}]];
        var prefix = ctx + "system/train";
        let datas = []
        $.ajax({
            url: ctx + "system/area/getAllList",
            type: 'GET',
            data:{parentId:''} ,
            success:((res)=>{
                datas = res.data
            }) ,
        });
        let userList = []
        $.ajax({
            url: ctx + "system/user/list",
            type: 'POST',
            success:((res)=>{
                userList = res.rows
            }) ,
        });
        $(function() {
            var options = {
                url: prefix + "/list",
                createUrl: prefix + "/add",
                updateUrl: prefix + "/edit/{id}",
                detailUrl: prefix + "/detail/{id}",
                removeUrl: prefix + "/remove",
                exportUrl: prefix + "/export",
                modalName: "涉密人员培训",
                columns: [{
                    checkbox: true
                },
                {
                    field: 'id',
                    title: 'ID',
                    visible: false
                },
                {
                    field: 'areaid',
                    title: '所属地市',
                    visible: false,
                    formatter: function(value, row, index) {
                        return getCity(datas, value)
                    }

                },
                {
                    field: 'trainName',
                    title: '培训人员'
                },
                {
                    field: 'framework',
                    title: '所属区县',
                    visible: false,
                    formatter: function(value, row, index) {
                        return getCity(datas, value)
                    }
                },
                {
                    field: 'username',
                    title: '人员姓名',
                    formatter:function (value, row, index) {
                        return getUser(userList,value)
                    }
                },
                {
                    field: 'deptName',
                    title: '单位名称',
                    visible: false
                },
                {
                    field: 'trainType',
                    title: '培训类型',
                    formatter: function(value, row, index) {
                       return $.table.selectDictLabel(trainTypeDatas, value);
                    }
                },
                {
                    field: 'trainSubject',
                    title: '培训对象',
                    formatter: function(value, row, index) {
                       return $.table.selectDictLabel(trainSubjectDatas, value);
                    }
                },
                {
                    field: 'trainAddress',
                    title: '培训地点'
                },
                {
                    field: 'trainDate',
                    title: '培训开始日期'
                },
                {
                    field: 'trainTimeend',
                    title: '培训结束日期'
                },
                {
                    field: 'createStaffid',
                    title: '创建人',
                    visible: false
                },
                {
                    field: 'createDepartid',
                    title: '创建单位',
                    visible: false
                },
                {
                    field: 'createDate',
                    title: '创建日期',
                    visible: false
                },
                {
                    field: 'updateDepartid',
                    title: '更新单位',
                    visible: false
                },
                {
                    field: 'updateStaffid',
                    title: '审核人员'//
                },
                {
                    field: 'updateDate',
                    title: '审核时间',
                    visible: false
                },
                {
                    field: 'trainState',
                    title: '培训状态',//
                    formatter: function(value, row, index) {
                       return $.table.selectDictLabel(trainStateDatas, value);
                    }
                },
                {
                    field: 'part',
                    title: '部门',
                    visible: false
                },
                {
                    field: 'traininfo',
                    title: '培训评价',//
                    visible: false
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function(value, row, index) {
                        var actions = [];
                        if (row.trainState === 2){
                            actions.push('<a class="btn btn-warning btn-xs ' + detailFlag + '" href="javascript:void(0)" onclick="$.operate.detail(\'' + row.id + '\')"><i class="fa fa-search"></i>详细</a> ');
                            actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.edit(\'' + row.id + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                            actions.push('<a class="btn btn-success btn-xs ' + examineFlag + '" href="javascript:void(0)" onclick="examine(\'' + row.id + '\')"><i class="fa fa-edit"></i>审核</a> ');
                            actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.id + '\')"><i class="fa fa-remove"></i>删除</a>');
                        }else{
                            actions.push('<a class="btn btn-warning btn-xs ' + detailFlag + '" href="javascript:void(0)" onclick="$.operate.detail(\'' + row.id + '\')"><i class="fa fa-search"></i>详细</a> ');
                            actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.edit(\'' + row.id + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                            actions.push('<a disabled class="btn btn-success btn-xs ' + examineFlag + '" href="javascript:void(0)"><i class="fa fa-edit"></i>审核</a> ');
                            actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.id + '\')"><i class="fa fa-remove"></i>删除</a>');
                        }
                        return actions.join('');
                    }
                }]
            };
            $.table.init(options);
        });
        function examine(id) {
            var url = prefix + '/examine/' + id;
            $.modal.open("涉密人员培训审核", url);
        }
        function getUser(datas,value){
            if ($.common.isEmpty(datas) || $.common.isEmpty(value)) {
                return '';
            }
            var actions = []
            $.each(datas, function(index, user) {
                if (user.userId ==  value) {
                    actions.push($.common.sprintf("<span>%s</span>", user.userName));
                    return false;
                }
            });
            if (actions.length === 0) {
                actions.push($.common.sprintf("<span>%s</span>", value))
            }
            return actions.join('');
        }

        var app = new Vue({
            el: '#app',
            data: {
                CityList: [],
                City:'',
                params:{
                    parentId:'',
                }
            },
            mounted(){
                // 初始化地市列表
                this.getCityList();
            },
            methods:{
                getCityList(){
                    $.ajax({
                        url: ctx + "system/area/getSysAreaList",
                        type: 'GET',
                        data:this.params ,
                        success:((res)=>{
                            this.CityList = res.data
                        }) ,
                    });
                },
            }
        })
    </script>
</body>
</html>
