feat: 电子药箱小程序 - 4Tab药品管理
- 电子药箱: 药品库存管理 + 手动录入 + 今日用药打卡 - 药品百科: 搜索 + 分类筛选 + 20种药品静态数据 - 惠教中心: 4条药品使用指南课程 - 我的: 家庭成员信息管理 - 自定义TabBar + navigation-bar组件 - SVG药品分类插图
This commit is contained in:
@@ -0,0 +1,168 @@
|
||||
import { request } from "../../../utils/request";
|
||||
import { join, leave, addCustomEventListener, removeCustomEventListener } from "../../../utils/server-sent-events";
|
||||
const statusId = "roomId-1";
|
||||
|
||||
Component({
|
||||
properties: {
|
||||
open: { type: Boolean, value: false },
|
||||
hasTabBar: {
|
||||
type: Boolean,
|
||||
value: false,
|
||||
},
|
||||
productNum: {
|
||||
type: Number,
|
||||
value: 1,
|
||||
},
|
||||
joinedGroupId: { type: String, value: "" }, // 用户房间号
|
||||
},
|
||||
|
||||
data: {
|
||||
name: "商品名称",
|
||||
price: 0,
|
||||
picUrl: "https://oneppp.mn188.cn/oneppp/image/037b08ef-e576-4063-9609-090773b50dfa.jpg",
|
||||
skuId: 0,
|
||||
joined: false,
|
||||
skuRes: {},
|
||||
show: false,
|
||||
stock: 0,
|
||||
count:0
|
||||
|
||||
},
|
||||
|
||||
lifetimes: {
|
||||
async attached() {
|
||||
const that = this as any;
|
||||
|
||||
// join SSE 频道
|
||||
try {
|
||||
if (!that.data.joined) {
|
||||
await join(statusId);
|
||||
that.setData({ joined: true });
|
||||
}
|
||||
} catch (err) {
|
||||
console.warn("join失败", err);
|
||||
}
|
||||
|
||||
// 绑定 SSE 事件
|
||||
that._listenerFn = async (data: any) => {
|
||||
const that = this as any;
|
||||
if (!data || data.type !== "product" || !data.skuId) return;
|
||||
try {
|
||||
if (that.data.skuId == data.skuId) {
|
||||
that.setData({
|
||||
show: true
|
||||
});
|
||||
wx.nextTick(() => {
|
||||
that.setData({ open: true });
|
||||
});
|
||||
return;
|
||||
}
|
||||
const info = await request({
|
||||
options: {
|
||||
url: `/app/shop-store/sku-one`,
|
||||
data: { id: Number(data.skuId) }
|
||||
},
|
||||
isLoading: false
|
||||
});
|
||||
that.setData({
|
||||
name: info.name,
|
||||
price: info.price,
|
||||
picUrl: info.picUrl,
|
||||
skuId: info.skuId,
|
||||
skuRes: info,
|
||||
show: true,
|
||||
stock: info.stock,
|
||||
count: info.count
|
||||
});
|
||||
wx.nextTick(() => {
|
||||
that.setData({ open: true });
|
||||
});
|
||||
} catch (err) {
|
||||
console.error("获取商品信息失败", err);
|
||||
}
|
||||
};
|
||||
|
||||
addCustomEventListener("pushMsg", that._listenerFn);
|
||||
},
|
||||
|
||||
async detached() {
|
||||
const that = this as any;
|
||||
|
||||
// leave SSE 频道
|
||||
try {
|
||||
if (that.data.joined) {
|
||||
await leave(statusId);
|
||||
that.setData({ joined: false });
|
||||
}
|
||||
} catch (err) {
|
||||
console.warn("leave失败", err);
|
||||
}
|
||||
|
||||
// 移除事件监听
|
||||
if (that._listenerFn) {
|
||||
removeCustomEventListener("pushMsg", that._listenerFn);
|
||||
that._listenerFn = null;
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
methods: {
|
||||
handleClick() {
|
||||
const that = this as any;
|
||||
wx.navigateTo({
|
||||
url: `/pages/common/live-good-detail/live-good-detail?skuId=${that.data.skuId}&roomId=${that.data.joinedGroupId}`
|
||||
});
|
||||
},
|
||||
handleClose() {
|
||||
const that = this as any;
|
||||
that.setData({ open: false });
|
||||
},
|
||||
openPopup(){
|
||||
const that = this as any;
|
||||
const popup = that.selectComponent('#goodDetailPopup')
|
||||
popup.openPopup()
|
||||
}
|
||||
// ,
|
||||
// handleAddShopCart() {
|
||||
// const that = this as any;
|
||||
// const mbuId = wx.getStorageSync("mbuId");
|
||||
// let allShoppingCart = wx.getStorageSync("shoppingCart");
|
||||
|
||||
// if (!Array.isArray(allShoppingCart)) {
|
||||
// allShoppingCart = [];
|
||||
// }
|
||||
|
||||
// let shoppingCart: any = allShoppingCart.find(
|
||||
// (item: any) => item.mbuId == mbuId
|
||||
// );
|
||||
|
||||
// if (shoppingCart) {
|
||||
// const temp = shoppingCart.data.find(
|
||||
// (item: any) => item.skuId == that.data.skuId
|
||||
// );
|
||||
// if (temp) {
|
||||
// //购物车里已经有了
|
||||
// temp.count += 1;
|
||||
// if (temp.count > that.data.stock) {
|
||||
// wx.showToast({ title: "购物车数量超过库存数量了!", icon: "none" })
|
||||
// return;
|
||||
// }
|
||||
// } else {
|
||||
// //没有在购物车里
|
||||
// shoppingCart.data.push({ ...that.data, count: 1 });
|
||||
// }
|
||||
// } else {
|
||||
// //无添加购物车历史
|
||||
// shoppingCart = {
|
||||
// mbuId,
|
||||
// // @ts-ignore
|
||||
// data: [{ ...this.data, count: 1 }]
|
||||
// };
|
||||
// allShoppingCart.push(shoppingCart);
|
||||
// }
|
||||
|
||||
// wx.setStorageSync("shoppingCart", allShoppingCart);
|
||||
// wx.showToast({ title: "加入购物车成功!" })
|
||||
// }
|
||||
}
|
||||
});
|
||||
Reference in New Issue
Block a user