diff --git a/components/delivery-time-op/delivery-time-op.vue b/components/delivery-time-op/delivery-time-op.vue
new file mode 100644
index 0000000..98a3e2a
--- /dev/null
+++ b/components/delivery-time-op/delivery-time-op.vue
@@ -0,0 +1,324 @@
+
+
+
+
+
+
+
+ {{ title }}
+ ×
+
+
+
+
+
+ {{ item.date_title }}
+
+
+
+
+
+
+ {{ item.time_title }}
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/config/config.js b/config/config.js
index 7c3c038..9d1e38a 100644
--- a/config/config.js
+++ b/config/config.js
@@ -383,6 +383,7 @@ export default {
"sel": ip + "shop/userCart/sel",
// "checkout": iu + "?ctl=Cart&met=checkout&typ=json",
"checkout": ip + "shop/userCart/checkout",
+ "getTimeSlots":ip+"/shop/userOrder/booking_time_args",
"checkDelivery": iu + "?ctl=Cart&met=checkDelivery&typ=json",
"order": iu + "?ctl=Cart&met=order&typ=e",
// "getselect":iu + "?ctl=Cart&met=getselect&typ=json",
diff --git a/member/order/detail.vue b/member/order/detail.vue
index d2e909c..be9c18d 100644
--- a/member/order/detail.vue
+++ b/member/order/detail.vue
@@ -302,6 +302,14 @@
deliveryTypeName(OrderInfo.delivery_type_id)
}}
+
+
+ 预约时间
+ {{
+ OrderInfo.booking_begin_time
+ }}
+
+
{{
item.show_typename
}}{{ item.product_name }}
+ >{{ item.product_name }}_
x{{ item.order_item_quantity }}
@@ -615,10 +623,10 @@
-
+
¥{{
- item.item_unit_price
+ item.order_item_amount
}}
diff --git a/package.json b/package.json
new file mode 100644
index 0000000..24d5500
--- /dev/null
+++ b/package.json
@@ -0,0 +1,18 @@
+{
+ "id": "delivery-time-op",
+ "name": "仿美团选择预送达时间组件delivery-time-op",
+ "displayName": "仿美团选择预送达时间组件delivery-time-op",
+ "version": "1.0.5",
+ "description": "简单实用的选择时间组件,源码简单易懂注释清楚,可根据需求随意更改方案。",
+ "keywords": [
+ "点餐",
+ "时间选择",
+ "送达时间"
+ ],
+ "dcloudext": {
+ "category": [
+ "前端组件",
+ "通用组件"
+ ]
+ }
+}
\ No newline at end of file
diff --git a/pages/checkout/checkout.vue b/pages/checkout/checkout.vue
index 6a8bb46..ed6ed62 100644
--- a/pages/checkout/checkout.vue
+++ b/pages/checkout/checkout.vue
@@ -46,7 +46,7 @@
style="border-radius:50%;width:26rpx;height:26rpx;border:1px solid #db384c" />
{{__('门店自提')}}
-->
-
+
-
@@ -126,14 +126,41 @@
-
+ -->
-
-
-
+
+
+
+
+
+ 立即配送
+ {{ immediateDeliveryTime }}
+
+
+ 预约配送
+ {{ activeTab === 'scheduled' ? dateTitle && selectedTime ? dateTitle + ' ' + selectedTime : '请选择时间' : '请选择时间' }} >
+
+
+
+
+
+
+ >
+
+
@@ -766,7 +793,7 @@
import paymentBox from "../../components/payment-box.vue";
import loginPopup from "../../components/loginPopup.vue";
import { mapState, mapMutations } from "vuex";
-
+import deliveryTimeOp from '@/components/delivery-time-op/delivery-time-op.vue'
export default {
data() {
return {
@@ -783,6 +810,10 @@ export default {
items: [],
UserMembership: {},
},
+ selectedTime:"",
+ dateTitle:"",
+ activeTab: "immediate",
+ content:[],
user_voucher_ids: [],
redemption_ids: [],
order_message: {},
@@ -792,6 +823,7 @@ export default {
paymentData: {},
integral: "",
discount: 0,
+ immediateDeliveryTime:"",
disbursements: "",
IsUseCoupon: 1,
canSelfpick: 0, //是否允许自提
@@ -874,6 +906,7 @@ export default {
components: {
paymentBox,
loginPopup,
+ deliveryTimeOp
},
computed: mapState([
"Config",
@@ -1001,6 +1034,7 @@ export default {
});
// var n = this.shopInfo.VendorFeatureSet;
// n.indexOf("Membership") > -1 ? this.setData({isMembership: true}) : this.setData({isMembership: false}), n.indexOf("ECashCard") > -1 ? this.setData({isECashCard: true}) : this.setData({isECashCard: false}), n.indexOf("Coupon") > -1 ? this.setData({isCoupon: true}) : this.setData({isCoupon: false}), n.indexOf("TmplMsg") > -1 ? this.setData({isTmplMsg: true}) : this.setData({isTmplMsg: false})
+ this.getTimeSlots();
},
onUnload: function () {
//移除通知
@@ -1039,6 +1073,50 @@ export default {
that.getCartList();
});
},
+ setActiveTab(tab) {
+ this.activeTab = tab;
+ if (tab === 'immediate') {
+ this.selectedTime = "";
+ this.dateTitle = "";
+ this.booking_state = 1; // 立即下单
+ } else {
+ this.booking_state = 2; // 预订单
+ }
+ },
+ openTimePicker(){
+ this.$refs.model.open();
+ },
+ closeTimePicker() {
+ this.$refs.model.model = false; // 关闭时间选择器
+ },
+ // 处理日期选择回调
+ dataCallback(item) {
+ console.log('日期选择回调', item);
+ // 你可以在这里处理日期选择的逻辑
+ },
+ timeCallback(item) {
+ console.log('时间选择回调', item);
+ this.selectedTime = item.time_title; // 选中的时间
+ this.dateTitle = item.date_title; // 选中的日期
+
+ if (this.selectedTime !== "立即送出") {
+ this.activeTab = 'scheduled'; // 如果选择的时间不是“立即送出”,激活“预约配送”
+
+ // 直接使用从接口获取的时间参数
+ this.booking_at = item.booking_at; // 预约时间戳
+ this.booking_begin_time = item.booking_begin_time; // 预约开始时间
+ this.booking_end_time = item.booking_end_time; // 预约结束时间
+ this.booking_state = 2; // 预订单状态
+ } else {
+ this.activeTab = 'immediate'; // 如果选择的时间是“立即送出”,激活“立即配送”
+ this.booking_state = 1; // 立即下单状态
+ }
+
+ // 打印确认字段是否正确赋值
+ console.log('booking_at:', this.booking_at);
+ console.log('booking_begin_time:', this.booking_begin_time);
+ console.log('booking_end_time:', this.booking_end_time);
+ },
inputud_name: function (e) {
this.setData({
ud_name: e.detail.value,
@@ -1157,6 +1235,30 @@ export default {
});
//this.getCartList()
},
+ async getTimeSlots() {
+ try {
+ const res = await uni.request({
+ url: this.Config.URL.cart.getTimeSlots, // 替换为实际的接口地址
+ method: 'GET',
+ data: {
+ store_ids: 80
+ }
+ });
+
+ if (res[1].statusCode === 200) {
+ console.log("接口返回的数据", res[1].data); // 打印返回的数据
+ if (res[1].data && Array.isArray(res[1].data.data)) {
+ this.content = res[1].data.data;
+ } else {
+ console.error('接口返回的数据格式不正确', res[1].data);
+ }
+ } else {
+ console.error('获取时间槽列表失败:', res[1].data.message);
+ }
+ } catch (error) {
+ console.error('请求时间槽列表时发生错误:', error);
+ }
+ },
RefreshRedemption: function (options) {
var that = this;
var redemption_items = that.$.parseJSON(options.val);
@@ -1537,260 +1639,211 @@ export default {
) || null
);
},
- submitorder: function (e) {
- let that = this;
- if (that.$.isNull(that.order_id)) {
- var params = that.urlArgs;
+submitorder: function (e) {
+ let that = this;
+ if (that.$.isNull(that.order_id)) {
+ var params = that.urlArgs;
- if (that.user_voucher_ids.length == 1) {
- params.user_voucher_id = that.user_voucher_ids[0];
- }
+ if (that.user_voucher_ids.length == 1) {
+ params.user_voucher_id = that.user_voucher_ids[0];
+ }
- if (this.ud_id == 0) {
- let msg = that.__("请选择你的收货地址!");
+ if (this.ud_id == 0) {
+ let msg = that.__("请选择你的收货地址!");
+ if (that.isVirtual) {
+ msg = that.__("请选择你的个人联系信息!");
+ }
+ that.$.showModal({
+ title: that.__("提示"),
+ showCancel: false,
+ content: msg,
+ });
+ return;
+ }
- if (that.isVirtual) {
- msg = that.__("请选择你的个人联系信息!");
- }
+ if (this.isVirtual) {
+ var datetime = this.date + " " + this.time,
+ n = datetime.replace(/-/g, "/");
+ var r = new Date();
+ var i = new Date(n);
+ var s = r.getTime(),
+ o = i.getTime();
+ if (o - s < 0) {
+ that.$.showModal({
+ title: "提示",
+ showCancel: false,
+ content: "您选择的预约时间已不在服务预约时间范围内!",
+ });
+ return;
+ }
+
+ if (this.product_service_date_flag)
+ if (that.$.isNull(this.date) || that.$.isNull(this.time)) {
that.$.showModal({
- title: that.__("提示"),
+ title: "提示",
showCancel: false,
- content: msg,
+ content: "请选择预约服务日期与时间!",
});
return;
}
+ }
- if (this.isVirtual) {
- var datetime = this.date + " " + this.time,
- n = datetime.replace(/-/g, "/");
- var r = new Date();
- var i = new Date(n);
- var s = r.getTime(),
- o = i.getTime();
+ // 设置预约相关字段
+ if (that.booking_state === 2) {
+ // 预订单
+ params.booking_at = that.booking_at; // 预约时间戳
+ params.booking_begin_time = that.booking_begin_time; // 预约开始时间
+ params.booking_end_time = that.booking_end_time; // 预约结束时间
+ params.booking_state = that.booking_state; // 预订单状态
+ } else {
+ // 立即下单
+ params.booking_state = 1; // 立即下单状态
+ }
- if (o - s < 0) {
- that.$.showModal({
- title: "提示",
- showCancel: false,
- content: "您选择的预约时间已不在服务预约时间范围内!",
- });
- return;
- }
+ var paymentTypeId = that.submitinfo.items[0].items[0].payment_type_id;
+ params.payment_form_id = paymentTypeId;
- if (this.product_service_date_flag)
- if (that.$.isNull(this.date) || that.$.isNull(this.time)) {
- that.$.showModal({
- title: "提示",
- showCancel: false,
- content: "请选择预约服务日期与时间!",
- });
- return;
- }
+ params.user_voucher_ids = JSON.stringify(that.user_voucher_ids);
+ params.redemption_ids = JSON.stringify(that.redemption_ids);
+ params.ud_id = params.ud_id || that.ud_id;
+ params.ifcart = that.ifcart; // 传入cart_id时直接购买,未传时走购物车
+ params.cart_id = that.cart_id;
+ params.payment_type_id = that.StateCode.PAYMENT_TYPE_ONLINE;
- /*
- if (!/^1[23456789]\d{9}$/.test(this.phone) && this.product_service_contactor_flag) {
- that.$.showModal({title: "提示", showCancel: false, content: "手机号有误!"});
- return
- }
+ if (that.selfpickFlag || that.storeServeFlag) {
+ params.delivery_type_id = 5;
+ } else if (that.addressFlag) {
+ params.delivery_type_id = 10;
+ } else if (that.intraCityService) {
+ params.delivery_type_id = 16;
+ }
- if (this.sp == 1) {
- if (that.$.isNull(this.ud_name) && this.product_service_contactor_flag) {
- that.$.showModal({title: "提示", showCancel: false, content: "请填写预约人姓名!"});
- return
- }
- if (that.$.isNull(this.phone) && this.product_service_contactor_flag) {
- that.$.showModal({title: "提示", showCancel: false, content: "请填写预约人手机号码!"});
- return
- }
- } else {
- if (that.$.isNull(this.ud_name) && this.product_service_contactor_flag) {
- that.$.showModal({title: "提示", showCancel: false, content: "请填写预约人姓名!"});
- return
- }
- if (that.$.isNull(this.phone) && this.product_service_contactor_flag) {
- that.$.showModal({title: "提示", showCancel: false, content: "请填写预约人手机号码!"});
- return
- }
- if (that.$.isNull(this.detail)) {
- that.$.showModal({title: "提示", showCancel: false, content: "请填写预约人服务地址!"});
- return
- }
- }
- */
- }
- var paymentTypeId = that.submitinfo.items[0].items[0].payment_type_id;
- params.payment_form_id = paymentTypeId;
+ params.invoice_type_id = 1;
+ params.order_invoice_title = "";
- params.user_voucher_ids = JSON.stringify(that.user_voucher_ids);
- params.redemption_ids = JSON.stringify(that.redemption_ids);
- params.ud_id = params.ud_id || that.ud_id;
- params.ifcart = that.ifcart; // 传入cart_id时直接购买,未传时走购物车
- params.cart_id = that.cart_id;
- params.payment_type_id = that.StateCode.PAYMENT_TYPE_ONLINE;
+ params.order_message = JSON.stringify(that.order_message);
- // 决定配送方式
- if (that.selfpickFlag || that.storeServeFlag) {
- params.delivery_type_id = 5;
- } else if (that.addressFlag) {
- params.delivery_type_id = 10;
- } else if (that.intraCityService) {
- params.delivery_type_id = 16;
- }
- // params.delivery_type_id = that.selfpickFlag ? 5 : 10; //是否自提; //DELIVERY_TYPE_SELF_PICK_UP = 5
- params.delivery_time_id = 1;
+ params.virtual_service_date = that.date;
+ params.virtual_service_time = that.date + " " + that.time;
+ params.chain_id = that.chain_id;
+ params.checked_store = that.checked_store;
- params.invoice_type_id = 1;
- params.order_invoice_title = "";
+ params.distributor_id = uni.getStorageSync("store_id");
+ params.salesperson_id = that.salesperson_id;
+ params.user_invoice_id = that.user_invoice_id;
- params.order_message = JSON.stringify(that.order_message);
+ let source_item_id = uni.getStorageSync("source_item_id");
+ params.source_item_id = source_item_id;
- params.virtual_service_date = that.date;
- params.virtual_service_time = that.date + " " + that.time;
- params.chain_id = that.chain_id;
- params.checked_store = that.checked_store;
+ params.is_delivery = that.selfpickFlag ? 0 : 1; //是否自提
+ params.kind_id = that.kind_id;
+ params.kind_id = that.kind_id;
+ console.log("哈哈哈哈哈哈",params)
+ that.$.request({
+ url: this.Config.URL.user.order_add,
+ data: params,
+ method: "POST",
+ success: function (data, status, msg, code) {
+ if (200 == status) {
+ // 删除旧数据
+ if (source_item_id) {
+ let source_item_id_row = JSON.parse(source_item_id);
+ for (
+ let store_idx = 0;
+ store_idx < data.items.length;
+ store_idx++
+ ) {
+ for (
+ let item_idx = 0;
+ item_idx < data.items[store_idx].items.length;
+ item_idx++
+ ) {
+ let order_item_id =
+ data.items[store_idx].items[item_idx].item_id;
- params.distributor_id = uni.getStorageSync("store_id");
- params.salesperson_id = that.salesperson_id;
- params.user_invoice_id = that.user_invoice_id;
-
- let source_item_id = uni.getStorageSync("source_item_id");
- params.source_item_id = source_item_id;
-
- params.is_delivery = that.selfpickFlag ? 0 : 1; //是否自提
- params.kind_id = that.kind_id;
- that.$.request({
- url: this.Config.URL.user.order_add,
- data: params,
- method: "POST",
- success: function (data, status, msg, code) {
- //console.info(JSON.stringify(data));
- if (200 == status) {
- //删除旧数据
- if (source_item_id) {
- let source_item_id_row = JSON.parse(source_item_id);
- for (
- let store_idx = 0;
- store_idx < data.items.length;
- store_idx++
- ) {
- for (
- let item_idx = 0;
- item_idx < data.items[store_idx].items.length;
- item_idx++
- ) {
- let order_item_id =
- data.items[store_idx].items[item_idx].item_id;
-
- //完成后删除数据吧
- if (source_item_id) {
- for (var tk in source_item_id_row) {
- if (source_item_id_row[tk].u) {
- if (tk == order_item_id) {
- delete source_item_id_row[tk];
- } else {
- let time = parseInt(Date.parse(new Date()) / 100);
- //判断是否超时
- if (time - source_item_id_row[tk].t > 86400 * 30) {
- delete source_item_id_row[tk];
- }
- }
- } else {
+ if (source_item_id) {
+ for (var tk in source_item_id_row) {
+ if (source_item_id_row[tk].u) {
+ if (tk == order_item_id) {
+ delete source_item_id_row[tk];
+ } else {
+ let time = parseInt(Date.parse(new Date()) / 100);
+ if (time - source_item_id_row[tk].t > 86400 * 30) {
delete source_item_id_row[tk];
}
}
+ } else {
+ delete source_item_id_row[tk];
}
}
}
-
- uni.setStorageSync(
- "source_item_id",
- JSON.stringify(source_item_id_row)
- );
- }
-
- that.setData({
- order_id: data.order_id.join(","),
- });
-
- if (data.gb_id) {
- that.isFightGroup = data.gb_id;
- }
-
- that.setData({
- paymentData: {
- order_id: that.order_id,
- orderSelMoneyAmount: data.orderSelMoneyAmount.toFixed(2),
-
- user_money: data.user_money,
- user_points: data.user_points,
- user_recharge_card: that.userInfo.user_recharge_card,
- user_sp: that.userInfo.user_sp,
- },
- });
-
- that.reloadUserResource(function (user_info) {});
-
- /*
- that.$.showToast({
- title: "添加订单成功!"
- });
- */
- //
- // that.gotopay();
- // 判断如果是虚拟商品
- // const item = that.submitinfo.items[0].items[0];
- // if(item.payment_type_id === 1){
- // that.$.gotopage("/member/order/detail?on=" + that.order_id)
- // } else {
- that.notice.postNotificationName("GotoPayCheckout");
- // }
- } else {
- /*
- setTimeout(() => {
-
- that.setData({
- showPopupFlag: true,
- popupMsg: msg
- });
-
- }, 10);
- */
- if (
- (data && data.hasOwnProperty("mobile_is_bind")) ||
- code == 77011
- ) {
- that.$.confirm(
- msg,
- function (data) {
- if (data.confirm) {
- //绑定手机操作
- that.$.gopage("/member/member/bindphone");
- }
- },
- true
- );
- } else {
- that.$.confirm(msg);
}
}
- },
- fail: function (data, status, msg, code) {
- that.$.showToast({
- title: msg,
- });
- },
- });
- } else {
- const item = that.submitinfo.items[0].items[0];
- if (item.payment_type_id === 1) {
- that.$.gotopage(`/member/order/detail?on=${that.order_id}&subscribe=1`);
+
+ uni.setStorageSync(
+ "source_item_id",
+ JSON.stringify(source_item_id_row)
+ );
+ }
+
+ that.setData({
+ order_id: data.order_id.join(","),
+ });
+
+ if (data.gb_id) {
+ that.isFightGroup = data.gb_id;
+ }
+
+ that.setData({
+ paymentData: {
+ order_id: that.order_id,
+ orderSelMoneyAmount: data.orderSelMoneyAmount.toFixed(2),
+
+ user_money: data.user_money,
+ user_points: data.user_points,
+ user_recharge_card: that.userInfo.user_recharge_card,
+ user_sp: that.userInfo.user_sp,
+ },
+ });
+
+ that.reloadUserResource(function (user_info) {});
+
+ that.notice.postNotificationName("GotoPayCheckout");
} else {
- that.gotopay();
+ if (
+ (data && data.hasOwnProperty("mobile_is_bind")) ||
+ code == 77011
+ ) {
+ that.$.confirm(
+ msg,
+ function (data) {
+ if (data.confirm) {
+ that.$.gopage("/member/member/bindphone");
+ }
+ },
+ true
+ );
+ } else {
+ that.$.confirm(msg);
+ }
}
- //that.gotopay()
- }
- },
+ },
+ fail: function (data, status, msg, code) {
+ that.$.showToast({
+ title: msg,
+ });
+ },
+ });
+ } else {
+ const item = that.submitinfo.items[0].items[0];
+ if (item.payment_type_id === 1) {
+ that.$.gotopage(`/member/order/detail?on=${that.order_id}&subscribe=1`);
+ } else {
+ that.gotopay();
+ }
+ }
+},
gotopay: function (e) {
//console.info('gotopay');
setTimeout(() => {
@@ -2251,12 +2304,28 @@ export default {
urlArgs: urlArgs,
});
},
+ calculateImmediateDeliveryTime() {
+ const now = new Date();
+ const startTime = new Date(now.getTime() + 25 * 60 * 1000); // 当前时间 + 25 分钟
+ const endTime = new Date(now.getTime() + 35 * 60 * 1000); // 当前时间 + 35 分钟
+
+ const formatTime = (date) => {
+ const hours = String(date.getHours()).padStart(2, '0');
+ const minutes = String(date.getMinutes()).padStart(2, '0');
+ return `${hours}:${minutes}`;
+ };
+
+ this.immediateDeliveryTime = `预计${formatTime(startTime)}-${formatTime(endTime)}送达`;
+ },
+ },
+ mounted() {
+ this.calculateImmediateDeliveryTime();
},
};
-