2 lines
4.7 KiB
JavaScript
2 lines
4.7 KiB
JavaScript
"use strict";const e=require("../../common/vendor.js"),t=require("../../utils/api.js");if(!Array){(e.resolveComponent("t-loading")+e.resolveComponent("t-empty")+e.resolveComponent("t-tag")+e.resolveComponent("t-button")+e.resolveComponent("t-stepper")+e.resolveComponent("t-dialog"))()}Math||((()=>"../../uni_modules/tdesign-uniapp/components/loading/loading.js")+(()=>"../../uni_modules/tdesign-uniapp/components/empty/empty.js")+(()=>"../../uni_modules/tdesign-uniapp/components/tag/tag.js")+(()=>"../../uni_modules/tdesign-uniapp/components/button/button.js")+(()=>"../../uni_modules/tdesign-uniapp/components/stepper/stepper.js")+(()=>"../../uni_modules/tdesign-uniapp/components/dialog/dialog.js"))();const a=e.defineComponent({__name:"booking",setup(a){const o=e.ref((()=>{const e=new Date;return`${e.getFullYear()}-${String(e.getMonth()+1).padStart(2,"0")}-${String(e.getDate()).padStart(2,"0")}`})()),l=e.ref([]),n=e.ref(!1),i=e.ref(!1),s=e.ref(null),r=e.ref(1),u=e.ref(""),p=e.ref(!1),c=e.ref(new Date),d=["日","一","二","三","四","五","六"],v=e.ref({}),g=e.ref({}),m=e.computed((()=>`${c.value.getFullYear()}年${c.value.getMonth()+1}月`)),h=e.computed((()=>l.value.reduce(((e,t)=>e+t.current_people),0))),_=e.computed((()=>{const e=c.value.getFullYear(),t=c.value.getMonth(),a=new Date(e,t,1),o=new Date(e,t+1,0),l=new Date,n=[];for(let i=a.getDay()-1;i>=0;i--)n.push({day:"",dateStr:"",isPlaceholder:!0,isOtherMonth:!1,isToday:!1,bookingCount:0,hasBookings:!1});for(let i=1;i<=o.getDate();i++){const a=new Date(e,t,i),o=a.getFullYear(),s=a.getMonth()+1,r=a.getDate(),u=`${o}-${String(s).padStart(2,"0")}-${String(r).padStart(2,"0")}`,p=l.getFullYear(),c=l.getMonth(),d=l.getDate(),m=o===p&&s-1===c&&r===d;n.push({day:i,dateStr:u,isPlaceholder:!1,isOtherMonth:!1,isToday:m,bookingCount:v.value[u]||0,hasBookings:g.value[u]||!1})}return n}));e.onMounted((()=>{e.index.getStorageSync("token")?(y(),f()):e.index.redirectTo({url:"/pages/login/login"})}));const f=async()=>{try{const e=await t.api.timeslots.getList({is_active:!0}),a={},o={};e.forEach((e=>{const t=e.date.split("T")[0];a[t]=(a[t]||0)+e.current_people,o[t]=!0})),v.value=a,g.value=o}catch(e){console.error("加载日期预约统计失败",e)}},y=async()=>{n.value=!0;try{const e=await t.api.timeslots.getList({date:o.value,is_active:!0});l.value=e}catch(e){console.error("加载时间槽失败",e)}finally{n.value=!1}},b=e=>{const t=(e.split("T")[1]||e).split("+")[0].split("Z")[0],[a,o]=t.split(":");return`${a}:${o}`},S=async()=>{if(s.value){p.value=!0;try{await t.api.appointments.create(s.value.id,r.value,u.value),e.index.showToast({title:"预约成功",icon:"success"}),i.value=!1,y(),f()}catch(a){i.value=!1}finally{p.value=!1}}};return(t,a)=>{var c,v,g,f;return e.e({a:e.t(m.value),b:e.f(d,((t,a,o)=>({a:e.t(t),b:t}))),c:e.f(_.value,((t,a,l)=>e.e({a:!t.isPlaceholder},t.isPlaceholder?{}:{b:e.t(t.day)},{c:!t.isPlaceholder&&t.bookingCount>0},!t.isPlaceholder&&t.bookingCount>0?{d:e.t(t.bookingCount)}:{},{e:t.dateStr||`placeholder-${a}`,f:t.isPlaceholder?1:"",g:t.dateStr===o.value?1:"",h:t.isToday?1:"",i:t.hasBookings||t.isPlaceholder?"":1,j:t.hasBookings?1:"",k:e.o((e=>!t.isPlaceholder&&(e=>{o.value=e.dateStr,y()})(t)),t.dateStr||`placeholder-${a}`)}))),d:e.t(o.value),e:h.value>0},h.value>0?{f:e.t(h.value)}:{},{g:n.value},n.value?{h:e.p({loading:!0})}:0===l.value.length?{j:e.p({description:"暂无可预约时间段"})}:{k:e.f(l.value,((t,a,o)=>({a:e.t(b(t.start_time)),b:e.t(b(t.end_time)),c:e.t(t.current_people),d:e.t(t.max_people),e:"6ce25a93-2-"+o,f:e.p({theme:t.current_people>=t.max_people?"danger":"success",size:"small"}),g:e.t(t.current_people>=t.max_people?"已满":"预约"),h:e.o((a=>(t=>{if(p.value)e.index.showToast({title:"正在处理,请稍候",icon:"none"});else{if(!t.is_active||t.current_people>=t.max_people)return console.log("时间槽不可用",t),void e.index.showToast({title:"该时间段已不可用",icon:"none"});s.value=t,r.value=1,u.value="",i.value=!0,console.log("打开弹窗",i.value)}})(t)),t.id),i:"6ce25a93-3-"+o,j:e.p({"t-class":"btn-primary",size:"small",theme:"primary",disabled:!t.is_active||t.current_people>=t.max_people}),k:t.id,l:!t.is_active||t.current_people>=t.max_people?1:""})))},{i:0===l.value.length,l:e.t(o.value),m:e.t((null==(c=s.value)?void 0:c.start_time)?b(s.value.start_time):""),n:e.t((null==(v=s.value)?void 0:v.end_time)?b(s.value.end_time):""),o:e.o((e=>r.value=e)),p:e.p({min:1,max:(null==(g=s.value)?void 0:g.max_people)-(null==(f=s.value)?void 0:f.current_people)||1,disabled:!0,size:"small",modelValue:r.value}),q:e.o(S),r:e.o((e=>i.value=!1)),s:e.o((e=>i.value=e)),t:e.p({title:"预约确认",cancelBtn:"取消",confirmBtn:"确认预约","t-class-confirm":"btn-primary",visible:i.value})})}}}),o=e._export_sfc(a,[["__scopeId","data-v-6ce25a93"]]);wx.createPage(o);
|