reservation.js 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462
  1. "use strict";
  2. const common_vendor = require("../../common/vendor.js");
  3. const _sfc_main = {
  4. props: {
  5. isQuantum: {
  6. type: Boolean,
  7. default: true
  8. },
  9. isMultiple: {
  10. //是否多选
  11. type: Boolean,
  12. default: false
  13. },
  14. // isSection: { //预约时间段
  15. // type: Boolean,
  16. // default: false
  17. // },
  18. disableText: {
  19. //禁用显示的文本
  20. type: String,
  21. default: "已预约"
  22. },
  23. disableSumText: {
  24. type: String,
  25. default: "已约满"
  26. },
  27. undisableText: {
  28. //未禁用显示的文本
  29. type: String,
  30. default: "可预约"
  31. },
  32. // timeInterval: { // 时间间隔,小时为单位
  33. // type: Number,
  34. // default: 1
  35. // },
  36. selectedTabColor: {
  37. // 日期栏选中的颜色
  38. type: String,
  39. default: "#51bf81"
  40. },
  41. selectedItemColor: {
  42. // 时间选中的颜色
  43. type: String,
  44. default: "#51bf81"
  45. },
  46. // beginTime: {
  47. // type: String,
  48. // default: "08:30"
  49. // },
  50. // endTime: {
  51. // type: String,
  52. // default: "19:30"
  53. // },
  54. appointTime: {
  55. // 预约的时间
  56. type: Array,
  57. default() {
  58. return [];
  59. }
  60. }
  61. },
  62. watch: {
  63. //监控appointTime变化,去控制预约时间的状态
  64. appointTime: {
  65. handler(val) {
  66. if (val && val.length) {
  67. this.initOnload();
  68. }
  69. }
  70. },
  71. //监控排课列表的里面的属性reservation_status的值,从而保持前后端预约时间状态的一致性。
  72. shcedule_list: {
  73. handler(val) {
  74. if (val && val.length) {
  75. this.initOnload();
  76. }
  77. }
  78. }
  79. },
  80. data() {
  81. return {
  82. data: [
  83. {
  84. "teacher_id": 6,
  85. "teacher_name": "张老师",
  86. "list": [
  87. {
  88. "id": 4,
  89. "course_id": 1,
  90. "teacher_id": 6,
  91. "start_time": 1732060800,
  92. "end_time": 1732063500,
  93. "duration": 45,
  94. "course_number": 0,
  95. "reservation_number": 0,
  96. "teacher_name": "张老师",
  97. "teacher_desc": "擅长舞蹈",
  98. "course_name": "拳击初级课",
  99. "course_image": "../../static/logo2.jpg",
  100. "course_desc": "拳击讲解",
  101. "address": "一方天地",
  102. "reservation_status": 0
  103. },
  104. {
  105. "id": 6,
  106. "course_id": 1,
  107. "teacher_id": 6,
  108. "start_time": 1732064400,
  109. "end_time": 1732068e3,
  110. "duration": 60,
  111. "course_number": 30,
  112. "reservation_number": 0,
  113. "teacher_name": "张老师",
  114. "teacher_desc": "擅长舞蹈",
  115. "course_name": "拳击初级课",
  116. "course_image": "../../static/logo2.jpg",
  117. "course_desc": "拳击讲解",
  118. "address": "一方天地",
  119. "reservation_status": 1
  120. }
  121. ]
  122. },
  123. {
  124. "teacher_id": 7,
  125. "teacher_name": "王老师",
  126. "list": [
  127. {
  128. "id": 7,
  129. "course_id": 1,
  130. "teacher_id": 7,
  131. "start_time": 1732520086,
  132. "end_time": 1732520086,
  133. "duration": 60,
  134. "course_number": 30,
  135. "reservation_number": 0,
  136. "teacher_name": "王老师",
  137. "teacher_desc": "从业20年,资深老教室",
  138. "course_name": "拳击初级课",
  139. "course_image": "../../static/logo2.jpg",
  140. "course_desc": "拳击讲解",
  141. "address": "一方天地",
  142. "reservation_status": 1
  143. }
  144. ]
  145. }
  146. ],
  147. shcedule_list: [],
  148. //排课列表
  149. teacher_desc: "",
  150. //当前老师的一个介绍
  151. course_name: "",
  152. //当前老师的名字
  153. course_image: "",
  154. //当前老师的图片
  155. orders_product_id: 0,
  156. //商品id
  157. course_id: 0,
  158. //课程id
  159. schedule_id: 0,
  160. //排课id
  161. teacherActive: -1,
  162. orderDateTime: "暂无选择",
  163. // 选中时间
  164. orderTimeArr: {},
  165. //多选的时间
  166. dateArr: [],
  167. //日期数据
  168. timeArr: [],
  169. //时间数据
  170. nowDate: "",
  171. // 当前日期
  172. dateActive: -1,
  173. //选中的日期索引
  174. timeActive: 0,
  175. //选中的时间索引
  176. timeQuanBeginIndex: 0,
  177. //时间段开始的下标
  178. selectDate: "",
  179. //选择的日期
  180. timeQuanBegin: "",
  181. //时间段开始时间
  182. timeQuanEnd: ""
  183. //时间段结束时间
  184. };
  185. },
  186. onLoad(e) {
  187. let { orders_product_id, course_id } = e;
  188. this.orders_product_id = orders_product_id;
  189. this.course_id = course_id;
  190. },
  191. onShow() {
  192. if (this.orders_product_id > 0 && this.course_id > 0) {
  193. this.$http.request("api/course/get_schedule_list", { orders_product_id: this.orders_product_id, course_id: this.course_id }, "post").then((res) => {
  194. if (res.code === "success") {
  195. this.data = res.data;
  196. this.defaultTeacherDesc();
  197. this.initOnload();
  198. }
  199. });
  200. }
  201. },
  202. methods: {
  203. //老师选择事件
  204. selectTeacher(index, item) {
  205. if (this.teacherActive == index)
  206. return;
  207. this.teacherActive = index;
  208. if (this.data.length > 0) {
  209. if (this.teacherActive == index) {
  210. this.shcedule_list = this.data[index]["list"];
  211. this.schedule_id = this.data[index].teacher_id;
  212. this.course_name = this.shcedule_list[0].course_name;
  213. this.teacher_desc = this.shcedule_list[0].teacher_desc;
  214. this.course_image = this.shcedule_list[0].course_image;
  215. this.initOnload();
  216. }
  217. }
  218. },
  219. //默认选项
  220. defaultTeacherDesc() {
  221. this.teacherActive = 0;
  222. if (this.data.length > 0) {
  223. this.schedule_id = this.data[0].teacher_id;
  224. this.shcedule_list = this.data[0]["list"];
  225. this.course_name = this.shcedule_list[0].course_name;
  226. this.teacher_desc = this.shcedule_list[0].teacher_desc;
  227. this.course_image = this.shcedule_list[0].course_image;
  228. console.log(this.shcedule_list);
  229. }
  230. },
  231. //预约课程事件
  232. reservationPopup() {
  233. if (this.schedule_id === 0) {
  234. common_vendor.index.showToast({
  235. title: "请选择老师",
  236. icon: "none"
  237. });
  238. return;
  239. }
  240. if (this.dateActive < 0) {
  241. common_vendor.index.showToast({
  242. title: "请选择预约日期",
  243. icon: "none"
  244. });
  245. return;
  246. }
  247. if (this.timeActive < 0) {
  248. common_vendor.index.showToast({
  249. title: "请选择预约时间",
  250. icon: "none"
  251. });
  252. return;
  253. }
  254. this.$http.request("api/course/reservation/", { orders_product_id: this.orders_product_id, schedule_id: this.schedule_id }, "post").then((res) => {
  255. if (res.code === "success") {
  256. this.handleSubmit();
  257. this.initOnload();
  258. this.$refs.outcomePopup.open("center");
  259. } else {
  260. common_vendor.index.showToast({
  261. title: `${res.msg}`,
  262. icon: "error"
  263. });
  264. return;
  265. }
  266. });
  267. },
  268. outcomeButton() {
  269. this.orderDateTime = "暂无选择";
  270. this.$refs.outcomePopup.close();
  271. },
  272. initOnload() {
  273. this.dateArr = this.initData();
  274. this.timeArr = this.initTime(this.isQuantum);
  275. console.log(this.timeArr);
  276. this.timeQuanBegin = this.timeQuanEnd = "";
  277. console.log(this.orderTimeArr);
  278. this.timeArr.forEach((item, index) => {
  279. if (this.isQuantum) {
  280. if (this.shcedule_list[index].reservation_status === 1) {
  281. item.disable = true;
  282. }
  283. this.appointTime.forEach((t) => {
  284. let [date, time] = t.split(" ");
  285. if (date == this.selectDate && item.begin == time) {
  286. item.disable = true;
  287. }
  288. });
  289. }
  290. });
  291. this.timeActive = -1;
  292. },
  293. // 日期选择事件
  294. selectDateEvent(index, item) {
  295. if (this.dateActive == index)
  296. return;
  297. this.dateActive = index;
  298. this.selectDate = item.date;
  299. this.initOnload();
  300. },
  301. // 时间选择事件
  302. selectTimeEvent(index, item) {
  303. if (item.disable)
  304. return;
  305. if (item.disableSum)
  306. return;
  307. if (this.isQuantum) {
  308. return this.handleSelectQuantum(index, item);
  309. }
  310. },
  311. handleSelectQuantum(index, item) {
  312. if (item.disable)
  313. return;
  314. this.timeActive = index;
  315. this.orderDateTime = {
  316. begin: `${this.selectDate} ${item.begin}`,
  317. end: `${this.selectDate} ${item.end}`
  318. };
  319. },
  320. handleSubmit() {
  321. this.appointTime.push(this.orderDateTime.begin);
  322. console.log(this.appointTime);
  323. },
  324. //字符串拼接
  325. strFormat(str) {
  326. return str < 10 ? `0${str}` : str;
  327. },
  328. // 获取当前时间
  329. currentTime() {
  330. const myDate = /* @__PURE__ */ new Date();
  331. const y = myDate.getFullYear();
  332. const m = myDate.getMonth() + 1;
  333. const d = myDate.getDate();
  334. const date = y + "-" + this.strFormat(m) + "-" + this.strFormat(d);
  335. const hour = myDate.getHours();
  336. const min = myDate.getMinutes();
  337. const secon = myDate.getSeconds();
  338. const time = this.strFormat(hour) + ":" + this.strFormat(min) + ":" + this.strFormat(secon);
  339. return {
  340. date,
  341. time
  342. };
  343. },
  344. //时间戳转日期
  345. timeStamp(time, isQuantum) {
  346. const dates = new Date(time);
  347. const year = dates.getFullYear();
  348. const month = dates.getMonth() + 1;
  349. const date = dates.getDate();
  350. const day = dates.getDay();
  351. const hour = dates.getHours();
  352. const min = dates.getMinutes();
  353. const days = ["日", "一", "二", "三", "四", "五", "六"];
  354. return {
  355. allDate: `${year}/${this.strFormat(month)}/${this.strFormat(date)}`,
  356. date: `${this.strFormat(year)}-${this.strFormat(month)}-${this.strFormat(date)}`,
  357. //返回的日期 07-01
  358. day: `周${days[day]}`,
  359. //返回的礼拜天数 星期一
  360. hour: this.strFormat(hour) + ":" + this.strFormat(min) + (isQuantum ? "" : "")
  361. //返回的时钟 08:00
  362. };
  363. },
  364. //获取最近7天的日期和礼拜天数
  365. initData() {
  366. const time = [];
  367. const date = /* @__PURE__ */ new Date();
  368. const now = date.getTime();
  369. let timeStr = 3600 * 24 * 1e3;
  370. let obj = {
  371. 0: "今天"
  372. // 1: "明天",
  373. // 2: "后天"
  374. };
  375. for (let i = 0; i < 7; i++) {
  376. time.push({
  377. date: this.timeStamp(now + timeStr * i).date,
  378. //保存日期
  379. timeStamp: now + timeStr * i,
  380. //保存时间戳
  381. week: obj[i] ?? this.timeStamp(now + timeStr * i).day
  382. });
  383. }
  384. return time;
  385. },
  386. //时间数组
  387. initTime(isQuantum) {
  388. const time = [];
  389. this.shcedule_list.forEach((cruTiem) => {
  390. let starTimeStamp = cruTiem.start_time * 1e3;
  391. let endTimeStamp = cruTiem.end_time * 1e3;
  392. 60 * 1e3 * cruTiem.duration;
  393. console.log(starTimeStamp, endTimeStamp);
  394. if (isQuantum) {
  395. time.push({
  396. begin: this.timeStamp(starTimeStamp, isQuantum).hour,
  397. end: this.timeStamp(endTimeStamp, isQuantum).hour,
  398. reservationSum: `${cruTiem.reservation_number}/${cruTiem.course_number}`,
  399. disable: false
  400. });
  401. }
  402. });
  403. return time;
  404. }
  405. }
  406. };
  407. if (!Array) {
  408. const _easycom_uni_popup2 = common_vendor.resolveComponent("uni-popup");
  409. _easycom_uni_popup2();
  410. }
  411. const _easycom_uni_popup = () => "../../uni_modules/uni-popup/components/uni-popup/uni-popup.js";
  412. if (!Math) {
  413. _easycom_uni_popup();
  414. }
  415. function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
  416. return {
  417. a: common_vendor.t($data.course_name),
  418. b: common_vendor.t($data.teacher_desc),
  419. c: $data.course_image,
  420. d: common_vendor.f($data.data, (item, index, i0) => {
  421. return {
  422. a: common_vendor.t(item.teacher_name),
  423. b: index,
  424. c: common_vendor.o(($event) => $options.selectTeacher(index, item), index),
  425. d: common_vendor.n(index === $data.teacherActive ? "active" : "")
  426. };
  427. }),
  428. e: common_vendor.f($data.dateArr, (item, index, i0) => {
  429. return {
  430. a: common_vendor.t(item.week),
  431. b: common_vendor.t(item.date),
  432. c: index,
  433. d: common_vendor.o(($event) => $options.selectDateEvent(index, item), index),
  434. e: index == $data.dateActive ? 1 : "",
  435. f: index == $data.dateActive ? $props.selectedTabColor : "#333"
  436. };
  437. }),
  438. f: common_vendor.f($data.timeArr, (item, _index, i0) => {
  439. return {
  440. a: common_vendor.t(item.disable ? $props.disableText : $props.undisableText),
  441. b: common_vendor.t(item.begin),
  442. c: common_vendor.t(item.end),
  443. d: common_vendor.t(item.reservationSum),
  444. e: _index,
  445. f: item.disable ? 1 : "",
  446. g: ($props.isMultiple ? item.isActive : _index == $data.timeActive) ? 1 : "",
  447. h: $props.isMultiple ? item.isActive ? "#fff" : "#333" : _index == $data.timeActive ? "#fff" : "#333",
  448. i: $props.isMultiple ? item.isActive ? $props.selectedItemColor : "" : _index == $data.timeActive ? $props.selectedItemColor : "",
  449. j: common_vendor.o(($event) => $options.selectTimeEvent(_index, item), _index)
  450. };
  451. }),
  452. g: common_vendor.o(($event) => $options.reservationPopup()),
  453. h: common_vendor.t($data.orderDateTime.begin),
  454. i: common_vendor.o(($event) => $options.outcomeButton()),
  455. j: common_vendor.sr("outcomePopup", "46f39ab6-0"),
  456. k: common_vendor.p({
  457. ["is-mask-click"]: false
  458. })
  459. };
  460. }
  461. const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["render", _sfc_render]]);
  462. wx.createPage(MiniProgramPage);