Merge remote-tracking branch 'origin/ps618' into wsc1

This commit is contained in:
王思川 2024-06-18 21:59:35 +08:00
commit db4b346455
5 changed files with 414 additions and 322 deletions

View File

@ -2,6 +2,8 @@ import datetime
from django.db import models from django.db import models
from application.org_mgnt.models import PrimaryDepartment, SecondaryDepartment
# 岗位表 # 岗位表
class Position(models.Model): class Position(models.Model):
@ -104,15 +106,16 @@ class EmployeeInformation(models.Model):
ethnicity = models.CharField(max_length=255, verbose_name='民族', blank=True) ethnicity = models.CharField(max_length=255, verbose_name='民族', blank=True)
domicile = models.CharField(max_length=255, verbose_name='户籍地', blank=True) domicile = models.CharField(max_length=255, verbose_name='户籍地', blank=True)
marital_status = models.CharField(max_length=50, choices=MARITAL_STATUS_CHOICES, verbose_name='婚姻状态') marital_status = models.CharField(max_length=50, choices=MARITAL_STATUS_CHOICES, verbose_name='婚姻状态')
political_affiliation = models.CharField(max_length=50, choices=POLITICAL_AFFILIATION_CHOICES, verbose_name='政治面貌') political_affiliation = models.CharField(max_length=50, choices=POLITICAL_AFFILIATION_CHOICES,
verbose_name='政治面貌')
entry_date = models.DateField(verbose_name='入职日期') entry_date = models.DateField(verbose_name='入职日期')
regularization_date = models.DateField(null=True, blank=True, verbose_name='转正日期') regularization_date = models.DateField(null=True, blank=True, verbose_name='转正日期')
employment_type = models.CharField(max_length=50, choices=EMPLOYMENT_TYPE_CHOICES, verbose_name='用工性质') employment_type = models.CharField(max_length=50, choices=EMPLOYMENT_TYPE_CHOICES, verbose_name='用工性质')
status = models.CharField(max_length=50, choices=STATUS_CHOICES, verbose_name='状态') status = models.CharField(max_length=50, choices=STATUS_CHOICES, verbose_name='状态')
primary_department = models.ForeignKey('org_mgnt.PrimaryDepartment', on_delete=models.SET_NULL, null=True, verbose_name='一级部门') primary_department = models.CharField(max_length=255, verbose_name='一级部门', default='星河')
secondary_department = models.ForeignKey('org_mgnt.SecondaryDepartment', on_delete=models.SET_NULL, null=True, verbose_name='二级部门', blank=True) secondary_department = models.CharField(max_length=255, verbose_name='二级部门', default='数资团队')
position = models.ForeignKey('Position', on_delete=models.SET_NULL, null=True, verbose_name='岗位') position = models.CharField(max_length=255, verbose_name='岗位', default='数据分析师')
rank = models.ForeignKey('Rank', on_delete=models.SET_NULL, null=True, verbose_name='职级', blank=True) rank = models.CharField(max_length=255, verbose_name='职级', default='P1')
contract_end_date = models.DateField(null=True, blank=True, verbose_name='当前合同到期日期') contract_end_date = models.DateField(null=True, blank=True, verbose_name='当前合同到期日期')
mobile_number = models.CharField(max_length=255, verbose_name='手机号') mobile_number = models.CharField(max_length=255, verbose_name='手机号')
email = models.EmailField(verbose_name='邮箱') email = models.EmailField(verbose_name='邮箱')
@ -128,11 +131,30 @@ class EmployeeInformation(models.Model):
base_salary = models.TextField(verbose_name='基础工资(元)', blank=True) base_salary = models.TextField(verbose_name='基础工资(元)', blank=True)
salary_account_number = models.CharField(max_length=255, verbose_name='工资卡号', blank=True) salary_account_number = models.CharField(max_length=255, verbose_name='工资卡号', blank=True)
bank_of_salary_account = models.CharField(max_length=255, verbose_name='工资卡开户行', blank=True) bank_of_salary_account = models.CharField(max_length=255, verbose_name='工资卡开户行', blank=True)
resignation_type = models.CharField(max_length=50, choices=RESIGNATION_TYPE_CHOICES, verbose_name='离职类型', blank=True) resignation_type = models.CharField(max_length=50, choices=RESIGNATION_TYPE_CHOICES, verbose_name='离职类型',
blank=True)
resignation_reason = models.TextField(verbose_name='离职原因', blank=True) resignation_reason = models.TextField(verbose_name='离职原因', blank=True)
resignation_date = models.DateField(null=True, blank=True, verbose_name='离职日期') resignation_date = models.DateField(null=True, blank=True, verbose_name='离职日期')
excluded_fields = ['resignation_type', 'resignation_reason', 'resignation_date'] def save(self, *args, **kwargs):
primary_department_name = PrimaryDepartment.objects.filter(department_name=self.primary_department).first()
secondary_department = SecondaryDepartment.objects.filter(secondary_department_name=self.secondary_department).first()
position = Position.objects.filter(position_name=self.position).first()
rank = Rank.objects.filter(rank_name=self.rank).first()
if not primary_department_name:
raise ValueError("一级部门不存在")
if not secondary_department:
raise ValueError("二级部门不存在")
if not position:
raise ValueError("岗位不存在")
if not rank:
raise ValueError("职位不存在")
super(EmployeeInformation, self).save(*args, **kwargs)
class Meta: class Meta:
verbose_name = '人员基本信息表' verbose_name = '人员基本信息表'
@ -189,7 +211,8 @@ class OtherLeaveDetails(models.Model):
] ]
record_id = models.AutoField(primary_key=True) record_id = models.AutoField(primary_key=True)
attendance_record = models.ForeignKey(EmployeeAttendanceRecord, on_delete=models.CASCADE, related_name='other_leaves', verbose_name='考勤记录') attendance_record = models.ForeignKey(EmployeeAttendanceRecord, on_delete=models.CASCADE,
related_name='other_leaves', verbose_name='考勤记录')
leave_type = models.CharField(max_length=255, choices=LEAVE_TYPE_CHOICES, verbose_name='假期类型') leave_type = models.CharField(max_length=255, choices=LEAVE_TYPE_CHOICES, verbose_name='假期类型')
days = models.IntegerField(verbose_name='天数') days = models.IntegerField(verbose_name='天数')
description = models.TextField(verbose_name='说明') description = models.TextField(verbose_name='说明')

