<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('新增文件下发')" />
    <th:block th:include="include :: select2-css" />
    <th:block th:include="include :: bootstrap-select-css" />
    <th:block th:include="include :: datetimepicker-css" />
</head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-fileprovide-add">
            <div class="row">
                <div class="col-sm-6">
                    <div class="form-group">
                        <label class="col-sm-4 control-label is-required">所属地市：</label>
                        <div class="col-sm-8">
                            <select id="City" name="frameworkId" required class="form-control m-b">
                                <option value="">---请选择---</option>
                            </select>
                        </div>
                    </div>
                </div>
                <div class="col-sm-6">
                    <div class="form-group">
                        <label class="col-sm-4 control-label is-required">所属区县：</label>
                        <div class="col-sm-8">
                            <select id="Area" name="areaid" required class="form-control m-b">
                                <option value="">---请选择---</option>
                            </select>
                        </div>
                    </div>
                </div>
            </div>
            <div class="row">
                <div class="col-sm-6">
                    <div class="form-group">
                        <label class="col-sm-4 control-label is-required">文件标题：</label>
                        <div class="col-sm-8">
                            <input name="fileName" placeholder="请输入文件标题" required class="form-control" type="text">
                        </div>
                    </div>
                </div>
                <div class="col-sm-6">
                    <div class="form-group">
                        <label class="col-sm-4 control-label is-required">发文人员：</label>
                        <div class="col-sm-8">
                            <input name="provideUserid" required readonly th:value="${user.userName}" class="form-control" type="text">
                        </div>
                    </div>
                </div>


            </div>
            <div class="row">
                <div class="col-sm-6">
                    <div class="form-group">
                        <label class="col-sm-4 control-label is-required">文件密级：</label>
                        <div class="col-sm-8">
                            <select name="fileSecret" required class="form-control m-b" th:with="type=${@dict.getType('sys_file_miji')}">
                                <option value="">---请选择---</option>
                                <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                            </select>
                        </div>
                    </div>
                </div>
                <div class="col-sm-6">
                    <div class="form-group">
                        <label class="col-sm-4 control-label is-required">保密期限：</label>
                        <div class="col-sm-8">
                            <input name="releaseSecretid" placeholder="请输入保密期限" required class="form-control" type="text">
                        </div>
                    </div>
                </div>
            </div>
            <div class="row">
                <div class="col-sm-6">
                    <div class="form-group">
                        <label class="col-sm-4 control-label is-required">紧急程度：</label>
                        <div class="col-sm-8">
                            <select name="instancyExtent" required class="form-control m-b" th:with="type=${@dict.getType('sys_file_jinjichengdu')}">
                                <option value="">---请选择---</option>
                                <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                            </select>
                        </div>
                    </div>
                </div>
                <div class="col-sm-6">
                    <div class="form-group">
                        <label class="col-sm-4 control-label is-required">文号：</label>
                        <div class="col-sm-8">
                            <input name="fileNum" placeholder="请输入文号" required class="form-control" type="text">
                        </div>
                    </div>
                </div>
            </div>
            <div class="row">
                <div class="col-sm-6">
                    <div class="form-group">
                        <label class="col-sm-4 control-label is-required">收文单位：</label>
                        <div class="col-sm-8">
                            <select  name="targetDepart" id="targetDepart" class="form-control select2-multiple" required multiple>
                                <option th:each="item : ${dept}" th:if="${item.deptId != 100}" th:text="${item.deptName}" th:value="${item.deptName}" ></option>
                            </select>
                        </div>
                    </div>
                </div>
                <div class="col-sm-6">
                    <div class="form-group">
                        <label class="col-sm-4 control-label is-required">发文份数：</label>
                        <div class="col-sm-8">
                            <input name="provideCount" required digits="true" placeholder="请输入发文份数" class="form-control"  type="text">
                        </div>
                    </div>
                </div>

            </div>
            <div class="row">
                <div class="col-sm-6">
                    <div class="form-group">
                        <label class="col-sm-4 control-label is-required">发文单位：</label>
                        <div class="col-sm-8">
                            <input name="provideDepart" required readonly th:value="${user.dept.deptName}" class="form-control" type="text">
                        </div>
                    </div>
                </div>
                <div class="col-sm-6">
                    <div class="form-group">
                        <label class="col-sm-4 control-label is-required">发文日期：</label>
                        <div class="col-sm-8">
                            <div class="input-group date">
                                <input name="provideDate" required class="form-control" placeholder="yyyy-MM-dd" type="text">
                                <span class="input-group-addon"><i class="fa fa-calendar"></i></span>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            <div class="row">
                <div class="col-sm-12">
                    <div class="form-group">
                        <label class="col-sm-2 control-label is-required">定密依据：</label>
                        <div class="col-sm-10">
                            <textarea name="allianceFile"  placeholder="请输入定密依据" required class="form-control" type="text"></textarea>
                        </div>
                    </div>
                </div>
            </div>
            <div class="row">
                <div class="col-sm-12">
                    <div class="form-group">
                        <label class="col-sm-2 control-label">文件备注：</label>
                        <div class="col-sm-10">
                            <textarea name="remark"  placeholder="请输入备注"  class="form-control" type="text"></textarea>
                        </div>
                    </div>
                </div>
            </div>
        </form>
    </div>
    <th:block th:include="include :: footer" />
    <th:block th:include="include :: select2-js" />
    <th:block th:include="include :: bootstrap-select-js" />
    <th:block th:include="include :: datetimepicker-js" />
    <script th:inline="javascript">
        var prefix = ctx + "system/fileprovide"
        $("#form-fileprovide-add").validate({
            focusCleanup: true
        });
        $(document).ready(function() {
            // 获取市级数据并填充到城市下拉框
            $.ajax({
                url: ctx + "system/area/getSysAreaList",
                method: 'GET',
                success: function(res) {
                    var cities = res.data; // 假设返回的数据中有一个叫做 'cities' 的字段包含市级数据
                    var $citySelect = $('#City');

                    // 填充城市下拉框
                    cities.forEach(function(city) {
                        $citySelect.append($('<option>', {
                            value: city.id,
                            text: city.name
                        }));
                    });

                    // 初始化 select2 插件
                    $citySelect.select2();
                },
                error: function(err) {
                    console.error('Failed to load city data:', err);
                }
            });

            // 监听城市下拉框的变化事件
            $('#City').on('change', function() {
                var selectedCityId = $(this).val();

                // 如果未选择城市，则不执行后续操作
                if (!selectedCityId) return;

                // 根据选中的城市ID发送请求获取对应的区级数据
                $.ajax({
                    url: ctx + "system/area/getSysAreaList",
                    data:{parentId:selectedCityId},
                    method: 'GET',
                    success: function(res) {
                        var areas = res.data; // 假设返回的数据中有一个叫做 'areas' 的字段包含区级数据
                        var $areaSelect = $('#Area');

                        // 清空区级下拉框并填充数据
                        $areaSelect.empty().append($('<option>', {
                            value: '',
                            text: '请选择区'
                        }));

                        areas.forEach(function(area) {
                            $areaSelect.append($('<option>', {
                                value: area.id,
                                text: area.name
                            }));
                        });

                        // 更新 select2 插件
                        $areaSelect.select2();
                    },
                    error: function(err) {
                        console.error('Failed to load area data:', err);
                    }
                });
            });
        });
        function submitHandler() {
            if ($.validate.form()) {
                $.operate.save(prefix + "/add", $('#form-fileprovide-add').serialize());
            }
        }
        $("input[name='provideDate']").datetimepicker({
            format: "yyyy-mm-dd",
            minView: "month",
            autoclose: true
        });
        $(function() {
            $('#targetDepart').select2({
                placeholder: "请选择收文单位",
                allowClear: true
            });
        })
    </script>
</body>
</html>
