|
|
@@ -50,7 +50,9 @@ Page({
|
|
|
tomorrowDay: '',
|
|
|
timeIntervals: [],
|
|
|
columns: [],
|
|
|
- combinedTextValue: '',
|
|
|
+ selectTimeshow: false,
|
|
|
+ time: '',//取件时间
|
|
|
+ userAddr: '',//取件地址
|
|
|
sendInfo: {},
|
|
|
currentSelectedIndex: -1, // 初始没有选中项,索引设为 -1
|
|
|
cancelPay: false,
|
|
|
@@ -180,6 +182,133 @@ Page({
|
|
|
}
|
|
|
})
|
|
|
},
|
|
|
+ /**
|
|
|
+ * 选择时间和地址
|
|
|
+ */
|
|
|
+ choose(e){
|
|
|
+ let type = e.currentTarget.dataset.type
|
|
|
+ if(type == 'time'){
|
|
|
+ this.getDayTime()
|
|
|
+ this.getTime()
|
|
|
+ let day = []
|
|
|
+ day.push({
|
|
|
+ id: 1,
|
|
|
+ text: this.data.nomDay
|
|
|
+ }, {
|
|
|
+ id: 2,
|
|
|
+ text: this.data.tomorrowDay
|
|
|
+ })
|
|
|
+ let data = []
|
|
|
+ data.push({
|
|
|
+ values: day,
|
|
|
+ className: 'column1',
|
|
|
+ }, {
|
|
|
+ values: this.data.timeIntervals,
|
|
|
+ defaultIndex: 2,
|
|
|
+ className: 'column2',
|
|
|
+ })
|
|
|
+ this.setData({
|
|
|
+ selectTimeshow: true,
|
|
|
+ columns: data
|
|
|
+ })
|
|
|
+ }else{//选择地址
|
|
|
+ wx.navigateTo({
|
|
|
+ url: '/pages/delivery-address/delivery-address?order=write',
|
|
|
+ })
|
|
|
+ }
|
|
|
+ },
|
|
|
+ onCancel: function () {
|
|
|
+ this.setData({
|
|
|
+ selectTimeshow: false
|
|
|
+ })
|
|
|
+ },
|
|
|
+ onConfirm(event) {
|
|
|
+ const {
|
|
|
+ picker,
|
|
|
+ value,
|
|
|
+ index
|
|
|
+ } = event.detail;
|
|
|
+ var currentDate = new Date();
|
|
|
+ var currentYear = currentDate.getFullYear();
|
|
|
+ if (value.length >= 2) {
|
|
|
+ const text1 = value[0].text; //text1为12月25日
|
|
|
+ const text2 = value[1].text.slice(0, 5); //text2为15:00
|
|
|
+ const month = ("0" + (parseInt(text1.split("月")[0]))).slice(-2); // 将中文月格式转换为数字(注意要减1,因为月份是从0开始计数),并补0
|
|
|
+ const day = text1.split("月")[1].split("日")[0];
|
|
|
+ const hour = text2.split(":")[0];
|
|
|
+ const minute = text2.split(":")[1];
|
|
|
+ const combinedText = `${currentYear}-${month}-${day} ${hour}:${minute}:00`;
|
|
|
+ let dateObj = new Date(combinedText);
|
|
|
+ let timestamp = Math.floor(dateObj.getTime() / 1000);
|
|
|
+ // 获取配送费
|
|
|
+ let that = this
|
|
|
+ console.log(combinedText);
|
|
|
+ this.setData({
|
|
|
+ time: combinedText,
|
|
|
+ selectTimeshow: false
|
|
|
+ });
|
|
|
+ }
|
|
|
+ },
|
|
|
+
|
|
|
+ // 获取今明天并转换
|
|
|
+ getDayTime: function () {
|
|
|
+ const today = new Date();
|
|
|
+ const month = (today.getMonth() + 1).toString().padStart(2, '0');
|
|
|
+ const day = today.getDate().toString().padStart(2, '0');
|
|
|
+ const todayFormat = `${month}月${day}日(今天)`;
|
|
|
+ const tomorrow = new Date(today.getTime() + 24 * 60 * 60 * 1000);
|
|
|
+ const tomorrowMonth = (tomorrow.getMonth() + 1).toString().padStart(2, '0');
|
|
|
+ const tomorrowDay = tomorrow.getDate().toString().padStart(2, '0');
|
|
|
+ const tomorrowFormat = `${tomorrowMonth}月${tomorrowDay}日(明天)`;
|
|
|
+ this.setData({
|
|
|
+ nomDay: todayFormat,
|
|
|
+ tomorrowDay: tomorrowFormat
|
|
|
+ })
|
|
|
+ },
|
|
|
+
|
|
|
+ // 时间段转换
|
|
|
+ getTime: function (selectedDate) {
|
|
|
+ const timeIntervals = [];
|
|
|
+ // 如果没有传入日期参数(首次加载等情况),则使用当前日期
|
|
|
+ const now = selectedDate ? new Date(selectedDate) : new Date();
|
|
|
+ if (isNaN(now.getTime())) {
|
|
|
+ console.error('传入的日期格式不正确,无法解析为有效日期');
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ const currentTimeStamp = now.getTime();
|
|
|
+ for (let hour = 0; hour < 23; hour++) {
|
|
|
+ const start = hour.toString().padStart(2, '0') + ':00';
|
|
|
+ const end = (hour + 1).toString().padStart(2, '0') + ':00';
|
|
|
+ const interval = start + '~' + end;
|
|
|
+ // 创建对应时间段开始时间的日期对象
|
|
|
+ const startDate = new Date(now);
|
|
|
+ startDate.setHours(hour, 0, 0, 0);
|
|
|
+ const startTimestamp = startDate.getTime();
|
|
|
+ // 通过比较时间戳来判断时间段是否已过去
|
|
|
+ const hidden = startTimestamp < currentTimeStamp;
|
|
|
+ timeIntervals.push({
|
|
|
+ text: interval,
|
|
|
+ disabled: hidden
|
|
|
+ });
|
|
|
+ }
|
|
|
+ this.setData({
|
|
|
+ timeIntervals
|
|
|
+ });
|
|
|
+ },
|
|
|
+
|
|
|
+ // 日期转换方法
|
|
|
+ convertDateToNumber: function (dateStr) {
|
|
|
+ if (!dateStr) {
|
|
|
+ throw new Error('日期字符串不能为空');
|
|
|
+ }
|
|
|
+ dateStr = dateStr.trim();
|
|
|
+ let parts = dateStr.match(/(\d+)月(\d+)日/);
|
|
|
+ if (!parts) {
|
|
|
+ throw new Error('日期格式不正确,请按照XX月XX日的格式输入');
|
|
|
+ }
|
|
|
+ return new Date(2024, parseInt(parts[1]) - 1, parseInt(parts[2]));
|
|
|
+ },
|
|
|
+
|
|
|
|
|
|
/**
|
|
|
* 生命周期函数--监听页面初次渲染完成
|