商品管理编辑更新,修复单规格多规格切换保存报错问题,增加部分必填项验证
This commit is contained in:
@@ -47,17 +47,18 @@
|
||||
</view>
|
||||
<template v-if="FormData.typeEnum!='group'">
|
||||
<view class="u-relative">
|
||||
<uni-forms-item label="所属分类" required showRequired name="categoryId">
|
||||
<uni-data-picker :clear-icon="false" :map="{text:'name',value:'id'}"
|
||||
<uni-forms-item label="所属分类" required showRequired name="categoryId">
|
||||
<uni-data-picker :clear-icon="false" :map="{text:'name',value:'id'}"
|
||||
placeholder="请选择分类" popup-title="请选择分类" :localdata="pageData.category"
|
||||
v-model="FormData.categoryId">
|
||||
</uni-data-picker>
|
||||
</uni-forms-item>
|
||||
<view class="zhezhao u-absolute position-all" @click="canEditGoodsCategory(true)" v-if="option.type=='edit'&&disabledChangeCategory">
|
||||
|
||||
<view class="zhezhao u-absolute position-all" @click="canEditGoodsCategory(true)"
|
||||
v-if="option.type=='edit'&&disabledChangeCategory">
|
||||
|
||||
</view>
|
||||
</view>
|
||||
|
||||
|
||||
</template>
|
||||
|
||||
|
||||
@@ -129,7 +130,7 @@
|
||||
:key="index">
|
||||
<view class="u-flex-1 u-text-left">{{item.specSnap}}</view>
|
||||
<view class="u-flex-1">¥{{item.salePrice}}</view>
|
||||
<view class="u-flex-1">{{item.stockNumber}}</view>
|
||||
<view class="u-flex-1">{{item.stockNumber||0}}</view>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
@@ -216,7 +217,7 @@
|
||||
<!-- <view class="u-m-t-32 u-font-32 u-m-l-10 u-m-b-32">规格属性</view> -->
|
||||
<view class="block" v-for="(sku,index) in skuList.list" :key="index">
|
||||
<view class="border-top-0">
|
||||
<uni-forms-item label="售价">
|
||||
<uni-forms-item label="售价" required showRequired >
|
||||
<uni-easyinput :paddingNone="inputPaddingNone"
|
||||
@blur="priceFormat(sku,'salePrice')" :placeholderStyle="placeholderStyle"
|
||||
:inputBorder="inputBorder" v-model="sku.salePrice" type="digit"
|
||||
@@ -241,7 +242,7 @@
|
||||
:inputBorder="inputBorder" v-model="sku.originPrice" type="digit"
|
||||
placeholder="请输入原价(元)" />
|
||||
</uni-forms-item> -->
|
||||
<uni-forms-item label="起售数量">
|
||||
<uni-forms-item label="起售数量" required showRequired >
|
||||
<uni-easyinput @blur="priceFormat(sku,'suit')" :paddingNone="inputPaddingNone"
|
||||
:placeholderStyle="placeholderStyle" :inputBorder="inputBorder"
|
||||
v-model="sku.suit" type="digit" placeholder="请输入起售数量" />
|
||||
@@ -418,8 +419,7 @@
|
||||
</uni-forms-item>
|
||||
<template v-if="FormData.isStock">
|
||||
<uni-forms-item label="库存数量">
|
||||
<uni-easyinput :paddingNone="inputPaddingNone"
|
||||
:disabled="disabledStock"
|
||||
<uni-easyinput :paddingNone="inputPaddingNone" :disabled="disabledStock"
|
||||
:placeholderStyle="placeholderStyle" :inputBorder="inputBorder"
|
||||
v-model="FormData.stockNumber" type="digit" placeholder="请输入库存数量" />
|
||||
</uni-forms-item>
|
||||
@@ -1092,10 +1092,10 @@
|
||||
}
|
||||
}
|
||||
}
|
||||
res.skuList = (res.skuList.length ? res.skuList : [])
|
||||
$goodsData = res
|
||||
console.log(res);
|
||||
skuList.list = res.skuList
|
||||
Object.assign(FormData, res)
|
||||
skuList.list = res.skuList || []
|
||||
//多规格
|
||||
if (res.typeEnum === 'sku') {
|
||||
const selectSpec = JSON.parse(res.selectSpec)
|
||||
@@ -1139,8 +1139,12 @@
|
||||
}),
|
||||
specList: [],
|
||||
}
|
||||
} else {
|
||||
// 单规格
|
||||
|
||||
}
|
||||
|
||||
|
||||
})
|
||||
}
|
||||
|
||||
@@ -1321,14 +1325,23 @@
|
||||
return infoBox.showToast('请上传商品图片')
|
||||
}
|
||||
const skuSnap = []
|
||||
let submitSkuList = FormData.specificationsGroup ? skuList.list : [{
|
||||
...$defaultSku,
|
||||
barCode: `${uni.getStorageSync("shopId")}${dayjs().valueOf()}`
|
||||
}];
|
||||
if (typeEnum == 'normal') {
|
||||
submitSkuList = skuList.list;
|
||||
let submitSkuList = skuList.list || []
|
||||
if(option.type=='edit'){
|
||||
submitSkuList=submitSkuList.map(v=>{
|
||||
return{
|
||||
...v,productId:FormData.id,shopId:uni.getStorageSync('shopId')
|
||||
}
|
||||
})
|
||||
}
|
||||
console.log(submitSkuList);
|
||||
// if(typeEnum!=$goodsData.typeEnum){
|
||||
// if(typeEnum=='normal'){
|
||||
// submitSkuList = skuList.list;
|
||||
// }else{
|
||||
// submitSkuList = skuList.list;
|
||||
// }
|
||||
// }else{
|
||||
// submitSkuList = skuList.list;
|
||||
// }
|
||||
if (FormData.specificationsGroup) {
|
||||
for (let i of FormData.specificationsGroup.selectSpec) {
|
||||
if (i.selectSpecResult.length) {
|
||||
@@ -1340,22 +1353,37 @@
|
||||
}
|
||||
}
|
||||
console.log(FormData.specificationsGroup);
|
||||
const selectSpec = FormData.typeEnum != 'sku' ? '' : JSON.stringify(FormData.specificationsGroup
|
||||
.selectSpec.map(spe => {
|
||||
return {
|
||||
...spe,
|
||||
value: spe.value.map(v => {
|
||||
return typeof v === 'string' ? v : v.text || v.value
|
||||
})
|
||||
}
|
||||
}))
|
||||
const selectSpec = FormData.typeEnum != 'sku' ? '[]' : JSON.stringify((FormData.specificationsGroup
|
||||
.selectSpec || []).map(spe => {
|
||||
return {
|
||||
...spe,
|
||||
value: spe.value.map(v => {
|
||||
return typeof v === 'string' ? v : v.text || v.value
|
||||
})
|
||||
}
|
||||
}))
|
||||
const lowPrice = submitSkuList[0] ? submitSkuList[0].salePrice : FormData.salePrice
|
||||
// const lowPrice = submitSkuList[0] ? submitSkuList[0].salePrice : FormData.salePrice
|
||||
const suit = submitSkuList[0] ? submitSkuList[0].suit : 0
|
||||
if(typeEnum=='normal'){
|
||||
if(lowPrice===''){
|
||||
return infoBox.showToast('请输入售价')
|
||||
}
|
||||
if(lowPrice===''){
|
||||
return infoBox.showToast('请输入售价')
|
||||
}
|
||||
if(suit<=0){
|
||||
return infoBox.showToast('起售数量不能小于0!')
|
||||
}
|
||||
}
|
||||
|
||||
const submitData = {
|
||||
...FormData,
|
||||
images: images,
|
||||
coverImg: images[0] || '',
|
||||
skuList: submitSkuList,
|
||||
specInfo: JSON.stringify(submitSkuList),
|
||||
lowPrice: submitSkuList[0].salePrice,
|
||||
lowPrice,
|
||||
specificationsGroup: undefined,
|
||||
selectSpec,
|
||||
skuSnap: JSON.stringify(skuSnap)
|
||||
@@ -1402,6 +1430,7 @@
|
||||
uni.$off('emitspecificationsSave')
|
||||
uni.$on('emitspecificationsSave', function(data) {
|
||||
FormData.specificationsGroup = data
|
||||
FormData.specId = data.specId
|
||||
skuList.list = data.result.map(v => {
|
||||
return {
|
||||
...v.skus,
|
||||
@@ -1499,35 +1528,50 @@
|
||||
|
||||
|
||||
watch(() => FormData.typeEnum, (newval) => {
|
||||
if (option.type === 'add') {
|
||||
if (newval === 'sku') {
|
||||
skuList.list = []
|
||||
if (option.type == 'edit') {
|
||||
FormData.specId = newval == 'normal' ? '' : ($goodsData.specId || '')
|
||||
if (newval == $goodsData.typeEnum) {
|
||||
skuList.list = $goodsData.skuList
|
||||
} else {
|
||||
skuList.list[0] = {
|
||||
...$defaultSku,
|
||||
barCode: `${uni.getStorageSync("shopId")}${dayjs().valueOf()}`
|
||||
if (newval == 'normal') {
|
||||
skuList.list = [{
|
||||
...$defaultSku,
|
||||
productId: FormData.id,
|
||||
shopId: uni.getStorageSync('shopId'),
|
||||
barCode: `${uni.getStorageSync("shopId")}${dayjs().valueOf()}`
|
||||
}]
|
||||
} else {
|
||||
skuList.list = []
|
||||
}
|
||||
}
|
||||
}else{
|
||||
//编辑
|
||||
if (newval === 'sku') {
|
||||
skuList.list = []
|
||||
} else {
|
||||
FormData.specId = ''
|
||||
if (newval == 'normal') {
|
||||
skuList.list = [{
|
||||
...$defaultSku,
|
||||
shopId: uni.getStorageSync('shopId'),
|
||||
barCode: `${uni.getStorageSync("shopId")}${dayjs().valueOf()}`
|
||||
}]
|
||||
} else {
|
||||
skuList.list=$goodsData.skuList
|
||||
skuList.list = []
|
||||
}
|
||||
}
|
||||
|
||||
})
|
||||
|
||||
|
||||
/**
|
||||
* 权限start
|
||||
*/
|
||||
|
||||
|
||||
// 允许修改商品库存
|
||||
let disabledStock=ref(false)
|
||||
let disabledStock = ref(false)
|
||||
async function canEditGoodsStock() {
|
||||
if (option.type === 'edit') {
|
||||
const res=await hasPermission({text:'允许修改商品库存',tips:false})
|
||||
disabledStock.value=!res
|
||||
const res = await hasPermission({
|
||||
text: '允许修改商品库存',
|
||||
tips: false
|
||||
})
|
||||
disabledStock.value = !res
|
||||
}
|
||||
}
|
||||
watch(() => FormData.isStock, (newval) => {
|
||||
@@ -1536,18 +1580,21 @@
|
||||
}
|
||||
})
|
||||
// 允许修改商品分类
|
||||
let disabledChangeCategory=ref(false)
|
||||
async function canEditGoodsCategory(tips=false) {
|
||||
let disabledChangeCategory = ref(false)
|
||||
async function canEditGoodsCategory(tips = false) {
|
||||
if (option.type === 'edit') {
|
||||
const res=await hasPermission({text:'允许修改分类',tips})
|
||||
disabledChangeCategory.value=!res
|
||||
const res = await hasPermission({
|
||||
text: '允许修改分类',
|
||||
tips
|
||||
})
|
||||
disabledChangeCategory.value = !res
|
||||
}
|
||||
}
|
||||
/**
|
||||
* 权限end
|
||||
*/
|
||||
|
||||
|
||||
|
||||
|
||||
watch(() => pageData.types, (newval) => {
|
||||
Forms.value.setRules(rules)
|
||||
})
|
||||
|
||||
@@ -1,8 +1,11 @@
|
||||
<template>
|
||||
<view class="u-relative choose-haocai">
|
||||
<view class="input u-flex" @click="toggle" >
|
||||
<!-- <view class="input u-flex" @click="toggle" >
|
||||
<up-input @blur="blur" @change="filterHaocaiList" border="none" v-model="text" placeholder="请选择"></up-input>
|
||||
<up-icon :size="10" name="arrow-down-fill"></up-icon>
|
||||
</view> -->
|
||||
<view class="input u-flex" >
|
||||
<up-input @blur="blur" disabled="true" @change="filterHaocaiList" border="none" v-model="text" placeholder="请选择"></up-input>
|
||||
</view>
|
||||
<view class="u-absolute" v-if="popShow">
|
||||
<scroll-view scroll-y="true" class="scroll">
|
||||
|
||||
Reference in New Issue
Block a user