| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400 |
- {% extends "base.html" %}
- {% block title %}逐鹿人才-证件合同管理系统-查看合同 - {{ contract.name }}{% endblock %}
- {% block content %}
- <div class="container mt-5">
- <!-- 页面标题与操作按钮 -->
- <div class="d-flex justify-content-between align-items-center mb-4 flex-wrap">
- <h2 class="text-dark mb-2"><i class="bi bi-file-text"></i> 查看合同 - {{ contract.name }}</h2>
- <div class="btn-toolbar mb-2" role="toolbar">
- <div class="btn-group me-2 mb-2" role="group">
- {% if current_user.can_edit %}
- <a href="{{ url_for('edit_contract', contract_id=contract.id) }}" class="btn btn-outline-secondary btn-sm">
- <i class="bi bi-pencil-square"></i> 编辑
- </a>
- {% endif %}
- {% if current_user.can_create and contract.is_active %}
- <a href="{{ url_for('renew_contract', contract_id=contract.id) }}" class="btn btn-outline-info btn-sm">
- <i class="bi bi-arrow-clockwise"></i> 续签
- </a>
- {% endif %}
- </div>
- <div class="btn-group me-2 mb-2" role="group">
- {% if current_user.can_delete %}
- <form action="{{ url_for('delete_contract', contract_id=contract.id) }}" method="POST" class="d-inline">
- <button type="submit" class="btn btn-warning btn-sm"
- onclick="return confirm('确定要终止此合同吗?')">
- <i class="bi bi-x-circle"></i> 终止
- </button>
- </form>
- <form action="{{ url_for('delete_contract_permanent', contract_id=contract.id) }}" method="POST" class="d-inline">
- <button type="submit" class="btn btn-danger btn-sm"
- onclick="return confirm('⚠️ 该操作不可恢复!确定要彻底删除此合同吗?')">
- <i class="bi bi-trash-fill"></i> 删除
- </button>
- </form>
- {% endif %}
- </div>
- <div class="btn-group mb-2" role="group">
- <a href="{{ url_for('contract_versions', contract_id=contract.id) }}" class="btn btn-outline-secondary btn-sm">
- <i class="bi bi-clock-history"></i> 历史版本
- </a>
- <a href="{{ url_for('contract_list') }}" class="btn btn-outline-primary btn-sm">
- <i class="bi bi-list-ul"></i> 返回列表
- </a>
- </div>
- </div>
- </div>
- <!-- 合同基本信息 -->
- <div class="card shadow-sm mb-4">
- <div class="card-header bg-light"><h5 class="mb-0"><i class="bi bi-info-circle"></i> 合同基本信息</h5></div>
- <div class="card-body">
- <div class="row">
- <div class="col-md-6">
- <table class="table table-borderless mb-0">
- <tr><th>合同编号</th><td>{{ contract.contract_number }}</td></tr>
- <tr><th>合同名称</th><td>{{ contract.name }}</td></tr>
- <tr><th>合同类型</th><td>{{ contract.type.name }}</td></tr>
- <tr><th>我方主体</th><td>{{ contract.company_entity.name }}</td></tr>
- <tr><th>我方签约人</th><td>{{ contract.signer.name }}</td></tr>
- <tr><th>签约方式</th><td>{{ contract.signing_method }}</td></tr>
- <tr><th>存储盒名称</th><td>{{ contract.storage_box }}</td></tr>
- </table>
- </div>
- <div class="col-md-6">
- <table class="table table-borderless mb-0">
- <tr><th>开始日期</th><td>{{ contract.start_date.strftime('%Y-%m-%d') }}</td></tr>
- <tr><th>结束日期</th><td>{{ contract.end_date.strftime('%Y-%m-%d') }}</td></tr>
- <tr><th>合同收回时间</th>
- <td>{% if contract.collected_date %}{{ contract.collected_date.strftime('%Y-%m-%d') }}{% else %}-{% endif %}</td>
- </tr>
- <tr><th>状态</th>
- <td>{% if contract.is_active %}
- <span class="badge bg-success">有效</span>
- {% else %}
- <span class="badge bg-secondary">终止</span>
- {% endif %}
- </td>
- </tr>
- <tr><th>创建人</th><td>{{ contract.creator.name }}</td></tr>
- <tr><th>创建时间</th><td>{{ contract.created_at.strftime('%Y-%m-%d %H:%M') }}</td></tr>
- </table>
- </div>
- </div>
- </div>
- </div>
- <!-- 对方主体 -->
- <div class="card shadow-sm mb-4">
- <div class="card-header bg-light"><h5 class="mb-0"><i class="bi bi-people"></i> 对方主体</h5></div>
- <div class="card-body">
- <ul class="list-group list-group-flush">
- {% for cp in counterparties %}
- <li class="list-group-item">{{ cp.name }}</li>
- {% endfor %}
- </ul>
- </div>
- </div>
- <!-- 备注 -->
- {% if contract.notes %}
- <div class="card shadow-sm mb-4">
- <div class="card-header bg-light"><h5 class="mb-0"><i class="bi bi-journal-text"></i> 备注</h5></div>
- <div class="card-body"><p>{{ contract.notes }}</p></div>
- </div>
- {% endif %}
- <!-- 附件 -->
- {% if attachments %}
- <div class="card shadow-sm mb-4">
- <div class="card-header bg-light d-flex justify-content-between align-items-center">
- <h5 class="mb-0"><i class="bi bi-paperclip"></i> 附件</h5>
- <div class="scroll-hint text-muted d-none d-md-block">
- <i class="bi bi-arrow-left-right"></i> 左右滑动查看所有附件
- </div>
- </div>
- <div class="card-body">
- <div class="attachments-container">
- <div class="attachments-scroll">
- {% set preview_attachments = [] %}
- {% for attachment in attachments %}
- {% set ext = attachment.filepath.split('.')[-1].lower() %}
- {% if ext in ['pdf','jpg','jpeg','png','gif','bmp','tiff','webp'] %}
- {% set _ = preview_attachments.append(attachment) %}
- {% endif %}
- {% endfor %}
- {% for attachment in attachments %}
- {% set ext = attachment.filepath.split('.')[-1].lower() %}
- <div class="attachment-item">
- {% if ext in ['pdf','jpg','jpeg','png','gif','bmp','tiff','webp'] %}
- {% set preview_index = preview_attachments.index(attachment) %}
- <a href="#" data-bs-toggle="modal" data-bs-target="#attachmentCarouselModal"
- data-preview-index="{{ preview_index }}" class="d-flex align-items-center">
- {% if ext == 'pdf' %}
- <i class="bi bi-file-earmark-pdf-fill text-danger me-2" style="font-size:1.8rem;"></i>
- {% else %}
- <img src="{{ url_for('view_attachment', attachment_id=attachment.id) }}"
- class="img-thumbnail me-2" style="width:40px; height:40px; object-fit:cover;">
- {% endif %}
- <span class="attachment-name">{{ attachment.filename }}</span>
- </a>
- {% else %}
- <a href="{{ url_for('download_file', attachment_id=attachment.id) }}" target="_blank" class="d-flex align-items-center">
- <i class="bi bi-file-earmark-text-fill text-primary me-2" style="font-size:1.8rem;"></i>
- <span class="attachment-name">{{ attachment.filename }}</span>
- </a>
- {% endif %}
- </div>
- {% endfor %}
- </div>
- </div>
- </div>
- </div>
- <!-- 轮播模态,只显示 PDF 和图片 -->
- <div class="modal fade" id="attachmentCarouselModal" tabindex="-1">
- <div class="modal-dialog modal-xl modal-dialog-centered">
- <div class="modal-content">
- <div class="modal-header d-flex justify-content-between align-items-center">
- <h5 class="modal-title" id="carouselAttachmentTitle"></h5>
- <div class="d-flex gap-2">
- <a id="carouselDownloadBtn" href="#" class="btn btn-primary btn-sm">
- <i class="bi bi-download"></i> 下载
- </a>
- <button id="carouselPrintBtn" type="button" class="btn btn-info btn-sm">
- <i class="bi bi-printer"></i> 打印
- </button>
- <button type="button" class="btn btn-secondary btn-sm" data-bs-dismiss="modal">
- <i class="bi bi-x-lg"></i> 关闭
- </button>
- </div>
- </div>
- <div class="modal-body text-center">
- <!-- 关闭自动轮播:移除 data-bs-ride -->
- <div id="attachmentCarousel" class="carousel slide">
- <div class="carousel-inner">
- {% for attachment in preview_attachments %}
- {% set ext = attachment.filepath.split('.')[-1].lower() %}
- <div class="carousel-item {% if loop.first %}active{% endif %}"
- data-filename="{{ attachment.filename }}"
- data-attachment-id="{{ attachment.id }}">
- {% if ext == 'pdf' %}
- <iframe src="{{ url_for('view_attachment', attachment_id=attachment.id) }}"
- width="100%" height="600px"></iframe>
- {% else %}
- <img src="{{ url_for('view_attachment', attachment_id=attachment.id) }}"
- class="img-fluid rounded" style="max-height: 600px;">
- {% endif %}
- </div>
- {% endfor %}
- </div>
- <button class="carousel-control-prev" type="button" data-bs-target="#attachmentCarousel" data-bs-slide="prev">
- <span class="carousel-control-prev-icon"></span>
- </button>
- <button class="carousel-control-next" type="button" data-bs-target="#attachmentCarousel" data-bs-slide="next">
- <span class="carousel-control-next-icon"></span>
- </button>
- </div>
- <!-- 缩略图导航 - 使用与附件列表相同的样式 -->
- <div class="card shadow-sm mt-3">
- <div class="card-header bg-light py-2">
- <h6 class="mb-0">附件列表</h6>
- </div>
- <div class="card-body p-2">
- <div class="attachments-container" style="max-height: 150px; overflow-y: auto;">
- <div class="attachments-scroll">
- {% for attachment in preview_attachments %}
- {% set ext = attachment.filepath.split('.')[-1].lower() %}
- <div class="attachment-item" style="cursor: pointer;" data-bs-target="#attachmentCarousel" data-bs-slide-to="{{ loop.index0 }}">
- {% if ext == 'pdf' %}
- <div class="d-flex align-items-center">
- <i class="bi bi-file-earmark-pdf-fill text-danger me-2" style="font-size:1.5rem;"></i>
- <span class="attachment-name">{{ attachment.filename }}</span>
- </div>
- {% else %}
- <div class="d-flex align-items-center">
- <img src="{{ url_for('view_attachment', attachment_id=attachment.id) }}"
- class="img-thumbnail me-2" style="width:35px; height:35px; object-fit:cover;">
- <span class="attachment-name">{{ attachment.filename }}</span>
- </div>
- {% endif %}
- </div>
- {% endfor %}
- </div>
- </div>
- </div>
- </div>
- </div>
- </div>
- </div>
- </div>
- <script>
- var carouselModal = document.getElementById('attachmentCarouselModal');
- var carousel = document.getElementById('attachmentCarousel');
- var carouselTitle = document.getElementById('carouselAttachmentTitle');
- var downloadBtn = document.getElementById('carouselDownloadBtn');
- var printBtn = document.getElementById('carouselPrintBtn');
- carouselModal.addEventListener('show.bs.modal', function (event) {
- var trigger = event.relatedTarget;
- var previewIndex = parseInt(trigger.getAttribute('data-preview-index'));
- var carouselInstance = bootstrap.Carousel.getInstance(carousel) || new bootstrap.Carousel(carousel);
- carouselInstance.to(previewIndex);
- var items = carousel.querySelectorAll('.carousel-item');
- var currentItem = items[previewIndex];
- var filename = currentItem.getAttribute('data-filename');
- var attachmentId = currentItem.getAttribute('data-attachment-id');
- carouselTitle.textContent = filename;
- downloadBtn.href = "{{ url_for('download_file', attachment_id=0) }}".replace('0', attachmentId);
- });
- carousel.addEventListener('slid.bs.carousel', function () {
- var activeItem = carousel.querySelector('.carousel-item.active');
- var filename = activeItem.getAttribute('data-filename');
- var attachmentId = activeItem.getAttribute('data-attachment-id');
- carouselTitle.textContent = filename;
- downloadBtn.href = "{{ url_for('download_file', attachment_id=0) }}".replace('0', attachmentId);
- });
- // 新增打印按钮功能
- printBtn.addEventListener('click', function() {
- var activeItem = carousel.querySelector('.carousel-item.active');
- var iframe = activeItem.querySelector('iframe');
- var img = activeItem.querySelector('img');
- var attachmentId = activeItem.getAttribute('data-attachment-id');
- if (iframe) {
- // PDF打印处理
- try {
- iframe.contentWindow.focus();
- iframe.contentWindow.print();
- } catch (e) {
- console.error("PDF打印失败:", e);
- // 备选方案:打开新窗口打印
- var printWindow = window.open(
- "{{ url_for('view_attachment', attachment_id=0) }}".replace('0', attachmentId),
- '_blank'
- );
- printWindow.onload = function() {
- printWindow.print();
- };
- }
- } else if (img) {
- // 图片打印处理
- var printWindow = window.open('', '_blank');
- printWindow.document.write(`
- <html>
- <head>
- <title>打印图片</title>
- <style>
- body { margin: 0; display: flex; justify-content: center; align-items: center; min-height: 100vh; }
- img { max-width: 100%; max-height: 100vh; object-fit: contain; }
- </style>
- </head>
- <body>
- <img src="${img.src}">
- </body>
- </html>
- `);
- printWindow.document.close();
- printWindow.onload = function() {
- printWindow.print();
- };
- }
- });
- </script>
- {% endif %}
- </div>
- <style>
- .text-truncate {
- overflow: hidden;
- white-space: nowrap;
- text-overflow: ellipsis;
- }
- .card-header {
- font-weight: 500;
- }
- .table th {
- width: 35%;
- }
- /* 附件容器样式 */
- .attachments-container {
- overflow-x: auto;
- padding-bottom: 10px;
- }
- .attachments-scroll {
- display: flex;
- flex-wrap: nowrap;
- gap: 15px;
- padding: 5px 0;
- }
- .attachment-item {
- flex: 0 0 auto;
- min-width: 200px;
- padding: 10px 15px;
- background-color: #f8f9fa;
- border-radius: 8px;
- border: 1px solid #e9ecef;
- transition: all 0.2s;
- }
- .attachment-item:hover {
- background-color: #e9ecef;
- transform: translateY(-2px);
- box-shadow: 0 4px 8px rgba(0,0,0,0.1);
- }
- .attachment-name {
- font-size: 0.9rem;
- word-break: break-word;
- text-align: left;
- max-width: 180px;
- }
- .scroll-hint {
- font-size: 0.85rem;
- opacity: 0.7;
- }
- /* 滚动条样式 */
- .attachments-container::-webkit-scrollbar {
- height: 8px;
- }
- .attachments-container::-webkit-scrollbar-track {
- background: #f1f1f1;
- border-radius: 10px;
- }
- .attachments-container::-webkit-scrollbar-thumb {
- background: #c1c1c1;
- border-radius: 10px;
- }
- .attachments-container::-webkit-scrollbar-thumb:hover {
- background: #a8a8a8;
- }
- /* 响应式调整 */
- @media (max-width: 768px) {
- .attachment-item {
- min-width: 180px;
- }
- .attachment-name {
- max-width: 150px;
- }
- /* 小屏幕下按钮垂直排列 */
- .modal-header .d-flex {
- flex-direction: column;
- align-items: flex-end;
- gap: 5px;
- }
- }
- </style>
- {% endblock %}
|