wangzhibo
2025-10-23 cad64c1de2c45856b0774933c5801b05b64984e8
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
"use strict";
const common_vendor = require("../../common/vendor.js");
const stores_user = require("../../stores/user.js");
const pages_index_assets = require("./assets.js");
const apiservice_apiService = require("../../apiservice/apiService.js");
const userStore = stores_user.useUserStore();
function getTodayISO() {
  const now = /* @__PURE__ */ new Date();
  const tzOffset = now.getTimezoneOffset() * 6e4;
  return new Date(now - tzOffset).toISOString().split("T")[0];
}
const _sfc_main = {
  data() {
    return {
      today: getTodayISO(),
      //today: new Date().toLocaleDateString('zh-CN', { year: 'numeric', month: '2-digit', day: '2-digit' }).replace(/\//g, '-'),
      booking_sites: pages_index_assets.ASSETS.booking_sites,
      timeSlots: [],
      form: {
        selectedSiteIndex: 0,
        visitdate: "",
        selectedTimeSlotIndex: null,
        contactperson: userStore.username,
        contactphone: userStore.phone,
        personcount: 1
      }
    };
  },
  onShareAppMessage() {
    return {
      title: "欢迎来荆门市园博园游玩!",
      path: "/pages/index/index"
    };
  },
  onShareTimeline() {
    return {
      title: "欢迎来荆门市园博园游玩!"
    };
  },
  watch: {
    "form.selectedSiteIndex": "fetchTimeSlots",
    "form.visitdate": "fetchTimeSlots"
  },
  methods: {
    onVenueChange(e) {
      this.form.selectedSiteIndex = e.detail.value;
      this.form.visitdate = "";
    },
    onDateChange(e) {
      this.form.visitdate = e.detail.value;
    },
    onTimeSlotChange(e) {
      this.form.selectedTimeSlotIndex = e.detail.value;
    },
    async fetchTimeSlots() {
      if (!this.form.visitdate)
        return;
      const sitename = this.booking_sites[this.form.selectedSiteIndex];
      const visitdate = this.form.visitdate;
      apiservice_apiService.apiService.bookingAvailableCount();
      try {
        common_vendor.index.showLoading({
          title: "查询中..."
        });
        const payload = {
          sitename,
          visitdate
        };
        apiservice_apiService.apiService.bookingAvailableCount(payload).then((res) => {
          if (res.code === 1e3) {
            this.timeSlots = [
              `上午(09:00-12:00 余${res.data.am.remain}/共${res.data.am.total}人)`,
              `下午(13:00-17:00 余${res.data.pm.remain}/共${res.data.pm.total}人)`
            ];
            this.selectedTimeSlotIndex = 0;
          } else {
            common_vendor.index.__f__("warn", "at pages/index/booking.vue:181", "查询失败:", res.message);
          }
        }).catch((err) => {
          common_vendor.index.showToast({
            title: "发生错误,请联系管理员",
            icon: "none"
          });
        });
      } catch (err) {
        common_vendor.index.__f__("error", "at pages/index/booking.vue:190", "查询错误:", err);
        common_vendor.index.showToast({
          title: "网络错误",
          icon: "none"
        });
      } finally {
        common_vendor.index.hideLoading();
      }
      this.form.selectedTimeSlotIndex = null;
    },
    incrementCompanions() {
      if (this.form.personcount < 5)
        this.form.personcount++;
    },
    decrementCompanions() {
      if (this.form.personcount > 1)
        this.form.personcount--;
    },
    async submitForm() {
      if (!this.form.contactperson || this.form.contactperson.length > 10) {
        common_vendor.index.showToast({
          title: "姓名不能为空,且最多10个字",
          icon: "none"
        });
        return;
      }
      const phonePattern = /^(\d{11}|(\d{3,4}-?\d{7,8}))$/;
      if (!phonePattern.test(this.form.contactphone)) {
        common_vendor.index.showToast({
          title: "联系电话格式不正确",
          icon: "none"
        });
        return;
      }
      if (!this.form.visitdate) {
        common_vendor.index.showToast({
          title: "请选择预约日期",
          icon: "none"
        });
        return;
      }
      if (this.form.selectedTimeSlotIndex === null) {
        common_vendor.index.showToast({
          title: "请选择预约时段",
          icon: "none"
        });
        return;
      } else {
        const now = /* @__PURE__ */ new Date();
        const currentHour = now.getHours();
        if (this.form.visitdate == this.today && currentHour > 17) {
          common_vendor.index.showToast({
            title: "预约时段已过,请重新选择",
            icon: "none",
            duration: 2e3
          });
          return;
        } else if (this.form.visitdate == this.today && currentHour > 12 && this.form.selectedTimeSlotIndex == 0) {
          common_vendor.index.showToast({
            title: "预约时段已过,请重新选择",
            icon: "none",
            duration: 2e3
          });
          return;
        }
      }
      try {
        common_vendor.index.showLoading({
          title: "保存中..."
        });
        const checkingPayload = {
          uuid: userStore.uuid,
          sitename: this.booking_sites[this.form.selectedSiteIndex],
          visitdate: this.form.visitdate,
          visittimefield: Number(this.form.selectedTimeSlotIndex) === 0 ? "visittimeam" : "visittimepm"
        };
        common_vendor.index.__f__("log", "at pages/index/booking.vue:270", checkingPayload);
        const res = await apiservice_apiService.apiService.bookingCheck(checkingPayload);
        if (res.code === 1e3) {
          common_vendor.index.__f__("log", "at pages/index/booking.vue:273", res.data);
          if (res.data.exist === 0) {
            common_vendor.index.__f__("log", "at pages/index/booking.vue:276", "start saving");
            const payload = {
              uuid: userStore.uuid,
              sitename: this.booking_sites[this.form.selectedSiteIndex],
              visitdate: this.form.visitdate,
              visittimeam: Number(this.form.selectedTimeSlotIndex) === 0 ? "09:00-12:00" : "",
              visittimepm: Number(this.form.selectedTimeSlotIndex) === 1 ? "13:00-17:00" : "",
              contactperson: this.form.contactperson,
              contactphone: this.form.contactphone,
              personcount: this.form.personcount
            };
            common_vendor.index.__f__("log", "at pages/index/booking.vue:288", payload);
            const saveres = await apiservice_apiService.apiService.bookingAdd(payload);
            common_vendor.index.__f__("log", "at pages/index/booking.vue:291", saveres.code);
            if (saveres.code === 1e3) {
              common_vendor.index.showModal({
                title: "预约成功",
                content: "请按时前往场馆,并扫码核销以便入场。",
                showCancel: false,
                confirmText: "我知道了"
              });
              this.form.visitdate = "";
              this.form.selectedTimeSlotIndex = null;
              common_vendor.index.navigateTo({
                url: "/pages/ucenter/my-booking"
              });
            } else {
              common_vendor.index.__f__("warn", "at pages/index/booking.vue:308", "预约失败:", saveres.message);
            }
          } else {
            common_vendor.index.showToast({
              title: "您已有预约相同日期和时段的该场馆信息,请更改信息。",
              icon: "none",
              duration: 3e3
              // 显示 3 秒
            });
          }
        } else {
          common_vendor.index.__f__("warn", "at pages/index/booking.vue:321", "查询失败:", res.message);
        }
      } catch (err) {
        common_vendor.index.__f__("error", "at pages/index/booking.vue:326", "查询错误:", err);
        common_vendor.index.showToast({
          title: "网络错误",
          icon: "none"
        });
      } finally {
        common_vendor.index.hideLoading();
      }
    }
  }
};
function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
  return {
    a: common_vendor.t($data.booking_sites[$data.form.selectedSiteIndex] || "请选择场馆"),
    b: $data.booking_sites,
    c: $data.form.selectedSiteIndex,
    d: common_vendor.o((...args) => $options.onVenueChange && $options.onVenueChange(...args)),
    e: common_vendor.t($data.form.visitdate || "请选择日期"),
    f: $data.form.visitdate,
    g: common_vendor.o((...args) => $options.onDateChange && $options.onDateChange(...args)),
    h: $data.today,
    i: common_vendor.t($data.form.selectedTimeSlotIndex !== null ? $data.timeSlots[$data.form.selectedTimeSlotIndex] : "请选择时段"),
    j: $data.timeSlots,
    k: $data.form.selectedTimeSlotIndex,
    l: common_vendor.o((...args) => $options.onTimeSlotChange && $options.onTimeSlotChange(...args)),
    m: $data.form.contactperson,
    n: common_vendor.o(($event) => $data.form.contactperson = $event.detail.value),
    o: $data.form.contactphone,
    p: common_vendor.o(($event) => $data.form.contactphone = $event.detail.value),
    q: common_vendor.o((...args) => $options.decrementCompanions && $options.decrementCompanions(...args)),
    r: common_vendor.t($data.form.personcount),
    s: common_vendor.o((...args) => $options.incrementCompanions && $options.incrementCompanions(...args)),
    t: common_vendor.o((...args) => $options.submitForm && $options.submitForm(...args))
  };
}
const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["render", _sfc_render]]);
_sfc_main.__runtimeHooks = 6;
wx.createPage(MiniProgramPage);
//# sourceMappingURL=../../../.sourcemap/mp-weixin/pages/index/booking.js.map