reservation.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647
  1. <template>
  2. <view class="reservation_layout">
  3. <view class="header_title">
  4. <view class="left">
  5. <view class="title">{{course_name}}</view>
  6. <view class="subtitle">{{teacher_desc}}</view>
  7. </view>
  8. <view class="right">
  9. <image :src="course_image" class="image" mode=""></image>
  10. </view>
  11. </view>
  12. <view class="teacher_list">
  13. <view class="teacher_item" v-for="(item,index) in data" :key="index" @click="selectTeacher(index,item)" :class="index === teacherActive? 'active':''">
  14. <text>{{item.teacher_name}}</text>
  15. </view>
  16. </view>
  17. <view class="course">
  18. <scroll-view scroll-x >
  19. <view class="days">
  20. <view class="day" v-for="(item, index) in dateArr" :key="index" @click="selectDateEvent(index,item)" :class="{ borderb: index==dateActive}" :style="{color:index==dateActive?selectedTabColor:'#333'}">
  21. <text>{{ item.week }}</text>
  22. <view>{{item.date}}</view>
  23. </view>
  24. </view>
  25. </scroll-view>
  26. <view class="times">
  27. <scroll-view scroll-y="true" >
  28. <view class="time_list">
  29. <view class="day" v-for="(item,_index) in timeArr" :key="_index" :class="{'disable':item.disable,
  30. 'active':isMultiple?item.isActive:_index==timeActive}" :style="{color:isMultiple?item.isActive? '#fff':'#333'
  31. :_index==timeActive?'#fff':'#333',backgroundColor:isMultiple?item.isActive? selectedItemColor:''
  32. :_index==timeActive?selectedItemColor:''}" @click="selectTimeEvent(_index,item)">
  33. <view class="disableText">{{item.disable?disableText:undisableText}}</view>
  34. <view class="time">{{item.begin}}~{{item.end}}</view>
  35. <view class="num" >{{item.reservationSum}}</view>
  36. </view>
  37. </view>
  38. </scroll-view>
  39. </view>
  40. </view>
  41. <!-- <view class="">
  42. 预约时间:{{orderDateTime.begin}}
  43. </view> -->
  44. <button @click="reservationPopup()" class="confirm_button" >确认预约</button>
  45. <uni-popup ref="outcomePopup" :is-mask-click="false" >
  46. <view class="outcome_popup_layout">
  47. <view class="outcome_title">
  48. 预约成功
  49. </view>
  50. <view class="outcome_text" >
  51. 你已经预约:{{orderDateTime.begin}}直播主持课程
  52. </view>
  53. <button class="outcome_button" @click="outcomeButton()" >确认</button>
  54. </view>
  55. </uni-popup>
  56. </view>
  57. </template>
  58. <script>
  59. export default {
  60. props: {
  61. isQuantum: {
  62. type: Boolean,
  63. default: true
  64. },
  65. isMultiple: { //是否多选
  66. type: Boolean,
  67. default: false
  68. },
  69. isSection: { //预约时间段
  70. type: Boolean,
  71. default: false
  72. },
  73. disableText:{ //禁用显示的文本
  74. type: String,
  75. default: "已预约"
  76. },
  77. disableSumText:{
  78. type:String,
  79. default:"已约满"
  80. },
  81. undisableText: { //未禁用显示的文本
  82. type: String,
  83. default: "可预约"
  84. },
  85. timeInterval: { // 时间间隔,小时为单位
  86. type: Number,
  87. default: 1
  88. },
  89. selectedTabColor: { // 日期栏选中的颜色
  90. type: String,
  91. default: "#51bf81"
  92. },
  93. selectedItemColor: { // 时间选中的颜色
  94. type: String,
  95. default: "#51bf81"
  96. },
  97. beginTime: {
  98. type: String,
  99. default: "08:30"
  100. },
  101. endTime: {
  102. type: String,
  103. default: "19:30"
  104. },
  105. appointTime: { // 预约的时间
  106. type: Array,
  107. default () {
  108. return []
  109. }
  110. },
  111. disableTimeSlot: { // 预约开始和结束时间,来禁用时间段
  112. type: Array,
  113. default () {
  114. return []
  115. }
  116. }
  117. },
  118. watch: {
  119. appointTime: {
  120. handler(val) {
  121. if (val && val.length) {
  122. this.initOnload()
  123. }
  124. }
  125. },
  126. // disableTimeSlot: {
  127. // handler(val) {
  128. // if (val && val.length) {
  129. // this.initOnload()
  130. // }
  131. // }
  132. // },
  133. shcedule_list:{
  134. handler(val) {
  135. if(val && val.length){
  136. this.initOnload()
  137. }
  138. }
  139. }
  140. },
  141. data() {
  142. return {
  143. data:[
  144. ],
  145. shcedule_list:[],//排课列表
  146. teacher_desc: "",//当前老师的一个介绍
  147. course_name: "",//当前老师的名字
  148. course_image: "",//当前老师的图片
  149. orders_product_id:0,//商品id
  150. course_id:0,//课程id
  151. schedule_id:0,//排课id
  152. teacherActive:-1,
  153. orderDateTime: '暂无选择', // 选中时间
  154. orderTimeArr: {}, //多选的时间
  155. dateArr: [], //日期数据
  156. timeArr: [], //时间数据
  157. nowDate: "", // 当前日期
  158. dateActive: 0, //选中的日期索引
  159. timeActive: 0, //选中的时间索引
  160. timeQuanBeginIndex: 0, //时间段开始的下标
  161. selectDate: "", //选择的日期
  162. timeQuanBegin: "", //时间段开始时间
  163. timeQuanEnd: "", //时间段结束时间
  164. // isTime:[],
  165. }
  166. },
  167. onLoad(e) {
  168. //接受url参数
  169. let {orders_product_id,course_id} = e
  170. this.orders_product_id = orders_product_id
  171. this.course_id = course_id
  172. },
  173. onShow() {
  174. console.log(22222)
  175. if(this.orders_product_id > 0 && this.course_id > 0){
  176. this.$http.request('api/course/get_schedule_list',{orders_product_id:this.orders_product_id,course_id:this.course_id},'post').then((res)=>{
  177. if(res.code === "success"){
  178. this.data = res.data
  179. this.selectDate = this.currentTime().date
  180. this.defaultTeacherDesc()
  181. this.initOnload()
  182. }
  183. })
  184. }
  185. },
  186. methods: {
  187. //老师选择事件
  188. selectTeacher(index,item){
  189. if(this.teacherActive == index)return
  190. this.teacherActive = index;
  191. if(this.data.length >0){
  192. if(this.teacherActive == index){
  193. this.shcedule_list = this.data[index]["list"]
  194. this.teacher_id = this.data[index].teacher_id
  195. this.course_name = this.shcedule_list[0].course_name
  196. this.teacher_desc = this.shcedule_list[0].teacher_desc
  197. this.course_image = this.shcedule_list[0].course_image
  198. this.initOnload()
  199. }
  200. }
  201. },
  202. //默认选项
  203. defaultTeacherDesc(){
  204. this.teacherActive = 0
  205. if(this.data.length>0){
  206. this.teacher_id = this.data[0].teacher_id
  207. this.shcedule_list = this.data[0]["list"]
  208. this.course_name = this.shcedule_list[0].course_name
  209. this.teacher_desc = this.shcedule_list[0].teacher_desc
  210. this.course_image = this.shcedule_list[0].course_image
  211. console.log(this.shcedule_list);
  212. }
  213. },
  214. //预约课程事件
  215. reservationPopup(){
  216. //如果没有选择老师
  217. if(this.teacher_id === 0){
  218. uni.showToast({
  219. title:"请选择老师",
  220. icon:"none"
  221. })
  222. return
  223. }
  224. //没有选择预约日期
  225. if(this.dateActive < 0){
  226. uni.showToast({
  227. title:"请选择预约日期",
  228. icon:"none"
  229. })
  230. return
  231. }
  232. //没有选择预约时间
  233. if(this.timeActive < 0){
  234. uni.showToast({
  235. title:"请选择预约时间",
  236. icon:"none"
  237. })
  238. return
  239. }
  240. console.log(66,this.shcedule_id)
  241. this.$http.request("api/course/reservation/",{orders_product_id:this.orders_product_id,schedule_id:this.shcedule_id},'post').then((res)=>{
  242. if(res.code === 'success'){
  243. this.handleSubmit();
  244. this.initOnload();
  245. this.$refs.outcomePopup.open("center")
  246. this.$http.request('api/course/get_schedule_list',{orders_product_id:this.orders_product_id,course_id:this.course_id},'post').then((res)=>{
  247. if(res.code === "success"){
  248. this.data = res.data
  249. this.selectDate = this.currentTime().date
  250. this.defaultTeacherDesc()
  251. this.initOnload()
  252. }
  253. })
  254. }else{
  255. uni.showToast({
  256. title:`${res.msg}`,
  257. icon:"error"
  258. })
  259. return
  260. }
  261. })
  262. },
  263. outcomeButton(){
  264. this.orderDateTime = '暂无选择'
  265. this.$refs.outcomePopup.close();
  266. },
  267. initOnload() {
  268. this.dateArr = this.initData() // 日期栏初始化
  269. console.log(this.isQuantum)
  270. this.timeArr = this.initTime(this.isQuantum) //时间选项初始化
  271. console.log(3,this.timeArr);
  272. this.timeQuanBegin = this.timeQuanEnd = ""
  273. console.log(4,this.orderTimeArr)
  274. let isFullTime = true
  275. this.timeArr.forEach((item, index) => {
  276. // 时间段
  277. if (this.isQuantum) {
  278. if(item.reservation_status === 1){
  279. item.disable = true
  280. }
  281. // 将预约的时间禁用
  282. this.appointTime.forEach(t => {
  283. let [date, time] = t.split(' ')
  284. if (date == this.selectDate && item.begin == time) {
  285. item.disable = true
  286. }
  287. })
  288. }
  289. })
  290. this.timeActive = -1
  291. },
  292. // 日期选择事件
  293. selectDateEvent(index, item) {
  294. if(this.dateActive == index)return
  295. this.dateActive = index
  296. this.selectDate = item.date
  297. console.log(1,this.selectDate)
  298. console.log(2,this.dateActive)
  299. this.initOnload()
  300. },
  301. // 时间选择事件
  302. selectTimeEvent(index, item) {
  303. if (item.disable) return
  304. if(item.disableSum) return
  305. console.log(item.shcedule_id)
  306. this.shcedule_id = item.shcedule_id
  307. if (this.isQuantum) {
  308. return this.handleSelectQuantum(index, item)
  309. }
  310. // if (this.isMultiple) {
  311. // item.isActive = !item.isActive
  312. // this.timeArr = this.timeArr.slice()
  313. // this.orderTimeArr[this.selectDate] = this.timeArr.reduce((prev, cur) => {
  314. // cur.isActive && prev.push(cur.time)
  315. // return prev
  316. // }, [])
  317. // } else {
  318. // this.timeActive = index
  319. // this.orderDateTime = `${this.selectDate} ${item.time}`
  320. // }
  321. },
  322. handleSelectQuantum(index, item) {
  323. if (item.disable) return
  324. this.timeActive = index
  325. this.orderDateTime = {
  326. begin: `${this.selectDate} ${item.begin}`,
  327. end: `${this.selectDate} ${item.end}`,
  328. }
  329. },
  330. handleSubmit() {
  331. this.appointTime.push(this.orderDateTime.begin)
  332. console.log(this.appointTime);
  333. },
  334. //字符串拼接
  335. strFormat(str) {
  336. return str < 10 ? `0${str}` : str
  337. },
  338. // 获取当前时间
  339. currentTime() {
  340. const myDate = new Date();
  341. const y = myDate.getFullYear()
  342. const m = myDate.getMonth() + 1;
  343. const d = myDate.getDate();
  344. const date = y + '-' + this.strFormat(m) + '-' + this.strFormat(d);
  345. const hour = myDate.getHours()
  346. const min = myDate.getMinutes()
  347. const secon = myDate.getSeconds()
  348. const time = this.strFormat(hour) + ':' + this.strFormat(min) + ':' + this.strFormat(secon);
  349. return {
  350. date,
  351. time
  352. }
  353. },
  354. //时间戳转日期
  355. timeStamp(time, isQuantum) {
  356. const dates = new Date(time)
  357. const year = dates.getFullYear()
  358. const month = dates.getMonth() + 1
  359. const date = dates.getDate()
  360. const day = dates.getDay()
  361. const hour = dates.getHours()
  362. const min = dates.getMinutes()
  363. const days = [ '日', '一', '二', '三', '四', '五', '六']
  364. return {
  365. allDate: `${year}/${this.strFormat(month)}/${this.strFormat(date)}`,
  366. date: `${this.strFormat(year)}-${this.strFormat(month)}-${this.strFormat(date)}`, //返回的日期 07-01
  367. day: `周${days[day]}`, //返回的礼拜天数 星期一
  368. hour: this.strFormat(hour) + ':' + this.strFormat(min) + (isQuantum ? "" : '') //返回的时钟 08:00
  369. }
  370. },
  371. //获取最近7天的日期和礼拜天数
  372. initData() {
  373. const time = []
  374. const date = new Date()
  375. const now = date.getTime() //获取当前日期的时间戳
  376. // const now = this.start_time *1000
  377. let timeStr = 3600 * 24 * 1000 //一天的时间戳
  378. let obj = {
  379. 0: "今天",
  380. // 1: "明天",
  381. // 2: "后天"
  382. }
  383. for (let i = 0; i < 7; i++) {
  384. time.push({
  385. date: this.timeStamp(now + timeStr * i).date, //保存日期
  386. timeStamp: now + timeStr * i, //保存时间戳
  387. week: obj[i]?? this.timeStamp(now + timeStr * i).day
  388. })
  389. }
  390. return time
  391. },
  392. //时间数组
  393. // this.shcedule_list[{"start_time":1732060800,"end_time":1732063500}];
  394. initTime( isQuantum) {
  395. const time = []
  396. this.shcedule_list.forEach((cruTiem)=>{
  397. let selectDateStr = new Date(this.selectDate + ' 00:00:00').getTime()
  398. let starTimeStamp = cruTiem.start_time * 1000
  399. let endTimeStamp = cruTiem.end_time * 1000
  400. if (starTimeStamp >= selectDateStr && (selectDateStr + 24*60*60*1000) >= endTimeStamp) {
  401. let timeStr = 60 * 1000 * cruTiem.duration
  402. console.log(starTimeStamp,endTimeStamp);
  403. // timeStr = 60 * 1000 * i.duration
  404. if (isQuantum) {
  405. time.push({
  406. begin: this.timeStamp(starTimeStamp , isQuantum).hour,
  407. end: this.timeStamp(endTimeStamp , isQuantum).hour,
  408. reservationSum:`${cruTiem.reservation_number}/${cruTiem.course_number}`,
  409. reservation_status:cruTiem.reservation_status,
  410. shcedule_id:cruTiem.id,
  411. disable: false
  412. })
  413. }
  414. }
  415. })
  416. return time
  417. },
  418. }
  419. }
  420. </script>
  421. <style lang="less">
  422. .reservation_layout{
  423. width: 750rpx;
  424. // margin: 30rpx auto;
  425. .header_title{
  426. width: 690rpx;
  427. margin: 30rpx auto;
  428. display: flex;
  429. justify-content: space-between;
  430. .left{
  431. display: inline-flex;
  432. flex-direction: column;
  433. justify-content: center;
  434. .title {
  435. font-size: 50rpx;
  436. font-weight: bold;
  437. margin-bottom: 10rpx;
  438. }
  439. .subtitle{
  440. font-size: 26rpx;
  441. color: #868686;
  442. }
  443. }
  444. .right{
  445. width: 154rpx;
  446. height: 154rpx;
  447. .image{
  448. width: 154rpx;
  449. height: 154rpx;
  450. border-radius: 50%;
  451. }
  452. }
  453. }
  454. .teacher_list{
  455. width: 690rpx;
  456. margin: 30rpx auto;
  457. display: flex;
  458. flex-wrap: wrap;
  459. .teacher_item{
  460. background-color: #ffffff;
  461. width: 280rpx;
  462. padding: 10rpx;
  463. margin: 20rpx;
  464. border-radius: 20rpx;
  465. text-align: center;
  466. }
  467. .teacher_item.active{
  468. color: #51bf81;
  469. border: 2rpx solid #51bf81;
  470. }
  471. }
  472. .course{
  473. width: 690rpx;
  474. margin: 0rpx auto;
  475. // border: 2rpx solid;
  476. scroll-view{
  477. width: 100%;
  478. white-space: nowrap;
  479. height: 75px;
  480. background-color: #fff;
  481. position: relative;
  482. padding-top: 10rpx;
  483. }
  484. .days{
  485. display: flex;
  486. background-color: #ffffff;
  487. .day{
  488. display: inline-flex;
  489. flex-direction: column;
  490. justify-content: center;
  491. align-items: center;
  492. margin: 0rpx 20rpx;
  493. height: 115rpx;
  494. text{
  495. margin: 10rpx 0rpx;
  496. }
  497. }
  498. .day.borderb {
  499. border-bottom: 2px solid #51bf81;
  500. }
  501. }
  502. .times{
  503. // border: 2rpx solid;
  504. scroll-view{
  505. width: 100%;
  506. // white-space: nowrap;
  507. height: 300px;
  508. background-color: #fff;
  509. // position: relative;
  510. padding-top: 10rpx;
  511. }
  512. .time_list{
  513. display: flex;
  514. flex-wrap: wrap;
  515. background-color: #ffffff;
  516. .day{
  517. display: flex;
  518. flex-direction: column;
  519. justify-content: center;
  520. align-items: center;
  521. width: 200rpx;
  522. height: 200rpx;
  523. background-color: #f3f3f3;
  524. margin: 10rpx;
  525. border-radius: 20rpx;
  526. .time{
  527. margin: 20rpx;
  528. }
  529. }
  530. }
  531. }
  532. }
  533. .confirm_button {
  534. font-size: 40rpx;
  535. font-weight: 600;
  536. width: 690rpx;
  537. left: 30rpx;
  538. position: fixed;
  539. bottom: 100rpx;
  540. background-color:#51bf81;
  541. color: #fff;
  542. padding: 5px;
  543. border-radius: 60rpx;
  544. }
  545. .popup_layout{
  546. background-color: #ffffff;
  547. width: 750rpx;
  548. height: 60vh;
  549. border-radius: 40rpx;
  550. padding-top: 1px;
  551. .title{
  552. font-size: 40rpx;
  553. font-weight: bold;
  554. margin: 30rpx;
  555. }
  556. .time_list{
  557. display: flex;
  558. justify-content: space-between;
  559. flex-wrap: wrap;
  560. margin: 30rpx;
  561. .time_item{
  562. display: inline-flex;
  563. justify-content: center;
  564. align-items: center;
  565. padding: 10rpx;
  566. width: 200rpx;
  567. margin: 10rpx 0rpx;
  568. border: 2rpx solid;
  569. }
  570. }
  571. }
  572. .outcome_popup_layout{
  573. width: 690rpx;
  574. background-color: #ffffff;
  575. display: flex;
  576. flex-direction: column;
  577. border-radius: 40rpx;
  578. overflow: hidden;
  579. .outcome_title{
  580. display: inline-flex;
  581. justify-content: center;
  582. align-items: center;
  583. padding: 10rpx;
  584. margin: 30rpx;
  585. font-size: 40rpx;
  586. font-weight: bold;
  587. color: #000000;
  588. }
  589. .outcome_text{
  590. display: inline-flex;
  591. justify-content: center;
  592. align-items: center;
  593. margin: 30rpx auto;
  594. width: 576rpx;
  595. height: 50rpx;
  596. padding:20rpx;
  597. }
  598. .outcome_button{
  599. width: 100%;
  600. height: 100%;
  601. // height: 100%;
  602. }
  603. }
  604. }
  605. </style>