Просмотр исходного кода

改用复选框组选择合伙人指定客户

sy 19 часов назад
Родитель
Сommit
095fe5e5a3

+ 27 - 16
web-scaffold/src/components/PartnerCustomerPicker.tsx

@@ -1,5 +1,5 @@
 import { useEffect, useState } from "react";
-import { Plus, Search, X } from "lucide-react";
+import { Search, X } from "lucide-react";
 import { customerGetList, rowsOf } from "../lib/api/bos";
 import { useLoad } from "../lib/useLoad";
 import { SearchInput } from "./ui/search-input";
@@ -50,20 +50,31 @@ export function PartnerCustomerPicker({ selectedIds, blockedIds, onChange, disab
               <button className="org-inline-link" type="button" onClick={results.reload}>重试</button>
             </div>
           ) : matches.length ? (
-            <ul className="partner-customer-list">
-              {matches.map(({ id, name }) => {
-                const selected = selectedIds.includes(id);
-                const blocked = blockedIds.has(id);
-                return (
-                  <li key={id}>
-                    <div className="partner-customer-label"><span title={name}>{name}</span>{name !== id && <small title={id}>{id}</small>}</div>
-                    {selected || blocked ? <span className="partner-customer-status">{selected ? "已选" : "其他合伙人已选"}</span> : (
-                      <button className="partner-customer-icon" aria-label={`添加 ${name}`} title="添加" disabled={disabled} onClick={() => onChange([...selectedIds, id])} type="button"><Plus size={16} /></button>
-                    )}
-                  </li>
-                );
-              })}
-            </ul>
+            <fieldset className="partner-customer-options" disabled={disabled}>
+              <legend className="sr-only">可选客户</legend>
+              <ul className="partner-customer-list">
+                {matches.map(({ id, name }) => {
+                  const selected = selectedIds.includes(id);
+                  const blocked = blockedIds.has(id) && !selected;
+                  return (
+                    <li key={id}>
+                      <label className="partner-customer-option">
+                        <input
+                          type="checkbox"
+                          checked={selected}
+                          disabled={blocked}
+                          onChange={(event) => onChange(event.target.checked
+                            ? [...selectedIds, id]
+                            : selectedIds.filter((customerId) => customerId !== id))}
+                        />
+                        <span className="partner-customer-label"><span title={name}>{name}</span>{name !== id && <small title={id}>{id}</small>}</span>
+                        {blocked && <span className="partner-customer-status">其他合伙人已选</span>}
+                      </label>
+                    </li>
+                  );
+                })}
+              </ul>
+            </fieldset>
           ) : <p className="partner-customer-feedback" role="status">{keyword ? "未找到匹配的客户。" : "暂无可选客户。"}</p>}
         </div>
         <div className="partner-customer-pane">
@@ -75,7 +86,7 @@ export function PartnerCustomerPicker({ selectedIds, blockedIds, onChange, disab
                 return (
                   <li key={id}>
                     <div className="partner-customer-label"><span title={name}>{name}</span>{name !== id && <small title={id}>{id}</small>}</div>
-                    <button className="partner-customer-icon is-remove" aria-label={`移除 ${name}`} title="移除" disabled={disabled} onClick={() => onChange(selectedIds.filter((selected) => selected !== id))} type="button"><X size={15} /></button>
+                    <button className="partner-customer-icon" aria-label={`移除 ${name}`} title="移除" disabled={disabled} onClick={() => onChange(selectedIds.filter((selected) => selected !== id))} type="button"><X size={15} /></button>
                   </li>
                 );
               })}

+ 9 - 3
web-scaffold/src/pages/__tests__/partner-management.test.tsx

