2024-06-06 18:02:55 +08:00
|
|
|
{% load tags %}
|
|
|
|
<form id="addEditForm" method="post">
|
|
|
|
{% csrf_token %}
|
2024-06-06 21:27:24 +08:00
|
|
|
{% if form.instance.pk %}
|
|
|
|
<input type="hidden" name="id" value="{{ form.instance.pk }}">
|
2024-06-06 18:02:55 +08:00
|
|
|
{% endif %}
|
|
|
|
<div class="card-body">
|
|
|
|
<div class="row">
|
|
|
|
<div class="col-md-6">
|
|
|
|
{% for field in form %}
|
|
|
|
{% if forloop.counter0|divisibleby:2 %}
|
|
|
|
<div class="mb-3">
|
|
|
|
<label class="form-label" for="{{ field.id_for_label }}">{{ field.label }}</label>
|
2024-06-06 21:27:24 +08:00
|
|
|
{% if field.field.widget.input_type == "text" %}
|
|
|
|
<input type="text" class="form-control" id="{{ field.id_for_label }}" name="{{ field.name }}" value="{{ field.value|default_if_none:'' }}" placeholder="{{ field.label }}">
|
|
|
|
{% elif field.field.widget.input_type == "number" %}
|
|
|
|
<input type="number" class="form-control" id="{{ field.id_for_label }}" name="{{ field.name }}" value="{{ field.value|default_if_none:'' }}" placeholder="{{ field.label }}">
|
|
|
|
{% elif field.field.widget.input_type == "select" %}
|
2024-06-06 18:02:55 +08:00
|
|
|
<select class="form-control" id="{{ field.id_for_label }}" name="{{ field.name }}">
|
|
|
|
{% for choice in field.field.choices %}
|
|
|
|
<option value="{{ choice.0 }}" {% if choice.0 == field.value %}selected{% endif %}>{{ choice.1 }}</option>
|
|
|
|
{% endfor %}
|
|
|
|
</select>
|
|
|
|
{% elif field|is_input_type:"textarea" %}
|
2024-06-06 21:27:24 +08:00
|
|
|
<textarea class="form-control" id="{{ field.id_for_label }}" name="{{ field.name }}" rows="3">{{ field.value|default_if_none:'' }}</textarea>
|
|
|
|
{% elif field.field.widget.input_type == "date" %}
|
|
|
|
<input type="date" class="form-control" id="{{ field.id_for_label }}" name="{{ field.name }}" value="{{ field.value|date:"Y-m-d" }}">
|
2024-06-16 06:06:51 +08:00
|
|
|
{% elif field.field.widget.input_type == "datetime-local" %}
|
|
|
|
<input type="datetime-local" class="form-control" id="{{ field.id_for_label }}" name="{{ field.name }}" value="{{ field.value|date:"Y-m-d\TH:i" }}">
|
2024-06-06 21:27:24 +08:00
|
|
|
{% elif field.field.widget.input_type == "email" %}
|
|
|
|
<input type="email" class="form-control" id="{{ field.id_for_label }}" name="{{ field.name }}" value="{{ field.value|default_if_none:'' }}" placeholder="{{ field.label }}">
|
|
|
|
{% elif field.field.widget.input_type == "password" %}
|
2024-06-06 18:02:55 +08:00
|
|
|
<input type="password" class="form-control" id="{{ field.id_for_label }}" name="{{ field.name }}" placeholder="{{ field.label }}">
|
2024-06-06 21:27:24 +08:00
|
|
|
{% elif field.field.widget.input_type == "checkbox" %}
|
2024-06-06 18:02:55 +08:00
|
|
|
<div class="form-check">
|
|
|
|
<input type="checkbox" class="form-check-input" id="{{ field.id_for_label }}" name="{{ field.name }}" {% if field.value %}checked{% endif %}>
|
|
|
|
<label class="form-check-label" for="{{ field.id_for_label }}">{{ field.label }}</label>
|
|
|
|
</div>
|
|
|
|
{% else %}
|
|
|
|
{{ field }}
|
|
|
|
{% endif %}
|
|
|
|
{% if field.help_text %}
|
|
|
|
<small class="form-text text-muted">{{ field.help_text }}</small>
|
|
|
|
{% endif %}
|
|
|
|
{% for error in field.errors %}
|
|
|
|
<div class="text-danger">{{ error }}</div>
|
|
|
|
{% endfor %}
|
|
|
|
</div>
|
|
|
|
{% endif %}
|
|
|
|
{% endfor %}
|
|
|
|
</div>
|
|
|
|
<div class="col-md-6">
|
|
|
|
{% for field in form %}
|
|
|
|
{% if not forloop.counter0|divisibleby:2 %}
|
|
|
|
<div class="mb-3">
|
|
|
|
<label class="form-label" for="{{ field.id_for_label }}">{{ field.label }}</label>
|
2024-06-06 21:27:24 +08:00
|
|
|
{% if field.field.widget.input_type == "text" %}
|
|
|
|
<input type="text" class="form-control" id="{{ field.id_for_label }}" name="{{ field.name }}" value="{{ field.value|default_if_none:'' }}" placeholder="{{ field.label }}">
|
|
|
|
{% elif field.field.widget.input_type == "number" %}
|
|
|
|
<input type="number" class="form-control" id="{{ field.id_for_label }}" name="{{ field.name }}" value="{{ field.value|default_if_none:'' }}" placeholder="{{ field.label }}">
|
|
|
|
{% elif field.field.widget.input_type == "select" %}
|
2024-06-06 18:02:55 +08:00
|
|
|
<select class="form-control" id="{{ field.id_for_label }}" name="{{ field.name }}">
|
|
|
|
{% for choice in field.field.choices %}
|
|
|
|
<option value="{{ choice.0 }}" {% if choice.0 == field.value %}selected{% endif %}>{{ choice.1 }}</option>
|
|
|
|
{% endfor %}
|
|
|
|
</select>
|
|
|
|
{% elif field|is_input_type:"textarea" %}
|
2024-06-06 21:27:24 +08:00
|
|
|
<textarea class="form-control" id="{{ field.id_for_label }}" name="{{ field.name }}" rows="3">{{ field.value|default_if_none:'' }}</textarea>
|
|
|
|
{% elif field.field.widget.input_type == "date" %}
|
|
|
|
<input type="date" class="form-control" id="{{ field.id_for_label }}" name="{{ field.name }}" value="{{ field.value|date:"Y-m-d" }}">
|
2024-06-16 06:06:51 +08:00
|
|
|
{% elif field.field.widget.input_type == "datetime-local" %}
|
|
|
|
<input type="datetime-local" class="form-control" id="{{ field.id_for_label }}" name="{{ field.name }}" value="{{ field.value|date:"Y-m-d\TH:i" }}">
|
2024-06-07 14:20:58 +08:00
|
|
|
{% elif field.field.widget.input_type == "month" %}
|
|
|
|
<input type="date" class="form-control" id="{{ field.id_for_label }}" name="{{ field.name }}" value="{{ field.value|date:"Y-m-d" }}">
|
2024-06-06 21:27:24 +08:00
|
|
|
{% elif field.field.widget.input_type == "email" %}
|
|
|
|
<input type="email" class="form-control" id="{{ field.id_for_label }}" name="{{ field.name }}" value="{{ field.value|default_if_none:'' }}" placeholder="{{ field.label }}">
|
|
|
|
{% elif field.field.widget.input_type == "password" %}
|
2024-06-06 18:02:55 +08:00
|
|
|
<input type="password" class="form-control" id="{{ field.id_for_label }}" name="{{ field.name }}" placeholder="{{ field.label }}">
|
2024-06-06 21:27:24 +08:00
|
|
|
{% elif field.field.widget.input_type == "checkbox" %}
|
2024-06-06 18:02:55 +08:00
|
|
|
<div class="form-check">
|
|
|
|
<input type="checkbox" class="form-check-input" id="{{ field.id_for_label }}" name="{{ field.name }}" {% if field.value %}checked{% endif %}>
|
|
|
|
<label class="form-check-label" for="{{ field.id_for_label }}">{{ field.label }}</label>
|
|
|
|
</div>
|
|
|
|
{% else %}
|
|
|
|
{{ field }}
|
|
|
|
{% endif %}
|
|
|
|
{% if field.help_text %}
|
|
|
|
<small class="form-text text-muted">{{ field.help_text }}</small>
|
|
|
|
{% endif %}
|
|
|
|
{% for error in field.errors %}
|
|
|
|
<div class="text-danger">{{ error }}</div>
|
|
|
|
{% endfor %}
|
|
|
|
</div>
|
|
|
|
{% endif %}
|
|
|
|
{% endfor %}
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
2024-06-06 21:27:24 +08:00
|
|
|
<div class="modal-footer">
|
|
|
|
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">取消</button>
|
|
|
|
<button type="submit" class="btn btn-primary" id="submitForm">保存</button>
|
|
|
|
</div>
|
2024-06-06 18:02:55 +08:00
|
|
|
</form>
|
2024-06-16 13:30:21 +08:00
|
|
|
|
|
|
|
<script type="text/javascript">
|
|
|
|
$(document).ready(function () {
|
2024-06-16 15:24:35 +08:00
|
|
|
function updateSecondaryDepartments(primaryDepartmentId, selectedSecondaryDepartmentId = null) {
|
2024-06-16 14:48:38 +08:00
|
|
|
var url = "{% url 'load_secondary_departments' %}";
|
2024-06-16 13:30:21 +08:00
|
|
|
$.ajax({
|
|
|
|
url: url,
|
|
|
|
data: {
|
|
|
|
'primary_department_id': primaryDepartmentId
|
|
|
|
},
|
|
|
|
success: function (data) {
|
|
|
|
$('#id_secondary_department').html('');
|
|
|
|
$('#id_secondary_department').append('<option value="">选择二级部门</option>');
|
|
|
|
$.each(data, function (key, value) {
|
2024-06-16 14:48:38 +08:00
|
|
|
$('#id_secondary_department').append('<option value="' + value.secondary_department_id + '">' + value.secondary_department_name + '</option>');
|
2024-06-16 13:30:21 +08:00
|
|
|
});
|
2024-06-16 15:24:35 +08:00
|
|
|
if (selectedSecondaryDepartmentId) {
|
|
|
|
$('#id_secondary_department').val(selectedSecondaryDepartmentId);
|
|
|
|
}
|
2024-06-16 13:30:21 +08:00
|
|
|
}
|
|
|
|
});
|
2024-06-16 14:48:38 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
$('#id_primary_department').change(function () {
|
|
|
|
var primaryDepartmentId = $(this).val();
|
|
|
|
if (primaryDepartmentId) {
|
|
|
|
updateSecondaryDepartments(primaryDepartmentId);
|
|
|
|
} else {
|
|
|
|
$('#id_secondary_department').html('<option value="">选择二级部门</option>');
|
|
|
|
}
|
2024-06-16 13:30:21 +08:00
|
|
|
});
|
2024-06-16 14:48:38 +08:00
|
|
|
|
|
|
|
// 如果在页面加载时已选择一级部门,则加载相应的二级部门
|
|
|
|
var initialPrimaryDepartmentId = $('#id_primary_department').val();
|
2024-06-16 15:24:35 +08:00
|
|
|
var initialSecondaryDepartmentId = $('#id_secondary_department').val();
|
2024-06-16 14:48:38 +08:00
|
|
|
if (initialPrimaryDepartmentId) {
|
2024-06-16 15:24:35 +08:00
|
|
|
updateSecondaryDepartments(initialPrimaryDepartmentId, initialSecondaryDepartmentId);
|
2024-06-16 14:48:38 +08:00
|
|
|
}
|
2024-06-16 13:30:21 +08:00
|
|
|
});
|
2024-06-16 19:34:15 +08:00
|
|
|
</script>
|
|
|
|
<script type="text/javascript">
|
|
|
|
$(document).ready(function () {
|
|
|
|
// 动态生成id_seal_type的select选项
|
|
|
|
var sealTypeOptions = [
|
|
|
|
{ value: '公章', text: '公章' },
|
|
|
|
{ value: '法人章', text: '法人章' },
|
|
|
|
{ value: '合同章', text: '合同章' },
|
|
|
|
{ value: '财务章', text: '财务章' },
|
|
|
|
{ value: '其他', text: '其他' }
|
|
|
|
];
|
|
|
|
|
|
|
|
var $sealTypeSelect = $('<select>', {
|
|
|
|
class: 'form-control',
|
|
|
|
id: 'id_seal_type',
|
|
|
|
name: 'seal_type'
|
|
|
|
});
|
|
|
|
|
|
|
|
$.each(sealTypeOptions, function (index, option) {
|
|
|
|
$sealTypeSelect.append($('<option>', {
|
|
|
|
value: option.value,
|
|
|
|
text: option.text
|
|
|
|
}));
|
|
|
|
});
|
|
|
|
|
|
|
|
// 替换现有的#id_seal_type元素
|
|
|
|
$('#id_seal_type').replaceWith($sealTypeSelect);
|
|
|
|
|
|
|
|
// 如果需要在选择时执行某些操作,可以添加监听器
|
|
|
|
$('#id_seal_type').change(function() {
|
|
|
|
var selectedSealType = $(this).val();
|
|
|
|
console.log('选择的用印类型是:' + selectedSealType);
|
|
|
|
// 在这里添加其他需要的处理逻辑
|
|
|
|
});
|
|
|
|
});
|
|
|
|
</script>
|