代客下单修改,登录页面修改,部分页面调整,请求封装调整
This commit is contained in:
47
stores/account.js
Normal file
47
stores/account.js
Normal file
@@ -0,0 +1,47 @@
|
||||
import { defineStore } from "pinia";
|
||||
import { shopStaffInfo } from "@/http/yskApi/account/shopStaff";
|
||||
import { login, getCodeImg } from "@/http/yskApi/login.js";
|
||||
|
||||
export const useAccountStore = defineStore("account", {
|
||||
state: () => {
|
||||
return {
|
||||
shopInfo: {},
|
||||
//员工信息
|
||||
shopStaff: {},
|
||||
//员工账号
|
||||
staffUserName: "",
|
||||
loginInfo: {},
|
||||
tokenInfo: {},
|
||||
shopId: "",
|
||||
loginType: "",
|
||||
};
|
||||
},
|
||||
getters: {},
|
||||
actions: {
|
||||
//获取员工信息
|
||||
async getShopStaffInfo() {
|
||||
const res = await shopStaffInfo();
|
||||
if (res) {
|
||||
this.shopStaffInfo = res;
|
||||
}
|
||||
},
|
||||
async login(params) {
|
||||
const res = await login(params);
|
||||
if (res) {
|
||||
this.loginInfo = res;
|
||||
this.shopInfo = res.shopInfo;
|
||||
this.tokenInfo = res.tokenInfo;
|
||||
this.shopId = res.shopInfo.id;
|
||||
this.loginType = res.loginType;
|
||||
this.shopStaff = res.shopStaff;
|
||||
this.staffUserName = params.staffUserName
|
||||
uni.setStorageSync("shopInfo", res.shopInfo);
|
||||
uni.setStorageSync("tokenInfo", res.tokenInfo);
|
||||
uni.setStorageSync("shopId", res.shopInfo.id);
|
||||
uni.setStorageSync("loginType", res.loginType);
|
||||
}
|
||||
return res;
|
||||
},
|
||||
},
|
||||
unistorage: true, // 开启后对 state 的数据读写都将持久化
|
||||
});
|
||||
305
stores/cart.js
305
stores/cart.js
@@ -1,15 +1,296 @@
|
||||
// stores/counter.js
|
||||
import { defineStore } from 'pinia';
|
||||
import { defineStore } from "pinia";
|
||||
import yskUtils from "ysk-utils";
|
||||
import { getNowCart } from "@/pagesCreateOrder/util.js";
|
||||
import * as orderApi from "@/http/api/order.js";
|
||||
|
||||
export const useCounterStore = defineStore('cart', {
|
||||
state: () => {
|
||||
return {
|
||||
selCoupon: [],
|
||||
};
|
||||
},
|
||||
actions: {
|
||||
setSelCoupon(coupon) {
|
||||
this.selCoupon = coupon
|
||||
},
|
||||
},
|
||||
export function formatCartGoods(goods) {
|
||||
return {
|
||||
...goods,
|
||||
// 商品单价(会员价或普通价)
|
||||
salePrice: goods.salePrice || goods.price,
|
||||
number: goods.number || goods.num,
|
||||
isGift: goods.isGift || goods.is_gift || 0,
|
||||
is_gift: goods.is_gift || goods.isGift || 0,
|
||||
};
|
||||
}
|
||||
|
||||
export const useCartStore = defineStore("cart", {
|
||||
state: () => {
|
||||
return {
|
||||
WebsocketUtil: null,
|
||||
//商品列表
|
||||
goodsList: [],
|
||||
//购物车列表
|
||||
cartList: [],
|
||||
//历史订单购物车数据
|
||||
oldCartList: [],
|
||||
//商品map
|
||||
goodsMap: {},
|
||||
//订单数据
|
||||
order: null,
|
||||
// 台桌
|
||||
table: null,
|
||||
//选择的优惠券
|
||||
selCoupon: [],
|
||||
//活动列表
|
||||
activityList: [],
|
||||
// 商家减免,初始配置:默认无减免(固定金额 0 元)
|
||||
merchantReductionConfig: {
|
||||
type: "fixed_amount",
|
||||
fixedAmount: 0,
|
||||
},
|
||||
//积分规则
|
||||
pointDeductionRule: {
|
||||
pointsPerYuan: 0,
|
||||
maxDeductionAmount: Infinity,
|
||||
},
|
||||
//使用积分数量
|
||||
userPoints: 0,
|
||||
//新客立减
|
||||
newUserDiscount: 0,
|
||||
//满减活动
|
||||
fullReductionActivities: [],
|
||||
// 商家霸王餐配置
|
||||
freeDineConfig: null,
|
||||
//店铺信息
|
||||
shopInfo: {
|
||||
tableFee: 0,
|
||||
isTableFee: 0,
|
||||
isMemberPrice: 0,
|
||||
},
|
||||
//店铺用户
|
||||
shopUserInfo: {},
|
||||
//限时折扣
|
||||
limitTimeDiscount: null,
|
||||
//当前点餐类型
|
||||
currentDinnerType: "dine-in",
|
||||
//就餐人数
|
||||
personCount: 0, //就餐人数
|
||||
};
|
||||
},
|
||||
getters: {
|
||||
//餐费费
|
||||
seatFeeConfig: (state) => {
|
||||
return {
|
||||
pricePerPerson: state.shopInfo.tableFee || 0,
|
||||
personCount: state.personCount, //就餐人数
|
||||
isEnabled: !state.shopInfo.isTableFee,
|
||||
};
|
||||
},
|
||||
// 用户是否是会员
|
||||
userIsVip: (state) => {
|
||||
return state.shopUserInfo && state.shopUserInfo.isVip == 1;
|
||||
},
|
||||
//是否使用会员价
|
||||
useVipPrice: (state) => {
|
||||
if (state.shopInfo.isMemberPrice == 1 && state.userIsVip) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
},
|
||||
orderExtraConfig: (state) => {
|
||||
return {
|
||||
// 引用扩展后的商家减免配置
|
||||
merchantReduction: state.merchantReductionConfig,
|
||||
additionalFee: 0,
|
||||
pointDeductionRule: state.pointDeductionRule,
|
||||
seatFeeConfig: state.seatFeeConfig,
|
||||
currentStoreId: "",
|
||||
userPoints: state.userPoints,
|
||||
isMember: state.useVipPrice,
|
||||
memberDiscountRate: 1,
|
||||
newUserDiscount: state.newUserDiscount,
|
||||
fullReductionActivities: state.fullReductionActivities,
|
||||
currentDinnerType: state.currentDinnerType,
|
||||
isFreeDine: false, //霸王餐
|
||||
freeDineConfig: state.freeDineConfig,
|
||||
limitTimeDiscount: state.limitTimeDiscount,
|
||||
shopUserInfo: state.shopUserInfo,
|
||||
};
|
||||
},
|
||||
//全部购物车数据
|
||||
allCartList: (state) => {
|
||||
// return [...state.oldCartList, ...state.cartList];
|
||||
return state.oldCartList;
|
||||
},
|
||||
// 订单费用汇总
|
||||
orderCostSummary: (state) => {
|
||||
const costSummary =
|
||||
yskUtils.OrderPriceCalculator.calculateOrderCostSummary(
|
||||
state.allCartList,
|
||||
state.currentDinnerType,
|
||||
state.selCoupon,
|
||||
state.activityList,
|
||||
state.orderExtraConfig,
|
||||
{},
|
||||
new Date()
|
||||
);
|
||||
console.log(" 订单费用汇总", costSummary);
|
||||
return costSummary;
|
||||
},
|
||||
},
|
||||
actions: {
|
||||
setSelCoupon(coupon) {
|
||||
this.selCoupon = coupon;
|
||||
},
|
||||
/**
|
||||
* 发送消息
|
||||
*/
|
||||
sendMessage(message, isAutoAppendDefaultValue = true) {
|
||||
if (!message) {
|
||||
return;
|
||||
}
|
||||
if (!this.WebsocketUtil) {
|
||||
return uni.showToast({
|
||||
title: "socket未连接",
|
||||
icon: "none",
|
||||
});
|
||||
}
|
||||
if (!this.table || !this.table.tableCode) {
|
||||
return uni.showToast({
|
||||
title: "无台桌码",
|
||||
icon: "none",
|
||||
});
|
||||
}
|
||||
if (isAutoAppendDefaultValue) {
|
||||
this.WebsocketUtil.send(
|
||||
JSON.stringify({
|
||||
table_code: this.table.tableCode,
|
||||
shop_id: this.shopInfo.id || uni.getStorageSync("shopInfo").id,
|
||||
account: uni.getStorageSync("tokenInfo").loginId,
|
||||
...message,
|
||||
type: "pad",
|
||||
})
|
||||
);
|
||||
} else {
|
||||
this.WebsocketUtil.send(
|
||||
JSON.stringify({
|
||||
...message,
|
||||
})
|
||||
);
|
||||
}
|
||||
},
|
||||
//socket收到消息处理
|
||||
onMessage(message) {
|
||||
if (!message) {
|
||||
return;
|
||||
}
|
||||
let msg = JSON.parse(message);
|
||||
// console.log("socket收到消息", msg);
|
||||
let cartItem;
|
||||
if (msg.msg_id) {
|
||||
this.WebsocketUtil.send(
|
||||
JSON.stringify({
|
||||
type: "receipt",
|
||||
msg_id: msg.msg_id,
|
||||
})
|
||||
);
|
||||
}
|
||||
if (msg.status == 0) {
|
||||
uni.showToast({
|
||||
title: "添加失败",
|
||||
icon: "none",
|
||||
});
|
||||
return false;
|
||||
}
|
||||
|
||||
switch (msg.operate_type) {
|
||||
case "pad_init":
|
||||
this.cartList = msg.data;
|
||||
this.limitTimeDiscount = msg.time_dis_info;
|
||||
break;
|
||||
case "pad_add":
|
||||
case "add":
|
||||
cartItem = getNowCart(msg.data, $goods, pageData.user);
|
||||
cartControls(cartItem, "add");
|
||||
break;
|
||||
case "pad_edit":
|
||||
case "bulk_edit":
|
||||
this.sendMessage({
|
||||
operate_type: "init",
|
||||
});
|
||||
this.getOrder();
|
||||
break;
|
||||
case "edit":
|
||||
getCart();
|
||||
break;
|
||||
case "pad_del":
|
||||
case "del":
|
||||
cartItem = getNowCart(msg.data, $goods, pageData.user);
|
||||
cartControls(cartItem, "del");
|
||||
break;
|
||||
case "pad_cleanup":
|
||||
case "cleanup":
|
||||
goods.list = [];
|
||||
$seatFee.totalNumber = 0;
|
||||
$seatFee.totalAmount = 0;
|
||||
userNumbers.defaultCateIndex = 0;
|
||||
init();
|
||||
break;
|
||||
case "product_update":
|
||||
init();
|
||||
break;
|
||||
case "pad_batch":
|
||||
init();
|
||||
break;
|
||||
}
|
||||
},
|
||||
/**
|
||||
* socket通知购物车商品数量修改处理
|
||||
*/
|
||||
cartControls(cartItem, type) {
|
||||
if (!this.table) {
|
||||
this.table = { tableCode: cartItem.table_code };
|
||||
}
|
||||
let cartIndex = 0;
|
||||
|
||||
this.cartList.map((item, index) => {
|
||||
if (item.id == cartItem.id) {
|
||||
cartIndex = index;
|
||||
}
|
||||
});
|
||||
|
||||
if (type == "del") {
|
||||
this.cartList.splice(cartIndex, 1);
|
||||
return;
|
||||
}
|
||||
if (type == "add") {
|
||||
this.cartList.push({ ...cartItem, packNumber: cartItem.pack_number });
|
||||
}
|
||||
if (type == "edit") {
|
||||
this.cartList[cartIndex].number = cartItem.number;
|
||||
this.cartList[cartIndex].pack_number = cartItem.pack_number;
|
||||
this.cartList[cartIndex].packNumber = cartItem.pack_number;
|
||||
}
|
||||
},
|
||||
/**
|
||||
*
|
||||
* @returns 历史订单数据
|
||||
*/
|
||||
async getOrder() {
|
||||
const res = await orderApi.getOrderById({ orderId: this.order.id });
|
||||
if (res) {
|
||||
this.setOrder(res);
|
||||
return res;
|
||||
}
|
||||
},
|
||||
/**
|
||||
* 设置历史订单数据,给商品列表赋值
|
||||
*/
|
||||
setOrder(order) {
|
||||
this.order = order;
|
||||
this.oldCartList = Object.values(order.detailMap).reduce((pre, cur) => {
|
||||
pre.push(
|
||||
...cur.map((v) => {
|
||||
const goods = formatCartGoods(v);
|
||||
return { ...goods, isHistory: true };
|
||||
})
|
||||
);
|
||||
return pre;
|
||||
}, []);
|
||||
|
||||
},
|
||||
},
|
||||
unistorage: true, // 开启后对 state 的数据读写都将持久化
|
||||
});
|
||||
|
||||
24
stores/test.js
Normal file
24
stores/test.js
Normal file
@@ -0,0 +1,24 @@
|
||||
import { defineStore } from "pinia";
|
||||
export const useTestStore = defineStore("test", {
|
||||
state: () => {
|
||||
return {
|
||||
a: 2,
|
||||
b:10
|
||||
};
|
||||
},
|
||||
getters:{
|
||||
//a+b
|
||||
sum:(state)=>{
|
||||
return state.a+state.b
|
||||
},
|
||||
//sub*2
|
||||
sub:(state)=>{
|
||||
return state.sum*2
|
||||
}
|
||||
},
|
||||
actions: {
|
||||
increment() {
|
||||
this.count++;
|
||||
},
|
||||
},
|
||||
});
|
||||
Reference in New Issue
Block a user