CaiWuXiTong/resources/views/business/pages/partials/installation-fee-summary.blade.php

1101 lines
40 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<style>
.installation-fee-board {
margin: 1rem 1.5rem;
}
.installation-fee-card {
--installation-fee-accent: #856632;
--installation-fee-accent-soft: #f7f0de;
--installation-fee-accent-ring: rgba(133, 102, 50, 0.2);
position: relative;
display: flex;
width: 100%;
height: 8rem;
min-height: 0;
flex-direction: column;
box-sizing: border-box;
padding: 0.7rem 1rem 0 1.15rem;
border: 1px solid #d8d2c7;
border-right: 3px solid var(--installation-fee-accent);
border-left: 3px solid var(--installation-fee-accent);
border-radius: 0.75rem;
background: #ffffff;
color: #171717;
box-shadow: 0 1px 2px rgba(16, 24, 40, 0.04);
font-family: "JetBrains Mono", "Microsoft YaHei", "PingFang SC", monospace;
text-align: left;
}
.installation-fee-card__top {
display: flex;
align-items: center;
justify-content: space-between;
gap: 1rem;
}
.installation-fee-card__title {
flex: 0 0 auto;
color: #171717;
font-size: 0.75rem;
font-weight: 600;
line-height: 1.35;
}
.installation-fee-status {
max-width: 31rem;
color: #595959;
font-size: 0.6875rem;
line-height: 1.45;
text-align: right;
}
.installation-fee-status.is-error {
color: #b80000;
}
.installation-fee-card__main {
display: flex;
align-items: baseline;
gap: 0.35rem;
min-width: 0;
margin: 0.2rem 0 0.3rem;
}
.installation-fee-card__value {
color: #171717;
font-size: 2.5rem;
font-weight: 700;
line-height: 1;
letter-spacing: 0;
font-variant-numeric: tabular-nums;
}
.installation-fee-card__unit {
color: #595959;
font-size: 0.875rem;
font-weight: 500;
}
.installation-fee-card__trend {
margin-left: 0.4rem;
color: #595959;
font-size: 0.75rem;
font-weight: 600;
font-variant-numeric: tabular-nums;
}
.installation-fee-card__trend.is-up {
color: #935f07;
}
.installation-fee-card__trend.is-down {
color: #53793e;
}
.installation-fee-card__trend-note {
color: #595959;
font-size: 0.6875rem;
font-weight: 400;
}
.installation-fee-card__split {
display: flex;
align-items: center;
justify-content: space-between;
gap: 0.45rem;
flex-wrap: wrap;
margin: auto -1rem 0 -1.15rem;
padding: 0.43rem 1rem 0.48rem 1.15rem;
border-top: 1px solid #e5e0d7;
color: #171717;
font-size: 0.75rem;
line-height: 1.45;
font-variant-numeric: tabular-nums;
}
.installation-fee-card__split-summary {
display: flex;
min-width: 0;
align-items: center;
gap: 0.45rem;
flex-wrap: wrap;
}
.installation-fee-card__split strong {
font-weight: 600;
}
.installation-fee-card__split-percent {
margin-left: 0.1rem;
color: #595959;
font-weight: 400;
}
.installation-fee-card__split-unit {
margin-left: 0.12rem;
color: #595959;
font-size: 0.6875rem;
font-weight: 400;
}
.installation-fee-card__split-sep {
color: #d8d2c7;
font-weight: 400;
}
.installation-fee-card__detail-button {
display: inline-flex;
min-height: 1.55rem;
align-items: center;
justify-content: center;
gap: 0.25rem;
margin-left: auto;
padding: 0 0.45rem;
border: 0;
border-radius: 0.3rem;
background: transparent;
color: var(--installation-fee-accent);
cursor: pointer;
font: inherit;
font-size: 0.75rem;
font-weight: 600;
white-space: nowrap;
}
.installation-fee-card__detail-button:hover {
background: var(--installation-fee-accent-soft);
}
.installation-fee-card__detail-button:focus-visible {
background: var(--installation-fee-accent-soft);
box-shadow: 0 0 0 3px var(--installation-fee-accent-ring);
outline: none;
}
@media (max-width: 720px) {
.installation-fee-card {
height: auto;
min-height: 8rem;
padding: 0.7rem 0.85rem 0 0.95rem;
}
.installation-fee-card__top {
flex-direction: column;
gap: 0.25rem;
}
.installation-fee-status {
max-width: none;
text-align: left;
}
.installation-fee-card__main {
flex-wrap: wrap;
}
.installation-fee-card__value {
font-size: 2.5rem;
}
.installation-fee-card__split {
margin-right: -0.85rem;
margin-left: -0.95rem;
padding-right: 0.85rem;
padding-left: 0.95rem;
}
.installation-fee-card__detail-button {
width: 100%;
justify-content: flex-end;
}
}
.installation-fee-dialog {
--installation-fee-table-cell-padding: 0.7rem 0.65rem;
--installation-fee-table-head-padding: 0.75rem 0.65rem;
width: min(68rem, calc(100vw - 2rem));
max-width: none;
max-height: calc(100vh - 2rem);
box-sizing: border-box;
padding: 0;
border: 1px solid #d8d2c7;
border-radius: 0.75rem;
background: #ffffff;
color: #171717;
box-shadow: 0 10px 30px rgba(23, 23, 23, 0.18);
}
.installation-fee-dialog::backdrop {
background: rgba(23, 23, 23, 0.38);
}
.installation-fee-dialog[open] {
display: flex;
flex-direction: column;
}
.installation-fee-dialog__head {
display: flex;
align-items: flex-start;
justify-content: space-between;
gap: 1rem;
padding: 1rem 1.1rem 0.8rem;
border-bottom: 1px solid #eee8dd;
}
.installation-fee-dialog__head h2 {
margin: 0;
font-size: 0.9375rem;
}
.installation-fee-dialog__head p {
margin: 0.25rem 0 0;
color: #595959;
font-size: 0.6875rem;
}
.installation-fee-dialog__side {
display: flex;
align-items: flex-start;
gap: 1rem;
}
.installation-fee-dialog__total {
text-align: right;
}
.installation-fee-dialog__total span {
display: block;
color: #595959;
font-size: 0.6875rem;
}
.installation-fee-dialog__total strong {
display: block;
margin-top: 0.2rem;
font-size: 1rem;
font-variant-numeric: tabular-nums;
}
.installation-fee-dialog__close {
display: inline-flex;
width: 1.8rem;
height: 1.8rem;
align-items: center;
justify-content: center;
border: 1px solid #d8d2c7;
border-radius: 50%;
background: #ffffff;
color: #595959;
cursor: pointer;
}
.installation-fee-filters {
display: grid;
grid-template-columns: repeat(4, minmax(8.5rem, 1fr));
gap: 0.75rem;
padding: 0.8rem 1.1rem;
border-bottom: 1px solid #eee8dd;
}
.installation-fee-tabs {
display: flex;
align-items: stretch;
gap: 1.25rem;
overflow-x: auto;
padding: 0 1.1rem;
border-bottom: 1px solid #e8e0d2;
background: #ffffff;
overscroll-behavior-inline: contain;
scrollbar-width: thin;
white-space: nowrap;
}
.installation-fee-tab {
flex: 0 0 auto;
min-height: 2.75rem;
padding: 0 0.2rem;
border: 0;
border-bottom: 2px solid transparent;
background: transparent;
color: #595959;
cursor: pointer;
font: inherit;
font-size: 0.8125rem;
font-weight: 600;
}
.installation-fee-tab:hover {
color: #856632;
}
.installation-fee-tab[aria-selected="true"] {
border-bottom-color: #b9954f;
color: #856632;
}
.installation-fee-tab:focus-visible {
outline: 3px solid rgba(133, 102, 50, 0.2);
outline-offset: -3px;
}
.installation-fee-filter span {
display: block;
margin-bottom: 0.25rem;
color: #595959;
font-size: 0.6875rem;
}
.installation-fee-filter select {
width: 100%;
height: 2.1rem;
padding: 0 0.5rem;
border: 1px solid #d8d2c7;
border-radius: 0.375rem;
background: #ffffff;
color: #171717;
font-size: 0.75rem;
}
.installation-fee-dialog__scroll {
flex: 1 1 auto;
min-height: 0;
box-sizing: border-box;
overflow: auto;
padding: 0 1.1rem 0.65rem;
overscroll-behavior: contain;
scrollbar-color: #b9954f #f1ece3;
scrollbar-gutter: stable;
scrollbar-width: thin;
cursor: grab;
touch-action: pan-x pan-y;
}
.installation-fee-dialog__scroll.is-dragging {
cursor: grabbing;
user-select: none;
}
.installation-fee-dialog__scroll::-webkit-scrollbar {
width: 8px;
height: 8px;
}
.installation-fee-dialog__scroll::-webkit-scrollbar-track {
background: #f1ece3;
}
.installation-fee-dialog__scroll::-webkit-scrollbar-thumb {
border-radius: 999px;
background: #b9954f;
}
.installation-fee-dialog__scroll::-webkit-scrollbar-thumb:hover {
background: #856632;
}
.installation-fee-panel {
min-width: 100%;
}
.installation-fee-table {
width: 100%;
min-width: 100%;
table-layout: fixed;
border-collapse: collapse;
font-size: 0.75rem;
font-variant-numeric: tabular-nums;
}
.installation-fee-table col:nth-child(1) {
width: 34%;
}
.installation-fee-table col:nth-child(2) {
width: 22%;
}
.installation-fee-table col:nth-child(3) {
width: 18%;
}
.installation-fee-table col:nth-child(4) {
width: 26%;
}
.installation-fee-table th,
.installation-fee-table td {
padding: var(--installation-fee-table-cell-padding);
border-bottom: 1px solid #eee8dd;
line-height: 1.5;
text-align: left;
vertical-align: middle;
overflow-wrap: anywhere;
white-space: normal;
}
.installation-fee-table thead th {
position: sticky;
top: 0;
z-index: 1;
padding: var(--installation-fee-table-head-padding);
background: #f7f0de;
color: #595959;
font-weight: 600;
}
.installation-fee-table .is-number {
text-align: right;
white-space: nowrap;
}
.installation-fee-empty {
padding: 2rem 0.5rem;
color: #595959;
font-size: 0.75rem;
text-align: center;
}
.installation-fee-platform-summary {
margin: 0;
padding: 0;
}
.installation-fee-panel[hidden] {
display: none !important;
}
.installation-fee-panel.is-active:not([hidden]) {
display: block !important;
}
.installation-fee-platform-summary table {
width: 100%;
min-width: 32rem;
border-collapse: collapse;
font-size: 0.75rem;
font-variant-numeric: tabular-nums;
}
.installation-fee-platform-summary th,
.installation-fee-platform-summary td {
padding: var(--installation-fee-table-cell-padding);
border-bottom: 1px solid #eee8dd;
line-height: 1.5;
text-align: left;
vertical-align: middle;
white-space: nowrap;
}
.installation-fee-platform-summary th {
padding: var(--installation-fee-table-head-padding);
background: #f7f0de;
color: #595959;
font-weight: 600;
}
.installation-fee-platform-summary .is-number {
text-align: right;
}
.installation-fee-dialog__foot {
padding: 0.65rem 1.1rem;
border-top: 1px solid #eee8dd;
color: #595959;
font-size: 0.6875rem;
}
@media (max-width: 900px) {
.installation-fee-filters { grid-template-columns: repeat(2, minmax(10rem, 1fr)); }
}
@media (max-width: 720px) {
.installation-fee-filters { grid-template-columns: 1fr; }
.installation-fee-dialog__head { flex-direction: column; }
.installation-fee-dialog__side { width: 100%; justify-content: space-between; }
}
</style>
<section class="installation-fee-board" aria-label="安装费金额汇总">
<div
class="installation-fee-card"
data-installation-fee-card
>
<span class="installation-fee-card__top">
<strong class="installation-fee-card__title">安装费金额</strong>
<span class="installation-fee-status" data-installation-fee-status aria-live="polite">请选择完整的客服审核起止日期</span>
</span>
<span class="installation-fee-card__main">
<strong class="installation-fee-card__value" data-installation-fee-total>0.00</strong>
<span class="installation-fee-card__unit">万元</span>
<span class="installation-fee-card__trend" data-installation-fee-trend>—</span>
<span class="installation-fee-card__trend-note">较上月</span>
</span>
<span class="installation-fee-card__split">
<span class="installation-fee-card__split-summary">
<span>包安装金额 <strong data-installation-fee-package>0.00</strong><span class="installation-fee-card__split-unit">万元</span><span class="installation-fee-card__split-percent" data-installation-fee-package-percent>(0.0%)</span></span>
<span class="installation-fee-card__split-sep" aria-hidden="true">|</span>
<span>不包安装金额 <strong data-installation-fee-non-package>0.00</strong><span class="installation-fee-card__split-unit">万元</span><span class="installation-fee-card__split-percent" data-installation-fee-non-package-percent>(0.0%)</span></span>
</span>
<button
type="button"
class="installation-fee-card__detail-button"
data-installation-fee-open
data-url="{{ route('business.installation-details.summary') }}"
aria-label="查看安装费金额明细"
>查看明细 →</button>
</span>
</div>
</section>
<dialog class="installation-fee-dialog" id="installation-fee-dialog" aria-labelledby="installation-fee-dialog-title">
<div class="installation-fee-dialog__head">
<div>
<h2 id="installation-fee-dialog-title">安装费金额 · 明细汇总</h2>
<p data-installation-fee-subtitle>按客服审核时间汇总店铺、安装公司和包安装分类</p>
</div>
<div class="installation-fee-dialog__side">
<div class="installation-fee-dialog__total">
<span>当前筛选合计(万元)</span>
<strong data-installation-fee-current-total>¥0.00</strong>
</div>
<button type="button" class="installation-fee-dialog__close" data-installation-fee-close aria-label="关闭安装费明细">×</button>
</div>
</div>
<div class="installation-fee-filters" aria-label="安装费明细筛选">
<label class="installation-fee-filter">
<span>平台</span>
<select data-installation-fee-platform aria-label="筛选平台">
<option value="">全部平台</option>
</select>
</label>
<label class="installation-fee-filter">
<span>店铺名称</span>
<select data-installation-fee-store aria-label="筛选店铺名称">
<option value="">全部店铺</option>
</select>
</label>
<label class="installation-fee-filter">
<span>安装公司</span>
<select data-installation-fee-company aria-label="筛选安装公司">
<option value="">全部安装公司</option>
</select>
</label>
<label class="installation-fee-filter">
<span>收款渠道</span>
<select data-installation-fee-channel aria-label="筛选收款渠道">
<option value="">全部渠道</option>
</select>
</label>
</div>
<div class="installation-fee-tabs" role="tablist" aria-label="安装费汇总子页面">
<button type="button" class="installation-fee-tab" id="installationFeePlatformTab" role="tab" aria-selected="true" aria-controls="installationFeePlatformPanel" data-installation-fee-tab="platform" tabindex="0">平台汇总</button>
<button type="button" class="installation-fee-tab" id="installationFeeDetailTab" role="tab" aria-selected="false" aria-controls="installationFeeDetailPanel" data-installation-fee-tab="detail" tabindex="-1">店铺明细</button>
</div>
<div
class="installation-fee-dialog__scroll"
data-installation-fee-scroll
aria-label="安装费明细表格,内容超出时可左右拖动或使用底部滚动条"
>
<section class="installation-fee-platform-summary installation-fee-panel is-active" id="installationFeePlatformPanel" role="tabpanel" aria-labelledby="installationFeePlatformTab" data-installation-fee-panel="platform">
<table>
<thead>
<tr>
<th scope="col">平台</th>
<th scope="col" class="is-number">结算明细金额(万元)</th>
</tr>
</thead>
<tbody data-installation-fee-platform-rows></tbody>
</table>
<div class="installation-fee-empty" data-installation-fee-platform-empty hidden>当前客服审核时间内没有平台汇总。</div>
</section>
<section class="installation-fee-panel" id="installationFeeDetailPanel" role="tabpanel" aria-labelledby="installationFeeDetailTab" data-installation-fee-panel="detail" hidden>
<table class="installation-fee-table">
<colgroup>
<col>
<col>
<col>
<col>
</colgroup>
<thead>
<tr>
<th scope="col">店铺名称</th>
<th scope="col">安装公司</th>
<th scope="col">收款渠道</th>
<th scope="col" class="is-number">结算明细金额(万元)</th>
</tr>
</thead>
<tbody data-installation-fee-rows></tbody>
</table>
<div class="installation-fee-empty" data-installation-fee-empty>请选择客服审核日期后查看明细</div>
</section>
</div>
<div class="installation-fee-dialog__foot">
<span data-installation-fee-count>共 0 条平台汇总</span>
</div>
</dialog>
<script>
(function () {
var form = document.getElementById('installationFilterForm');
var card = document.querySelector('[data-installation-fee-card]');
var openButton = document.querySelector('[data-installation-fee-open]');
var dialog = document.getElementById('installation-fee-dialog');
if (!form || !card || !openButton || !dialog) { return; }
var fromInput = form.elements.namedItem('date_from');
var toInput = form.elements.namedItem('date_to');
var cardTotal = card.querySelector('[data-installation-fee-total]');
var status = card.querySelector('[data-installation-fee-status]');
var trend = card.querySelector('[data-installation-fee-trend]');
var packageAmount = card.querySelector('[data-installation-fee-package]');
var packagePercent = card.querySelector('[data-installation-fee-package-percent]');
var nonPackageAmount = card.querySelector('[data-installation-fee-non-package]');
var nonPackagePercent = card.querySelector('[data-installation-fee-non-package-percent]');
var subtitle = dialog.querySelector('[data-installation-fee-subtitle]');
var currentTotal = dialog.querySelector('[data-installation-fee-current-total]');
var platformFilter = dialog.querySelector('[data-installation-fee-platform]');
var storeFilter = dialog.querySelector('[data-installation-fee-store]');
var companyFilter = dialog.querySelector('[data-installation-fee-company]');
var channelFilter = dialog.querySelector('[data-installation-fee-channel]');
var rowsEl = dialog.querySelector('[data-installation-fee-rows]');
var platformRowsEl = dialog.querySelector('[data-installation-fee-platform-rows]');
var emptyEl = dialog.querySelector('[data-installation-fee-empty]');
var platformEmptyEl = dialog.querySelector('[data-installation-fee-platform-empty]');
var countEl = dialog.querySelector('[data-installation-fee-count]');
var scrollEl = dialog.querySelector('[data-installation-fee-scroll]');
var tabButtons = Array.from(dialog.querySelectorAll('[data-installation-fee-tab]'));
var tabPanels = Array.from(dialog.querySelectorAll('[data-installation-fee-panel]'));
var allRows = [];
var loadedSignature = '';
var timer = null;
var controller = null;
var detailRowCount = 0;
var platformRowCount = 0;
var activeTab = 'platform';
function updateCount() {
var count = activeTab === 'platform' ? platformRowCount : detailRowCount;
var suffix = activeTab === 'platform' ? '平台汇总' : '明细汇总';
countEl.textContent = '共 ' + count.toLocaleString('zh-CN') + ' 条' + suffix;
}
function activateTab(name, focusTab) {
activeTab = name;
tabButtons.forEach(function (tab) {
var selected = tab.dataset.installationFeeTab === name;
tab.setAttribute('aria-selected', selected ? 'true' : 'false');
tab.tabIndex = selected ? 0 : -1;
if (selected && focusTab) {
tab.focus();
}
});
tabPanels.forEach(function (panel) {
var selected = panel.dataset.installationFeePanel === name;
panel.hidden = !selected;
panel.classList.toggle('is-active', selected);
panel.style.display = selected ? 'block' : 'none';
panel.setAttribute('aria-hidden', selected ? 'false' : 'true');
});
if (scrollEl) {
scrollEl.scrollTop = 0;
scrollEl.scrollLeft = 0;
}
updateCount();
}
function amount(value) {
return Number(value || 0).toLocaleString('zh-CN', {
minimumFractionDigits: 2,
maximumFractionDigits: 2
});
}
function wanAmount(value) {
return amount(Number(value || 0) / 10000);
}
function rawYuan(value) {
return '¥' + amount(value);
}
function wanYuan(value) {
return '¥' + wanAmount(value);
}
function captionRange(value) {
var matchFrom = /^(\d{4})-(\d{2})-(\d{2})$/.exec(value.from);
var matchTo = /^(\d{4})-(\d{2})-(\d{2})$/.exec(value.to);
if (!matchFrom || !matchTo) {
return value.from + ' 至 ' + value.to;
}
var end = matchFrom[1] === matchTo[1]
? matchTo[2] + '-' + matchTo[3]
: value.to;
return value.from + ' 至 ' + end;
}
function setTrend(changeRate) {
trend.className = 'installation-fee-card__trend';
if (changeRate === null || changeRate === undefined || !Number.isFinite(Number(changeRate))) {
trend.textContent = '—';
return;
}
var rate = Number(changeRate);
if (rate > 0) {
trend.textContent = '↑' + Math.abs(rate).toLocaleString('zh-CN', { minimumFractionDigits: 1, maximumFractionDigits: 1 }) + '%';
trend.classList.add('is-up');
} else if (rate < 0) {
trend.textContent = '↓' + Math.abs(rate).toLocaleString('zh-CN', { minimumFractionDigits: 1, maximumFractionDigits: 1 }) + '%';
trend.classList.add('is-down');
} else {
trend.textContent = '持平';
}
}
function setCardValue(total, rows, value, data) {
var packageTotal = 0;
var nonPackageTotal = 0;
rows.forEach(function (row) {
if (row.payment_channel === '包安装') {
packageTotal += Number(row.amount || 0);
} else {
nonPackageTotal += Number(row.amount || 0);
}
});
var packageRate = total > 0 ? Math.round((packageTotal / total) * 1000) / 10 : 0;
var nonPackageRate = total > 0 ? Math.round((100 - packageRate) * 10) / 10 : 0;
var percent = function (rate) {
return Number(rate || 0).toLocaleString('zh-CN', {
minimumFractionDigits: 1,
maximumFractionDigits: 1
});
};
cardTotal.textContent = wanAmount(total);
cardTotal.title = '¥' + amount(total);
packageAmount.textContent = wanAmount(packageTotal);
packageAmount.title = '¥' + amount(packageTotal);
nonPackageAmount.textContent = wanAmount(nonPackageTotal);
nonPackageAmount.title = '¥' + amount(nonPackageTotal);
packagePercent.textContent = '(' + percent(packageRate) + '%)';
nonPackagePercent.textContent = '(' + percent(nonPackageRate) + '%)';
setTrend(data.change_rate);
status.classList.remove('is-error');
status.textContent = '按客服审核时间 · ' + captionRange(value) + ' · ' + rows.length + ' 单';
}
function resetCard(message) {
cardTotal.textContent = '0.00';
packageAmount.textContent = '0.00';
nonPackageAmount.textContent = '0.00';
cardTotal.removeAttribute('title');
packageAmount.removeAttribute('title');
nonPackageAmount.removeAttribute('title');
packagePercent.textContent = '(0.0%)';
nonPackagePercent.textContent = '(0.0%)';
setTrend(null);
status.textContent = message;
status.classList.toggle('is-error', message.indexOf('失败') >= 0 || message.indexOf('不能') >= 0);
}
function range() {
return {
from: String(fromInput?.value || ''),
to: String(toInput?.value || '')
};
}
function signature(value) {
return value.from + '|' + value.to;
}
function fillFilter(select, placeholder, values) {
select.replaceChildren();
var all = document.createElement('option');
all.value = '';
all.textContent = placeholder;
select.appendChild(all);
values.forEach(function (value) {
var option = document.createElement('option');
option.value = value;
option.textContent = value;
select.appendChild(option);
});
select.value = '';
}
function distinct(key) {
return Array.from(new Set(allRows.map(function (row) {
return String(row[key] || '').trim();
}).filter(Boolean))).sort(function (left, right) {
return left.localeCompare(right, 'zh-CN');
});
}
function renderRows() {
var platform = platformFilter.value;
var store = storeFilter.value;
var company = companyFilter.value;
var channel = channelFilter.value;
var rows = allRows.filter(function (row) {
return (!platform || row.platform === platform)
&& (!store || row.store_name === store)
&& (!company || row.installation_company === company)
&& (!channel || row.payment_channel === channel);
});
var total = rows.reduce(function (sum, row) {
return sum + Number(row.amount || 0);
}, 0);
rowsEl.replaceChildren();
rows.forEach(function (row) {
var tr = document.createElement('tr');
[row.store_name || '—', row.installation_company || '—', row.payment_channel || '—'].forEach(function (value) {
var td = document.createElement('td');
td.textContent = value;
tr.appendChild(td);
});
var amount = document.createElement('td');
amount.className = 'is-number';
amount.textContent = wanYuan(row.amount);
amount.title = rawYuan(row.amount);
tr.appendChild(amount);
rowsEl.appendChild(tr);
});
var byPlatform = {};
rows.forEach(function (row) {
var key = row.platform || '其他';
byPlatform[key] ??= 0;
byPlatform[key] += Number(row.amount || 0);
});
detailRowCount = rows.length;
platformRowCount = Object.keys(byPlatform).length;
platformRowsEl.replaceChildren();
Object.keys(byPlatform).sort(function (left, right) {
return Math.abs(byPlatform[right]) - Math.abs(byPlatform[left])
|| left.localeCompare(right, 'zh-CN');
}).forEach(function (name) {
var tr = document.createElement('tr');
var platformCell = document.createElement('td');
platformCell.textContent = name;
tr.appendChild(platformCell);
var amount = document.createElement('td');
amount.className = 'is-number';
amount.textContent = wanYuan(byPlatform[name]);
amount.title = rawYuan(byPlatform[name]);
tr.appendChild(amount);
platformRowsEl.appendChild(tr);
});
currentTotal.textContent = wanYuan(total);
currentTotal.title = rawYuan(total);
updateCount();
emptyEl.hidden = rows.length > 0;
emptyEl.textContent = allRows.length
? '当前筛选条件下没有安装费明细。'
: '当前客服审核时间内没有安装费明细。';
platformEmptyEl.hidden = platformRowCount > 0;
platformEmptyEl.textContent = allRows.length
? '当前筛选条件下没有平台汇总。'
: '当前客服审核时间内没有平台汇总。';
}
function resetDialog(message) {
allRows = [];
loadedSignature = '';
detailRowCount = 0;
platformRowCount = 0;
rowsEl.replaceChildren();
platformRowsEl.replaceChildren();
currentTotal.textContent = '¥0.00';
updateCount();
emptyEl.hidden = false;
emptyEl.textContent = message;
platformEmptyEl.hidden = false;
platformEmptyEl.textContent = message;
fillFilter(storeFilter, '全部店铺', []);
fillFilter(platformFilter, '全部平台', []);
fillFilter(companyFilter, '全部安装公司', []);
fillFilter(channelFilter, '全部渠道', []);
}
function openDialog() {
activateTab('platform', false);
if (typeof dialog.showModal === 'function') {
dialog.showModal();
} else {
dialog.setAttribute('open', '');
}
}
function closeDialog() {
if (typeof dialog.close === 'function') {
dialog.close();
} else {
dialog.removeAttribute('open');
}
}
function refresh(force) {
var value = range();
if (!value.from || !value.to) {
resetCard('请选择完整的客服审核起止日期');
resetDialog('请选择完整的客服审核起止日期');
return Promise.resolve(false);
}
if (value.from > value.to) {
resetCard('客服审核结束日期不能早于开始日期');
resetDialog('客服审核结束日期不能早于开始日期');
return Promise.resolve(false);
}
var currentSignature = signature(value);
if (!force && loadedSignature === currentSignature) {
return Promise.resolve(true);
}
if (controller) { controller.abort(); }
controller = new AbortController();
dialog.setAttribute('aria-busy', 'true');
status.classList.remove('is-error');
status.textContent = '按客服审核时间 · 正在汇总…';
cardTotal.textContent = '…';
var url = new URL(openButton.dataset.url, window.location.origin);
url.searchParams.set('customer_review_from', value.from);
url.searchParams.set('customer_review_to', value.to);
return window.fetch(url.toString(), {
headers: { 'X-Requested-With': 'XMLHttpRequest', 'Accept': 'application/json' },
credentials: 'same-origin',
signal: controller.signal
}).then(function (response) {
return response.json().catch(function () { return {}; }).then(function (data) {
if (!response.ok) {
throw new Error(data.message || '安装费汇总读取失败。');
}
return data;
});
}).then(function (data) {
allRows = Array.isArray(data.rows) ? data.rows : [];
loadedSignature = currentSignature;
setCardValue(Number(data.total || 0), allRows, value, data);
subtitle.textContent = value.from + ' 至 ' + value.to + ' · 按客服审核时间汇总';
fillFilter(platformFilter, '全部平台', distinct('platform'));
fillFilter(storeFilter, '全部店铺', distinct('store_name'));
fillFilter(companyFilter, '全部安装公司', distinct('installation_company'));
fillFilter(channelFilter, '全部渠道', distinct('payment_channel'));
renderRows();
dialog.removeAttribute('aria-busy');
return true;
}).catch(function (error) {
if (error && error.name === 'AbortError') { return false; }
resetCard(error.message || '安装费汇总读取失败');
resetDialog(error.message || '安装费汇总读取失败,请稍后重试。');
dialog.removeAttribute('aria-busy');
return false;
});
}
function scheduleRefresh() {
window.clearTimeout(timer);
timer = window.setTimeout(function () { refresh(true); }, 250);
}
var dragState = null;
function finishHorizontalDrag(event) {
if (!dragState) {
return;
}
var state = dragState;
dragState = null;
scrollEl.classList.remove('is-dragging');
if (event && state.pointerId !== null && scrollEl.hasPointerCapture(state.pointerId)) {
scrollEl.releasePointerCapture(state.pointerId);
}
}
if (scrollEl) {
scrollEl.addEventListener('pointerdown', function (event) {
if (event.button !== 0 || event.target.closest('button, a, input, select, textarea')) {
return;
}
dragState = {
active: false,
pointerId: event.pointerId,
startX: event.clientX,
startY: event.clientY,
scrollLeft: scrollEl.scrollLeft
};
});
scrollEl.addEventListener('pointermove', function (event) {
if (!dragState || dragState.pointerId !== event.pointerId) {
return;
}
var dx = event.clientX - dragState.startX;
var dy = event.clientY - dragState.startY;
if (!dragState.active) {
if (Math.abs(dx) < 6 || Math.abs(dx) <= Math.abs(dy)) {
return;
}
dragState.active = true;
scrollEl.classList.add('is-dragging');
scrollEl.setPointerCapture(event.pointerId);
var selection = window.getSelection();
if (selection) {
selection.removeAllRanges();
}
}
event.preventDefault();
scrollEl.scrollLeft = dragState.scrollLeft - dx;
});
['pointerup', 'pointercancel', 'lostpointercapture'].forEach(function (eventName) {
scrollEl.addEventListener(eventName, finishHorizontalDrag);
});
scrollEl.addEventListener('wheel', function (event) {
if (!event.shiftKey || Math.abs(event.deltaY) <= Math.abs(event.deltaX)) {
return;
}
scrollEl.scrollLeft += event.deltaY;
event.preventDefault();
}, { passive: false });
}
openButton.addEventListener('click', function () {
openDialog();
refresh(false);
});
tabButtons.forEach(function (tab, index) {
tab.addEventListener('click', function (event) {
event.preventDefault();
activateTab(tab.dataset.installationFeeTab, false);
});
tab.addEventListener('keydown', function (event) {
var nextIndex = null;
if (event.key === 'ArrowRight') {
nextIndex = (index + 1) % tabButtons.length;
} else if (event.key === 'ArrowLeft') {
nextIndex = (index - 1 + tabButtons.length) % tabButtons.length;
} else if (event.key === 'Home') {
nextIndex = 0;
} else if (event.key === 'End') {
nextIndex = tabButtons.length - 1;
}
if (nextIndex === null) {
return;
}
event.preventDefault();
activateTab(tabButtons[nextIndex].dataset.installationFeeTab, true);
});
});
[fromInput, toInput].forEach(function (input) {
if (input) { input.addEventListener('change', scheduleRefresh); }
});
[platformFilter, storeFilter, companyFilter, channelFilter].forEach(function (select) {
select.addEventListener('change', renderRows);
});
dialog.querySelector('[data-installation-fee-close]').addEventListener('click', closeDialog);
dialog.addEventListener('click', function (event) {
if (event.target === dialog) { closeDialog(); }
});
refresh(true);
})();
</script>