374 lines
11 KiB
JavaScript
374 lines
11 KiB
JavaScript
"use strict";
|
||
const common_vendor = require("../../common/vendor.js");
|
||
const api_shop_goods_index = require("../../api/shop/goods/index.js");
|
||
const api_shop_goodsCategory_index = require("../../api/shop/goodsCategory/index.js");
|
||
const uni_modules_uvUiTools_libs_function_index = require("../../uni_modules/uv-ui-tools/libs/function/index.js");
|
||
const store_modules_tenant = require("../../store/modules/tenant.js");
|
||
const tenantStore = store_modules_tenant.useTenantStore();
|
||
const _sfc_main = {
|
||
data() {
|
||
return {
|
||
goodsList: [],
|
||
// 瀑布流全部数据
|
||
list1: [],
|
||
// 瀑布流第一列数据
|
||
list2: [],
|
||
// 瀑布流第二列数据
|
||
goodsCategoryList: [],
|
||
// 商品分类
|
||
leftGap: 10,
|
||
rightGap: 10,
|
||
columnGap: 10,
|
||
// 小程序导航图标
|
||
navigation: [],
|
||
// 骨架屏
|
||
hideTools: true,
|
||
// 商品分类
|
||
categoryId: void 0
|
||
};
|
||
},
|
||
computed: {
|
||
imageStyle(item) {
|
||
return (item2) => {
|
||
const v = common_vendor.index.upx2px(750) - this.leftGap - this.rightGap - this.columnGap;
|
||
const w = v / 2;
|
||
const rate = w / item2.w;
|
||
const h = rate * item2.h;
|
||
return {
|
||
width: w + "px",
|
||
height: h + "px"
|
||
};
|
||
};
|
||
}
|
||
},
|
||
async onLoad() {
|
||
const info = await tenantStore.fetchTenantInfo();
|
||
if (info.mpMenus) {
|
||
const arr1 = info.mpMenus.filter((d) => d.type == 3);
|
||
console.log("info.mpMenus: ", arr1);
|
||
if (arr1) {
|
||
this.navigation = arr1;
|
||
}
|
||
}
|
||
this.reload();
|
||
},
|
||
methods: {
|
||
async reload() {
|
||
const app = this;
|
||
const info = await tenantStore.fetchTenantInfo();
|
||
if (common_vendor.index.getStorageSync("user_id") && common_vendor.index.getStorageSync("access_token")) {
|
||
app.isLogin = true;
|
||
}
|
||
if (info.mpMenus) {
|
||
const arr1 = info.mpMenus.filter((d) => d.type == 3);
|
||
console.log("info.mpMenus: ", arr1);
|
||
if (arr1) {
|
||
app.navigation = arr1;
|
||
}
|
||
}
|
||
Promise.all([app.pageGoods(), app.getGoodsCategory()]).then((res) => {
|
||
app.goodsList = res[0];
|
||
app.goodsCategoryList = res[1];
|
||
app.hideTools = false;
|
||
});
|
||
},
|
||
pageGoods() {
|
||
const { categoryId } = this;
|
||
return new Promise((resolve, reject) => {
|
||
api_shop_goods_index.pageGoods({ parentId: categoryId }).then((result) => {
|
||
resolve(result.list);
|
||
}).catch(reject);
|
||
});
|
||
},
|
||
getGoodsCategory() {
|
||
return new Promise((resolve, reject) => {
|
||
api_shop_goodsCategory_index.pageGoodsCategory({ parentId: 0 }).then((result) => {
|
||
resolve(result.list);
|
||
}).catch(reject);
|
||
});
|
||
},
|
||
navTo(item) {
|
||
common_vendor.index.navigateTo({
|
||
url: "/package/goods/detail?id=" + item.goodsId
|
||
});
|
||
},
|
||
onCategory(item) {
|
||
this.categoryId = item.categoryId;
|
||
this.goodsList = [];
|
||
this.list1 = [];
|
||
this.list2 = [];
|
||
this.reload();
|
||
},
|
||
// 这点非常重要:e.name在这里返回是list1或list2,要手动将数据追加到相应列
|
||
changeList(e) {
|
||
console.log("e: ", e);
|
||
this[e.name].push(e.value);
|
||
},
|
||
// 模拟的后端数据
|
||
getData() {
|
||
return new Promise((resolve) => {
|
||
const imgs = [
|
||
{
|
||
url: "https://via.placeholder.com/100x110.png/3c9cff/fff",
|
||
width: 100,
|
||
height: 110
|
||
},
|
||
{
|
||
url: "https://via.placeholder.com/200x220.png/f9ae3d/fff",
|
||
width: 200,
|
||
height: 220
|
||
},
|
||
{
|
||
url: "https://via.placeholder.com/300x340.png/5ac725/fff",
|
||
width: 300,
|
||
height: 340
|
||
},
|
||
{
|
||
url: "https://via.placeholder.com/400x400.png/f56c6c/fff",
|
||
width: 400,
|
||
height: 400
|
||
},
|
||
{
|
||
url: "https://via.placeholder.com/500x510.png/909399/fff",
|
||
width: 500,
|
||
height: 510
|
||
},
|
||
{
|
||
url: "https://via.placeholder.com/600x606.png/3c9cff/fff",
|
||
width: 600,
|
||
height: 606
|
||
},
|
||
{
|
||
url: "https://via.placeholder.com/310x422.png/f1a532/fff",
|
||
width: 310,
|
||
height: 422
|
||
},
|
||
{
|
||
url: "https://via.placeholder.com/320x430.png/3c9cff/fff",
|
||
width: 320,
|
||
height: 430
|
||
},
|
||
{
|
||
url: "https://via.placeholder.com/330x424.png/f9ae3d/fff",
|
||
width: 330,
|
||
height: 424
|
||
},
|
||
{
|
||
url: "https://via.placeholder.com/340x435.png/5ac725/fff",
|
||
width: 340,
|
||
height: 435
|
||
},
|
||
{
|
||
url: "https://via.placeholder.com/350x440.png/f56c6c/fff",
|
||
width: 350,
|
||
height: 440
|
||
},
|
||
{
|
||
url: "https://via.placeholder.com/380x470.png/909399/fff",
|
||
width: 380,
|
||
height: 470
|
||
}
|
||
];
|
||
let list = [];
|
||
const doFn = (i) => {
|
||
const randomIndex = Math.floor(Math.random() * 10);
|
||
return {
|
||
id: uni_modules_uvUiTools_libs_function_index.guid(),
|
||
allowEdit: i == 0,
|
||
image: imgs[randomIndex].url,
|
||
w: imgs[randomIndex].width,
|
||
h: imgs[randomIndex].height,
|
||
title: i % 2 == 0 ? `(${this.list.length + i + 1})体验uv-ui框架` : `(${this.list.length + i + 1})uv-ui支持多平台`,
|
||
desc: i % 2 == 0 ? `(${this.list.length + i + 1})欢迎使用uv-ui,uni-app生态专用的UI框架` : `(${this.list.length + i})开发者编写一套代码, 可发布到iOS、Android、H5、以及各种小程序`
|
||
};
|
||
};
|
||
setTimeout(() => {
|
||
for (let i = 0; i < 20; i++) {
|
||
list.push(doFn(i));
|
||
}
|
||
resolve({
|
||
data: list
|
||
});
|
||
}, 200);
|
||
});
|
||
}
|
||
}
|
||
};
|
||
if (!Array) {
|
||
const _easycom_uv_skeleton2 = common_vendor.resolveComponent("uv-skeleton");
|
||
const _easycom_uni_card2 = common_vendor.resolveComponent("uni-card");
|
||
const _easycom_uv_waterfall2 = common_vendor.resolveComponent("uv-waterfall");
|
||
const _easycom_uv_gap2 = common_vendor.resolveComponent("uv-gap");
|
||
(_easycom_uv_skeleton2 + _easycom_uni_card2 + _easycom_uv_waterfall2 + _easycom_uv_gap2)();
|
||
}
|
||
const _easycom_uv_skeleton = () => "../../uni_modules/uv-skeleton/components/uv-skeleton/uv-skeleton.js";
|
||
const _easycom_uni_card = () => "../../uni_modules/uni-card/components/uni-card/uni-card.js";
|
||
const _easycom_uv_waterfall = () => "../../uni_modules/uv-waterfall/components/uv-waterfall/uv-waterfall.js";
|
||
const _easycom_uv_gap = () => "../../uni_modules/uv-gap/components/uv-gap/uv-gap.js";
|
||
if (!Math) {
|
||
(_easycom_uv_skeleton + _easycom_uni_card + _easycom_uv_waterfall + _easycom_uv_gap)();
|
||
}
|
||
function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
|
||
return common_vendor.e({
|
||
a: $data.navigation.length > 0
|
||
}, $data.navigation.length > 0 ? {
|
||
b: common_vendor.f($data.goodsCategoryList, (item, index, i0) => {
|
||
return {
|
||
a: item.image,
|
||
b: common_vendor.t(item.title),
|
||
c: common_vendor.o(($event) => $options.onCategory(item), index),
|
||
d: index
|
||
};
|
||
})
|
||
} : {
|
||
c: common_vendor.p({
|
||
rows: "0",
|
||
avatar: true,
|
||
loading: $data.hideTools,
|
||
title: false
|
||
}),
|
||
d: common_vendor.p({
|
||
rows: "0",
|
||
avatar: true,
|
||
loading: $data.hideTools,
|
||
title: false
|
||
}),
|
||
e: common_vendor.p({
|
||
rows: "0",
|
||
avatar: true,
|
||
loading: $data.hideTools,
|
||
title: false
|
||
}),
|
||
f: common_vendor.p({
|
||
rows: "0",
|
||
avatar: true,
|
||
loading: $data.hideTools,
|
||
title: false
|
||
}),
|
||
g: common_vendor.p({
|
||
border: false,
|
||
padding: "12px 4px"
|
||
})
|
||
}, {
|
||
h: !$data.hideTools
|
||
}, !$data.hideTools ? {
|
||
i: common_vendor.f($data.list1, (item, index, i0) => {
|
||
return {
|
||
a: item.image ? JSON.parse(item.image)[0] : [],
|
||
b: item.width + "px",
|
||
c: common_vendor.s($options.imageStyle(item)),
|
||
d: common_vendor.o(($event) => $options.navTo(item), item.id),
|
||
e: common_vendor.t(item.goodsName),
|
||
f: common_vendor.o(($event) => $options.navTo(item), item.id),
|
||
g: common_vendor.t(item.price),
|
||
h: item.id
|
||
};
|
||
}),
|
||
j: common_vendor.f($data.list2, (item, index, i0) => {
|
||
return {
|
||
a: item.image ? JSON.parse(item.image)[0] : [],
|
||
b: item.width + "px",
|
||
c: common_vendor.s($options.imageStyle(item)),
|
||
d: common_vendor.o(($event) => $options.navTo(item), item.id),
|
||
e: common_vendor.t(item.goodsName),
|
||
f: common_vendor.o(($event) => $options.navTo(item), item.id),
|
||
g: common_vendor.t(item.price),
|
||
h: item.id
|
||
};
|
||
}),
|
||
k: common_vendor.sr("waterfall", "111bd4f2-5"),
|
||
l: common_vendor.o($options.changeList),
|
||
m: common_vendor.o(($event) => $data.goodsList = $event),
|
||
n: common_vendor.p({
|
||
["add-time"]: 10,
|
||
["left-gap"]: $data.leftGap,
|
||
["right-gap"]: $data.rightGap,
|
||
["column-gap"]: $data.columnGap,
|
||
modelValue: $data.goodsList
|
||
})
|
||
} : {
|
||
o: common_vendor.p({
|
||
rows: "0",
|
||
avatar: true,
|
||
avatarShape: "square",
|
||
avatarSize: "100",
|
||
loading: $data.hideTools,
|
||
title: false
|
||
}),
|
||
p: common_vendor.p({
|
||
height: "16"
|
||
}),
|
||
q: common_vendor.p({
|
||
rows: "2",
|
||
loading: $data.hideTools,
|
||
title: false
|
||
}),
|
||
r: common_vendor.p({
|
||
border: false,
|
||
padding: "18px 6px"
|
||
}),
|
||
s: common_vendor.p({
|
||
rows: "0",
|
||
avatar: true,
|
||
avatarShape: "square",
|
||
avatarSize: "100",
|
||
loading: $data.hideTools,
|
||
title: false
|
||
}),
|
||
t: common_vendor.p({
|
||
height: "16"
|
||
}),
|
||
v: common_vendor.p({
|
||
rows: "2",
|
||
loading: $data.hideTools,
|
||
title: false
|
||
}),
|
||
w: common_vendor.p({
|
||
border: false,
|
||
padding: "18px 6px"
|
||
}),
|
||
x: common_vendor.p({
|
||
rows: "0",
|
||
avatar: true,
|
||
avatarShape: "square",
|
||
avatarSize: "100",
|
||
loading: $data.hideTools,
|
||
title: false
|
||
}),
|
||
y: common_vendor.p({
|
||
height: "16"
|
||
}),
|
||
z: common_vendor.p({
|
||
rows: "2",
|
||
loading: $data.hideTools,
|
||
title: false
|
||
}),
|
||
A: common_vendor.p({
|
||
border: false,
|
||
padding: "18px 6px"
|
||
}),
|
||
B: common_vendor.p({
|
||
rows: "0",
|
||
avatar: true,
|
||
avatarShape: "square",
|
||
avatarSize: "100",
|
||
loading: $data.hideTools,
|
||
title: false
|
||
}),
|
||
C: common_vendor.p({
|
||
height: "16"
|
||
}),
|
||
D: common_vendor.p({
|
||
rows: "2",
|
||
loading: $data.hideTools,
|
||
title: false
|
||
}),
|
||
E: common_vendor.p({
|
||
border: false,
|
||
padding: "18px 6px"
|
||
})
|
||
});
|
||
}
|
||
const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["render", _sfc_render], ["__scopeId", "data-v-111bd4f2"], ["__file", "/Users/gxwebsoft/APP/gxtyzx-uniapp-cli/src/pages/shop/shop.vue"]]);
|
||
wx.createPage(MiniProgramPage);
|