@@ -54,14 +54,20 @@ it("账号从列表独立打开,指定客户跨搜索保留并按主体号保
   const edit = screen.getByRole("dialog", { name: "编辑合伙人" });
   expect(within(edit).queryByRole("button", { name: "重置激活码" })).toBeNull();
   expect(within(edit).getByRole("button", { name: "移除 LEGACY" })).toBeTruthy();
-  fireEvent.click(await within(edit).findByRole("button", { name: "添加 客户甲" }));
+  const options = await within(edit).findByRole("group", { name: "可选客户" });
+  const customer = within(options).getByRole("checkbox", { name: /^客户甲/ });
+  fireEvent.click(customer);
+  expect(within(options).getByRole("checkbox", { name: /^客户甲/, checked: true })).toBe(customer);
+  fireEvent.click(customer);
+  expect(within(edit).queryByRole("button", { name: "移除 客户甲" })).toBeNull();
+  fireEvent.click(customer);
   expect(within(edit).getByText("其他合伙人已选")).toBeTruthy();
-  expect(within(edit).queryByRole("button", { name: "添加 已被分配的客户" })).toBeNull();
+  expect((within(options).getByRole("checkbox", { name: /^已被分配的客户/ }) as HTMLInputElement).disabled).toBe(true);
 
   const search = within(edit).getByRole("textbox", { name: "搜索客户" });
   fireEvent.change(search, { target: { value: "客户乙" } });
   fireEvent.keyDown(search, { key: "Enter" });
-  await within(edit).findByRole("button", { name: "添加 客户乙" });
+  await within(edit).findByRole("checkbox", { name: /^客户乙/ });
   expect(within(edit).getByRole("button", { name: "移除 客户甲" })).toBeTruthy();
   fireEvent.click(within(edit).getByRole("button", { name: "移除 LEGACY" }));
   fireEvent.click(within(edit).getByRole("button", { name: "保存档案" }));

+ 8 - 4
web-scaffold/src/styles/organization.css

@@ -713,17 +713,21 @@ a.org-overview-card{text-decoration:none;color:inherit}
 .partner-customer-search { display: flex; align-items: center; gap: 6px; margin: 8px 10px 4px; color: var(--muted-foreground); }
 .partner-customer-search svg { flex: none; }
 .partner-customer-search input { min-width: 0; }
+.partner-customer-options { min-width: 0; margin: 0; padding: 0; border: 0; }
 .partner-customer-list { max-height: 184px; overflow: auto; margin: 0; padding: 0 10px; list-style: none; scrollbar-gutter: stable; }
 .partner-customer-list li { display: flex; align-items: center; justify-content: space-between; gap: 6px; min-height: 42px; padding: 5px 0; }
+.partner-customer-options .partner-customer-list li { padding: 0; }
+.partner-customer-option { display: flex; align-items: center; gap: 8px; width: 100%; min-height: 42px; padding: 5px 0; cursor: pointer; }
+.partner-customer-option:has(input:disabled) { cursor: not-allowed; }
+.partner-customer-option input { flex: none; width: 16px; height: 16px; margin: 0; accent-color: var(--primary); cursor: inherit; }
+.partner-customer-option .partner-customer-label { flex: 1; }
 .partner-customer-list li + li { border-top: 1px solid var(--border-subtle); }
 .partner-customer-label { min-width: 0; font-size: var(--type-support); color: var(--foreground); }
 .partner-customer-label :is(span, small) { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
 .partner-customer-label small, .partner-customer-status { color: var(--muted-foreground); font-size: var(--type-meta); }
 .partner-customer-status { flex: none; }
-.partner-customer-icon { display: grid; place-items: center; flex: none; width: 28px; height: 28px; border: 0; border-radius: 6px; background: var(--primary-soft); color: var(--primary); cursor: pointer; }
-.partner-customer-icon.is-remove { background: var(--surface-subtle); color: var(--text-secondary); }
-.partner-customer-icon:hover:not(:disabled) { background: var(--primary-border); }
-.partner-customer-icon.is-remove:hover:not(:disabled) { background: var(--destructive-soft); color: var(--destructive); }
+.partner-customer-icon { display: grid; place-items: center; flex: none; width: 28px; height: 28px; border: 0; border-radius: 6px; background: var(--surface-subtle); color: var(--text-secondary); cursor: pointer; }
+.partner-customer-icon:hover:not(:disabled) { background: var(--destructive-soft); color: var(--destructive); }
 .partner-customer-icon:disabled { opacity: .5; cursor: not-allowed; }
 .partner-customer-feedback { padding: 8px 11px; color: var(--muted-foreground); font-size: var(--type-support); overflow-wrap: anywhere; }
 .partner-customer-feedback[role="alert"] p { margin: 0 0 4px; color: var(--destructive); }