cashier_app/pagesCreateOrder/index/util.js

82 lines
2.2 KiB
JavaScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

//根据店铺信息返回是否是后付款
export function $trturnPayAfter(shop) {
//before 先付 after 后付
const payAfter = shop.registerType == "before" ? false : true;
return payAfter
}
//根据店铺信息返回就餐类型
export function $returnUseType(shop, useType) {
//是否是后付款
const payAfter = $trturnPayAfter(shop)
let result = "takeout";
if (useType == "takeout") {
result = 'takeout'
} else {
//堂食
result = `dine-in-${payAfter ? "after" : "before"}`;
}
return result
}
//判断商品是否可以下单
export function isCanBuy(skuGoods,goods) {
if(goods.type!='sku'){
//单规格
return goods.isSale&&goods.isSoldStock==0&&(goods.isStock?goods.stockNumber>0:true);
}else{
//多规格
return goods.isSale&&goods.isSoldStock==0&&skuGoods.isGrounding&&skuGoods.isPauseSale==0&&(goods.isStock?goods.stockNumber>0:true);
}
}
// 一个数组是否包含另外一个数组全部元素
function arrayContainsAll(arr1, arr2) {
for (let i = 0; i < arr2.length; i++) {
if (!arr1.includes(arr2[i])) {
return false;
}
}
return true;
}
//n项 n-1项组合生成全部结果
function generateCombinations(arr, k) {
let result = [];
console.log("current.length === k",arr)
function helper(index, current) {
if (current.length === k) {
result.push(current.slice()); // 使用slice()来避免直接修改原始数组
} else {
for (let i = index; i < arr.length; i++) {
current.push(arr[i]); // 将当前元素添加到组合中
helper(i + 1, current); // 递归调用,索引增加以避免重复选择相同的元素
current.pop(); // 回溯,移除当前元素以便尝试其他组合
}
console.log(current)
}
}
helper(0, []); // 从索引0开始初始空数组作为起点
return result;
}
function returnReverseVal(val, isReturnString = true) {
const isBol = typeof val === "boolean";
const isString = typeof val === "string";
let reverseNewval = "";
if (isBol) {
reverseNewval = !val;
}
if (isString) {
reverseNewval = val === "true" ? "false" : "true";
}
return reverseNewval;
}
export default {
isCanBuy,
arrayContainsAll,
generateCombinations,
returnReverseVal,$returnUseType
}