reservation.vue 17 KB

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