<!doctype html>
<html lang="en">
<head>
    <base href="/systembase/">
    <meta charset="utf-8">
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="assets/fonts/font-awesome/css/font-awesome.css"/>
    <link rel="stylesheet" href="assets/layuiadmin/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="assets/layuiadmin/style/admin.css" media="all">
    <link rel="stylesheet" type="text/css" href="assets/js/vendor/viewer/viewer.min.css">
</head>
<body>
<div class="layui-fluid layui-anim layui-anim-fadein">
    <div class="layui-card">
        <div class="layui-card-header">
            <span class="layui-breadcrumb" lay-filter="breadcrumb" style="visibility: visible;">
              <a class="close" href="javascript:void(0);">上级列表</a><span lay-separator="">/</span>
              <a href="javascript:void(0);"><cite>新增内容</cite></a>
            </span>
        </div>
        <div class="layui-card-body" style="padding: 15px;">
            <form class="layui-form layui-form-pane" lay-filter="dataForm">
                <div class="layui-form-item">
                    <label class="layui-form-label">群防群治组织表ID</label>
                    <div class="layui-input-block">
                        <input type="text" id="massPreventionId" name="massPreventionId" class="layui-input" value="" placeholder="请输入群防群治组织表ID"  maxlength="36">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">组织名称</label>
                    <div class="layui-input-block">
                        <input type="hidden" id="organizeName" name="organizeName" value="">
                        <input type="text" id="organizeNameSelectUser" class="layui-input" placeholder="请选择组织名称" data-name="organizeName" readonly style="cursor:pointer;">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">姓名</label>
                    <div class="layui-input-block">
                        <input type="text" id="name" name="name" class="layui-input" value="" placeholder="请输入姓名"  maxlength="50">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">性别字典表ID</label>
                    <div class="layui-input-block layui-form" id="sexSelectTemplateBox" lay-filter="sexSelectTemplateBox"></div>
                    <script id="sexSelectTemplate" type="text/html">
                        <select id="sex" name="sex">
                            <option value="">请选择性别字典表ID</option>
                            {{# for(var i = 0, item; item = d[i++];) { }}
                            <option value="{{item.selectId}}">{{item.selectName}}</option>
                            {{# } }}
                        </select>
                    </script>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">性别名称</label>
                    <div class="layui-input-block">
                        <input type="text" id="sexName" name="sexName" class="layui-input" value="" placeholder="请输入性别名称"  maxlength="20">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">性别编码</label>
                    <div class="layui-input-block">
                        <input type="text" id="sexCode" name="sexCode" class="layui-input" value="" placeholder="请输入性别编码"  maxlength="1">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">民族字典表ID</label>
                    <div class="layui-input-block layui-form" id="nationSelectTemplateBox" lay-filter="nationSelectTemplateBox"></div>
                    <script id="nationSelectTemplate" type="text/html">
                        <select id="nation" name="nation">
                            <option value="">请选择民族字典表ID</option>
                            {{# for(var i = 0, item; item = d[i++];) { }}
                            <option value="{{item.selectId}}">{{item.selectName}}</option>
                            {{# } }}
                        </select>
                    </script>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">名族名称</label>
                    <div class="layui-input-block">
                        <input type="text" id="nationName" name="nationName" class="layui-input" value="" placeholder="请输入名族名称"  maxlength="20">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">民族编码</label>
                    <div class="layui-input-block">
                        <input type="text" id="nationCode" name="nationCode" class="layui-input" value="" placeholder="请输入民族编码"  maxlength="2">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">政治面貌字典表ID</label>
                    <div class="layui-input-block layui-form" id="politicalOutlookSelectTemplateBox" lay-filter="politicalOutlookSelectTemplateBox"></div>
                    <script id="politicalOutlookSelectTemplate" type="text/html">
                        <select id="politicalOutlook" name="politicalOutlook">
                            <option value="">请选择政治面貌字典表ID</option>
                            {{# for(var i = 0, item; item = d[i++];) { }}
                            <option value="{{item.selectId}}">{{item.selectName}}</option>
                            {{# } }}
                        </select>
                    </script>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">政治面貌名称</label>
                    <div class="layui-input-block">
                        <input type="text" id="politicalOutlookName" name="politicalOutlookName" class="layui-input" value="" placeholder="请输入政治面貌名称"  maxlength="20">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">政治面貌编码</label>
                    <div class="layui-input-block">
                        <input type="text" id="politicalOutlookCode" name="politicalOutlookCode" class="layui-input" value="" placeholder="请输入政治面貌编码"  maxlength="2">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">证件代码字典表ID</label>
                    <div class="layui-input-block layui-form" id="cardCodeSelectTemplateBox" lay-filter="cardCodeSelectTemplateBox"></div>
                    <script id="cardCodeSelectTemplate" type="text/html">
                        <select id="cardCode" name="cardCode">
                            <option value="">请选择证件代码字典表ID</option>
                            {{# for(var i = 0, item; item = d[i++];) { }}
                            <option value="{{item.selectId}}">{{item.selectName}}</option>
                            {{# } }}
                        </select>
                    </script>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">证件代码名称</label>
                    <div class="layui-input-block">
                        <input type="text" id="cardCodeName" name="cardCodeName" class="layui-input" value="" placeholder="请输入证件代码名称"  maxlength="20">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">证件代码编码</label>
                    <div class="layui-input-block">
                        <input type="text" id="cardCodeCode" name="cardCodeCode" class="layui-input" value="" placeholder="请输入证件代码编码"  maxlength="3">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">证件号码</label>
                    <div class="layui-input-block">
                        <input type="text" id="cardNum" name="cardNum" class="layui-input" value="" placeholder="请输入证件号码"  maxlength="30">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">出生日期</label>
                    <div class="layui-input-block">
                        <input type="text" id="birthday" name="birthday" class="layui-input" value="" placeholder="请选择出生日期" readonly style="cursor: pointer;" lay-verify="required">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">职务</label>
                    <div class="layui-input-block">
                        <input type="text" id="post" name="post" class="layui-input" value="" placeholder="请输入职务"  maxlength="30">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">专业特长</label>
                    <div class="layui-input-block">
                        <input type="text" id="professionalExpertise" name="professionalExpertise" class="layui-input" value="" placeholder="请输入专业特长"  maxlength="80">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">学历字典表ID</label>
                    <div class="layui-input-block layui-form" id="educationSelectTemplateBox" lay-filter="educationSelectTemplateBox"></div>
                    <script id="educationSelectTemplate" type="text/html">
                        <select id="education" name="education">
                            <option value="">请选择学历字典表ID</option>
                            {{# for(var i = 0, item; item = d[i++];) { }}
                            <option value="{{item.selectId}}">{{item.selectName}}</option>
                            {{# } }}
                        </select>
                    </script>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">学历名称</label>
                    <div class="layui-input-block">
                        <input type="text" id="educationName" name="educationName" class="layui-input" value="" placeholder="请输入学历名称"  maxlength="20">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">学历编码</label>
                    <div class="layui-input-block">
                        <input type="text" id="educationCode" name="educationCode" class="layui-input" value="" placeholder="请输入学历编码"  maxlength="2">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">手机号码</label>
                    <div class="layui-input-block">
                        <input type="text" id="phone" name="phone" class="layui-input" value="" placeholder="请输入手机号码"  maxlength="18">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">固定电话</label>
                    <div class="layui-input-block">
                        <input type="text" id="fixedPhone" name="fixedPhone" class="layui-input" value="" placeholder="请输入固定电话"  maxlength="18">
                    </div>
                </div>
                <div class="layui-form-item layui-layout-admin">
                    <div class="layui-input-block">
                        <div class="layui-footer" style="left: 0;">
                            <button type="button" class="layui-btn" lay-submit lay-filter="submitForm">提交新增</button>
                            <button type="button" class="layui-btn layui-btn-primary close">返回上级</button>
                        </div>
                    </div>
                </div>
            </form>
        </div>
    </div>
</div>
<script src="assets/js/vendor/wangEditor/wangEditor.min.js"></script>
<script src="assets/js/vendor/ckplayer/ckplayer/ckplayer.js"></script>
<script src="assets/js/vendor/viewer/viewer.min.js"></script>
<script src="assets/layuiadmin/layui/layui.js"></script>
<script>
    layui.config({
        base: 'assets/layuiadmin/' //静态资源所在路径
    }).extend({
        index: 'lib/index' //主入口模块
    }).use(['index', 'form', 'laydate', 'laytpl'], function(){
        var $ = layui.$;
        var form = layui.form;
        var laytpl = layui.laytpl;
        var laydate = layui.laydate;
        var wangEditor = window.wangEditor;
        var wangEditorObj = {};
        var viewerObj = {};

        function closeBox() {
            parent.layer.close(parent.layer.getFrameIndex(window.name));
        }

        function refreshDownloadTemplet(fileName, file) {
            var dataRander = {};
            dataRander[fileName] = file;

            laytpl(document.getElementById(fileName +'FileDownload').innerHTML).render(dataRander, function(html) {
                document.getElementById(fileName +'FileBox').innerHTML = html;
            });
        }

        // 初始化文件列表
        function initFileList(fileName, ids, callback) {
            var dataForm = {};
            dataForm[fileName] = ids;
            form.val('dataForm', dataForm);

            if(!ids) {
                refreshDownloadTemplet(fileName, []);
                if(callback) {
                    callback(fileName, []);
                }
                return;
            }

            top.restAjax.get(top.restAjax.path('api/file/list', []), {
                ids: ids
            }, null, function(code, data) {
                refreshDownloadTemplet(fileName, data);
                if(callback) {
                    callback(fileName, data);
                }
            }, function(code, data) {
                top.dialog.msg(data.msg);
            });
        }

        // 初始化视频
        function initVideo(fileName, data) {
            for(var i = 0, item; item = data[i++];) {
                var player = new ckplayer({
                    container: '#'+ fileName + i,
                    variable: 'player',
                    flashplayer: false,
                    video: {
                        file: 'route/file/download/true/'+ item.fileId,
                        type: 'video/mp4'
                    }
                });
            }
        }

        // 初始化组织名称选择人员
        function initOrganizeNameSelectUser() {
            $(document.body).on('click', '#organizeNameSelectUser', function() {
                var name = this.dataset.name;
                top.dialog.dialogData.selectedUserIds = $('#'+ name).val();
                top.dialog.open({
                    url: top.restAjax.path('route/department/user/select-user', []),
                    title: '选择用户',
                    width: '500px',
                    height: '500px',
                    onClose: function() {
                        var selectedUsers = top.dialog.dialogData.selectedDepartmentUsers;
                        // 填写逻辑
                        if(selectedUsers != null && selectedUsers.length > 0) {
                            for (var i = 0, item; item = selectedUsers[i++];) {
                                console.log(item);
                            }
                        }
                    }
                })
            });
        }

        // 初始化性别字典表ID下拉选择
        function initSexSelect() {
            top.restAjax.get(top.restAjax.path('api/url/selectUrl', []), {}, null, function(code, data, args) {
                laytpl(document.getElementById('sexSelectTemplate').innerHTML).render(data, function(html) {
                    document.getElementById('sexSelectTemplateBox').innerHTML = html;
                });
                form.render('select', 'sexSelectTemplateBox');
            }, function(code, data) {
                top.dialog.msg(data.msg);
            });
        }

        // 初始化民族字典表ID下拉选择
        function initNationSelect() {
            top.restAjax.get(top.restAjax.path('api/url/selectUrl', []), {}, null, function(code, data, args) {
                laytpl(document.getElementById('nationSelectTemplate').innerHTML).render(data, function(html) {
                    document.getElementById('nationSelectTemplateBox').innerHTML = html;
                });
                form.render('select', 'nationSelectTemplateBox');
            }, function(code, data) {
                top.dialog.msg(data.msg);
            });
        }

        // 初始化政治面貌字典表ID下拉选择
        function initPoliticalOutlookSelect() {
            top.restAjax.get(top.restAjax.path('api/url/selectUrl', []), {}, null, function(code, data, args) {
                laytpl(document.getElementById('politicalOutlookSelectTemplate').innerHTML).render(data, function(html) {
                    document.getElementById('politicalOutlookSelectTemplateBox').innerHTML = html;
                });
                form.render('select', 'politicalOutlookSelectTemplateBox');
            }, function(code, data) {
                top.dialog.msg(data.msg);
            });
        }

        // 初始化证件代码字典表ID下拉选择
        function initCardCodeSelect() {
            top.restAjax.get(top.restAjax.path('api/url/selectUrl', []), {}, null, function(code, data, args) {
                laytpl(document.getElementById('cardCodeSelectTemplate').innerHTML).render(data, function(html) {
                    document.getElementById('cardCodeSelectTemplateBox').innerHTML = html;
                });
                form.render('select', 'cardCodeSelectTemplateBox');
            }, function(code, data) {
                top.dialog.msg(data.msg);
            });
        }

        // 初始化出生日期日期
        function initBirthdayDate() {
            laydate.render({
                elem: '#birthday',
                type: 'date',
                value: new Date(),
                trigger: 'click'
            });
        }

        // 初始化学历字典表ID下拉选择
        function initEducationSelect() {
            top.restAjax.get(top.restAjax.path('api/url/selectUrl', []), {}, null, function(code, data, args) {
                laytpl(document.getElementById('educationSelectTemplate').innerHTML).render(data, function(html) {
                    document.getElementById('educationSelectTemplateBox').innerHTML = html;
                });
                form.render('select', 'educationSelectTemplateBox');
            }, function(code, data) {
                top.dialog.msg(data.msg);
            });
        }


        // 初始化内容
        function initData() {
            initOrganizeNameSelectUser();
            initSexSelect();
            initNationSelect();
            initPoliticalOutlookSelect();
            initCardCodeSelect();
            initBirthdayDate();
            initEducationSelect();
        }
        initData();

        // 提交表单
        form.on('submit(submitForm)', function(formData) {
            top.dialog.confirm(top.dataMessage.commit, function(index) {
                top.dialog.close(index);
                var loadLayerIndex;
                top.restAjax.post(top.restAjax.path('api/masspreventionrank/save', []), formData.field, null, function(code, data) {
                    var layerIndex = top.dialog.msg(top.dataMessage.commitSuccess, {
                        time: 0,
                        btn: [top.dataMessage.button.yes, top.dataMessage.button.no],
                        shade: 0.3,
                        yes: function(index) {
                            top.dialog.close(index);
                            window.location.reload();
                        },
                        btn2: function() {
                            closeBox();
                        }
                    });
                }, function(code, data) {
                    top.dialog.msg(data.msg);
                }, function() {
                    loadLayerIndex = top.dialog.msg(top.dataMessage.committing, {icon: 16, time: 0, shade: 0.3});
                }, function() {
                    top.dialog.close(loadLayerIndex);
                });
            });
            return false;
        });

        $('.close').on('click', function() {
            closeBox();
        });

        // 校验
        form.verify({
        });
    });
</script>
</body>
</html>