|
|
- "use strict";
- const common_vendor = require("../../common/vendor.js");
- const pages_mixins_pullRefreshMixin = require("../mixins/pullRefreshMixin.js");
- const _sfc_main = {
- mixins: [pages_mixins_pullRefreshMixin.pullRefreshMixin],
- data() {
- return {
- statusBarHeight: 0,
- navBarHeight: 0,
- // px
- navBarHeightRpx: 0,
- // rpx
- fromRecycle: false,
- address: "",
- selectedAddress: null,
- selectedTime: "",
- agreed: false,
- selectedItems: [],
- showTimePicker: false,
- currentDateTab: 0,
- dateTabs: [],
- // 动态生成
- timeSlots: ["11:00~13:00", "13:00~15:00", "15:00~17:00"],
- selectedTimeSlot: 0,
- steps: [],
- // 改为空数组,由接口获取
- showAllItems: false,
- addressId: ""
- };
- },
- onShow() {
- common_vendor.index.__f__("log", "at pages/subcomponent/pickup.vue:171", "当前选中的地址:", this.selectedAddress);
- if (this.selectedAddress) {
- this.address = this.selectedAddress.address;
- this.addressId = this.selectedAddress.id;
- this.$forceUpdate();
- }
- },
- onLoad(options) {
- this.fromRecycle = options.fromRecycle === "true";
- if (this.fromRecycle && options.items) {
- try {
- this.selectedItems = JSON.parse(decodeURIComponent(options.items));
- } catch (e) {
- common_vendor.index.__f__("error", "at pages/subcomponent/pickup.vue:189", "解析衣物信息失败:", e);
- }
- }
- common_vendor.index.$on("addressSelected", (address) => {
- this.selectedAddress = address;
- this.address = address.address;
- this.addressId = address.id;
- if (address.addressDetails)
- this.selectedAddress.addressDetails = address.addressDetails;
- this.$forceUpdate();
- });
- common_vendor.index.$on("clearRecycleData", () => {
- common_vendor.index.$emit("clearRecycleOrderData");
- });
- const sysInfo = common_vendor.index.getSystemInfoSync();
- this.statusBarHeight = sysInfo.statusBarHeight;
- let navBarHeight = 44;
- try {
- const menuButtonInfo = common_vendor.index.getMenuButtonBoundingClientRect();
- navBarHeight = menuButtonInfo.bottom + menuButtonInfo.top - sysInfo.statusBarHeight;
- } catch (e) {
- }
- this.navBarHeight = navBarHeight;
- this.navBarHeightRpx = Math.round(navBarHeight * 750 / sysInfo.windowWidth);
- this.getAddressList();
- this.dateTabs = this.generateDateTabs();
- this.getAreaList();
- },
- onUnload() {
- common_vendor.index.$off("addressSelected");
- common_vendor.index.$off("clearRecycleData");
- },
- computed: {
- totalCount() {
- return this.selectedItems.reduce((sum, item) => sum + item.quantity, 0);
- },
- totalPriceRange() {
- if (this.selectedItems.length === 0)
- return "0-0";
- const total = this.selectedItems.reduce((sum, item) => sum + item.unitPrice * item.quantity, 0);
- return `${(total * 0.92).toFixed(2)}~${(total * 1.1).toFixed(2)}`;
- },
- canSubmit() {
- return this.agreed && this.selectedItems.length > 0 && this.selectedTime && this.displayAddress;
- },
- displayAddress() {
- if (this.selectedAddress) {
- return (this.selectedAddress.address || "") + (this.selectedAddress.addressDetails ? " " + this.selectedAddress.addressDetails : "");
- }
- return "";
- }
- },
- methods: {
- async onRefresh() {
- await new Promise((resolve) => setTimeout(resolve, 1e3));
- common_vendor.index.stopPullRefresh();
- },
- goBack() {
- common_vendor.index.navigateBack();
- },
- showMoreMenu() {
- common_vendor.index.showModal({ title: "更多", content: "这里可以放更多操作" });
- },
- showScan() {
- common_vendor.index.showModal({ title: "扫码", content: "这里可以实现扫码功能" });
- },
- selectAddress() {
- common_vendor.index.navigateTo({ url: "/pages/subcomponent/select?mode=select" });
- },
- openTimePicker() {
- this.showTimePicker = true;
- },
- closeTimePicker() {
- this.showTimePicker = false;
- },
- selectDateTab(index) {
- this.currentDateTab = index;
- },
- selectTimeSlot(index) {
- this.selectedTimeSlot = index;
- },
- confirmTime() {
- const tab = this.dateTabs[this.currentDateTab];
- const dateObj = tab.date;
- const timeStr = this.timeSlots[this.selectedTimeSlot];
- const startTime = timeStr.split("~")[0];
- const yyyy = dateObj.getFullYear();
- const mm = (dateObj.getMonth() + 1).toString().padStart(2, "0");
- const dd = dateObj.getDate().toString().padStart(2, "0");
- this.selectedTime = `${yyyy}-${mm}-${dd} ${startTime}:00`;
- this.closeTimePicker();
- },
- resetPicker() {
- this.currentDateTab = 0;
- this.selectedTimeSlot = 0;
- },
- toggleAgreement() {
- this.agreed = !this.agreed;
- },
- showServiceAgreement() {
- common_vendor.index.showModal({ title: "回收服务协议", content: "这里展示回收服务协议内容" });
- },
- showPrivacyPolicy() {
- common_vendor.index.showModal({ title: "隐私政策", content: "这里展示隐私政策内容" });
- },
- submitOrder() {
- if (!this.agreed) {
- common_vendor.index.showToast({ title: "请先同意服务协议", icon: "none" });
- return;
- }
- if (!this.displayAddress || this.displayAddress === "请选择取件地址") {
- common_vendor.index.showToast({ title: "请选择取件地址", icon: "none" });
- return;
- }
- if (!this.selectedTime) {
- common_vendor.index.showToast({ title: "请选择上门时间", icon: "none" });
- return;
- }
- if (this.selectedItems.length === 0) {
- common_vendor.index.showToast({ title: "请选择回收物品", icon: "none" });
- return;
- }
- const list = this.selectedItems.map((item) => ({
- shopId: item.id,
- num: item.quantity
- }));
- common_vendor.index.__f__("log", "at pages/subcomponent/pickup.vue:326", {
- addressId: this.addressId,
- strTime: this.selectedTime,
- list
- }, "createOrder");
- common_vendor.index.showLoading({ title: "提交中..." });
- this.$api("createOrder", {
- addressId: this.addressId,
- strTime: this.selectedTime,
- list: JSON.stringify(list)
- }, (res) => {
- if (res && res.success) {
- common_vendor.index.__f__("log", "at pages/subcomponent/pickup.vue:340", res, "createOrder-res");
- common_vendor.index.showToast({ title: "预约成功", icon: "success" });
- common_vendor.index.redirectTo({
- url: `/pages/subcomponent/detail?id=${res.result.id}`
- });
- }
- });
- },
- toggleExpandOrder() {
- this.showAllItems = !this.showAllItems;
- },
- async getAddressList() {
- const res = await this.$api("getAddressList", {});
- if (res && res.code === 200 && res.result && res.result.records) {
- const defaultAddr = res.result.records.find((item) => item.defaultFlag === "Y");
- if (defaultAddr) {
- this.selectedAddress = defaultAddr;
- this.address = defaultAddr.address;
- this.addressId = defaultAddr.id;
- if (defaultAddr.addressDetails)
- this.selectedAddress.addressDetails = defaultAddr.addressDetails;
- } else {
- this.selectedAddress = null;
- this.address = "";
- }
- }
- },
- generateDateTabs() {
- const weekMap = ["日", "一", "二", "三", "四", "五", "六"];
- const result = [];
- const today = /* @__PURE__ */ new Date();
- for (let i = 0; i < 6; i++) {
- const d = new Date(today);
- d.setDate(today.getDate() + i);
- const mm = (d.getMonth() + 1).toString().padStart(2, "0");
- const dd = d.getDate().toString().padStart(2, "0");
- let label = "";
- if (i === 0)
- label = `今天 ${mm}-${dd}`;
- else if (i === 1)
- label = `明天 ${mm}-${dd}`;
- else if (i === 2)
- label = `后天 ${mm}-${dd}`;
- else
- label = `周${weekMap[d.getDay()]} ${mm}-${dd}`;
- result.push({ label, date: new Date(d) });
- }
- return result;
- },
- getAreaList() {
- this.$api("getAreaList", {}, (res) => {
- if (res.code == 200 && Array.isArray(res.result)) {
- const sorted = res.result.slice().sort((a, b) => a.sort - b.sort);
- this.steps = sorted.map((item) => ({
- icon: item.image,
- text: item.title
- }));
- }
- });
- }
- }
- };
- if (!Array) {
- const _easycom_uni_icons2 = common_vendor.resolveComponent("uni-icons");
- _easycom_uni_icons2();
- }
- const _easycom_uni_icons = () => "../../uni_modules/uni-icons/components/uni-icons/uni-icons.js";
- if (!Math) {
- _easycom_uni_icons();
- }
- function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
- return common_vendor.e({
- a: common_vendor.p({
- type: "left",
- size: "20"
- }),
- b: common_vendor.o((...args) => $options.goBack && $options.goBack(...args)),
- c: $data.statusBarHeight + 88 + "rpx",
- d: $data.statusBarHeight + "px",
- e: common_vendor.f($data.steps, (step, i, i0) => {
- return common_vendor.e({
- a: step.icon,
- b: i === 0
- }, i === 0 ? {
- c: common_vendor.t(step.text)
- } : {
- d: common_vendor.t(step.text)
- }, {
- e: i
- });
- }),
- f: common_vendor.t($options.displayAddress || "请选择"),
- g: !$options.displayAddress ? 1 : "",
- h: common_vendor.o((...args) => $options.selectAddress && $options.selectAddress(...args)),
- i: common_vendor.t($data.selectedTime || "请选择"),
- j: !$data.selectedTime ? 1 : "",
- k: common_vendor.o((...args) => $options.openTimePicker && $options.openTimePicker(...args)),
- l: common_vendor.f($data.showAllItems ? $data.selectedItems : $data.selectedItems.slice(0, 3), (item, index, i0) => {
- return {
- a: item.icon,
- b: common_vendor.t(item.name),
- c: common_vendor.t(item.desc),
- d: common_vendor.t(item.unitPrice),
- e: common_vendor.t(item.quantity),
- f: common_vendor.t(item.unitPrice * item.quantity),
- g: index
- };
- }),
- m: $data.selectedItems.length > 3
- }, $data.selectedItems.length > 3 ? {
- n: common_vendor.t($data.showAllItems ? "收起" : `展开(共${$data.selectedItems.length}件)`),
- o: common_vendor.t($data.showAllItems ? "▲" : "▼"),
- p: common_vendor.o((...args) => $options.toggleExpandOrder && $options.toggleExpandOrder(...args))
- } : {}, {
- q: $data.agreed
- }, $data.agreed ? {} : {}, {
- r: $data.agreed ? 1 : "",
- s: common_vendor.o((...args) => $options.toggleAgreement && $options.toggleAgreement(...args)),
- t: common_vendor.o((...args) => $options.showServiceAgreement && $options.showServiceAgreement(...args)),
- v: common_vendor.o((...args) => $options.showPrivacyPolicy && $options.showPrivacyPolicy(...args)),
- w: common_vendor.t($options.totalCount),
- x: common_vendor.t($options.totalPriceRange),
- y: common_vendor.o((...args) => $options.submitOrder && $options.submitOrder(...args)),
- z: $data.showTimePicker
- }, $data.showTimePicker ? {
- A: common_vendor.o((...args) => $options.closeTimePicker && $options.closeTimePicker(...args)),
- B: common_vendor.o((...args) => $options.resetPicker && $options.resetPicker(...args)),
- C: common_vendor.f($data.dateTabs, (tab, index, i0) => {
- return {
- a: common_vendor.t(tab.label),
- b: index,
- c: common_vendor.n({
- active: $data.currentDateTab === index
- }),
- d: common_vendor.o(($event) => $options.selectDateTab(index), index)
- };
- }),
- D: common_vendor.f($data.timeSlots, (slot, idx, i0) => {
- return {
- a: common_vendor.t(slot),
- b: idx,
- c: common_vendor.n({
- active: $data.selectedTimeSlot === idx
- }),
- d: common_vendor.o(($event) => $options.selectTimeSlot(idx), idx)
- };
- }),
- E: common_vendor.o((...args) => $options.confirmTime && $options.confirmTime(...args))
- } : {}, {
- F: $data.navBarHeightRpx + "rpx"
- });
- }
- const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["render", _sfc_render], ["__scopeId", "data-v-c732bc46"]]);
- wx.createPage(MiniProgramPage);
- //# sourceMappingURL=../../../.sourcemap/mp-weixin/pages/subcomponent/pickup.js.map
|