"use strict"; const common_vendor = require("../../common/vendor.js"); const pages_mixins_tabBarMixin = require("../mixins/tabBarMixin.js"); const utils_pinyin = require("../../utils/pinyin.js"); const common_assets = require("../../common/assets.js"); const _sfc_main = { mixins: [pages_mixins_tabBarMixin.tabBarMixin], data() { return { value: 1, ishow: true, // 动态数据 allProducts: {}, // { [categoryId]: [商品数组] } allProductsPage: {}, // { [categoryId]: 当前已加载页码 } allProductsTotal: {}, // { [categoryId]: 总数 } pageSize: 10, currentCategory: 0, tabbarHeight: 0, showDetailPanel: false, showBrandPopup: false, showRulePopup: false, ruleImgUrl: "/static/回收/回收规则.png", showPickupConfirm: false, showBrandConfirm: false, brandConfirmInfo: { logo: "", name: "" }, brandList: [], brandIndexList: ["A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z"], currentLetter: "A", scrollToView: "", brandSearch: "", ruleHtml: "", // 回收规则富文本内容 loadingMore: false, finished: false, pendingBrandIndex: null // 记录待加一的品牌商品index }; }, computed: { // 当前分类的商品列表 recycleList() { var _a; const currentCategoryId = (_a = this.categories[this.currentCategory]) == null ? void 0 : _a.id; return this.allProducts[currentCategoryId] || []; }, // 计算总数量 totalCount() { return Object.values(this.allProducts).reduce((total, categoryItems) => { return total + categoryItems.reduce((sum, item) => sum + (item.quantity || 0), 0); }, 0); }, // 计算总价格 totalPrice() { const total = Object.values(this.allProducts).reduce((categoryTotal, categoryItems) => { return categoryTotal + categoryItems.reduce((sum, item) => sum + (item.quantity || 0) * Number(item.price), 0); }, 0); return total.toFixed(1); }, // 计算价格范围 priceRange() { if (this.totalCount === 0) { return { min: "0.0", max: "0.0" }; } const total = Number(this.totalPrice); const min = Math.max(0, total - 2.2).toFixed(1); const max = (total + 2.2).toFixed(1); return { min, max }; }, selectedProducts() { return Object.values(this.allProducts).flat().filter((item) => item.quantity > 0); }, filteredBrandList() { if (!this.brandSearch) return this.brandList; const keyword = this.brandSearch.trim().toLowerCase(); return this.brandList.filter((b) => b.name.toLowerCase().includes(keyword)); }, bannerList() { return getApp().globalData.bannerList || []; }, categories() { const list = getApp().globalData.pricePreviewList || []; return list.filter((item) => item.pid === "0").sort((a, b) => a.sort - b.sort); } }, methods: { changeTo(e) { this.value = e; if (e == 2) { common_vendor.index.reLaunch({ url: "/pages/component/my" }); } else if (e == 0) { common_vendor.index.__f__("log", "at pages/component/recycle.vue:354", e, "111"); common_vendor.index.reLaunch({ url: "/pages/component/home" }); } }, fetchGoodsList(categoryId, page = 1, callback) { this.$api("getClassGoodsList", { classId: categoryId, pageNo: page, pageSize: this.pageSize }, (res) => { if (res.code === 200 && res.result && Array.isArray(res.result.records)) { const oldList = this.allProducts[categoryId] || []; const newList = page === 1 ? res.result.records : oldList.concat(res.result.records); this.$set(this.allProducts, categoryId, newList); this.$set(this.allProductsPage, categoryId, page); this.$set(this.allProductsTotal, categoryId, res.result.total); } if (callback) callback(); }); }, // 获取分类商品总数 getCategoryItemCount(index) { var _a; const categoryId = (_a = this.categories[index]) == null ? void 0 : _a.id; const categoryItems = this.allProducts[categoryId] || []; return categoryItems.reduce((sum, item) => sum + (item.quantity || 0), 0); }, // 切换分类 switchCategory(index) { var _a; this.currentCategory = index; this.loadingMore = false; this.finished = false; const categoryId = (_a = this.categories[index]) == null ? void 0 : _a.id; if (!this.allProducts[categoryId]) { this.fetchGoodsList(categoryId, 1); } }, // 更新商品数量 updateQuantity(index, delta) { var _a, _b; const categoryId = (_a = this.categories[this.currentCategory]) == null ? void 0 : _a.id; const item = (_b = this.allProducts[categoryId]) == null ? void 0 : _b[index]; if (!item) return; if (item.shopCion && (item.quantity || 0) === 0 && delta > 0) { this.pendingBrandIndex = index; this.getGoodsBrandList(item.shopCion); this.showBrandPopup = true; return; } let newQuantity = (item.quantity || 0) + delta; if (newQuantity < 0) newQuantity = 0; this.$set(item, "quantity", newQuantity); }, // 显示回收规则 showRules(item) { this.$api("getGoodsRecycleRule", { goodsId: item.id }, (res) => { if (res.code === 200 && res.result) { this.ruleHtml = res.result; } else { this.ruleHtml = "

暂无回收规则

"; } this.showRulePopup = true; }); }, showMore() { common_vendor.index.showToast({ title: "更多规则请咨询客服", icon: "none" }); }, submitOrder() { if (this.totalCount === 0) { common_vendor.index.showToast({ title: "请选择要回收的物品", icon: "none" }); return; } this.showPickupConfirm = true; }, handlePickupCancel() { this.showPickupConfirm = false; }, handlePickupAgree() { this.showPickupConfirm = false; common_vendor.index.showLoading({ title: "提交中..." }); setTimeout(() => { common_vendor.index.hideLoading(); common_vendor.index.showToast({ title: "预约成功", icon: "success" }); this.goToPickup(); }, 1500); }, goToPickup() { const selectedItems = this.selectedProducts.map((item) => ({ id: item.id, name: item.name, icon: item.image, quantity: item.quantity, unitPrice: item.price, desc: "允许脏破烂,160码以上" })); const itemsStr = encodeURIComponent(JSON.stringify(selectedItems)); common_vendor.index.navigateTo({ url: `/pages/subcomponent/pickup?fromRecycle=true&items=${itemsStr}` }); }, checkBrand(index) { var _a, _b; const categoryId = (_a = this.categories[this.currentCategory]) == null ? void 0 : _a.id; const item = (_b = this.allProducts[categoryId]) == null ? void 0 : _b[index]; if (item == null ? void 0 : item.shopCion) { this.pendingBrandIndex = index; this.getGoodsBrandList(item.shopCion); this.showBrandPopup = true; } }, closeBrandPopup() { this.showBrandPopup = false; }, scrollToLetter(letter) { this.currentLetter = letter; this.scrollToView = "brand-letter-" + letter; }, // 添加下拉刷新方法 async refreshData() { try { this.currentCategory = 0; Object.values(this.allProducts).forEach((categoryItems) => { categoryItems.forEach((item) => { item.quantity = 0; }); }); await new Promise((resolve) => setTimeout(resolve, 1e3)); common_vendor.index.showToast({ title: "刷新成功", icon: "success" }); } catch (error) { common_vendor.index.showToast({ title: "刷新失败", icon: "none" }); } finally { common_vendor.index.stopPullDownRefresh(); } }, toggleDetailPanel() { this.showDetailPanel = !this.showDetailPanel; }, updateQuantityByProduct(item, delta) { if (!item.quantity) item.quantity = 0; item.quantity += delta; if (item.quantity < 0) item.quantity = 0; this.updateTotal(); }, openRulePopup() { this.showRulePopup = true; }, closeRulePopup() { this.showRulePopup = false; }, loadMoreGoods() { var _a; const categoryId = (_a = this.categories[this.currentCategory]) == null ? void 0 : _a.id; const page = (this.allProductsPage[categoryId] || 1) + 1; const total = this.allProductsTotal[categoryId] || 0; const loaded = (this.allProducts[categoryId] || []).length; if (this.loadingMore || this.finished) return; if (loaded < total) { this.loadingMore = true; this.fetchGoodsList(categoryId, page, () => { this.loadingMore = false; const newLoaded = (this.allProducts[categoryId] || []).length; this.finished = newLoaded >= (this.allProductsTotal[categoryId] || 0); }); } else { this.finished = true; } }, openBrandConfirm(brand) { this.brandConfirmInfo = { logo: brand.logo, name: brand.name }; this.showBrandConfirm = true; }, closeBrandConfirm() { this.showBrandConfirm = false; }, confirmBrand() { var _a, _b; this.showBrandConfirm = false; this.showBrandPopup = false; if (this.pendingBrandIndex !== null) { const categoryId = (_a = this.categories[this.currentCategory]) == null ? void 0 : _a.id; const item = (_b = this.allProducts[categoryId]) == null ? void 0 : _b[this.pendingBrandIndex]; if (item) { this.$set(item, "quantity", 1); } this.pendingBrandIndex = null; } }, getGoodsBrandList(iconId) { this.$api("getGoodsBrandList", { iconId }, (res) => { if (res && res.success && res.result && res.result.records) { this.brandList = res.result.records.map((item) => { const firstChar = this.getPinyinFirstLetter(item.name); return { logo: item.image || "/static/brand/alexander.png", name: item.name, letter: firstChar }; }); } }); }, // 获取中文拼音首字母 getPinyinFirstLetter(str) { if (!str) return "#"; const firstChar = str.charAt(0); for (let key in utils_pinyin.pinyin) { const chars = utils_pinyin.pinyin[key]; if (chars && chars.indexOf(firstChar) !== -1) { return key.charAt(0).toUpperCase(); } } return "#"; } }, created() { this.currentCategory = 0; this.$nextTick(() => { var _a; if (this.categories.length > 0) { const firstCategoryId = (_a = this.categories[0]) == null ? void 0 : _a.id; if (firstCategoryId) { this.fetchGoodsList(firstCategoryId, 1); } } }); }, mounted() { this.$nextTick(() => { const query = common_vendor.index.createSelectorQuery().in(this); query.select(".uv-tabbar").boundingClientRect((rect) => { if (rect && rect.height) { this.tabbarHeight = rect.height; } else { this.tabbarHeight = common_vendor.index.upx2px ? common_vendor.index.upx2px(95) : 45; } }).exec(); }); }, onLoad(options) { if (options && options.categoryId) { const idx = this.categories.findIndex((c) => c.id == options.categoryId); if (idx !== -1) this.currentCategory = idx; } this.fetchGoodsList(this.categories[this.currentCategory].id, 1); common_vendor.index.$on("bannerListUpdated", () => { this.$forceUpdate && this.$forceUpdate(); }); if (getApp().globalData.bannerList && getApp().globalData.bannerList.length > 0) { this.$forceUpdate && this.$forceUpdate(); } if (getApp().globalData.shouldClearRecycle) { Object.values(this.allProducts).forEach((categoryItems) => { categoryItems.forEach((item) => { this.$set(item, "quantity", 0); }); }); this.showDetailPanel = false; this.$forceUpdate(); getApp().globalData.shouldClearRecycle = false; } }, onUnload() { common_vendor.index.$off("bannerListUpdated"); common_vendor.index.$off("clearRecycleOrderData"); }, onShow() { const id = getApp().globalData.targetRecycleCategoryId; if (id) { const trySwitch = () => { var _a; if (this.categories.length > 0) { const idx = this.categories.findIndex((c) => String(c.id) === String(id)); if (idx !== -1) { this.currentCategory = idx; const categoryId = (_a = this.categories[idx]) == null ? void 0 : _a.id; if (categoryId && !this.allProducts[categoryId]) { this.loadingMore = false; this.finished = false; this.fetchGoodsList(categoryId, 1); } } getApp().globalData.targetRecycleCategoryId = null; } else { setTimeout(trySwitch, 100); } }; trySwitch(); } if (getApp().globalData.shouldClearRecycle) { Object.values(this.allProducts).forEach((categoryItems) => { categoryItems.forEach((item) => { this.$set(item, "quantity", 0); }); }); this.showDetailPanel = false; this.$forceUpdate(); getApp().globalData.shouldClearRecycle = false; } common_vendor.index.$on("clearRecycleOrderData", () => { Object.values(this.allProducts).forEach((categoryItems) => { categoryItems.forEach((item) => { this.$set(item, "quantity", 0); }); }); this.showDetailPanel = false; this.$forceUpdate(); }); }, watch: { categories(newVal) { var _a; const id = getApp().globalData.targetRecycleCategoryId; const idx = newVal.findIndex((c) => String(c.id) === String(id)); if (id && newVal.length > 0 && idx !== -1) { this.currentCategory = idx; getApp().globalData.targetRecycleCategoryId = null; const categoryId = (_a = newVal[idx]) == null ? void 0 : _a.id; if (categoryId && !this.allProducts[categoryId]) { this.loadingMore = false; this.finished = false; this.fetchGoodsList(categoryId, 1); } } } } }; const __injectCSSVars__ = () => { common_vendor.useCssVars((_ctx) => ({ "a20a0960": _ctx.tabbarHeight + "px" })); }; const __setup__ = _sfc_main.setup; _sfc_main.setup = __setup__ ? (props, ctx) => { __injectCSSVars__(); return __setup__(props, ctx); } : __injectCSSVars__; if (!Array) { const _easycom_uni_icons2 = common_vendor.resolveComponent("uni-icons"); const _easycom_uv_tabbar_item2 = common_vendor.resolveComponent("uv-tabbar-item"); const _easycom_uv_tabbar2 = common_vendor.resolveComponent("uv-tabbar"); (_easycom_uni_icons2 + _easycom_uv_tabbar_item2 + _easycom_uv_tabbar2)(); } const _easycom_uni_icons = () => "../../uni_modules/uni-icons/components/uni-icons/uni-icons.js"; const _easycom_uv_tabbar_item = () => "../../uni_modules/uv-tabbar/components/uv-tabbar-item/uv-tabbar-item.js"; const _easycom_uv_tabbar = () => "../../uni_modules/uv-tabbar/components/uv-tabbar/uv-tabbar.js"; if (!Math) { (_easycom_uni_icons + _easycom_uv_tabbar_item + _easycom_uv_tabbar)(); } function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) { return common_vendor.e({ a: common_vendor.f($options.bannerList, (item, index, i0) => { return { a: item.image, b: item.id || index }; }), b: common_vendor.f($options.categories, (category, index, i0) => { return common_vendor.e({ a: $options.getCategoryItemCount(index) > 0 }, $options.getCategoryItemCount(index) > 0 ? {} : {}, { b: common_vendor.t(category.title), c: category.id || index, d: $data.currentCategory === index ? 1 : "", e: common_vendor.o(($event) => $options.switchCategory(index), category.id || index) }); }), c: common_vendor.f($options.recycleList, (item, index, i0) => { return common_vendor.e({ a: item.image }, item.image ? { b: item.image } : {}, { c: common_vendor.t(item.name), d: "9e04663e-0-" + i0, e: common_vendor.o(($event) => $options.showRules(item), index), f: common_vendor.t(item.service), g: common_vendor.t(item.price), h: common_vendor.o(($event) => $options.updateQuantity(index, -1), index), i: common_vendor.t(item.quantity || 0), j: common_vendor.o(($event) => $options.updateQuantity(index, 1), index), k: item.shopCion }, item.shopCion ? { l: "9e04663e-1-" + i0, m: common_vendor.p({ type: "right", size: "14", color: "#ff7a0e" }), n: common_vendor.o(($event) => $options.checkBrand(index), index) } : {}, { o: index }); }), d: common_vendor.p({ type: "right", size: "14", color: "#999" }), e: common_assets._imports_0$1, f: $data.loadingMore }, $data.loadingMore ? {} : $data.finished ? {} : {}, { g: $data.finished, h: common_vendor.o((...args) => $options.loadMoreGoods && $options.loadMoreGoods(...args)), i: !$data.showDetailPanel }, !$data.showDetailPanel ? { j: common_vendor.t($options.totalCount), k: common_vendor.p({ type: "help", size: "18", color: "#b2b2b2" }), l: common_vendor.o($options.toggleDetailPanel), m: common_vendor.p({ type: $data.showDetailPanel ? "up" : "down", size: "18", color: "#5e5e5e" }), n: common_vendor.t($options.priceRange.min), o: common_vendor.t($options.priceRange.max), p: common_vendor.o((...args) => $options.submitOrder && $options.submitOrder(...args)) } : {}, { q: $data.showDetailPanel }, $data.showDetailPanel ? { r: common_vendor.o((...args) => $options.toggleDetailPanel && $options.toggleDetailPanel(...args)), s: common_vendor.f($options.selectedProducts, (item, idx, i0) => { return common_vendor.e({ a: item.image }, item.image ? { b: item.image } : {}, { c: common_vendor.t(item.name), d: common_vendor.t(item.price), e: common_vendor.o(($event) => $options.updateQuantityByProduct(item, -1), idx), f: common_vendor.t(item.quantity), g: common_vendor.o(($event) => $options.updateQuantityByProduct(item, 1), idx), h: idx }); }), t: common_vendor.t(2222), v: common_vendor.t($options.totalCount), w: common_vendor.p({ type: "help", size: "18", color: "#b2b2b2" }), x: common_vendor.o($options.toggleDetailPanel), y: common_vendor.p({ type: $data.showDetailPanel ? "up" : "down", size: "18", color: "#5e5e5e" }), z: common_vendor.t($options.priceRange.min), A: common_vendor.t($options.priceRange.max), B: common_vendor.o((...args) => $options.submitOrder && $options.submitOrder(...args)), C: common_vendor.o(() => { }), D: common_vendor.o((...args) => $options.toggleDetailPanel && $options.toggleDetailPanel(...args)) } : {}, { E: $data.ishow }, $data.ishow ? { F: common_assets._imports_5, G: common_assets._imports_6, H: common_vendor.p({ text: "首页" }), I: common_assets._imports_7, J: common_assets._imports_8, K: common_vendor.p({ text: "回收" }), L: common_assets._imports_9, M: common_assets._imports_10, N: common_vendor.p({ text: "我的" }), O: common_vendor.o($options.changeTo), P: common_vendor.p({ value: $data.value, fixed: true }) } : {}, { Q: $data.showBrandPopup }, $data.showBrandPopup ? { R: common_vendor.o((...args) => $options.closeBrandPopup && $options.closeBrandPopup(...args)), S: $data.brandSearch, T: common_vendor.o(($event) => $data.brandSearch = $event.detail.value), U: common_vendor.f($data.brandIndexList, (letter, k0, i0) => { return { a: common_vendor.t(letter), b: common_vendor.f($options.filteredBrandList.filter((b) => b.letter === letter), (brand, k1, i1) => { return { a: brand.logo, b: common_vendor.t(brand.name), c: brand.name, d: common_vendor.o(($event) => $options.openBrandConfirm(brand), brand.name) }; }), c: letter, d: "brand-letter-" + letter }; }), V: $data.scrollToView, W: common_vendor.f($data.brandIndexList, (letter, k0, i0) => { return { a: common_vendor.t(letter), b: letter, c: $data.currentLetter === letter ? 1 : "", d: common_vendor.o(($event) => $options.scrollToLetter(letter), letter) }; }) } : {}, { X: $data.showRulePopup }, $data.showRulePopup ? { Y: $data.ruleHtml, Z: common_vendor.o((...args) => $options.closeRulePopup && $options.closeRulePopup(...args)), aa: common_vendor.o((...args) => $options.closeRulePopup && $options.closeRulePopup(...args)) } : {}, { ab: $data.showPickupConfirm }, $data.showPickupConfirm ? { ac: common_vendor.o((...args) => $options.handlePickupCancel && $options.handlePickupCancel(...args)), ad: common_vendor.o((...args) => $options.handlePickupAgree && $options.handlePickupAgree(...args)) } : {}, { ae: $data.showBrandConfirm }, $data.showBrandConfirm ? { af: $data.brandConfirmInfo.logo, ag: common_vendor.t($data.brandConfirmInfo.name), ah: common_vendor.o((...args) => $options.closeBrandConfirm && $options.closeBrandConfirm(...args)), ai: common_vendor.o((...args) => $options.confirmBrand && $options.confirmBrand(...args)), aj: common_vendor.o((...args) => $options.closeBrandConfirm && $options.closeBrandConfirm(...args)) } : {}, { ak: common_vendor.s(_ctx.__cssVars()) }); } const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["render", _sfc_render], ["__scopeId", "data-v-9e04663e"]]); wx.createPage(MiniProgramPage); //# sourceMappingURL=../../../.sourcemap/mp-weixin/pages/component/recycle.js.map