feat: 增加OA审批人联想筛选 #792
@ -62,6 +62,7 @@ class ProcessDetails extends Controller
|
||||
'documentTypes' => $options['document_types'],
|
||||
'statuses' => $options['statuses'],
|
||||
'paymentStates' => $options['payment_states'],
|
||||
'currentApprovers' => $options['current_approvers'] ?? [],
|
||||
'mirrorStatus' => $result['status'],
|
||||
'mirrorSyncedAt' => $result['last_synced_at'],
|
||||
'mirrorStale' => $result['sync_stale'] ?? false,
|
||||
@ -89,6 +90,7 @@ class ProcessDetails extends Controller
|
||||
'documentTypes' => [],
|
||||
'statuses' => [],
|
||||
'paymentStates' => [],
|
||||
'currentApprovers' => [],
|
||||
'mirrorStatus' => 'unavailable',
|
||||
'mirrorSyncedAt' => null,
|
||||
'mirrorStale' => false,
|
||||
|
||||
@ -179,12 +179,22 @@ class DingProcessDetailMirrorRepository
|
||||
|
||||
/**
|
||||
* @param array<string,string> $filters
|
||||
* @return array{document_types:list<string>,statuses:list<string>,payment_states:list<string>}
|
||||
* @return array{
|
||||
* document_types:list<string>,
|
||||
* statuses:list<string>,
|
||||
* payment_states:list<string>,
|
||||
* current_approvers:list<string>
|
||||
* }
|
||||
*/
|
||||
public function filterOptions(array $filters = []): array
|
||||
{
|
||||
if (! Schema::connection($this->connection->getName())->hasTable('ding_process_detail_mirror')) {
|
||||
return ['document_types' => [], 'statuses' => [], 'payment_states' => []];
|
||||
return [
|
||||
'document_types' => [],
|
||||
'statuses' => [],
|
||||
'payment_states' => [],
|
||||
'current_approvers' => [],
|
||||
];
|
||||
}
|
||||
|
||||
$base = $this->connection->table('ding_process_detail_mirror')
|
||||
@ -208,9 +218,47 @@ class DingProcessDetailMirrorRepository
|
||||
->map(static fn (mixed $value): string => (string) $value)
|
||||
->all(),
|
||||
'payment_states' => $this->paymentStatesAvailableFor($filters),
|
||||
'current_approvers' => $this->currentApproverOptions(),
|
||||
];
|
||||
}
|
||||
|
||||
/** @return list<string> */
|
||||
private function currentApproverOptions(): array
|
||||
{
|
||||
if (! Schema::connection($this->connection->getName())->hasColumn(
|
||||
'ding_process_detail_mirror',
|
||||
'current_approver_name',
|
||||
)) {
|
||||
return [];
|
||||
}
|
||||
|
||||
$values = $this->connection->table('ding_process_detail_mirror')
|
||||
->where('source_scope', $this->scope())
|
||||
->whereNotNull('current_approver_name')
|
||||
->where('current_approver_name', '!=', '')
|
||||
->distinct()
|
||||
->pluck('current_approver_name');
|
||||
$names = [];
|
||||
foreach ($values as $value) {
|
||||
foreach (preg_split(
|
||||
'/\s*[、,,;;|]\s*/u',
|
||||
(string) $value,
|
||||
-1,
|
||||
PREG_SPLIT_NO_EMPTY,
|
||||
) ?: [] as $name) {
|
||||
$name = trim($name);
|
||||
if ($name !== '') {
|
||||
$names[$name] = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$names = array_keys($names);
|
||||
sort($names, SORT_NATURAL | SORT_FLAG_CASE);
|
||||
|
||||
return $names;
|
||||
}
|
||||
|
||||
/** @param array<string,string> $filters */
|
||||
public function exportCount(array $filters): int
|
||||
{
|
||||
|
||||
@ -88,6 +88,7 @@ class ProcessDetailsPageData
|
||||
'documentTypes' => $options['document_types'],
|
||||
'statuses' => $options['statuses'],
|
||||
'paymentStates' => $options['payment_states'],
|
||||
'currentApprovers' => $options['current_approvers'] ?? [],
|
||||
'mirrorStatus' => $result['status'],
|
||||
'mirrorSyncedAt' => $result['last_synced_at'],
|
||||
'mirrorStale' => $result['sync_stale'] ?? false,
|
||||
@ -113,6 +114,7 @@ class ProcessDetailsPageData
|
||||
'documentTypes' => [],
|
||||
'statuses' => [],
|
||||
'paymentStates' => [],
|
||||
'currentApprovers' => [],
|
||||
'mirrorStatus' => 'unavailable',
|
||||
'mirrorSyncedAt' => null,
|
||||
'mirrorStale' => false,
|
||||
|
||||
@ -3,6 +3,7 @@
|
||||
$summary ??= [];
|
||||
$documentTypes ??= [];
|
||||
$statuses ??= [];
|
||||
$currentApprovers ??= [];
|
||||
$error ??= null;
|
||||
$paymentStates = $paymentStates ?? ($pageData['paymentStates'] ?? []);
|
||||
$mirrorStale = $mirrorStale ?? ($pageData['mirrorStale'] ?? false);
|
||||
@ -244,6 +245,125 @@
|
||||
box-shadow: 0 0 0 3px rgba(133, 102, 50, .2);
|
||||
}
|
||||
|
||||
.process-details-combobox {
|
||||
position: relative;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.process-details-combobox input {
|
||||
width: 100%;
|
||||
padding-right: 2.25rem;
|
||||
}
|
||||
|
||||
.process-details-combobox input::-webkit-search-cancel-button {
|
||||
appearance: none;
|
||||
-webkit-appearance: none;
|
||||
}
|
||||
|
||||
.process-details-combobox__toggle {
|
||||
position: absolute;
|
||||
right: .25rem;
|
||||
display: inline-flex;
|
||||
width: 1.7rem;
|
||||
height: 1.7rem;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
padding: 0;
|
||||
border: 0;
|
||||
border-radius: .35rem;
|
||||
background: transparent;
|
||||
color: var(--vip-content-muted, #595959);
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.process-details-combobox__toggle:hover,
|
||||
.process-details-combobox__toggle:focus-visible {
|
||||
background: var(--vip-content-accent-soft, #F7F0DE);
|
||||
color: var(--vip-content-accent-dark, #856632);
|
||||
outline: none;
|
||||
}
|
||||
|
||||
.process-details-combobox__toggle .material-icons-outlined {
|
||||
font-size: 1.05rem;
|
||||
transition: transform .15s ease;
|
||||
}
|
||||
|
||||
.process-details-combobox.is-open
|
||||
.process-details-combobox__toggle
|
||||
.material-icons-outlined {
|
||||
transform: rotate(180deg);
|
||||
}
|
||||
|
||||
.process-details-combobox__menu {
|
||||
position: absolute;
|
||||
top: calc(100% + .35rem);
|
||||
right: 0;
|
||||
left: 0;
|
||||
z-index: 40;
|
||||
max-height: min(17rem, 48vh);
|
||||
overflow: auto;
|
||||
padding: .25rem;
|
||||
border: 1px solid var(--vip-border, #D8D2C7);
|
||||
border-radius: .5rem;
|
||||
background: #fff;
|
||||
box-shadow: 0 5px 14px rgba(23, 23, 23, .13);
|
||||
overscroll-behavior: contain;
|
||||
scrollbar-color: var(--vip-content-accent, #B9954F) #efede8;
|
||||
scrollbar-width: thin;
|
||||
}
|
||||
|
||||
.process-details-combobox__menu[hidden] {
|
||||
display: none !important;
|
||||
}
|
||||
|
||||
.process-details-combobox__option {
|
||||
display: block;
|
||||
width: 100%;
|
||||
min-height: 1.8rem;
|
||||
padding: .32rem .5rem;
|
||||
overflow: hidden;
|
||||
border: 0;
|
||||
border-radius: .35rem;
|
||||
background: transparent;
|
||||
color: var(--vip-content-ink, #171717);
|
||||
font: inherit;
|
||||
font-size: .75rem;
|
||||
text-align: left;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.process-details-combobox__option[hidden] {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.process-details-combobox__option:hover,
|
||||
.process-details-combobox__option.is-active {
|
||||
background: var(--vip-content-accent-soft, #F7F0DE);
|
||||
color: var(--vip-content-accent-dark, #856632);
|
||||
}
|
||||
|
||||
.process-details-combobox__option[aria-selected="true"] {
|
||||
color: var(--vip-content-accent-dark, #856632);
|
||||
font-weight: 700;
|
||||
}
|
||||
|
||||
.process-details-combobox__empty {
|
||||
margin: 0;
|
||||
padding: .55rem .5rem;
|
||||
color: var(--vip-content-muted, #595959);
|
||||
font-size: .72rem;
|
||||
line-height: 1.5;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.process-details-combobox__empty[hidden] {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.process-details-actions {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
@ -849,7 +969,53 @@
|
||||
</div>
|
||||
<div class="process-details-field is-approver">
|
||||
<label for="process-details-current-approver">当前审批人</label>
|
||||
<input id="process-details-current-approver" type="search" name="current_approver_name" value="{{ $filters['current_approver_name'] ?? '' }}" placeholder="支持包含查询">
|
||||
<div class="process-details-combobox" data-process-approver-combobox>
|
||||
<input
|
||||
id="process-details-current-approver"
|
||||
type="search"
|
||||
name="current_approver_name"
|
||||
value="{{ $filters['current_approver_name'] ?? '' }}"
|
||||
placeholder="输入姓名或展开选择"
|
||||
autocomplete="off"
|
||||
role="combobox"
|
||||
aria-expanded="false"
|
||||
aria-controls="process-details-current-approver-menu"
|
||||
aria-autocomplete="list"
|
||||
aria-haspopup="listbox"
|
||||
data-process-approver-input
|
||||
>
|
||||
<button
|
||||
type="button"
|
||||
class="process-details-combobox__toggle"
|
||||
aria-label="展开当前审批人选项"
|
||||
tabindex="-1"
|
||||
data-process-approver-toggle
|
||||
>
|
||||
<span class="material-icons-outlined" aria-hidden="true">expand_more</span>
|
||||
</button>
|
||||
<div
|
||||
id="process-details-current-approver-menu"
|
||||
class="process-details-combobox__menu"
|
||||
role="listbox"
|
||||
aria-label="当前审批人选项"
|
||||
data-process-approver-menu
|
||||
hidden
|
||||
>
|
||||
@foreach ($currentApprovers as $approver)
|
||||
<button
|
||||
type="button"
|
||||
class="process-details-combobox__option"
|
||||
role="option"
|
||||
aria-selected="{{ ($filters['current_approver_name'] ?? '') === $approver ? 'true' : 'false' }}"
|
||||
data-process-approver-option
|
||||
data-value="{{ $approver }}"
|
||||
>{{ $approver }}</button>
|
||||
@endforeach
|
||||
<p class="process-details-combobox__empty" data-process-approver-empty hidden>
|
||||
没有匹配的审批人,可直接输入查询
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="process-details-field is-date-range">
|
||||
<label for="process-details-paid-start">打款时间</label>
|
||||
@ -1139,6 +1305,146 @@
|
||||
</div>
|
||||
|
||||
<script>
|
||||
(() => {
|
||||
const combobox = document.querySelector('[data-process-approver-combobox]');
|
||||
const input = combobox?.querySelector('[data-process-approver-input]');
|
||||
const menu = combobox?.querySelector('[data-process-approver-menu]');
|
||||
const toggle = combobox?.querySelector('[data-process-approver-toggle]');
|
||||
const empty = combobox?.querySelector('[data-process-approver-empty]');
|
||||
if (!combobox || !input || !menu) return;
|
||||
|
||||
const options = [...menu.querySelectorAll('[data-process-approver-option]')];
|
||||
options.forEach((option, index) => {
|
||||
option.id = `${menu.id}-option-${index}`;
|
||||
});
|
||||
|
||||
let activeIndex = -1;
|
||||
const isOpen = () => !menu.hidden;
|
||||
const visibleOptions = () => options.filter((option) => !option.hidden);
|
||||
|
||||
const paint = () => {
|
||||
options.forEach((option, index) => {
|
||||
const active = index === activeIndex;
|
||||
option.classList.toggle('is-active', active);
|
||||
option.setAttribute(
|
||||
'aria-selected',
|
||||
option.dataset.value === input.value.trim() ? 'true' : 'false',
|
||||
);
|
||||
});
|
||||
|
||||
const active = options[activeIndex];
|
||||
if (active) {
|
||||
input.setAttribute('aria-activedescendant', active.id);
|
||||
active.scrollIntoView({ block: 'nearest' });
|
||||
} else {
|
||||
input.removeAttribute('aria-activedescendant');
|
||||
}
|
||||
};
|
||||
|
||||
const applyFilter = (showAll = false) => {
|
||||
const needle = showAll ? '' : input.value.trim().toLocaleLowerCase();
|
||||
let matched = 0;
|
||||
|
||||
options.forEach((option) => {
|
||||
const value = String(option.dataset.value || '').toLocaleLowerCase();
|
||||
const hit = needle === '' || value.includes(needle);
|
||||
option.hidden = !hit;
|
||||
if (hit) matched += 1;
|
||||
});
|
||||
|
||||
if (empty) empty.hidden = matched > 0;
|
||||
activeIndex = -1;
|
||||
paint();
|
||||
};
|
||||
|
||||
const open = (showAll = false) => {
|
||||
applyFilter(showAll);
|
||||
menu.hidden = false;
|
||||
combobox.classList.add('is-open');
|
||||
input.setAttribute('aria-expanded', 'true');
|
||||
};
|
||||
|
||||
const close = () => {
|
||||
menu.hidden = true;
|
||||
combobox.classList.remove('is-open');
|
||||
input.setAttribute('aria-expanded', 'false');
|
||||
input.removeAttribute('aria-activedescendant');
|
||||
activeIndex = -1;
|
||||
options.forEach((option) => option.classList.remove('is-active'));
|
||||
};
|
||||
|
||||
const move = (step) => {
|
||||
if (!isOpen()) {
|
||||
open();
|
||||
}
|
||||
const visible = visibleOptions();
|
||||
if (!visible.length) return;
|
||||
|
||||
const current = visible.indexOf(options[activeIndex]);
|
||||
const next = current === -1
|
||||
? (step > 0 ? 0 : visible.length - 1)
|
||||
: current + step;
|
||||
activeIndex = options.indexOf(
|
||||
visible[(next + visible.length) % visible.length],
|
||||
);
|
||||
paint();
|
||||
};
|
||||
|
||||
const pick = (option) => {
|
||||
input.value = String(option.dataset.value || option.textContent || '').trim();
|
||||
close();
|
||||
input.focus();
|
||||
};
|
||||
|
||||
input.addEventListener('focus', () => {
|
||||
if (!isOpen()) open();
|
||||
});
|
||||
input.addEventListener('click', () => {
|
||||
if (!isOpen()) open();
|
||||
});
|
||||
input.addEventListener('input', () => open());
|
||||
input.addEventListener('keydown', (event) => {
|
||||
if (event.key === 'ArrowDown' || event.key === 'ArrowUp') {
|
||||
event.preventDefault();
|
||||
move(event.key === 'ArrowDown' ? 1 : -1);
|
||||
return;
|
||||
}
|
||||
if (event.key === 'Escape' || event.key === 'Tab') {
|
||||
close();
|
||||
return;
|
||||
}
|
||||
if (event.key === 'Enter' && isOpen()) {
|
||||
const active = options[activeIndex];
|
||||
if (active && !active.hidden) {
|
||||
event.preventDefault();
|
||||
pick(active);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
toggle?.addEventListener('click', () => {
|
||||
if (isOpen()) {
|
||||
close();
|
||||
} else {
|
||||
open(true);
|
||||
input.focus();
|
||||
}
|
||||
});
|
||||
|
||||
options.forEach((option) => {
|
||||
option.addEventListener('mousedown', (event) => event.preventDefault());
|
||||
option.addEventListener('mouseenter', () => {
|
||||
activeIndex = options.indexOf(option);
|
||||
paint();
|
||||
});
|
||||
option.addEventListener('click', () => pick(option));
|
||||
});
|
||||
|
||||
document.addEventListener('click', (event) => {
|
||||
if (!combobox.contains(event.target)) close();
|
||||
});
|
||||
})();
|
||||
|
||||
(() => {
|
||||
const form = document.getElementById('process-details-filter-form');
|
||||
if (form && window.CaiWuDatePicker) {
|
||||
|
||||
@ -72,6 +72,7 @@ class ProcessDetailsPageTest extends FeatureTestCase
|
||||
'已付款',
|
||||
'不涉及付款',
|
||||
],
|
||||
'current_approvers' => ['王五', '赵六'],
|
||||
]);
|
||||
$this->app->instance(DingProcessDetailMirrorRepository::class, $repository);
|
||||
|
||||
@ -100,6 +101,11 @@ class ProcessDetailsPageTest extends FeatureTestCase
|
||||
->assertSee('name="paid_start"', false)
|
||||
->assertSee('name="paid_end"', false)
|
||||
->assertSee('name="current_approver_name"', false)
|
||||
->assertSee('data-process-approver-combobox', false)
|
||||
->assertSee('data-process-approver-option', false)
|
||||
->assertSee('role="combobox"', false)
|
||||
->assertSee('placeholder="输入姓名或展开选择"', false)
|
||||
->assertSee('data-value="赵六"', false)
|
||||
->assertSee('name="entry_start"', false)
|
||||
->assertSee('name="entry_end"', false)
|
||||
->assertSee('placeholder="开始日期"', false)
|
||||
|
||||
@ -59,6 +59,10 @@ class DingProcessDetailMirrorRepositoryTest extends TestCase
|
||||
'待付款',
|
||||
'已付款',
|
||||
], $options['payment_states']);
|
||||
$this->assertCount(3, $options['current_approvers']);
|
||||
$this->assertContains('王五', $options['current_approvers']);
|
||||
$this->assertContains('赵六', $options['current_approvers']);
|
||||
$this->assertContains('钱七', $options['current_approvers']);
|
||||
}
|
||||
|
||||
public function test_filter_options_only_return_payment_states_available_in_context(): void
|
||||
@ -451,7 +455,9 @@ class DingProcessDetailMirrorRepositoryTest extends TestCase
|
||||
'payment_source_state' => 'present',
|
||||
'cashier_status' => $status === '已完成' ? 'completed' : 'pending',
|
||||
'cashier_checked_at' => $now,
|
||||
'current_approver_name' => $businessId === '202601011200000000001' ? '王五' : '赵六',
|
||||
'current_approver_name' => $businessId === '202601011200000000001'
|
||||
? '王五'
|
||||
: '赵六、钱七',
|
||||
'current_task_started_at' => $businessId === '202601011200000000001'
|
||||
? '2026-01-02 09:00:00'
|
||||
: '2026-02-03 09:00:00',
|
||||
|
||||
@ -81,6 +81,7 @@ class ProcessDetailsPageDataTest extends TestCase
|
||||
'已付款',
|
||||
'不涉及付款',
|
||||
],
|
||||
'current_approvers' => ['王五', '赵六'],
|
||||
]);
|
||||
|
||||
$data = (new ProcessDetailsPageData($repository))->page(Request::create(
|
||||
@ -118,6 +119,7 @@ class ProcessDetailsPageDataTest extends TestCase
|
||||
],
|
||||
$data['paymentStates'],
|
||||
);
|
||||
$this->assertSame(['王五', '赵六'], $data['currentApprovers']);
|
||||
$this->assertTrue($data['mirrorStale']);
|
||||
$this->assertSame(15, $data['mirrorStaleAfterMinutes']);
|
||||
$this->assertArrayNotHasKey('months', $data);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user