爱简收旧衣按件回收前端代码仓库
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

352 lines
11 KiB

"use strict";
const common_vendor = require("../../common/vendor.js");
const pages_mixins_pullRefreshMixin = require("../mixins/pullRefreshMixin.js");
const common_assets = require("../../common/assets.js");
const _sfc_main = {
mixins: [pages_mixins_pullRefreshMixin.pullRefreshMixin],
data() {
return {
address: "",
selectedAddress: null,
displayAddress: "请选择取件地址",
addressDetail: {
province: "",
city: "",
district: "",
street: "",
address: "",
name: "",
phone: "",
isDefault: false
},
appointmentTime: "预约 周四 11:00~13:00",
timeDetail: {
date: "",
time: "",
displayText: ""
},
totalCount: 16,
estimatePrice: "73.6-75.8",
agreed: true,
showTimePicker: false,
currentDateTab: 0,
pickerValue: [0, 0, 0],
years: [],
months: [],
days: [],
selectedDate: "",
timeSlot: "11:00~13:00",
// 固定时间段
selectedItems: [
{
name: "羽绒服",
desc: "允许脏破烂,160码以上",
unitPrice: 8,
quantity: 8
},
{
name: "品牌羽绒服",
desc: "允许脏破烂,160码以上",
unitPrice: 10,
quantity: 1
}
],
totalPriceRange: "¥ 73.6-75.8"
};
},
computed: {
displayAddress() {
if (this.selectedAddress) {
return this.selectedAddress.address;
}
return "请选择取件地址";
},
totalPriceRange() {
const totalPrice = this.selectedItems.reduce((total, item) => total + item.unitPrice * item.quantity, 0);
return `¥ ${totalPrice.toFixed(2)}-${(totalPrice + 2).toFixed(2)}`;
},
canSubmit() {
return this.agreed && this.selectedAddress && this.timeDetail.date && this.selectedItems.length > 0;
}
},
methods: {
async onRefresh() {
await new Promise((resolve) => setTimeout(resolve, 1e3));
common_vendor.index.stopPullRefresh();
},
goBack() {
common_vendor.index.navigateBack();
},
selectAddress() {
common_vendor.index.navigateTo({
url: "/pages/component/select"
});
},
openTimePicker() {
this.showTimePicker = true;
if (!this.years.length) {
this.initDatePicker();
}
},
closeTimePicker() {
this.showTimePicker = false;
},
initDatePicker() {
const currentDate = /* @__PURE__ */ new Date();
const currentYear = currentDate.getFullYear();
this.years = Array.from({ length: 5 }, (_, i) => currentYear + i);
this.months = Array.from({ length: 12 }, (_, i) => i + 1);
this.updateDays(currentYear, currentDate.getMonth() + 1);
this.pickerValue = [0, currentDate.getMonth(), currentDate.getDate() - 1];
},
updateDays(year, month) {
const daysInMonth = new Date(year, month, 0).getDate();
this.days = Array.from({ length: daysInMonth }, (_, i) => i + 1);
},
selectDateTab(index) {
this.currentDateTab = index;
if (index < 3) {
const date = /* @__PURE__ */ new Date();
date.setDate(date.getDate() + index);
const yearIndex = this.years.findIndex((year) => year === date.getFullYear());
this.pickerValue = [
yearIndex,
date.getMonth(),
date.getDate() - 1
];
this.updateDays(date.getFullYear(), date.getMonth() + 1);
}
},
onPickerChange(e) {
this.currentDateTab = 3;
const values = e.detail.value;
const year = this.years[values[0]];
const month = this.months[values[1]];
this.updateDays(year, month);
if (values[2] >= this.days.length) {
values[2] = this.days.length - 1;
}
this.pickerValue = values;
},
resetPicker() {
this.initDatePicker();
this.currentDateTab = 0;
},
confirmTime() {
const year = this.years[this.pickerValue[0]];
const month = this.months[this.pickerValue[1]];
const day = this.days[this.pickerValue[2]];
const date = new Date(year, month - 1, day);
const weekDays = ["日", "一", "二", "三", "四", "五", "六"];
const weekDay = weekDays[date.getDay()];
this.timeDetail = {
date: `${year}-${month}-${day}`,
time: this.timeSlot,
displayText: `预约 周${weekDay} ${this.timeSlot}`
};
this.appointmentTime = this.timeDetail.displayText;
this.closeTimePicker();
},
handleAddressSelected(address) {
common_vendor.index.__f__("log", "at pages/subcomponent/order_edit.vue:356", "接收到选中的地址:", address);
this.selectedAddress = address;
this.address = address.address;
this.$forceUpdate();
},
handleTimeSelected(time) {
this.timeDetail = time;
this.appointmentTime = time.displayText;
},
showRules() {
common_vendor.index.navigateTo({
url: "/pages/rules/recycle"
});
},
toggleAgreement() {
this.agreed = !this.agreed;
},
viewAgreement() {
common_vendor.index.navigateTo({
url: "/pages/agreement/service"
});
},
viewPrivacy() {
common_vendor.index.navigateTo({
url: "/pages/agreement/privacy"
});
},
submitOrder() {
if (!this.agreed) {
return common_vendor.index.showToast({
title: "请先同意服务协议",
icon: "none"
});
}
if (!this.selectedAddress) {
return common_vendor.index.showToast({
title: "请选择取件地址",
icon: "none"
});
}
if (!this.timeDetail.date) {
return common_vendor.index.showToast({
title: "请选择上门时间",
icon: "none"
});
}
if (this.selectedItems.length === 0) {
return common_vendor.index.showToast({
title: "请选择回收物品",
icon: "none"
});
}
common_vendor.index.showLoading({
title: "提交中..."
});
({
address: this.selectedAddress,
time: this.timeDetail,
items: this.selectedItems,
totalCount: this.totalCount,
totalPrice: this.totalPriceRange
});
setTimeout(() => {
common_vendor.index.hideLoading();
common_vendor.index.showToast({
title: "修改成功",
icon: "success"
});
setTimeout(() => {
common_vendor.index.navigateBack();
}, 1500);
}, 1e3);
},
decreaseQuantity(index) {
if (this.selectedItems[index].quantity > 1) {
this.selectedItems[index].quantity--;
}
},
increaseQuantity(index) {
this.selectedItems[index].quantity++;
}
},
onLoad(options) {
if (options.id) {
this.addressDetail = {
province: "海南省",
city: "海口市",
district: "秀英区",
street: "秀英街道",
address: "5单元1...",
name: "张三",
phone: "13800138000"
};
this.timeDetail = {
date: "2024-03-21",
time: "11:00-13:00",
displayText: "周四 11:00~13:00"
};
}
common_vendor.index.$on("addressSelected", (address) => {
common_vendor.index.__f__("log", "at pages/subcomponent/order_edit.vue:465", "接收到选中的地址:", address);
this.selectedAddress = address;
this.address = address.address;
this.$forceUpdate();
});
},
onUnload() {
common_vendor.index.$off("addressSelected");
},
onShow() {
common_vendor.index.__f__("log", "at pages/subcomponent/order_edit.vue:477", "当前选中的地址:", this.selectedAddress);
if (this.selectedAddress) {
this.address = this.selectedAddress.address;
this.$forceUpdate();
}
const selectedTime = getApp().globalData.selectedTime;
if (selectedTime) {
this.handleTimeSelected(selectedTime);
getApp().globalData.selectedTime = null;
}
},
created() {
this.initDatePicker();
},
watch: {
showTimePicker(val) {
if (val) {
this.updateDays(this.pickerValue[0], this.pickerValue[1]);
}
}
}
};
function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
return common_vendor.e({
a: common_vendor.o((...args) => $options.goBack && $options.goBack(...args)),
b: common_assets._imports_0$3,
c: common_assets._imports_1$2,
d: common_assets._imports_2$2,
e: common_assets._imports_3$1,
f: common_vendor.t($options.displayAddress),
g: common_vendor.o((...args) => $options.selectAddress && $options.selectAddress(...args)),
h: common_vendor.t($data.appointmentTime),
i: common_vendor.o((...args) => $options.openTimePicker && $options.openTimePicker(...args)),
j: common_vendor.f($data.selectedItems, (item, index, i0) => {
return {
a: item.icon,
b: common_vendor.t(item.name),
c: common_vendor.o((...args) => $options.showRules && $options.showRules(...args), index),
d: common_vendor.t(item.desc),
e: common_vendor.t(item.unitPrice),
f: common_vendor.o(($event) => $options.decreaseQuantity(index), index),
g: common_vendor.t(item.quantity),
h: common_vendor.o(($event) => $options.increaseQuantity(index), index),
i: index
};
}),
k: $data.agreed
}, $data.agreed ? {} : {}, {
l: $data.agreed ? 1 : "",
m: common_vendor.o((...args) => $options.toggleAgreement && $options.toggleAgreement(...args)),
n: common_vendor.t($data.totalCount),
o: common_vendor.t($options.totalPriceRange),
p: !$options.canSubmit,
q: common_vendor.o((...args) => $options.submitOrder && $options.submitOrder(...args)),
r: $data.showTimePicker
}, $data.showTimePicker ? {
s: common_vendor.o((...args) => $options.closeTimePicker && $options.closeTimePicker(...args)),
t: common_vendor.o((...args) => $options.resetPicker && $options.resetPicker(...args)),
v: common_vendor.f(["今天", "明天", "后天", "自定义"], (tab, index, i0) => {
return {
a: common_vendor.t(tab),
b: index,
c: $data.currentDateTab === index ? 1 : "",
d: common_vendor.o(($event) => $options.selectDateTab(index), index)
};
}),
w: common_vendor.f($data.years, (year, k0, i0) => {
return {
a: common_vendor.t(year),
b: year
};
}),
x: common_vendor.f($data.months, (month, k0, i0) => {
return {
a: common_vendor.t(month),
b: month
};
}),
y: common_vendor.f($data.days, (day, k0, i0) => {
return {
a: common_vendor.t(day),
b: day
};
}),
z: $data.pickerValue,
A: common_vendor.o((...args) => $options.onPickerChange && $options.onPickerChange(...args)),
B: common_vendor.o((...args) => $options.confirmTime && $options.confirmTime(...args))
} : {});
}
const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["render", _sfc_render], ["__scopeId", "data-v-2cee0a47"]]);
wx.createPage(MiniProgramPage);
//# sourceMappingURL=../../../.sourcemap/mp-weixin/pages/subcomponent/order_edit.js.map