新建商品分类改内联并支持新建分类
- 分类不再用滚轮选择器,改成一排可点 chip(选中态高亮) - chip 末尾「+ 新建分类」,在表单内就地输入名称创建 - 新建复用库存入库建分类接口,建完直接选中且不关表单
This commit is contained in:
@@ -9,6 +9,7 @@ const {
|
||||
listStandaloneLines,
|
||||
fetchStockInboundSkuOptions,
|
||||
fetchStockInboundCategories,
|
||||
createStockInboundCategory,
|
||||
createStockInboundProduct,
|
||||
uploadProcessingInspectPhoto,
|
||||
submitProcessingInspection,
|
||||
@@ -245,6 +246,10 @@ Component({
|
||||
showOutputProductModal: false,
|
||||
outputProductForm: { name: '', categoryIndex: 0, spec: '', unit: '', origin: '' },
|
||||
outputCategoryOptions: [],
|
||||
/** 分类:就地新建(不弹滚轮选择器) */
|
||||
outputCategoryCreating: false,
|
||||
outputCategoryName: '',
|
||||
creatingOutputCategory: false,
|
||||
creatingOutputProduct: false,
|
||||
/**
|
||||
* ⚠️ 2026-10-23 复查结论:搜索框必须**受控**(wxml 绑定 `value="{{outputSkuSearch}}"`)。
|
||||
@@ -1009,6 +1014,8 @@ Component({
|
||||
this.setData({
|
||||
showOutputProductModal: true,
|
||||
outputProductForm: { name, categoryIndex: 0, spec: '', unit: '', origin: '' },
|
||||
outputCategoryCreating: false,
|
||||
outputCategoryName: '',
|
||||
});
|
||||
if (!(this.data.outputCategoryOptions || []).length) await this.loadOutputCategoryOptions();
|
||||
},
|
||||
@@ -1035,13 +1042,73 @@ Component({
|
||||
this.setData({ [`outputProductForm.${field}`]: e.detail.value });
|
||||
},
|
||||
|
||||
onOutputProductCategory(e) {
|
||||
this.setData({ 'outputProductForm.categoryIndex': Number(e.detail.value) || 0 });
|
||||
/** 分类:点标签选(内联,不弹滚轮选择器) */
|
||||
pickOutputCategory(e) {
|
||||
const index = Number(e.currentTarget.dataset.index);
|
||||
if (!Number.isInteger(index) || index < 0) return;
|
||||
this.setData({ 'outputProductForm.categoryIndex': index });
|
||||
},
|
||||
|
||||
toggleOutputCategoryCreate() {
|
||||
this.setData({
|
||||
outputCategoryCreating: !this.data.outputCategoryCreating,
|
||||
outputCategoryName: '',
|
||||
});
|
||||
},
|
||||
|
||||
cancelOutputCategoryCreate() {
|
||||
if (this.data.creatingOutputCategory) return;
|
||||
this.setData({ outputCategoryCreating: false, outputCategoryName: '' });
|
||||
},
|
||||
|
||||
onOutputCategoryNameInput(e) {
|
||||
const raw = e && e.detail ? e.detail.value : '';
|
||||
this.setData({ outputCategoryName: typeof raw === 'string' ? raw : '' });
|
||||
},
|
||||
|
||||
/** 新建分类(与库存入库同一个接口):建完直接选中,不关表单 */
|
||||
async submitOutputCategory() {
|
||||
if (this.data.creatingOutputCategory) return;
|
||||
const name = String(this.data.outputCategoryName || '').trim();
|
||||
if (!name) {
|
||||
wx.showToast({ title: '请填写分类名', icon: 'none' });
|
||||
return;
|
||||
}
|
||||
this.setData({ creatingOutputCategory: true });
|
||||
try {
|
||||
const res = await createStockInboundCategory(name);
|
||||
const row = (res && (res.data || res)) || {};
|
||||
const code = String(row.category_code || '');
|
||||
const label = String(row.category_name || row.label || name);
|
||||
if (!code) {
|
||||
wx.showToast({ title: '新建分类失败', icon: 'none' });
|
||||
return;
|
||||
}
|
||||
const options = (this.data.outputCategoryOptions || []).slice();
|
||||
const existed = options.findIndex((o) => o.code === code);
|
||||
if (existed >= 0) options[existed] = { code, label };
|
||||
else options.push({ code, label });
|
||||
const index = options.findIndex((o) => o.code === code);
|
||||
this.setData({
|
||||
outputCategoryOptions: options,
|
||||
'outputProductForm.categoryIndex': index < 0 ? 0 : index,
|
||||
outputCategoryCreating: false,
|
||||
outputCategoryName: '',
|
||||
});
|
||||
} catch (err) {
|
||||
wx.showToast({ title: err.message || '新建分类失败', icon: 'none' });
|
||||
} finally {
|
||||
this.setData({ creatingOutputCategory: false });
|
||||
}
|
||||
},
|
||||
|
||||
closeOutputProductForm() {
|
||||
if (this.data.creatingOutputProduct) return;
|
||||
this.setData({ showOutputProductModal: false });
|
||||
if (this.data.creatingOutputProduct || this.data.creatingOutputCategory) return;
|
||||
this.setData({
|
||||
showOutputProductModal: false,
|
||||
outputCategoryCreating: false,
|
||||
outputCategoryName: '',
|
||||
});
|
||||
},
|
||||
|
||||
async submitOutputProduct() {
|
||||
|
||||
@@ -274,9 +274,16 @@
|
||||
</view>
|
||||
<view class="field">
|
||||
<text class="field-label">分类</text>
|
||||
<picker mode="selector" range="{{outputCategoryOptions}}" range-key="label" value="{{outputProductForm.categoryIndex}}" bindchange="onOutputProductCategory">
|
||||
<view class="field-input">{{outputCategoryOptions[outputProductForm.categoryIndex].label || '选择分类'}} ▾</view>
|
||||
</picker>
|
||||
<!-- 内联分类标签(不再弹滚轮选择器);末尾可就地新建分类 -->
|
||||
<view class="cat-chips">
|
||||
<view wx:for="{{outputCategoryOptions}}" wx:key="code" class="cat-chip {{outputProductForm.categoryIndex === index ? 'is-on' : ''}}" data-index="{{index}}" catchtap="pickOutputCategory">{{item.label}}</view>
|
||||
<view class="cat-chip cat-chip-add" catchtap="toggleOutputCategoryCreate">+ 新建分类</view>
|
||||
</view>
|
||||
<view wx:if="{{outputCategoryCreating}}" class="cat-create-row">
|
||||
<input class="field-input cat-create-input" placeholder="分类名" value="{{outputCategoryName}}" bindinput="onOutputCategoryNameInput" />
|
||||
<view class="cat-create-btn {{creatingOutputCategory ? 'is-disabled' : ''}}" catchtap="submitOutputCategory">确定</view>
|
||||
<view class="cat-create-cancel" catchtap="cancelOutputCategoryCreate">取消</view>
|
||||
</view>
|
||||
</view>
|
||||
<view class="field-grid">
|
||||
<view class="field">
|
||||
|
||||
@@ -499,6 +499,70 @@
|
||||
color: #047857;
|
||||
}
|
||||
|
||||
/* 新建商品:分类内联标签(不弹滚轮选择器)+ 就地新建 */
|
||||
.cat-chips {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: 12rpx;
|
||||
}
|
||||
|
||||
.cat-chip {
|
||||
padding: 10rpx 22rpx;
|
||||
border-radius: 999rpx;
|
||||
border: 1px solid #d4d4d8;
|
||||
background: #ffffff;
|
||||
color: #475569;
|
||||
font-size: 24rpx;
|
||||
line-height: 1.4;
|
||||
}
|
||||
|
||||
.cat-chip.is-on {
|
||||
border-color: #10b981;
|
||||
background: #ecfdf5;
|
||||
color: #047857;
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.cat-chip-add {
|
||||
border-style: dashed;
|
||||
color: #047857;
|
||||
}
|
||||
|
||||
.cat-create-row {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 12rpx;
|
||||
margin-top: 12rpx;
|
||||
}
|
||||
|
||||
.cat-create-input {
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
}
|
||||
|
||||
.cat-create-btn {
|
||||
flex: none;
|
||||
padding: 0 24rpx;
|
||||
height: 72rpx;
|
||||
line-height: 72rpx;
|
||||
border-radius: 14rpx;
|
||||
background: #10b981;
|
||||
color: #ffffff;
|
||||
font-size: 26rpx;
|
||||
}
|
||||
|
||||
.cat-create-btn.is-disabled {
|
||||
opacity: 0.6;
|
||||
}
|
||||
|
||||
.cat-create-cancel {
|
||||
flex: none;
|
||||
padding: 0 8rpx;
|
||||
color: #64748b;
|
||||
font-size: 26rpx;
|
||||
line-height: 72rpx;
|
||||
}
|
||||
|
||||
.sku-name {
|
||||
font-size: 26rpx;
|
||||
font-weight: 600;
|
||||
|
||||
@@ -136,6 +136,23 @@ it('搜不到 → 用该名称新建商品(复用库存入库建品接口)',
|
||||
assert.ok(wxml.includes('showOutputProductModal'));
|
||||
});
|
||||
|
||||
/**
|
||||
* 2026-10-23 开发者(附截图):「新增商品这块 分类框优化一下别在展开弹窗了 支持新建分类」。
|
||||
* 建品表单里的分类从 `<picker>`(滚轮弹窗)改为内联标签 + 就地新建,新建复用库存入库同一个建分类接口。
|
||||
*/
|
||||
it('新建商品的分类框:内联标签 + 就地新建分类(不用滚轮选择器)', () => {
|
||||
assert.ok(!/<picker[^>]*onOutputProductCategory/.test(wxml), '不得再用 picker 选分类');
|
||||
assert.ok(wxml.includes('class="cat-chips"'));
|
||||
assert.ok(wxml.includes('catchtap="pickOutputCategory"'));
|
||||
assert.ok(wxml.includes('+ 新建分类'));
|
||||
assert.ok(wxml.includes('catchtap="toggleOutputCategoryCreate"'));
|
||||
assert.ok(wxml.includes('catchtap="submitOutputCategory"'));
|
||||
assert.ok(js.includes('await createStockInboundCategory(name);'));
|
||||
assert.ok(js.includes('createStockInboundCategory,'), '建分类接口必须从 request 引入');
|
||||
// 建完直接选中(不关表单)
|
||||
assert.ok(js.includes("'outputProductForm.categoryIndex': index < 0 ? 0 : index,"));
|
||||
});
|
||||
|
||||
it('订单/需求单加工:毛重净重流程保持原样(不许被改)', () => {
|
||||
assert.ok(js.includes('await completeProcessingWork({'));
|
||||
assert.ok(js.includes('gross_weight: grossWeight,'));
|
||||
|
||||
Reference in New Issue
Block a user