上传代码
This commit is contained in:
317
uniapp04/unpackage/dist/dev/mp-weixin/pages/merchant/merchant.js
vendored
Normal file
317
uniapp04/unpackage/dist/dev/mp-weixin/pages/merchant/merchant.js
vendored
Normal file
@ -0,0 +1,317 @@
|
||||
"use strict";
|
||||
const common_vendor = require("../../common/vendor.js");
|
||||
const common_assets = require("../../common/assets.js");
|
||||
const API_api = require("../../API/api.js");
|
||||
if (!Array) {
|
||||
const _easycom_uni_notice_bar2 = common_vendor.resolveComponent("uni-notice-bar");
|
||||
const _easycom_uni_rate2 = common_vendor.resolveComponent("uni-rate");
|
||||
const _easycom_uni_drawer2 = common_vendor.resolveComponent("uni-drawer");
|
||||
(_easycom_uni_notice_bar2 + _easycom_uni_rate2 + _easycom_uni_drawer2)();
|
||||
}
|
||||
const _easycom_uni_notice_bar = () => "../../uni_modules/uni-notice-bar/components/uni-notice-bar/uni-notice-bar.js";
|
||||
const _easycom_uni_rate = () => "../../uni_modules/uni-rate/components/uni-rate/uni-rate.js";
|
||||
const _easycom_uni_drawer = () => "../../uni_modules/uni-drawer/components/uni-drawer/uni-drawer.js";
|
||||
if (!Math) {
|
||||
(_easycom_uni_notice_bar + sort + _easycom_uni_rate + _easycom_uni_drawer)();
|
||||
}
|
||||
const sort = () => "./sort.js";
|
||||
const _sfc_main = /* @__PURE__ */ common_vendor.defineComponent({
|
||||
__name: "merchant",
|
||||
setup(__props) {
|
||||
const currentIndex = common_vendor.ref(0);
|
||||
const tabs = common_vendor.ref([
|
||||
{ name: "点餐" },
|
||||
{ name: "评价" },
|
||||
{ name: "商家信息" }
|
||||
]);
|
||||
const switchTab = (index) => {
|
||||
currentIndex.value = index;
|
||||
};
|
||||
const historyList = common_vendor.ref([]);
|
||||
const talk = () => {
|
||||
common_vendor.index.navigateTo({
|
||||
url: "/pages/talk/talk"
|
||||
});
|
||||
};
|
||||
common_vendor.ref(1);
|
||||
const showRight = common_vendor.ref(null);
|
||||
const showDrawer = () => {
|
||||
if (showRight.value) {
|
||||
showRight.value.open();
|
||||
}
|
||||
};
|
||||
const isLiked = common_vendor.ref(false);
|
||||
const collectState = () => {
|
||||
const businessItem = common_vendor.index.getStorageSync("businessItem");
|
||||
common_vendor.index.request({
|
||||
url: API_api.apiImageUrl + "/api/business/my/getById",
|
||||
method: "GET",
|
||||
data: {
|
||||
businessId: businessItem
|
||||
},
|
||||
success(res) {
|
||||
isLiked.value = Boolean(res.data.data.isCollected);
|
||||
},
|
||||
fail(error) {
|
||||
console.log(error);
|
||||
}
|
||||
});
|
||||
};
|
||||
common_vendor.onMounted(() => {
|
||||
collectState();
|
||||
});
|
||||
const toggleLike = () => {
|
||||
const originalState = isLiked.value;
|
||||
isLiked.value = !originalState;
|
||||
const action = originalState ? "delete" : "add";
|
||||
common_vendor.index.request({
|
||||
url: `${API_api.apiImageUrl}/api/collect/${action}`,
|
||||
method: "POST",
|
||||
data: {
|
||||
businessId: common_vendor.index.getStorageSync("businessItem") || "0"
|
||||
},
|
||||
header: {
|
||||
"cookie": common_vendor.index.getStorageSync("cookie") || ""
|
||||
},
|
||||
success(res) {
|
||||
if (res.data.code !== 200) {
|
||||
isLiked.value = originalState;
|
||||
common_vendor.index.showToast({
|
||||
title: res.data.msg || "操作失败",
|
||||
icon: "none",
|
||||
duration: 2e3
|
||||
});
|
||||
return;
|
||||
}
|
||||
common_vendor.index.showToast({
|
||||
title: originalState ? "已取消收藏" : "收藏成功",
|
||||
duration: 2e3
|
||||
});
|
||||
},
|
||||
fail() {
|
||||
isLiked.value = originalState;
|
||||
common_vendor.index.showToast({
|
||||
title: "网络错误,请重试",
|
||||
icon: "none",
|
||||
duration: 2e3
|
||||
});
|
||||
}
|
||||
});
|
||||
};
|
||||
const cartItems = common_vendor.ref([]);
|
||||
const updateCart = (newCartItems) => {
|
||||
cartItems.value = newCartItems;
|
||||
console.log("更新后的购物车:", cartItems.value);
|
||||
common_vendor.index.setStorageSync("cartItems", newCartItems);
|
||||
};
|
||||
common_vendor.onMounted(() => {
|
||||
cartItems.value = common_vendor.index.getStorageSync("cartItems") || [];
|
||||
});
|
||||
const deleteItem = (index) => {
|
||||
cartItems.value.splice(index, 1);
|
||||
common_vendor.index.setStorageSync("cartItems", cartItems.value);
|
||||
};
|
||||
common_vendor.onMounted(() => {
|
||||
cartItems.value = common_vendor.index.getStorageSync("cartItems") || [];
|
||||
});
|
||||
const incrementQuantity = (index) => {
|
||||
if (cartItems.value[index].quantity < 9) {
|
||||
cartItems.value[index].quantity++;
|
||||
}
|
||||
};
|
||||
const decrementQuantity = (index) => {
|
||||
if (cartItems.value[index].quantity > 1) {
|
||||
cartItems.value[index].quantity--;
|
||||
}
|
||||
};
|
||||
const totalAmount = common_vendor.computed(() => {
|
||||
return cartItems.value.reduce((total, item) => {
|
||||
return total + item.dishesPrice * item.quantity;
|
||||
}, 0);
|
||||
});
|
||||
const account = () => {
|
||||
let businessid = common_vendor.index.getStorageSync("businessItem") || "1830063677349658625";
|
||||
const orderDetails = cartItems.value.map((item) => ({
|
||||
attributeNames: "小份",
|
||||
dishesId: item.id,
|
||||
quantity: item.quantity
|
||||
}));
|
||||
const data = {
|
||||
businessId: String(businessid),
|
||||
notes: "",
|
||||
orderDetailAddRequest: orderDetails,
|
||||
payMethod: 0,
|
||||
phone: "15946398466",
|
||||
pickupMethod: 0,
|
||||
pickupTime: "",
|
||||
totalPrice: totalAmount.value,
|
||||
userName: "沙箱账号"
|
||||
};
|
||||
data.businessId = String(data.businessId);
|
||||
common_vendor.index.request({
|
||||
url: API_api.apiImageUrl + "/api/orders/add",
|
||||
method: "POST",
|
||||
data,
|
||||
header: {
|
||||
"cookie": common_vendor.index.getStorageSync("cookie") || ""
|
||||
},
|
||||
success(res) {
|
||||
console.log(data);
|
||||
console.log("Success:", res.data.data);
|
||||
const orderId = res.data.data;
|
||||
common_vendor.index.setStorageSync("notPay", orderId);
|
||||
common_vendor.index.navigateTo({
|
||||
url: "/pages/goToPay/goToPay"
|
||||
});
|
||||
},
|
||||
fail() {
|
||||
console.error("Error:", "请求失败");
|
||||
}
|
||||
});
|
||||
};
|
||||
const merchantId = common_vendor.ref();
|
||||
const getMerchantIdFromUrl = () => {
|
||||
const pages = getCurrentPages();
|
||||
const currentPage = pages[pages.length - 1];
|
||||
console.log("Current page options:", currentPage.options);
|
||||
if (currentPage && currentPage.options && currentPage.options.merchantId) {
|
||||
merchantId.value = currentPage.options.merchantId;
|
||||
console.log(`Merchant ID received: ${merchantId.value}`);
|
||||
} else {
|
||||
console.error("Could not retrieve merchantId from URL.");
|
||||
}
|
||||
};
|
||||
common_vendor.onMounted(() => {
|
||||
getMerchantIdFromUrl();
|
||||
});
|
||||
common_vendor.watch(merchantId, (newValue) => {
|
||||
common_vendor.index.$emit("merchantIdChanged", newValue);
|
||||
});
|
||||
const businessMessage = common_vendor.ref(common_vendor.index.getStorageSync("Mybusiness"));
|
||||
console.log(businessMessage.value);
|
||||
const review = () => {
|
||||
const businessId = common_vendor.index.getStorageSync("businessItem");
|
||||
common_vendor.index.request({
|
||||
url: API_api.apiImageUrl + "/api/level/list/business",
|
||||
method: "POST",
|
||||
data: {
|
||||
id: businessId
|
||||
},
|
||||
success(res) {
|
||||
console.log(res.data.data);
|
||||
historyList.value = res.data.data;
|
||||
},
|
||||
fail() {
|
||||
console.log("失败");
|
||||
}
|
||||
});
|
||||
};
|
||||
common_vendor.onMounted(() => {
|
||||
review();
|
||||
});
|
||||
const contentDetail = common_vendor.ref("");
|
||||
const fetchContentItem = async () => {
|
||||
const businessId = common_vendor.index.getStorageSync("businessItem");
|
||||
try {
|
||||
const res = await common_vendor.index.request({
|
||||
url: "http://39.101.78.35:6448/api/businessInfo/list",
|
||||
method: "POST",
|
||||
data: {
|
||||
id: businessId
|
||||
}
|
||||
});
|
||||
console.log(res.data.data.content);
|
||||
contentDetail.value = res.data.data.content;
|
||||
} catch (err) {
|
||||
console.error(err);
|
||||
}
|
||||
};
|
||||
common_vendor.onMounted(() => {
|
||||
fetchContentItem();
|
||||
});
|
||||
return (_ctx, _cache) => {
|
||||
return common_vendor.e({
|
||||
a: common_vendor.p({
|
||||
["show-icon"]: true,
|
||||
scrollable: true,
|
||||
text: contentDetail.value
|
||||
}),
|
||||
b: common_vendor.f(tabs.value, (tab, index, i0) => {
|
||||
return {
|
||||
a: common_vendor.t(tab.name),
|
||||
b: index,
|
||||
c: currentIndex.value === index ? 1 : "",
|
||||
d: common_vendor.o(($event) => switchTab(index), index)
|
||||
};
|
||||
}),
|
||||
c: currentIndex.value === 0
|
||||
}, currentIndex.value === 0 ? {
|
||||
d: common_vendor.o(updateCart),
|
||||
e: common_vendor.p({
|
||||
["merchant-id"]: merchantId.value
|
||||
})
|
||||
} : {}, {
|
||||
f: currentIndex.value === 1
|
||||
}, currentIndex.value === 1 ? {
|
||||
g: common_vendor.f(historyList.value, (item, index, i0) => {
|
||||
return common_vendor.e({
|
||||
a: common_vendor.t(item.createTime.substr(0, 19).replace("T", " ")),
|
||||
b: common_vendor.t(item.rating),
|
||||
c: "a7b7a9e4-2-" + i0,
|
||||
d: common_vendor.p({
|
||||
readonly: true,
|
||||
value: item.rating,
|
||||
["active-color"]: "#13c2c2",
|
||||
["is-fill"]: false,
|
||||
color: "#13c2c2"
|
||||
}),
|
||||
e: common_vendor.t(item.review),
|
||||
f: common_vendor.o(($event) => _ctx.reviewUser(item), index),
|
||||
g: item.businessReview && item.businessReview.trim() !== ""
|
||||
}, item.businessReview && item.businessReview.trim() !== "" ? {
|
||||
h: common_vendor.t(item.businessReview)
|
||||
} : {}, {
|
||||
i: index
|
||||
});
|
||||
})
|
||||
} : {}, {
|
||||
h: currentIndex.value === 2
|
||||
}, currentIndex.value === 2 ? {
|
||||
i: common_vendor.t(businessMessage.value.address),
|
||||
j: common_vendor.t(businessMessage.value.businessPhone),
|
||||
k: businessMessage.value.businessAvatar
|
||||
} : {}, {
|
||||
l: isLiked.value ? "../../static/small/starSelected.png" : "../../static/small/star.png",
|
||||
m: common_vendor.t(isLiked.value ? "已收藏" : "收藏店铺"),
|
||||
n: common_vendor.o(toggleLike),
|
||||
o: common_assets._imports_0$3,
|
||||
p: common_vendor.o(talk),
|
||||
q: common_vendor.o(($event) => showDrawer()),
|
||||
r: common_vendor.f(cartItems.value, (item, index, i0) => {
|
||||
return {
|
||||
a: item.dishesImage,
|
||||
b: common_vendor.o(($event) => deleteItem(index), index),
|
||||
c: common_vendor.t(item.dishesName),
|
||||
d: common_vendor.t(item.dishesPrice),
|
||||
e: common_vendor.o(($event) => decrementQuantity(index), index),
|
||||
f: common_vendor.t(item.quantity),
|
||||
g: common_vendor.o(($event) => incrementQuantity(index), index),
|
||||
h: index
|
||||
};
|
||||
}),
|
||||
s: common_assets._imports_1,
|
||||
t: common_vendor.t(totalAmount.value),
|
||||
v: common_vendor.o(account),
|
||||
w: common_vendor.sr(showRight, "a7b7a9e4-3", {
|
||||
"k": "showRight"
|
||||
}),
|
||||
x: common_vendor.o(($event) => _ctx.change($event, "showRight")),
|
||||
y: common_vendor.p({
|
||||
mode: "left",
|
||||
["mask-click"]: true
|
||||
})
|
||||
});
|
||||
};
|
||||
}
|
||||
});
|
||||
wx.createPage(_sfc_main);
|
Reference in New Issue
Block a user