3
This commit is contained in:
@@ -31,41 +31,18 @@
|
||||
<view class="row">
|
||||
<input v-model.trim="form.spec" placeholder="规格" />
|
||||
</view>
|
||||
<!-- 隐藏产地输入 -->
|
||||
<!-- 隐藏主单位选择 -->
|
||||
<view class="row">
|
||||
<input v-model.trim="form.origin" placeholder="产地" />
|
||||
</view>
|
||||
<view class="row">
|
||||
<picker mode="selector" :range="unitNames" @change="onPickUnit">
|
||||
<view class="picker">主单位:{{ unitLabel }}</view>
|
||||
</picker>
|
||||
<picker mode="selector" :range="categoryNames" @change="onPickCategory">
|
||||
<view class="picker">类别:{{ categoryLabel }}</view>
|
||||
</picker>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<view class="section">
|
||||
<view class="row">
|
||||
<text class="label">库存与安全库存</text>
|
||||
</view>
|
||||
<view class="row">
|
||||
<input type="number" v-model.number="form.stock" placeholder="当前库存" />
|
||||
<input type="number" v-model.number="form.safeMin" placeholder="安全库存下限" />
|
||||
<input type="number" v-model.number="form.safeMax" placeholder="安全库存上限" />
|
||||
</view>
|
||||
</view>
|
||||
<!-- 隐藏库存与安全库存输入 -->
|
||||
|
||||
<view class="section">
|
||||
<view class="row">
|
||||
<text class="label">价格(进价/零售/批发/大单)</text>
|
||||
</view>
|
||||
<view class="row prices">
|
||||
<input type="number" v-model.number="form.purchasePrice" placeholder="进货价" />
|
||||
<input type="number" v-model.number="form.retailPrice" placeholder="零售价" />
|
||||
<input type="number" v-model.number="form.wholesalePrice" placeholder="批发价" />
|
||||
<input type="number" v-model.number="form.bigClientPrice" placeholder="大单价" />
|
||||
</view>
|
||||
</view>
|
||||
<!-- 隐藏价格相关输入 -->
|
||||
|
||||
<view class="section">
|
||||
<text class="label">图片</text>
|
||||
@@ -94,14 +71,11 @@ export default {
|
||||
return {
|
||||
id: '',
|
||||
form: {
|
||||
name: '', barcode: '', brand: '', model: '', spec: '', origin: '',
|
||||
categoryId: '', unitId: '',
|
||||
stock: null, safeMin: null, safeMax: null,
|
||||
purchasePrice: null, retailPrice: null, wholesalePrice: null, bigClientPrice: null,
|
||||
name: '', barcode: '', brand: '', model: '', spec: '',
|
||||
categoryId: '',
|
||||
images: [], remark: '',
|
||||
platformStatus: '', sourceSubmissionId: ''
|
||||
},
|
||||
units: [],
|
||||
categories: [],
|
||||
keyboardHeight: 0
|
||||
}
|
||||
@@ -115,12 +89,7 @@ export default {
|
||||
this.disposeKeyboardListener()
|
||||
},
|
||||
computed: {
|
||||
unitNames() { return this.units.map(u => u.name) },
|
||||
categoryNames() { return this.categories.map(c => c.name) },
|
||||
unitLabel() {
|
||||
const u = this.units.find(x => String(x.id) === String(this.form.unitId))
|
||||
return u ? u.name : '选择单位'
|
||||
},
|
||||
categoryLabel() {
|
||||
const c = this.categories.find(x => String(x.id) === String(this.form.categoryId))
|
||||
return c ? c.name : '选择类别'
|
||||
@@ -128,7 +97,7 @@ export default {
|
||||
},
|
||||
methods: {
|
||||
async bootstrap() {
|
||||
await Promise.all([this.fetchUnits(), this.fetchCategories()])
|
||||
await Promise.all([this.fetchCategories()])
|
||||
if (this.id) this.loadDetail()
|
||||
},
|
||||
initKeyboardListener() {
|
||||
@@ -147,22 +116,12 @@ export default {
|
||||
}
|
||||
} catch (_) {}
|
||||
},
|
||||
async fetchUnits() {
|
||||
try {
|
||||
const res = await get('/api/product-units')
|
||||
this.units = Array.isArray(res?.list) ? res.list : (Array.isArray(res) ? res : [])
|
||||
} catch (_) {}
|
||||
},
|
||||
async fetchCategories() {
|
||||
try {
|
||||
const res = await get('/api/product-categories')
|
||||
this.categories = Array.isArray(res?.list) ? res.list : (Array.isArray(res) ? res : [])
|
||||
} catch (_) {}
|
||||
},
|
||||
onPickUnit(e) {
|
||||
const idx = Number(e.detail.value); const u = this.units[idx]
|
||||
this.form.unitId = u ? u.id : ''
|
||||
},
|
||||
onPickCategory(e) {
|
||||
const idx = Number(e.detail.value); const c = this.categories[idx]
|
||||
this.form.categoryId = c ? c.id : ''
|
||||
@@ -193,12 +152,8 @@ export default {
|
||||
const data = await get('/api/products/' + this.id)
|
||||
Object.assign(this.form, {
|
||||
name: data.name,
|
||||
barcode: data.barcode, brand: data.brand, model: data.model, spec: data.spec, origin: data.origin,
|
||||
categoryId: data.categoryId, unitId: data.unitId,
|
||||
stock: data.stock,
|
||||
safeMin: data.safeMin, safeMax: data.safeMax,
|
||||
purchasePrice: data.purchasePrice, retailPrice: data.retailPrice,
|
||||
wholesalePrice: data.wholesalePrice, bigClientPrice: data.bigClientPrice,
|
||||
barcode: data.barcode, brand: data.brand, model: data.model, spec: data.spec,
|
||||
categoryId: data.categoryId,
|
||||
images: (data.images || []).map(i => i.url || i),
|
||||
remark: data.remark || '',
|
||||
platformStatus: data.platformStatus || '',
|
||||
@@ -208,21 +163,13 @@ export default {
|
||||
},
|
||||
validate() {
|
||||
if (!this.form.name) { uni.showToast({ title: '请填写名称', icon: 'none' }); return false }
|
||||
if (this.form.safeMin != null && this.form.safeMax != null && Number(this.form.safeMin) > Number(this.form.safeMax)) {
|
||||
uni.showToast({ title: '安全库存区间不合法', icon: 'none' }); return false
|
||||
}
|
||||
return true
|
||||
},
|
||||
buildPayload() {
|
||||
const f = this.form
|
||||
return {
|
||||
name: f.name, barcode: f.barcode, brand: f.brand, model: f.model, spec: f.spec, origin: f.origin,
|
||||
categoryId: f.categoryId || null, unitId: f.unitId,
|
||||
safeMin: f.safeMin, safeMax: f.safeMax,
|
||||
prices: {
|
||||
purchasePrice: f.purchasePrice, retailPrice: f.retailPrice, wholesalePrice: f.wholesalePrice, bigClientPrice: f.bigClientPrice
|
||||
},
|
||||
stock: f.stock,
|
||||
name: f.name, barcode: f.barcode, brand: f.brand, model: f.model, spec: f.spec,
|
||||
categoryId: f.categoryId || null,
|
||||
images: f.images,
|
||||
remark: f.remark
|
||||
}
|
||||
@@ -236,7 +183,7 @@ export default {
|
||||
else await post('/api/products', payload)
|
||||
uni.showToast({ title: '保存成功', icon: 'success', mask: false })
|
||||
if (goOn && !this.id) {
|
||||
this.form = { name: '', barcode: '', brand: '', model: '', spec: '', origin: '', categoryId: '', unitId: '', stock: null, safeMin: null, safeMax: null, purchasePrice: null, retailPrice: null, wholesalePrice: null, bigClientPrice: null, images: [], remark: '', platformStatus: '', sourceSubmissionId: '' }
|
||||
this.form = { name: '', barcode: '', brand: '', model: '', spec: '', categoryId: '', images: [], remark: '', platformStatus: '', sourceSubmissionId: '' }
|
||||
} else {
|
||||
setTimeout(() => uni.navigateBack(), 400)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user