View File

@ -16,7 +16,7 @@
<div class="row"> <div class="row">
<div class="col-md-8"> <div class="col-md-8">
<!-- 筛选表单 开始 --> <!-- 筛选表单 开始 -->
<form action="{% url form_action_url %}" method="get"> <form action="{{ form_action_url }}" method="get">
{% csrf_token %} {% csrf_token %}
<div class="row"> <div class="row">
{% for filter in filters %} {% for filter in filters %}
@ -74,11 +74,13 @@
</div> </div>
<!-- 按钮组 开始 --> <!-- 按钮组 开始 -->
<div class="col-md-4 mt-4 text-end"> <div class="col-md-4 mt-4 text-end">
<button id="addItemBtn" class="btn btn-outline-secondary" {% render_button 'modify_records_button' %}
data-bs-toggle="modal" data-bs-target="#addEditModal">添加 {% render_button 'add_button' %}
</button> {% render_button 'report_excel_button' %}
<button class="btn btn-outline-primary" data-bs-toggle="modal" {#{% render_button 'import_excel_button' %}#}
data-bs-target="#uploadModal">上传Excel <button id="importExcelBtnTest" class="btn btn-outline-primary"
data-bs-toggle="modal" data-bs-target="#uploadModal">
上传Excel(测试)
</button> </button>
</div> </div>
<!-- 按钮组 结束 --> <!-- 按钮组 结束 -->
@ -171,20 +173,6 @@
</section> </section>
<div id="addEditModal" class="modal fade bd-example-modal-lg" tabindex="-1" role="dialog"
aria-labelledby="formModalCenterTitle" aria-hidden="true">
<div class="modal-dialog modal-dialog-centered modal-xl" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="formModalTitle">{{ form_title }}</h5>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body">
</div>
</div>
</div>
</div>
<div class="modal fade" id="resignationModal" tabindex="-1" role="dialog" aria-labelledby="resignationModalLabel" <div class="modal fade" id="resignationModal" tabindex="-1" role="dialog" aria-labelledby="resignationModalLabel"
aria-hidden="true"> aria-hidden="true">
<div class="modal-dialog" role="document"> <div class="modal-dialog" role="document">
@ -248,13 +236,81 @@
</div> </div>
</div> </div>
<div id="addEditModal" class="modal fade bd-example-modal-lg" tabindex="-1" role="dialog"
aria-labelledby="formModalCenterTitle" aria-hidden="true">
<div class="modal-dialog modal-dialog-centered modal-xl" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="formModalTitle">{{ form_title }}</h5>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body">
</div>
</div>
</div>
</div>
<div id="deleteModal" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="deleteModalLabel"
aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="deleteModalLabel">提示</h5>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body">
<p>此操作会删除当前数据,是否继续?</p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-light" data-bs-dismiss="modal">取消</button>
<button type="button" class="btn btn-danger" id="confirmDeleteBtn">删除</button>
</div>
</div>
</div>
</div>
<div id="uploadModal" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="uploadModalLabel"
aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
<form id="upload-form" method="post" enctype="multipart/form-data">
{% csrf_token %}
<div class="modal-header">
<h5 class="modal-title" id="uploadModalLabel">上传Excel文件</h5>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body">
<input id="inputFile" type="file" name="excel_file" class="form-control" hidden accept=".xlsx">
<label class="btn btn-outline-primary" for="inputFile">选择文件</label>
<span id="file-chosen" style="font-size: 12px; margin-left: 10px;">未选择文件</span>
</div>
<div class="modal-footer">
<button id="downloadExcelBtn" type="button" class="btn btn-secondary" onclick="#!">
下载填报模板
</button>
<button id="uploadBtn" type="button" class="btn btn-primary">上传Excel</button>
</div>
</form>
</div>
</div>
</div>
{% include 'modify_record_modal.html' with modify_records_url=modify_records_url %} {% include 'modify_record_modal.html' with modify_records_url=modify_records_url %}
{% include 'delete_modal.html' with delete_url=delete_url %}
{% include 'upload_excel_modal.html' with excel_upload_config=excel_upload_config %} {% block item_list_custom_content %}
{% endblock %}
<script> <script>
const add_url = "{{ add_url }}"; const add_url = "{{ add_url }}";
const modify_url = "{{ modify_url }}"; const modify_url = "{{ modify_url }}";
const deleteUrl = "{{ delete_url }}";
let targetIdToDelete = null;
var templateName = "{{ excel_upload_config.template_name }}";
var modelConfig = "{{ model_config }}";
var list_url = "{{ form_action_url }}"
function calculateAge(birthday) { function calculateAge(birthday) {
var birthDate = new Date(birthday); var birthDate = new Date(birthday);
@ -267,8 +323,24 @@
return age; return age;
} }
$(document).ready(function () { $(document).ready(function () {
function getCookie(name) {
let cookieValue = null;
if (document.cookie && document.cookie !== '') {
const cookies = document.cookie.split(';');
for (let i = 0; i < cookies.length; i++) {
const cookie = cookies[i].trim();
if (cookie.substring(0, name.length + 1) === (name + '=')) {
cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
break;
}
}
}
return cookieValue;
}
const csrftoken = getCookie('csrftoken');
// 处理添加按钮点击事件 // 处理添加按钮点击事件
$('#addItemBtn').click(function () { $('#addItemBtn').click(function () {
$.ajax({ $.ajax({
@ -279,6 +351,8 @@
$('#addEditModal .modal-body').html(response.form_html); $('#addEditModal .modal-body').html(response.form_html);
// 动态设置模态框标题 // 动态设置模态框标题
$('#formModalTitle').text('新增'); $('#formModalTitle').text('新增');
// 动态设置表单提交URL
$('#addEditForm').attr('action', add_url);
// 显示模态框 // 显示模态框
$('#addEditModal').modal('show'); $('#addEditModal').modal('show');
@ -303,6 +377,8 @@
// 将表单 HTML 插入到模态框中 // 将表单 HTML 插入到模态框中
$('#addEditModal .modal-body').html(response.form_html); $('#addEditModal .modal-body').html(response.form_html);
$('#formModalTitle').text('编辑'); $('#formModalTitle').text('编辑');
// 动态设置表单提交URL
$('#addEditForm').attr('action', modify_url);
// 显示模态框 // 显示模态框
$('#addEditModal').modal('show'); $('#addEditModal').modal('show');
@ -321,14 +397,13 @@
$('#addEditForm').submit(function (e) { $('#addEditForm').submit(function (e) {
e.preventDefault(); e.preventDefault();
$.ajax({ $.ajax({
url: modify_url, // 确保URL正确 url: $(this).attr('action'), // 动态获取URL
type: 'post', // 使用 POST 请求来提交表单 type: 'post', // 使用 POST 请求来提交表单
data: $(this).serialize(), data: $(this).serialize(),
success: function (response) { success: function (response) {
// 关闭模态框并显示成功消息 // 关闭模态框并显示成功消息
$('#addEditModal').modal('hide'); $('#addEditModal').modal('hide');
showAlert('success', response.message); showAlert('success', response.message);
// 你可以在这里刷新表格或更新页面内容
location.reload(); location.reload();
}, },
error: function (xhr) { error: function (xhr) {
@ -341,6 +416,86 @@
}); });
} }
// 删除和确认删除
$(document).on('click', '#deleteBtn, #confirmDeleteBtn', function (event) {
if (event.target.id === 'deleteBtn') {
// 打开删除模态框
targetIdToDelete = $(this).data('id');
$('#deleteModal').modal('show');
} else if (event.target.id === 'confirmDeleteBtn') {
// 确认删除
if (targetIdToDelete !== null) {
$.ajax({
type: 'GET',
url: deleteUrl,
data: {
'id': targetIdToDelete
},
success: function (response) {
showAlert('success', "删除成功");
location.reload();
},
error: function (response) {
showAlert('danger', "删除失败");
}
});
}
$('#deleteModal').modal('hide');
}
});
// 点击下载Excel模板按钮
$('#downloadExcelBtn').on('click', function () {
window.location.href = excel_upload_config.template_url;
});
// 当上传模态框显示时,清空文件输入框和文件名显示
$('#uploadModal').on('show.bs.modal', function () {
$('#inputFile').val('');
$('#file-chosen').text('未选择文件');
});
// 当选择文件变化时,更新文件名显示
$('#inputFile').on('change', function () {
var fileName = $(this).val().split('\\').pop();
$('#file-chosen').text(fileName || '未选择文件');
});
// 处理上传按钮的点击事件
$('#uploadBtn').on('click', function () {
var inputFile = $('#inputFile').get(0).files[0];
if (!inputFile) {
showAlert('danger', '未选择文件');
$('#uploadModal').modal('show');
return;
}
var formData = new FormData();
formData.append('file', inputFile); // 将文件添加到 FormData 中
formData.append('template_name', templateName);
formData.append('excel_valid_model', modelConfig);
formData.append('list_url', list_url)
$.ajax({
url: '{{ excel_upload_config.parse_url }}',
type: 'POST',
data: formData,
headers: {'X-CSRFToken': csrftoken},
contentType: false,
processData: false,
success: function (response) {
window.location.href = response.redirect_url;
},
error: function (xhr, status, error) {
var errorMsg = "解析Excel文件失败。";
if (xhr.responseJSON && xhr.responseJSON.error) {
errorMsg = xhr.responseJSON.error;
}
showAlert('danger', errorMsg);
}
});
});
$(document).on('change', '#id_birthday', function () { $(document).on('change', '#id_birthday', function () {
var birthday = $(this).val(); var birthday = $(this).val();
if (birthday) { if (birthday) {
@ -352,6 +507,7 @@
}); });
}); });
function showResignationModal(resignation_type, resignation_reason, resignation_date) { function showResignationModal(resignation_type, resignation_reason, resignation_date) {
// 填充模态框内容 // 填充模态框内容
document.getElementById('resignationType').innerText = resignation_type; document.getElementById('resignationType').innerText = resignation_type;

View File

@ -16,7 +16,7 @@
<div class="row"> <div class="row">
<div class="col-md-8"> <div class="col-md-8">
<!-- 筛选表单 开始 --> <!-- 筛选表单 开始 -->
<form action="{% url form_action_url %}" method="get"> <form action="{{ form_action_url }}" method="get">
{% csrf_token %} {% csrf_token %}
<div class="row"> <div class="row">
{% for filter in filters %} {% for filter in filters %}
@ -74,11 +74,13 @@
</div> </div>
<!-- 按钮组 开始 --> <!-- 按钮组 开始 -->
<div class="col-md-4 mt-4 text-end"> <div class="col-md-4 mt-4 text-end">
<button id="addItemBtn" class="btn btn-outline-secondary" {% render_button 'modify_records_button' %}
data-bs-toggle="modal" data-bs-target="#addEditModal">添加 {% render_button 'add_button' %}
</button> {% render_button 'report_excel_button' %}
<button class="btn btn-outline-primary" data-bs-toggle="modal" {# {% render_button 'import_excel_button' %}#}
data-bs-target="#uploadModal">上传Excel <button id="importExcelBtnTest" class="btn btn-outline-primary"
data-bs-toggle="modal" data-bs-target="#uploadModal">
上传Excel(测试)
</button> </button>
</div> </div>
<!-- 按钮组 结束 --> <!-- 按钮组 结束 -->
@ -135,10 +137,19 @@
{% endif %} {% endif %}
{% endfor %} {% endfor %}
<td class="text-center"> <td class="text-center">
<a href="#" class="edit-btn" <a href="#"
id="editBtn"
class="edit-btn"
data-id="{{ item|get_pk_value }}" data-id="{{ item|get_pk_value }}"
data-bs-toggle="modal" data-bs-toggle="modal"
data-bs-target="#addEditModal">编辑</a> data-bs-target="#addEditModal">编辑</a>
<a href="#"
id="deleteBtn"
class="edit-btn"
style="color: red"
data-id="{{ item|get_pk_value }}"
data-bs-toggle="modal"
data-bs-target="#deleteModal">删除</a>
</td> </td>
</tr> </tr>
{% empty %} {% empty %}
@ -165,19 +176,6 @@
</section> </section>
<div id="addEditModal" class="modal fade bd-example-modal-lg" tabindex="-1" role="dialog"
aria-labelledby="formModalCenterTitle" aria-hidden="true">
<div class="modal-dialog modal-dialog-centered modal-xl" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="formModalTitle">{{ form_title }}</h5>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body">
</div>
</div>
</div>
</div>
<div id="shareholdersModal" class="modal fade bd-example-modal-sm" tabindex="-1" role="dialog" <div id="shareholdersModal" class="modal fade bd-example-modal-sm" tabindex="-1" role="dialog"
aria-labelledby="formModalCenterTitle" aria-hidden="true"> aria-labelledby="formModalCenterTitle" aria-hidden="true">
<div class="modal-dialog modal-dialog-centered modal-sm" role="document"> <div class="modal-dialog modal-dialog-centered modal-sm" role="document">
@ -201,9 +199,9 @@
</div> </div>
</div> </div>
</div> </div>
<div id="showHistoryModal" class="modal fade bd-example-modal-lg" tabindex="-1" role="dialog" <div id="showHistoryModal" class="modal fade bd-example-modal-xl" tabindex="-1" role="dialog"
aria-labelledby="formModalCenterTitle" aria-hidden="true"> aria-labelledby="formModalCenterTitle" aria-hidden="true">
<div class="modal-dialog modal-dialog-centered modal-lg" role="document"> <div class="modal-dialog modal-dialog-centered modal-xl" role="document">
<div class="modal-content"> <div class="modal-content">
<div class="modal-header"> <div class="modal-header">
<h5 class="modal-title" id="formModalTitle">历史沿革</h5> <h5 class="modal-title" id="formModalTitle">历史沿革</h5>
@ -310,12 +308,12 @@
</div> </div>
</div> </div>
</div> </div>
<div id="deleteModal" class="modal fade" tabindex="-1" role="dialog" <div id="deleteBankAModal" class="modal fade" tabindex="-1" role="dialog"
aria-labelledby="deleteModalLabel" aria-hidden="true"> aria-labelledby="deleteBankModalLabel" aria-hidden="true">
<div class="modal-dialog" role="document"> <div class="modal-dialog" role="document">
<div class="modal-content"> <div class="modal-content">
<div class="modal-header"> <div class="modal-header">
<h5 class="modal-title" id="deleteModalLabel">提示 <h5 class="modal-title" id="deleteBankModalLabel">提示
</h5> </h5>
<button type="button" class="btn-close" data-bs-dismiss="modal" <button type="button" class="btn-close" data-bs-dismiss="modal"
aria-label="Close"></button> aria-label="Close"></button>
@ -377,17 +375,103 @@
</div> </div>
</div> </div>
<div id="addEditModal" class="modal fade bd-example-modal-lg" tabindex="-1" role="dialog"
aria-labelledby="formModalCenterTitle" aria-hidden="true">
<div class="modal-dialog modal-dialog-centered modal-xl" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="formModalTitle">{{ form_title }}</h5>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body">
</div>
</div>
</div>
</div>
<div id="deleteModal" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="deleteModalLabel"
aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="deleteModalLabel">提示</h5>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body">
<p>此操作会删除当前数据,是否继续?</p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-light" data-bs-dismiss="modal">取消</button>
<button type="button" class="btn btn-danger" id="confirmDeleteBtn">删除</button>
</div>
</div>
</div>
</div>
<div id="uploadModal" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="uploadModalLabel"
aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
<form id="upload-form" method="post" enctype="multipart/form-data">
{% csrf_token %}
<div class="modal-header">
<h5 class="modal-title" id="uploadModalLabel">上传Excel文件</h5>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body">
<input id="inputFile" type="file" name="excel_file" class="form-control" hidden accept=".xlsx">
<label class="btn btn-outline-primary" for="inputFile">选择文件</label>
<span id="file-chosen" style="font-size: 12px; margin-left: 10px;">未选择文件</span>
</div>
<div class="modal-footer">
<button id="downloadExcelBtn" type="button" class="btn btn-secondary" onclick="#!">
下载填报模板
</button>
<button id="uploadBtn" type="button" class="btn btn-primary">上传Excel</button>
</div>
</form>
</div>
</div>
</div>
{% include 'modify_record_modal.html' with modify_records_url=modify_records_url %} {% include 'modify_record_modal.html' with modify_records_url=modify_records_url %}
{% include 'delete_modal.html' with delete_url=delete_url %}
{% include 'upload_excel_modal.html' with excel_upload_config=excel_upload_config %} {% block item_list_custom_content %}
{% endblock %}
<script> <script>
const add_url = "{{ add_url }}"; const add_url = "{{ add_url }}";
const modify_url = "{{ modify_url }}"; const modify_url = "{{ modify_url }}";
const deleteUrl = "{{ delete_url }}";
let targetIdToDelete = null;
var templateName = "{{ excel_upload_config.template_name }}";
var modelConfig = "{{ model_config }}";
var list_url = "{{ form_action_url }}"
let accountIdToDelete; let accountIdToDelete;
let accountIdToEdit; let accountIdToEdit;
$(document).ready(function () { $(document).ready(function () {
function getCookie(name) {
let cookieValue = null;
if (document.cookie && document.cookie !== '') {
const cookies = document.cookie.split(';');
for (let i = 0; i < cookies.length; i++) {
const cookie = cookies[i].trim();
if (cookie.substring(0, name.length + 1) === (name + '=')) {
cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
break;
}
}
}
return cookieValue;
}
const csrftoken = getCookie('csrftoken');
// 处理添加按钮点击事件 // 处理添加按钮点击事件
$('#addItemBtn').click(function () { $('#addItemBtn').click(function () {
$.ajax({ $.ajax({
@ -398,6 +482,8 @@
$('#addEditModal .modal-body').html(response.form_html); $('#addEditModal .modal-body').html(response.form_html);
// 动态设置模态框标题 // 动态设置模态框标题
$('#formModalTitle').text('新增'); $('#formModalTitle').text('新增');
// 动态设置表单提交URL
$('#addEditForm').attr('action', add_url);
// 显示模态框 // 显示模态框
$('#addEditModal').modal('show'); $('#addEditModal').modal('show');
@ -412,7 +498,7 @@
}); });
// 处理编辑按钮点击事件 // 处理编辑按钮点击事件
$('.edit-btn').click(function () { $('#editBtn').click(function () {
var itemId = $(this).data('id'); var itemId = $(this).data('id');
$.ajax({ $.ajax({
url: modify_url, url: modify_url,
@ -422,6 +508,8 @@
// 将表单 HTML 插入到模态框中 // 将表单 HTML 插入到模态框中
$('#addEditModal .modal-body').html(response.form_html); $('#addEditModal .modal-body').html(response.form_html);
$('#formModalTitle').text('编辑'); $('#formModalTitle').text('编辑');
// 动态设置表单提交URL
$('#addEditForm').attr('action', modify_url);
// 显示模态框 // 显示模态框
$('#addEditModal').modal('show'); $('#addEditModal').modal('show');
@ -440,14 +528,13 @@
$('#addEditForm').submit(function (e) { $('#addEditForm').submit(function (e) {
e.preventDefault(); e.preventDefault();
$.ajax({ $.ajax({
url: modify_url, // 确保URL正确 url: $(this).attr('action'), // 动态获取URL
type: 'post', // 使用 POST 请求来提交表单 type: 'post', // 使用 POST 请求来提交表单
data: $(this).serialize(), data: $(this).serialize(),
success: function (response) { success: function (response) {
// 关闭模态框并显示成功消息 // 关闭模态框并显示成功消息
$('#addEditModal').modal('hide'); $('#addEditModal').modal('hide');
showAlert('success', response.message); showAlert('success', response.message);
// 你可以在这里刷新表格或更新页面内容
location.reload(); location.reload();
}, },
error: function (xhr) { error: function (xhr) {
@ -459,6 +546,86 @@
}); });
}); });
} }
// 删除和确认删除
$(document).on('click', '#deleteBtn, #confirmDeleteBtn', function (event) {
if (event.target.id === 'deleteBtn') {
// 打开删除模态框
targetIdToDelete = $(this).data('id');
$('#deleteModal').modal('show');
} else if (event.target.id === 'confirmDeleteBtn') {
// 确认删除
if (targetIdToDelete !== null) {
$.ajax({
type: 'GET',
url: deleteUrl,
data: {
'id': targetIdToDelete
},
success: function (response) {
showAlert('success', "删除成功");
location.reload();
},
error: function (response) {
showAlert('danger', "删除失败");
}
});
}
$('#deleteModal').modal('hide');
}
});
// 点击下载Excel模板按钮
$('#downloadExcelBtn').on('click', function () {
window.location.href = excel_upload_config.template_url;
});
// 当上传模态框显示时,清空文件输入框和文件名显示
$('#uploadModal').on('show.bs.modal', function () {
$('#inputFile').val('');
$('#file-chosen').text('未选择文件');
});
// 当选择文件变化时,更新文件名显示
$('#inputFile').on('change', function () {
var fileName = $(this).val().split('\\').pop();
$('#file-chosen').text(fileName || '未选择文件');
});
// 处理上传按钮的点击事件
$('#uploadBtn').on('click', function () {
var inputFile = $('#inputFile').get(0).files[0];
if (!inputFile) {
showAlert('danger', '未选择文件');
$('#uploadModal').modal('show');
return;
}
var formData = new FormData();
formData.append('file', inputFile); // 将文件添加到 FormData 中
formData.append('template_name', templateName);
formData.append('excel_valid_model', modelConfig);
formData.append('list_url', list_url)
$.ajax({
url: '{{ excel_upload_config.parse_url }}',
type: 'POST',
data: formData,
headers: {'X-CSRFToken': csrftoken},
contentType: false,
processData: false,
success: function (response) {
window.location.href = response.redirect_url;
},
error: function (xhr, status, error) {
var errorMsg = "解析Excel文件失败。";
if (xhr.responseJSON && xhr.responseJSON.error) {
errorMsg = xhr.responseJSON.error;
}
showAlert('danger', errorMsg);
}
});
});
}); });
function showShareholdersModal(data) { function showShareholdersModal(data) {
@ -577,7 +744,7 @@
deleteButton.className = 'btn btn-outline-danger btn-sm'; deleteButton.className = 'btn btn-outline-danger btn-sm';
deleteButton.onclick = () => { deleteButton.onclick = () => {
accountIdToDelete = account.account_id; accountIdToDelete = account.account_id;
const deleteModal = new bootstrap.Modal(document.getElementById('deleteModal')); const deleteModal = new bootstrap.Modal(document.getElementById('deleteBankModal'));
deleteModal.show(); deleteModal.show();
}; };
@ -691,7 +858,7 @@
const bankName = document.getElementById('editBankName').value; const bankName = document.getElementById('editBankName').value;
const accountNumber = document.getElementById('editAccountNumber').value; const accountNumber = document.getElementById('editAccountNumber').value;
const accountType = document.getElementById('editAccountType').value; const accountType = document.getElementById('editAccountType').value;
const accountStatus= document.getElementById('editAccountStatus').value; const accountStatus = document.getElementById('editAccountStatus').value;
fetch(`/basic_data/om/bank_accounts/${accountIdToEdit}/update/`, { fetch(`/basic_data/om/bank_accounts/${accountIdToEdit}/update/`, {
method: 'PUT', method: 'PUT',
@ -768,259 +935,5 @@
} }
</script> </script>
<script>
const add_url = "{{ add_url }}";
const modify_url = "{{ modify_url }}";
let Commission_id = '';
let deleteCommissionId = null;
$(document).ready(function () {
// 处理添加按钮点击事件
$('#addItemBtn').click(function () {
$.ajax({
url: add_url,
type: 'get',
success: function (response) {
// 将新的表单 HTML 插入到模态框中
$('#addEditModal .modal-body').html(response.form_html);
// 动态设置模态框标题
$('#formModalTitle').text('新增');
// 显示模态框
$('#addEditModal').modal('show');
// 绑定表单提交事件
bindFormSubmit();
},
error: function () {
$('#addEditModal').modal('hide');
showAlert('danger', '获取表单请求出错');
}
});
});
// 处理编辑按钮点击事件
$('.edit-btn').click(function () {
var itemId = $(this).data('id');
$.ajax({
url: modify_url,
type: 'get',
data: {id: itemId},
success: function (response) {
// 将表单 HTML 插入到模态框中
$('#addEditModal .modal-body').html(response.form_html);
$('#formModalTitle').text('编辑');
// 显示模态框
$('#addEditModal').modal('show');
// 绑定表单提交事件
bindFormSubmit();
},
error: function () {
$('#addEditModal').modal('hide');
showAlert('danger', '获取表单请求出错');
}
});
});
// 保存
function bindFormSubmit() {
$('#addEditForm').submit(function (e) {
e.preventDefault();
$.ajax({
url: modify_url, // 确保URL正确
type: 'post', // 使用 POST 请求来提交表单
data: $(this).serialize(),
success: function (response) {
// 关闭模态框并显示成功消息
$('#addEditModal').modal('hide');
showAlert('success', response.message);
// 你可以在这里刷新表格或更新页面内容
location.reload();
},
error: function (xhr) {
// 处理表单错误并显示错误消息
var response = xhr.responseJSON;
$('#addEditModal .modal-body').html(response.form_html);
bindFormSubmit();
}
});
});
}
});
function showCommissionModal(recordId) {
Commission_id = recordId;
fetch(`/basic_data/fm/get_employee_commission_details/${recordId}/`)
.then(response => response.json())
.then(data => {
const tableBody = document.getElementById('commissionTableBody');
const noDataMessage = document.getElementById('noCommissionMessage');
tableBody.innerHTML = '';
if (data.length === 0) {
noDataMessage.style.display = 'block';
} else {
noDataMessage.style.display = 'none';
data.forEach(detail => {
const row = document.createElement('tr');
row.innerHTML = `
<td class="text-center">${detail.employee_name}</td>
<td class="text-center">${detail.primary_department}</td>
<td class="text-center">${detail.year}</td>
<td class="text-center">${detail.performance_score}</td>
<td class="text-center">${detail.total_commission}</td>
<td class="text-center">${detail.amount_paid}</td>
<td class="text-center">${detail.accrued_amount}</td>
<td class="text-center">${detail.back_pay_amount}</td>
<td class="text-center">${detail.deduction_amount}</td>
<td class="text-center">
<button class="btn btn-outline-primary btn-sm me-2" onclick="showEditCommissionModal(${detail.record_id})">编辑</button>
<button class="btn btn-outline-danger btn-sm" onclick="showDeleteCommissionModal(${detail.record_id})">删除</button>
</td>
`;
tableBody.appendChild(row);
});
}
const commissionModal = new bootstrap.Modal(document.getElementById('commissionModal'));
commissionModal.show();
})
.catch(error => console.error('Error fetching employee commission details:', error));
}
function showAddCommissionModal() {
// 关闭员工提成详情模态框
const commissionModal = bootstrap.Modal.getInstance(document.getElementById('commissionModal'));
if (commissionModal) {
commissionModal.hide();
}
// Fetch employees and years
fetch('/basic_data/fm/get_employees/')
.then(response => response.json())
.then(data => {
const employeeSelect = document.getElementById('employee');
employeeSelect.innerHTML = '<option value="">请选择员工</option>';
data.employees.forEach(employee => {
const option = document.createElement('option');
option.value = employee.id;
option.name = employee.name;
option.textContent = employee.name;
employeeSelect.appendChild(option);
});
});
const yearSelect = document.getElementById('year');
yearSelect.innerHTML = '<option value="">请选择年度</option>';
const currentYear = new Date().getFullYear();
for (let year = currentYear; year >= 2000; year--) {
const option = document.createElement('option');
option.value = year;
option.textContent = year;
yearSelect.appendChild(option);
}
const addCommissionModal = new bootstrap.Modal(document.getElementById('addCommissionModal'));
addCommissionModal.show();
}
document.getElementById('employee').addEventListener('change', function () {
const employeeId = this.value;
if (employeeId) {
fetch(`/basic_data/fm/get_employee_info/${employeeId}/`)
.then(response => response.json())
.then(data => {
document.getElementById('primary_department').value = data.primary_department;
});
}
});
document.getElementById('year').addEventListener('change', function () {
const employeeId = document.getElementById('employee').value;
const year = this.value;
if (employeeId && year) {
fetch(`/basic_data/fm/get_performance_score/${employeeId}/${year}/`)
.then(response => response.json())
.then(data => {
document.getElementById('performance_score').value = data.performance_score;
});
}
});
function submitAddCommissionForm() {
const form = document.getElementById('addCommissionForm');
const formData = new FormData(form);
formData.append('project_commission', Commission_id); // 添加 project_commission_id
fetch('/basic_data/fm/add_employee_commission_detail/', {
method: 'POST',
body: formData,
headers: {
'X-CSRFToken': '{{ csrf_token }}'
}
})
.then(response => response.json())
.then(data => {
if (data.success) {
// 关闭新增模态框
const addCommissionModal = bootstrap.Modal.getInstance(document.getElementById('addCommissionModal'));
addCommissionModal.hide();
showAlert('success', '新建成功');
// 刷新员工提成详情表
showCommissionModal(recordId);
} else {
alert('保存失败: ' + data.message);
}
})
.catch(error => console.error('Error adding employee commission detail:', error));
}
function showDeleteCommissionModal(id) {
deleteCommissionId = id;
// 隐藏 ID 为 commissionModal 的模态框
const commissionModalElement = document.getElementById('commissionModal');
const commissionModalInstance = bootstrap.Modal.getInstance(commissionModalElement);
if (commissionModalInstance) {
commissionModalInstance.hide();
}
// 显示删除确认模态框
const showDeleteModalElement = document.getElementById('deleteCommissionModal');
let deleteModal = bootstrap.Modal.getInstance(showDeleteModalElement);
if (!deleteModal) {
deleteModal = new bootstrap.Modal(showDeleteModalElement);
}
deleteModal.show();
}
function deleteCommission() {
fetch(`/basic_data/fm/delete_employee_commission/${deleteCommissionId}/`, {
method: 'DELETE',
headers: {
'X-CSRFToken': '{{ csrf_token }}'
}
})
.then(response => response.json())
.then(data => {
if (data.success) {
alert('删除成功');
const deleteModal = bootstrap.Modal.getInstance(document.getElementById('deleteCommissionModal'));
deleteModal.hide();
showCommissionModal(Commission_id);
} else {
alert('删除失败: ' + data.message);
}
})
.catch(error => console.error('Error deleting employee commission:', error));
}
</script>
{% endblock %} {% endblock %}

View File

@ -117,7 +117,7 @@
data-bs-target="#addEditModal">编辑</a> data-bs-target="#addEditModal">编辑</a>
<a href="#" <a href="#"
id="deleteBtn" id="deleteBtn"
class="edit-btn" class="delete-btn"
style="color: red" style="color: red"
data-id="{{ item|get_pk_value }}" data-id="{{ item|get_pk_value }}"
data-bs-toggle="modal" data-bs-toggle="modal"
@ -264,7 +264,7 @@
}); });
// 处理编辑按钮点击事件 // 处理编辑按钮点击事件
$('#editBtn').click(function () { $('.edit-btn').click(function () {
var itemId = $(this).data('id'); var itemId = $(this).data('id');
$.ajax({ $.ajax({
url: modify_url, url: modify_url,
@ -314,7 +314,7 @@
} }
// 删除和确认删除 // 删除和确认删除
$(document).on('click', '#deleteBtn, #confirmDeleteBtn', function (event) { $(document).on('click', '.delete-btn, #confirmDeleteBtn', function (event) {
if (event.target.id === 'deleteBtn') { if (event.target.id === 'deleteBtn') {
// 打开删除模态框 // 打开删除模态框
targetIdToDelete = $(this).data('id'); targetIdToDelete = $(this).data('id');