Compare commits
6 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 7328d85912 | |||
| d7782cc048 | |||
| dd447b8b32 | |||
| e0d9b8ab09 | |||
| c7f36b2d72 | |||
| e012f6e02b |
@@ -135,6 +135,12 @@ th.act,td.act{width:78px;}
|
||||
thead th .fh{display:inline-flex; align-items:center; gap:5px; cursor:pointer;}
|
||||
thead th .fh.filtered{color:var(--primary);}
|
||||
.funnel{width:12px; height:12px; stroke-width:1.6;}
|
||||
/* 列头排序(2026-07-07):label+方向箭头;未排序淡 chevron-down 暗示可排,激活整体 primary。
|
||||
点击循环 无→升→降→无(服务端全局排序)。 */
|
||||
thead th .sh{display:inline-flex; align-items:center; gap:4px; cursor:pointer; user-select:none;}
|
||||
thead th .sh.on{color:var(--primary);}
|
||||
.sort-ic{width:12px; height:12px; stroke-width:2;}
|
||||
thead th .sh:not(.on) .sort-ic{opacity:.45;}
|
||||
tbody td{padding:12px 14px; font-size:var(--fs-body); border-bottom:1px solid var(--border-subtle); color:var(--text); white-space:nowrap;}
|
||||
tbody tr:last-child td{border-bottom:none;}
|
||||
tbody tr.click{cursor:pointer;} tbody tr:hover{background:var(--row-hover);}
|
||||
|
||||
@@ -57,8 +57,12 @@
|
||||
<div class="kpi alert click" onclick="filterStatus('已售')"><div class="ic ic-alert"><svg viewBox="0 0 24 24"><use href="#i-check"/></svg></div><div class="t">已售 · 点击筛选</div><div class="v">17</div><div class="d down">需补货 6 项</div></div>
|
||||
</div>
|
||||
<div class="toolbar">
|
||||
<div class="searchbox"><svg viewBox="0 0 24 24"><use href="#i-search"/></svg><input id="searchInput" placeholder="商品名 / 拼音" oninput="state.q=this.value; state.page=1; render()"></div>
|
||||
<div class="searchbox code"><svg viewBox="0 0 24 24"><use href="#i-search"/></svg><input id="codeInput" placeholder="商品编码" oninput="state.code=this.value; state.page=1; render()"></div>
|
||||
<!-- 搜索合一(2026-07-07 用户口径):名称/拼音/编码同框,与 Flutter 实现一致 -->
|
||||
<div class="searchbox"><svg viewBox="0 0 24 24"><use href="#i-search"/></svg><input id="searchInput" placeholder="商品名 / 拼音 / 编码" oninput="state.q=this.value; state.page=1; render()"></div>
|
||||
<!-- 2026-07-07 用户口径:筛选全部上移工具栏(参照出库管理),列头漏斗退役、只留排序 -->
|
||||
<div class="chip" id="chipSpec" onclick="openDimFilter('spec',this)">规格 <span class="cv" id="specVal"></span><svg viewBox="0 0 24 24"><use href="#i-chevron-down"/></svg></div>
|
||||
<div class="chip" id="chipSeries" onclick="openDimFilter('series',this)">系列 <span class="cv" id="seriesVal"></span><svg viewBox="0 0 24 24"><use href="#i-chevron-down"/></svg></div>
|
||||
<div class="chip" id="chipWh" onclick="openDimFilter('wh',this)">仓库 <span class="cv" id="whVal"></span><svg viewBox="0 0 24 24"><use href="#i-chevron-down"/></svg></div>
|
||||
<div class="chip" id="chipStatus">状态 <span class="cv" id="statusVal"></span><svg viewBox="0 0 24 24"><use href="#i-chevron-down"/></svg></div>
|
||||
<div class="sp"></div>
|
||||
<div class="btn ghost sm" onclick="clearFilters()">重置</div>
|
||||
@@ -113,19 +117,20 @@ const ITEMS=[
|
||||
{name:'水井坊 井台',code:'SJF-JT-500',spec:'500ml×6',series:'井台',batch:'PZ231209',cat:'浓香',qty:6,unit:'件',cost:'¥680',price:'¥4,080',prodDate:'2023-12-09',inDate:'2026-05-20',supplier:'四川水井坊',value:'¥4,100',status:'已售'},
|
||||
];
|
||||
const STATUS=['全部','在售','库存','已售'];
|
||||
const COLS=[{key:'product',label:'商品',fixed:true},{key:'spec',label:'规格'},{key:'series',label:'系列'},{key:'batch',label:'批次号'},{key:'qty',label:'库存',num:true},{key:'cost',label:'成本价',num:true},{key:'price',label:'总价',num:true},{key:'prodDate',label:'生产日期'},{key:'inDate',label:'入库时间'},{key:'supplier',label:'供应商'},{key:'status',label:'状态',filter:'status'},{key:'act',label:'操作',fixed:true}];
|
||||
const state={q:'',code:'',status:'全部',page:1,perPage:10,hidden:new Set()};
|
||||
const COLS=[{key:'product',label:'商品',fixed:true},{key:'spec',label:'规格'},{key:'series',label:'系列'},{key:'batch',label:'批次号'},{key:'qty',label:'库存',num:true,sort:true},{key:'cost',label:'成本价',num:true,sort:true},{key:'price',label:'总价',num:true,sort:true},{key:'prodDate',label:'生产日期',sort:true},{key:'inDate',label:'入库时间',sort:true},{key:'supplier',label:'供应商'},{key:'status',label:'状态'},{key:'act',label:'操作',fixed:true}];
|
||||
const state={q:'',code:'',status:'全部',page:1,perPage:10,hidden:new Set(),sortBy:null,sortAsc:true};
|
||||
|
||||
function setActive(k){ document.querySelectorAll('.nav[data-k]').forEach(e=>e.classList.toggle('active',e.dataset.k===k)); }
|
||||
function navTo(k){ setActive(k); const inv=document.querySelector('[data-view="inventory"]'), ph=document.querySelector('[data-view="placeholder"]'); if(k==='inventory'){inv.classList.add('active');ph.classList.remove('active');return;} inv.classList.remove('active');ph.classList.add('active'); const nav=NAVS.find(n=>n.k===k); document.getElementById('phTitle').textContent=nav.label; document.getElementById('phIcon').innerHTML=navSvg(nav.d); }
|
||||
|
||||
function visibleCols(){ return COLS.filter(c=>!state.hidden.has(c.key)); }
|
||||
function filtered(){ return ITEMS.filter(it=>{ if(state.status!=='全部'&&it.status!==state.status)return false; if(state.q){const q=state.q.toLowerCase(); if(!it.name.toLowerCase().includes(q))return false;} if(state.code){const c=state.code.toLowerCase(); if(!it.code.toLowerCase().includes(c))return false;} return true; }); }
|
||||
function filtered(){ const rows=ITEMS.filter(it=>{ if(state.status!=='全部'&&it.status!==state.status)return false; if(state.spec&&it.spec!==state.spec)return false; if(state.series&&it.series!==state.series)return false; if(state.wh&&it.supplier!==state.wh)return false; if(state.q){const q=state.q.toLowerCase(); if(!it.name.toLowerCase().includes(q)&&!it.code.toLowerCase().includes(q))return false;} return true; }); if(state.sortBy&&SORT_VAL[state.sortBy]){const v=SORT_VAL[state.sortBy];rows.sort((a,b)=>{const x=v(a),y=v(b);return (x<y?-1:x>y?1:0)*(state.sortAsc?1:-1);});} return rows; }
|
||||
function render(){
|
||||
document.getElementById('statusVal').textContent=state.status==='全部'?'':state.status;
|
||||
[['spec','chipSpec','specVal'],['series','chipSeries','seriesVal'],['wh','chipWh','whVal']].forEach(([k,cid,vid])=>{ document.getElementById(vid).textContent=state[k]||''; document.getElementById(cid).classList.toggle('on',!!state[k]); });
|
||||
document.getElementById('chipStatus').classList.toggle('on',state.status!=='全部');
|
||||
const cols=visibleCols();
|
||||
document.getElementById('thead').innerHTML='<tr>'+cols.map(c=>{ const cls=(c.num?'num ':'')+(c.key==='act'?'act ':''); if(c.filter){const on=state.status!=='全部'; return `<th class="${cls}"><span class="fh ${on?'filtered':''}" onclick="openFilter('${c.filter}',this)">${c.label} <svg class="funnel" viewBox="0 0 24 24"><use href="#i-ic22"/></svg></span></th>`;} return `<th class="${cls}">${c.label}</th>`; }).join('')+'</tr>';
|
||||
document.getElementById('thead').innerHTML='<tr>'+cols.map(c=>{ const cls=(c.num?'num ':'')+(c.key==='act'?'act ':''); if(c.filter){const on=state.status!=='全部'; return `<th class="${cls}"><span class="fh ${on?'filtered':''}" onclick="openFilter('${c.filter}',this)">${c.label} <svg class="funnel" viewBox="0 0 24 24"><use href="#i-ic22"/></svg></span></th>`;} if(c.sort){const on=state.sortBy===c.key; const ic=!on?'i-chevron-down':(state.sortAsc?'i-ic51':'i-chevron-down'); return `<th class="${cls}"><span class="sh ${on?'on':''}" onclick="toggleSort('${c.key}')">${c.label} <svg class="sort-ic" viewBox="0 0 24 24"><use href="#${ic}"/></svg></span></th>`;} return `<th class="${cls}">${c.label}</th>`; }).join('')+'</tr>';
|
||||
const rows=filtered(); const start=(state.page-1)*state.perPage; const pageRows=rows.slice(start,start+state.perPage); const tb=document.getElementById('tbody');
|
||||
if(rows.length===0){ tb.innerHTML=`<tr><td colspan="${cols.length}"><div class="empty">没有匹配的商品 · 试试调整筛选或搜索</div></td></tr>`; }
|
||||
else { tb.innerHTML=pageRows.map(it=>{ const idx=ITEMS.indexOf(it); return '<tr class="click" onclick="openProduct('+idx+')">'+cols.map(c=>{ if(c.key==='product')return `<td><div class="pname">${it.name}</div><div class="pcode">${it.code}</div></td>`; if(c.key==='qty')return `<td class="num"><span class="qty ${it.qty<=10?'low':''}">${it.qty}</span></td>`; if(c.key==='prodDate')return `<td style="font-family:var(--font-mono);color:var(--text)">${it.prodDate}</td>`; if(c.key==='inDate')return `<td style="font-family:var(--font-mono);color:var(--muted)">${it.inDate}</td>`; if(c.key==='status')return `<td><span class="badge b-${it.status}">${it.status}</span></td>`; if(c.key==='act')return `<td class="act"><div class="row-act" onclick="event.stopPropagation()"><svg viewBox="0 0 24 24" onclick="openProduct(${idx})"><use href="#i-eye"/></svg></div></td>`; return `<td class="${c.num?'num':''}">${it[c.key]}</td>`; }).join('')+'</tr>'; }).join(''); }
|
||||
@@ -138,9 +143,15 @@ const PAGE_SIZES=[10,20,50,100];
|
||||
function openPageSize(e){ openMenu(e.currentTarget, PAGE_SIZES.map(n=>({v:String(n),label:String(n),sel:n===state.perPage})), v=>{ closeMenus(); setPerPage(v); }, 'pgsize-menu', 88); }
|
||||
function setPerPage(v){ state.perPage=+v; state.page=1; const el=document.getElementById('pageSizeVal'); if(el)el.textContent=v; render(); }
|
||||
function filterStatus(s){ state.status=s; state.page=1; navTo('inventory'); render(); }
|
||||
function clearFilters(){ state.q='';state.code='';state.status='全部';state.page=1; document.getElementById('searchInput').value=''; document.getElementById('codeInput').value=''; render(); }
|
||||
// 列头排序:无→升→降→无 循环(真实实现为服务端全局排序)
|
||||
function toggleSort(k){ if(state.sortBy!==k){state.sortBy=k;state.sortAsc=true;} else if(state.sortAsc){state.sortAsc=false;} else {state.sortBy=null;state.sortAsc=true;} state.page=1; render(); }
|
||||
const SORT_VAL={qty:it=>it.qty,cost:it=>parseFloat(String(it.cost).replace(/[¥,]/g,''))||0,price:it=>parseFloat(String(it.price).replace(/[¥,]/g,''))||0,prodDate:it=>it.prodDate||'',inDate:it=>it.inDate||''};
|
||||
function clearFilters(){ state.q='';state.status='全部';state.spec=null;state.series=null;state.wh=null;state.page=1; document.getElementById('searchInput').value=''; render(); }
|
||||
|
||||
function openFilter(kind,t){ openMenu(t,STATUS.map(v=>({v,label:v,sel:v===state.status})),v=>{ state.status=v; state.page=1; closeMenus(); render(); }); }
|
||||
// 维度筛选 chip(规格/系列/仓库,2026-07-07 从列头漏斗上移;真实实现为多选)
|
||||
const DIM_KEY={spec:'spec',series:'series',wh:'supplier'};
|
||||
function openDimFilter(dim,t){ const key=DIM_KEY[dim]; const opts=['全部',...new Set(ITEMS.map(it=>it[key]).filter(Boolean))]; openMenu(t,opts.map(v=>({v,label:v,sel:(state[dim]||'全部')===v})),v=>{ state[dim]=v==='全部'?null:v; state.page=1; closeMenus(); render(); }); }
|
||||
document.getElementById('chipStatus').onclick=e=>openFilter('status',e.currentTarget);
|
||||
const COL_KEY='jiu-inv-hidden';
|
||||
function saveHidden(){ try{ localStorage.setItem(COL_KEY, JSON.stringify([...state.hidden])); }catch(e){} }
|
||||
|
||||
@@ -5,6 +5,16 @@ All notable changes to this project will be documented in this file.
|
||||
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
||||
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
||||
|
||||
## [1.1.7] - 2026-07-07
|
||||
|
||||
### 新功能
|
||||
- 库存列表列头排序:点击 库存 / 成本价 / 总价 / 生产日期 / 入库时间 列头
|
||||
即可全局排序(升序 ↑ / 降序 ↓ / 再点恢复默认)。
|
||||
|
||||
### 改进
|
||||
- 库存筛选全部移到工具栏(与出库管理同一形式):规格 / 系列 / 仓库 / 状态
|
||||
改为工具栏下拉标签,可单独清除;列头不再放筛选漏斗。
|
||||
|
||||
## [1.1.6] - 2026-07-07
|
||||
|
||||
### 新功能
|
||||
|
||||
@@ -5,6 +5,12 @@
|
||||
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
||||
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
||||
|
||||
## [1.1.11] - 2026-07-07
|
||||
|
||||
### 新功能
|
||||
- 库存列表支持按 库存 / 成本价 / 总价 / 生产日期 / 入库时间 排序,
|
||||
全局生效(跨分页),成本类按显示口径排序结果一致。
|
||||
|
||||
## [1.1.10] - 2026-07-07
|
||||
|
||||
### 新功能
|
||||
|
||||
@@ -158,6 +158,23 @@ func (h *InventoryHandler) List(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
// 排序(2026-07-07 列头排序):白名单列 → SQL 表达式,防注入;带 id 兜底保证分页稳定。
|
||||
// cost/price/prod_date 用与 SELECT 相同的 COALESCE 口径,排序结果与显示一致。
|
||||
orderExpr := "inv.id DESC"
|
||||
if sortCol, ok := map[string]string{
|
||||
"qty": "inv.quantity",
|
||||
"cost": "COALESCE(sii.cost_price, inv.unit_price, p.purchase_price)",
|
||||
"price": "inv.quantity * COALESCE(sii.cost_price, inv.unit_price, p.purchase_price)",
|
||||
"prod_date": "COALESCE(DATE(sii.production_date), DATE(inv.production_date))",
|
||||
"in_time": "inv.created_at",
|
||||
}[c.Query("sort_by")]; ok {
|
||||
dir := "ASC"
|
||||
if c.Query("sort_dir") == "desc" {
|
||||
dir = "DESC"
|
||||
}
|
||||
orderExpr = sortCol + " " + dir + ", inv.id DESC"
|
||||
}
|
||||
|
||||
// Data query
|
||||
dataSQL := `
|
||||
SELECT
|
||||
@@ -183,7 +200,7 @@ func (h *InventoryHandler) List(c *gin.Context) {
|
||||
LEFT JOIN products p ON p.id = inv.product_id AND p.deleted_at IS NULL
|
||||
LEFT JOIN warehouses w ON w.id = inv.warehouse_id
|
||||
WHERE ` + baseWhere + `
|
||||
ORDER BY inv.id DESC
|
||||
ORDER BY ` + orderExpr + `
|
||||
LIMIT ? OFFSET ?`
|
||||
|
||||
dataArgs := append(args, pageSize, (page-1)*pageSize)
|
||||
|
||||
@@ -3,6 +3,7 @@ package handler
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
@@ -525,3 +526,44 @@ func TestInventoryHandler_StatusTenantIsolation(t *testing.T) {
|
||||
require.NoError(t, db.Where("id = ?", invB.ID).First(&got).Error)
|
||||
assert.Equal(t, "stock", got.Status)
|
||||
}
|
||||
|
||||
// 列头排序(2026-07-07):白名单列全局排序,非法列忽略回默认
|
||||
func TestInventoryHandler_ListSort(t *testing.T) {
|
||||
db := testutil.SetupTestDB()
|
||||
shop := testutil.CreateTestShop(db, "INV_SORT")
|
||||
user := testutil.CreateTestUser(db, shop.ID, "admin", "pass", "admin")
|
||||
wh := testutil.CreateTestWarehouse(db, shop.ID, "仓")
|
||||
token := getAuthToken(user.ID, shop.ID, "admin")
|
||||
r := setupProtectedRouter(db)
|
||||
|
||||
for i, qty := range []float64{5, 20, 10} {
|
||||
p := testutil.CreateTestProduct(db, shop.ID, fmt.Sprintf("酒%d", i))
|
||||
price := float64(100 * (i + 1))
|
||||
require.NoError(t, db.Create(&model.Inventory{
|
||||
ShopID: shop.ID, WarehouseID: &wh.ID, ProductID: &p.ID,
|
||||
Quantity: qty, UnitPrice: &price,
|
||||
}).Error)
|
||||
}
|
||||
|
||||
qtys := func(w *httptest.ResponseRecorder) []float64 {
|
||||
rows := parseResponse(w)["data"].([]interface{})
|
||||
out := make([]float64, len(rows))
|
||||
for i, r := range rows {
|
||||
out[i] = r.(map[string]interface{})["quantity"].(float64)
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
// qty 升序
|
||||
w := makeRequest(r, "GET", "/api/v1/inventory?sort_by=qty&sort_dir=asc", token, nil)
|
||||
assert.Equal(t, []float64{5, 10, 20}, qtys(w))
|
||||
// qty 降序
|
||||
w = makeRequest(r, "GET", "/api/v1/inventory?sort_by=qty&sort_dir=desc", token, nil)
|
||||
assert.Equal(t, []float64{20, 10, 5}, qtys(w))
|
||||
// 总价 = qty×进价:5×100=500, 20×200=4000, 10×300=3000 → 升序 5,10,20
|
||||
w = makeRequest(r, "GET", "/api/v1/inventory?sort_by=price&sort_dir=asc", token, nil)
|
||||
assert.Equal(t, []float64{5, 10, 20}, qtys(w))
|
||||
// 非法列忽略 → 默认 id 倒序(最后插入的 qty=10 在前)
|
||||
w = makeRequest(r, "GET", "/api/v1/inventory?sort_by=evil;drop", token, nil)
|
||||
assert.Equal(t, []float64{10, 20, 5}, qtys(w))
|
||||
}
|
||||
|
||||
@@ -31,6 +31,8 @@ class InventoryListNotifier extends AsyncNotifier<PageResult<Inventory>> {
|
||||
String _keyword = '';
|
||||
String _code = ''; // 商品编码独立筛选(原型 codeInput)
|
||||
String _status = ''; // 三态筛选(空=后端默认排除已售)
|
||||
String _sortBy = ''; // 列头排序(空=默认 id 倒序)
|
||||
bool _sortAsc = true;
|
||||
List<String> _series = [];
|
||||
List<String> _spec = [];
|
||||
PageResult<Inventory>? _cache;
|
||||
@@ -55,6 +57,8 @@ class InventoryListNotifier extends AsyncNotifier<PageResult<Inventory>> {
|
||||
keyword: _keyword.isEmpty ? null : _keyword,
|
||||
code: _code.isEmpty ? null : _code,
|
||||
status: _status.isEmpty ? null : _status,
|
||||
sortBy: _sortBy.isEmpty ? null : _sortBy,
|
||||
sortAsc: _sortAsc,
|
||||
series: _series.isEmpty ? null : _series,
|
||||
spec: _spec.isEmpty ? null : _spec,
|
||||
page: _page,
|
||||
@@ -97,6 +101,13 @@ class InventoryListNotifier extends AsyncNotifier<PageResult<Inventory>> {
|
||||
reload();
|
||||
}
|
||||
|
||||
void setSort(String sortBy, bool asc) {
|
||||
_sortBy = sortBy;
|
||||
_sortAsc = asc;
|
||||
_page = 1;
|
||||
reload();
|
||||
}
|
||||
|
||||
void setSeries(List<String> series) {
|
||||
_series = series;
|
||||
_page = 1;
|
||||
|
||||
@@ -17,6 +17,8 @@ class InventoryRepository {
|
||||
List<String>? series,
|
||||
List<String>? spec,
|
||||
String? status, // 三态筛选:stock/on_sale/sold(逗号可多值);空=后端默认(排除已售)
|
||||
String? sortBy, // 列头排序:qty/cost/price/prod_date/in_time(后端白名单)
|
||||
bool sortAsc = true,
|
||||
int page = 1,
|
||||
int pageSize = 50,
|
||||
}) async {
|
||||
@@ -31,6 +33,10 @@ class InventoryRepository {
|
||||
if (series != null && series.isNotEmpty) 'series': series.join(','),
|
||||
if (spec != null && spec.isNotEmpty) 'spec': spec.join(','),
|
||||
if (status != null && status.isNotEmpty) 'status': status,
|
||||
if (sortBy != null && sortBy.isNotEmpty) ...{
|
||||
'sort_by': sortBy,
|
||||
'sort_dir': sortAsc ? 'asc' : 'desc',
|
||||
},
|
||||
};
|
||||
final resp = await _client.get('/inventory', params: params);
|
||||
return PageResult.fromJson(
|
||||
|
||||
@@ -141,6 +141,34 @@ class _InventoryListScreenState extends ConsumerState<InventoryListScreen> {
|
||||
.setStatus(_statusParam[label] ?? '');
|
||||
}
|
||||
|
||||
// ── 列头排序(点击循环 无→升→降→无,服务端全局排序) ──
|
||||
String _sortBy = ''; // 列 key(屏内),空=未排序
|
||||
bool _sortAsc = true;
|
||||
static const _sortParam = {
|
||||
'qty': 'qty',
|
||||
'cost': 'cost',
|
||||
'price': 'price',
|
||||
'prodDate': 'prod_date',
|
||||
'inTime': 'in_time',
|
||||
};
|
||||
|
||||
void _toggleSort(String key) {
|
||||
setState(() {
|
||||
if (_sortBy != key) {
|
||||
_sortBy = key;
|
||||
_sortAsc = true;
|
||||
} else if (_sortAsc) {
|
||||
_sortAsc = false;
|
||||
} else {
|
||||
_sortBy = '';
|
||||
_sortAsc = true;
|
||||
}
|
||||
});
|
||||
ref
|
||||
.read(inventoryListProvider.notifier)
|
||||
.setSort(_sortBy.isEmpty ? '' : _sortParam[_sortBy]!, _sortAsc);
|
||||
}
|
||||
|
||||
// 成本仅管理员可见(与出库同口径):非管理员隐藏成本价/总价列、卡片单价、货值 KPI。
|
||||
bool get _isAdmin => ref.watch(isAdminProvider);
|
||||
bool _colAllowed(ColDef c) =>
|
||||
@@ -178,7 +206,25 @@ class _InventoryListScreenState extends ConsumerState<InventoryListScreen> {
|
||||
if (v != null && mounted) _applyStatusFilter(v);
|
||||
}
|
||||
|
||||
// ── 多选漏斗(规格/系列/仓库) ──
|
||||
// ── 工具栏多选 chip(规格/系列/仓库,2026-07-07 从列头漏斗上移) ──
|
||||
Widget _multiChip(String label, List<String> options, Set<String> selected,
|
||||
ValueChanged<Set<String>> onChanged) {
|
||||
return Builder(
|
||||
builder: (chipCtx) => DsChip(
|
||||
label: label,
|
||||
value: selected.isEmpty
|
||||
? null
|
||||
: selected.length == 1
|
||||
? selected.first
|
||||
: '${selected.length} 项',
|
||||
onTap: () => _openMultiFilter(chipCtx,
|
||||
options: options, selected: selected, onChanged: onChanged),
|
||||
onClear: () => onChanged({}),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
// ── 多选菜单(规格/系列/仓库,chip 锚定) ──
|
||||
void _openMultiFilter(
|
||||
BuildContext anchorContext, {
|
||||
required List<String> options,
|
||||
@@ -880,11 +926,40 @@ class _InventoryListScreenState extends ConsumerState<InventoryListScreen> {
|
||||
);
|
||||
}
|
||||
|
||||
// 桌面 toolbar:合一搜索框 + 重置
|
||||
// (状态筛选 chip 已按用户口径删除,状态列漏斗保留)
|
||||
// 桌面 toolbar:搜索 + 筛选 chips + 重置
|
||||
// (2026-07-07 用户口径反转:筛选全部上移工具栏,形式
|
||||
// 参照出库管理;列头只留排序,漏斗退役)
|
||||
return Row(
|
||||
children: [
|
||||
SizedBox(width: 260, child: searchField),
|
||||
const SizedBox(width: AppDims.sp2),
|
||||
_multiChip('规格', specOptions, _filterSpec, (v) {
|
||||
setState(() => _filterSpec = v);
|
||||
ref
|
||||
.read(inventoryListProvider.notifier)
|
||||
.setSpec(v.toList());
|
||||
}),
|
||||
const SizedBox(width: AppDims.sp2),
|
||||
_multiChip('系列', seriesOptions, _filterSeries, (v) {
|
||||
setState(() => _filterSeries = v);
|
||||
ref
|
||||
.read(inventoryListProvider.notifier)
|
||||
.setSeries(v.toList());
|
||||
}),
|
||||
const SizedBox(width: AppDims.sp2),
|
||||
_multiChip('仓库', warehouseOptions, _filterWarehouse,
|
||||
(v) => setState(() => _filterWarehouse = v)),
|
||||
const SizedBox(width: AppDims.sp2),
|
||||
Builder(
|
||||
builder: (chipCtx) => DsChip(
|
||||
label: '状态',
|
||||
value: _statusFilter == '全部'
|
||||
? null
|
||||
: _statusFilter,
|
||||
onTap: () => _openStatusMenu(chipCtx),
|
||||
onClear: () => _applyStatusFilter('全部'),
|
||||
),
|
||||
),
|
||||
const Spacer(),
|
||||
DsButton('重置', small: true, onPressed: _clearFilters),
|
||||
],
|
||||
@@ -899,45 +974,18 @@ class _InventoryListScreenState extends ConsumerState<InventoryListScreen> {
|
||||
},
|
||||
emptyText: '没有匹配的商品 · 试试调整筛选或搜索',
|
||||
columns: visibleCols.map((c) {
|
||||
// 筛选已全部上移工具栏 chips(2026-07-07),列头只留排序。
|
||||
final Widget? header = switch (c.key) {
|
||||
'spec' => DsFilterHeader(
|
||||
// 可排序列(原型 COLS sort:true,服务端全局排序)
|
||||
'qty' ||
|
||||
'cost' ||
|
||||
'price' ||
|
||||
'prodDate' ||
|
||||
'inTime' =>
|
||||
DsSortHeader(
|
||||
label: c.label,
|
||||
filtered: _filterSpec.isNotEmpty,
|
||||
onOpen: (bctx) => _openMultiFilter(bctx,
|
||||
options: specOptions,
|
||||
selected: _filterSpec, onChanged: (v) {
|
||||
setState(() => _filterSpec = v);
|
||||
ref
|
||||
.read(inventoryListProvider.notifier)
|
||||
.setSpec(v.toList());
|
||||
}),
|
||||
),
|
||||
'series' => DsFilterHeader(
|
||||
label: c.label,
|
||||
filtered: _filterSeries.isNotEmpty,
|
||||
onOpen: (bctx) => _openMultiFilter(bctx,
|
||||
options: seriesOptions,
|
||||
selected: _filterSeries, onChanged: (v) {
|
||||
setState(() => _filterSeries = v);
|
||||
ref
|
||||
.read(inventoryListProvider.notifier)
|
||||
.setSeries(v.toList());
|
||||
}),
|
||||
),
|
||||
'warehouse' => DsFilterHeader(
|
||||
label: c.label,
|
||||
filtered: _filterWarehouse.isNotEmpty,
|
||||
onOpen: (bctx) => _openMultiFilter(bctx,
|
||||
options: warehouseOptions,
|
||||
selected: _filterWarehouse,
|
||||
onChanged: (v) =>
|
||||
setState(() => _filterWarehouse = v)),
|
||||
),
|
||||
// 原型 COLS 里带 filter 的列只有状态(单选)。
|
||||
'status' => DsFilterHeader(
|
||||
label: c.label,
|
||||
filtered: _statusFilter != '全部',
|
||||
onOpen: _openStatusMenu,
|
||||
ascending: _sortBy == c.key ? _sortAsc : null,
|
||||
onTap: () => _toggleSort(c.key),
|
||||
),
|
||||
_ => null,
|
||||
};
|
||||
|
||||
@@ -479,6 +479,50 @@ class _DsTableState extends State<DsTable> {
|
||||
}
|
||||
}
|
||||
|
||||
/// 原型 thead th .sh 排序列头(2026-07-07 登记):label + 方向箭头。
|
||||
/// 未排序 = 淡 chevron-down 暗示可排;激活整体 primary,asc=↑ / desc=↓。
|
||||
/// 点击由调用方循环 无→升→降→无(服务端全局排序)。
|
||||
class DsSortHeader extends StatelessWidget {
|
||||
final String label;
|
||||
|
||||
/// null = 未按本列排序;true = 升序;false = 降序
|
||||
final bool? ascending;
|
||||
final VoidCallback onTap;
|
||||
const DsSortHeader(
|
||||
{super.key, required this.label, this.ascending, required this.onTap});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final t = context.tokens;
|
||||
final on = ascending != null;
|
||||
final color = on ? t.primary : t.muted;
|
||||
return InkWell(
|
||||
onTap: onTap,
|
||||
child: Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Text(label,
|
||||
style: TextStyle(
|
||||
fontSize: AppDims.fsSm,
|
||||
fontWeight: FontWeight.w600,
|
||||
color: color)),
|
||||
const SizedBox(width: 4),
|
||||
Opacity(
|
||||
opacity: on ? 1 : .45,
|
||||
child: Icon(
|
||||
ascending == true
|
||||
? LucideIcons.chevronUp
|
||||
: LucideIcons.chevronDown,
|
||||
size: 12,
|
||||
color: color,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// 原型 thead th .fh 漏斗列头:label + funnel(12, sw1.6),有筛选值时整体 primary。
|
||||
/// 点击回调携带列头自身 BuildContext(供 showDsMenu 锚定)。
|
||||
class DsFilterHeader extends StatelessWidget {
|
||||
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 416 KiB After Width: | Height: | Size: 420 KiB |
Binary file not shown.
|
Before Width: | Height: | Size: 410 KiB After Width: | Height: | Size: 414 KiB |
Binary file not shown.
|
Before Width: | Height: | Size: 417 KiB After Width: | Height: | Size: 422 KiB |
@@ -52,6 +52,8 @@ class _FakeInvRepo implements InventoryRepository {
|
||||
List<String>? series,
|
||||
List<String>? spec,
|
||||
String? status,
|
||||
String? sortBy,
|
||||
bool sortAsc = true,
|
||||
int page = 1,
|
||||
int pageSize = 50,
|
||||
}) async =>
|
||||
|
||||
@@ -100,6 +100,8 @@ class _FakeInventoryRepository extends InventoryRepository {
|
||||
List<String>? series,
|
||||
List<String>? spec,
|
||||
String? status,
|
||||
String? sortBy,
|
||||
bool sortAsc = true,
|
||||
int page = 1,
|
||||
int pageSize = 50,
|
||||
}) async {
|
||||
|
||||
Reference in New Issue
Block a user