修改代客下单商品是否能够下单的逻辑

This commit is contained in:
YeMingfei666 2024-10-24 14:52:52 +08:00
parent 57ef84aae1
commit c473f30a37
2 changed files with 211 additions and 154 deletions

View File

@ -594,7 +594,11 @@
</div> -->
</div>
</div>
<div class="goods" v-infinite-scroll="loadMoreGoods">
<div
class="goods"
v-infinite-scroll="loadMoreGoods"
infinite-scroll-distance="40"
>
<template v-if="!isCreateOrder">
<div class="flex categoty u-col-center">
<div
@ -637,8 +641,8 @@
>
未找到相关商品
</div>
<div class="goods-list" v-if="goods.list.length">
<template v-if="goods.list.length">
<div class="goods-list">
<div
class="goods-item"
:class="{
@ -755,6 +759,10 @@
</div>
</div>
</div>
<div class="u-m-t-20 color-999 text-center">{{
goods.status=='end'?'没有更多了':'加载中'
}}</div>
</template>
<div
class="no-search-result"
v-if="goods.list.length <= 0 && goods.query.productId === ''"
@ -957,6 +965,7 @@
</div>
<div slot="footer">
<template v-if="skuGoods.data">
<div class="flex row-between">
<div>
<div class="price"> {{ skuGoods.data.salePrice | to2 }}</div>
@ -985,26 +994,51 @@
v-if="!skuGoods.data.isGrounding"
disabled
>
已下架/库存不足
已下架
</button>
<template v-else>
<button
class="my-btn disabled flex-1"
v-if="skuGoods.data.stockNumber <= 0"
v-else-if="
selGoods.isStock == 1 && skuGoods.data.stockNumber <= 0
"
disabled
>
库存不足
</button>
<button
class="my-btn primary flex-1"
v-else
:disabled="CanConfirm"
@click="chooseSkuConfirm"
>
<template v-else>
<button class="my-btn primary flex-1" @click="chooseSkuConfirm">
确定
</button>
</template>
</div>
</template>
<template v-else>
<div class="flex row-between">
<div>
<div class="price"></div>
<div class="sku-group-text">
<span> </span>
<span>库存</span>
</div>
</div>
<div class="flex">
<i class="icon-remove" @click="skuNumberReduce"></i>
<div style="width: 40px" class="number-box">
<el-input
:min="0"
:max="0"
type="number"
placeholder="0"
></el-input>
</div>
<!-- <i class="el-icon-remove"></i> -->
<i class="el-icon-circle-plus icon-add" @click="skuNumberAdd"></i>
</div>
</div>
<div class="flex" style="margin-top: 14px">
<button class="my-btn disabled flex-1" disabled>已下架/售罄</button>
</div>
</template>
</div>
</el-dialog>
@ -1305,10 +1339,7 @@ export default {
},
skuGoods: {
number: 1,
data: {
stockNumber: 0,
salePrice: 0,
},
data: undefined,
},
selGoods: {
isEdit: false,
@ -1324,12 +1355,13 @@ export default {
informationdialogshow: false,
informationdialogshowedit: false,
goods: {
status:'loadmore',//loadmore end
list: [],
query: {
productId: "",
categoryId: "",
page: 1,
size: 20,
size: 66,
},
loading: false,
total: 0,
@ -1566,13 +1598,22 @@ export default {
this.selGoods.show = false;
},
CanConfirm() {
if (!this.selGoods.skuList.length) {
return true;
}
return (
this.selGoods.skuList.filter((v) => v.sel !== "").length !==
this.selGoods.skuList.length
);
// if (!this.skuGoods.data) {
// return;
// }
// if (!this.selGoods.skuList.length) {
// return true;
// }
// const canBuyArr = this.selGoods.skuList.filter((v) =>
// isCanBuy(v, this.selGoods.isStock)
// );
// if (canBuyArr.length <= 0) {
// return true;
// }
// return (
// this.selGoods.skuList.filter((v) => v.sel !== "").length !==
// this.selGoods.skuList.length
// );
},
},
filters: {
@ -1596,6 +1637,7 @@ export default {
"goods.query.categoryId": function (newval) {
this.goods.query.page = 1;
this.goods.list = [];
this.goods.status='loadmore'
this.getGoods();
},
"useTypes.sel": function (newval, oldval) {
@ -2344,10 +2386,10 @@ export default {
tableId: this.table.tableId,
orderId: this.table.orderId,
vipUserId: this.vipUser.id,
useType: this.useTypes.sel == "takeout" ? "takeout" : ""
})
useType: this.useTypes.sel == "takeout" ? "takeout" : "",
});
this.masterId = res.masterId;
return res
return res;
},
onSelGoodsSkuClose() {
this.selGoods.isEdit = false;
@ -2900,7 +2942,7 @@ export default {
.filter((v) => v.specSnap.match(i))
.every((v) => {
// return isCanBuy(v,this.selGoods.data.isStock)
return !isCanBuy(v, true);
return !isCanBuy(v, this.selGoods.data);
});
}
}
@ -3023,7 +3065,7 @@ export default {
return prve;
}, {});
const canBudyGoods = this.selGoods.data.specList
.filter((v) => isCanBuy(v, true))
.filter((v) => isCanBuy(v, this.selGoods.data))
.sort((a, b) => {
const aNumber = a.specSnap.split(",").reduce((prve, cur) => {
return prve + skuMapNumber[cur];
@ -3037,6 +3079,7 @@ export default {
},
//,
setSkugoodsDefaultInit() {
this.skuGoods.data = undefined;
const skuList = this.selGoods.skuList;
const goodsListMap = this.selGoods.skuMap;
const skuGoods = this.findGoods(skuList, goodsListMap);
@ -3125,6 +3168,10 @@ export default {
}
},
async getGoods() {
if(this.goods.status=='end'){
return
}
this.goods.status='loadmore'
const res = await getGoodsLists(this.goods.query);
let $goodsMap = {};
const goods = res.records.filter((v) => {
@ -3143,6 +3190,7 @@ export default {
for (let i in goods) {
this.goods.list.push(goods[i]);
}
this.goods.status= this.goods.list.length>=res.total ? 'end' : 'loadmore'
this.goods.total = res.total;
this.$goodsData = goods;
},

View File

@ -1,6 +1,13 @@
//判断商品是否可以下单
export function isCanBuy(goods,isStock) {
return goods.isGrounding && goods.isPauseSale == 0 && (isStock?goods.stockNumber > 0:true) ;
export function isCanBuy(skuGoods,goods) {
if(goods.typeEnum=='normal'){
//单规格
return goods.isGrounding&&goods.isPauseSale==0&&(goods.isStock?goods.stockNumber>0:true);
}else{
//多规格
return goods.isGrounding&&goods.isPauseSale==0&&skuGoods.isGrounding&&skuGoods.isPauseSale==0&&(goods.isStock?goods.stockNumber>0:true);
}
}
// 一个数组是否包含另外一个数组全部元素
@ -15,6 +22,8 @@ export function arrayContainsAll(arr1, arr2) {
//n项 n-1项组合生成全部结果
export function generateCombinations(arr, k) {
console.log(arr)
console.log(k)
let result = [];
function helper(index, current) {