学员端小程序
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

406 lines
10 KiB

1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
  1. <template>
  2. <view class="step1">
  3. <view class="card">
  4. <view class="dateBox">
  5. <view class="month-row">
  6. <view class="month" @click="show=true">{{ currentMonth }}</view>
  7. <view class="arrow">
  8. <u-icon name="arrow-down" :size="12" :color="'#1989FA'"></u-icon>
  9. </view>
  10. </view>
  11. <view class="date_row">
  12. <view class="icon left" @click="changeDateIndex(-1)">
  13. <u-icon name="arrow-left" :size="12" :color="'#fff'"></u-icon>
  14. </view>
  15. <view class="dateArr" >
  16. <view class="dateWidth" v-for="(item,index) in dateArr[currentDay]" :key="index" @click="chooseDate(item)" >
  17. <u-transition :show="true" mode="fade">
  18. <view class="transition">
  19. <view class="date" :class="{active: chooseDay==item.date}">
  20. <!-- <view class="dian"></view> -->
  21. <view class="week">{{ item.week }}</view>
  22. <view class="num">{{ item.num }}</view>
  23. </view>
  24. </view>
  25. </u-transition>
  26. </view>
  27. </view>
  28. <view class="icon right" @click="changeDateIndex(1)">
  29. <u-icon name="arrow-right" :size="12" :color="'#fff'"></u-icon>
  30. </view>
  31. </view>
  32. </view>
  33. </view>
  34. <view class="card" >
  35. <view class="timeCon" v-if="timerArr.length||timerArr2.length">
  36. <view class="h2" v-if="timerArr.length">上午</view>
  37. <view class="time_box">
  38. <view class="time_item" v-for="(item,index) in timerArr" :key="index" @click="chooseCourse(item)" :class="{active: (FormData.courseArr.findIndex(val=>val.id==item.id))!=-1, disable: item.status!=0}" >
  39. <!-- <view class="flex" v-if="item.status==0">
  40. <view class="lab">{{ item.appointmentAlreadyCount ||0 }} <text>/</text> {{ item.appointmentSumCount}} </view>
  41. <view class="iconArrowBg" v-if="item.appointmentAlreadyCount">
  42. <u-icon name="arrow-right" :size="10" :color="'#fff'"></u-icon>
  43. </view>
  44. </view> -->
  45. <view class="lab" >{{ statusTxt[item.status] }}</view>
  46. <view class="time">{{ item.classTime }}</view>
  47. </view>
  48. </view>
  49. <view class="h2" v-if="timerArr2.length">下午</view>
  50. <view class="time_box">
  51. <view class="time_item" v-for="(item,index) in timerArr2" :key="index" @click="chooseCourse(item)" :class="{active: (FormData.courseArr.findIndex(val=>val.id==item.id))!=-1, disable: item.status!=0}">
  52. <!-- <view class="flex" v-if="item.status==0">
  53. <view class="lab">{{ item.appointmentAlreadyCount ||0 }} <text>/</text> {{ item.appointmentSumCount}} </view>
  54. <view class="iconArrowBg" v-if="item.appointmentAlreadyCount">
  55. <u-icon name="arrow-right" :size="10" :color="'#fff'"></u-icon>
  56. </view>
  57. </view> -->
  58. <view class="lab" >{{ statusTxt[item.status] }}</view>
  59. <view class="time">{{ item.classTime }}</view>
  60. </view>
  61. </view>
  62. </view>
  63. <view class="card" v-if="!timerArr2.length&&!timerArr.length" style="padding: 0 0 60rpx 0;">
  64. <nodata>暂无预约排课</nodata>
  65. </view>
  66. </view>
  67. <u-datetime-picker
  68. :show="show"
  69. v-model="chooseMonth"
  70. :minDate="minDate"
  71. :maxDate="maxDate"
  72. mode="year-month"
  73. @confirm="changeMonth"
  74. @cancel="show=false"
  75. ></u-datetime-picker>
  76. </view>
  77. </template>
  78. <script>
  79. import { getDates, getMonthsBetweenDates } from '@/config/utils.js'
  80. import { scheduleClass } from '@/config/api.js'
  81. export default {
  82. props: ['step', 'FormData'],
  83. data() {
  84. return {
  85. maxDate: 0,
  86. minDate: 0,
  87. monthArr: [],
  88. show: false,
  89. dateArr: [],
  90. currentDay: 0,//当前显示的日期组索引
  91. chooseDay: '',
  92. chooseMonth: '',
  93. timerArr: [],
  94. statusTxt: ['可预约', '未开放', '已过期', '已约满', '已约过'], //状态0、未过期 1、无排课,2、已过期,3已约满
  95. timerArr2: [],
  96. chooseTimerId: '',
  97. endDate: null,
  98. startDate: null,
  99. courseIds: '',
  100. radioVal: '',
  101. }
  102. },
  103. mounted() {
  104. this.initDate()
  105. },
  106. computed: {
  107. currentMonth() {
  108. let tiemr = new Date(this.chooseDay) * 1
  109. return this.$u.date(tiemr, 'yyyy.mm')
  110. }
  111. },
  112. watch: {
  113. courseIds: {
  114. handler(val) {
  115. let allTimer = [...this.timerArr,...this.timerArr2]
  116. let total = allTimer.reduce((pre, item)=>{
  117. if(item.status==1) {
  118. pre.push(item.classTime)
  119. }
  120. return pre
  121. },[])
  122. if(total.length==this.courseIds.length) {
  123. this.radioVal = 0
  124. }
  125. }
  126. }
  127. },
  128. methods: {
  129. // 获得排课
  130. async scheduleClassFn() {
  131. uni.showLoading({
  132. title: '正在加载...'
  133. })
  134. this.FormData.courseArr = []
  135. let obj = { "coachId": this.FormData.coachId, "trainType": this.FormData.trainType, "subject": this.FormData.subject, "classDate": this.chooseDay, "studentId": this.FormData.studentId}
  136. const {data: res} = await scheduleClass(obj)
  137. uni.hideLoading()
  138. this.timerArr2 = res.afternoonScheduleClass.sort((a,b)=>{
  139. return parseInt(a.classTime.slice(0,2)) - parseInt(b.classTime.slice(0,2))
  140. })
  141. this.timerArr = res.morningScheduleClass.sort((a,b)=>{
  142. return parseInt(a.classTime.slice(0,2)) - parseInt(b.classTime.slice(0,2))
  143. })
  144. // 如果是今天的日期检查有没有过期
  145. if(this.chooseDay==this.dateArr[0][0].date) {
  146. let arr = [...this.timerArr,...this.timerArr2]
  147. arr.forEach(item=>{
  148. let timer = new Date() * 1
  149. let date = this.chooseDay+' '+(item.classTime.split('-')[0])
  150. date = date.replace(/-/g,'/');
  151. let timer2 = new Date(date).getTime();
  152. if(timer>timer2) {
  153. item.status = 2
  154. }
  155. })
  156. }
  157. console.log(this.timerArr)
  158. },
  159. // 初始化日期
  160. async initDate() {
  161. this.startDate = this.$u.timeFormat(new Date()*1, 'yyyy-mm-dd');
  162. // 定义一个表示一个月的毫秒数
  163. this.minDate = new Date()*1
  164. const oneMonthMilliseconds = 30 * 24 * 60 * 60 * 1000;
  165. this.maxDate = this.endDate = this.minDate + oneMonthMilliseconds
  166. this.dateArr = getDates(this.startDate, this.endDate);
  167. this.chooseDay = this.dateArr[0][0].date
  168. console.log(this.dateArr)
  169. this.scheduleClassFn()
  170. },
  171. // 点击月份
  172. changeMonth(val) {
  173. let startDate = this.$u.date(val.value, 'yyyy-mm-dd')
  174. for(let i=0; i<this.dateArr.length; i++) {
  175. for(let j=0; j<this.dateArr[i].length; j++) {
  176. let date = this.dateArr[i][j].date
  177. if(startDate==date) {
  178. this.currentDay = i
  179. this.chooseDay = date
  180. }
  181. }
  182. }
  183. this.show = false
  184. },
  185. // 选择日期
  186. chooseDate(item) {
  187. this.chooseDay = item.date
  188. this.scheduleClassFn()
  189. // console.log('*****')
  190. // console.log(this.chooseDay)
  191. },
  192. changeDateIndex(num) {
  193. if(this.currentDay==0&&num==-1) return this.$u.toast('已是可选最小日期')
  194. if(this.currentDay==this.dateArr.length-1&&num==1) return this.$u.toast('已是可选最大日期')
  195. this.currentDay = this.currentDay + num
  196. this.chooseDay = this.dateArr[this.currentDay][0].date
  197. this.scheduleClassFn()
  198. },
  199. chooseCourse(item) {
  200. if(item.status!=0) return
  201. let index = this.FormData.courseArr.findIndex(val=>val.id==item.id)
  202. if( index==-1) {
  203. // 最大可预约次数
  204. let arr = [...this.timerArr,...this.timerArr2]
  205. let status4 = arr.reduce((p,v)=>{
  206. if(v.status==4) p++
  207. return p
  208. },0)
  209. if((status4+this.FormData.courseArr.length)>=4 ){
  210. this.$u.toast('一天最多能约四节课')
  211. }else {
  212. this.FormData.courseArr.push(item)
  213. }
  214. }else {
  215. this.FormData.courseArr.splice(index,1)
  216. }
  217. },
  218. }
  219. }
  220. </script>
  221. <style lang="scss" scoped>
  222. .card {
  223. width: 100%;
  224. margin-bottom: 24rpx;
  225. overflow: hidden;
  226. .dateBox {
  227. padding: 36rpx 0 40rpx 0;
  228. .month-row {
  229. display: flex;
  230. justify-content: center;
  231. align-items: center;
  232. margin-bottom: 36rpx;
  233. .month {
  234. font-size: 32rpx;
  235. color: $themC;
  236. }
  237. .arrow {
  238. margin-left: 6rpx;
  239. }
  240. }
  241. .date_row {
  242. width: 100%;
  243. height: 100rpx;
  244. position: relative;
  245. .icon {
  246. width: 40rpx;
  247. height: 40rpx;
  248. background: rgba(51,51,51,0.18);
  249. backdrop-filter: blur(4rpx);
  250. position: absolute;
  251. top: 50%;
  252. transform: translateY(-50%);
  253. display: flex;
  254. align-items: center;
  255. justify-content: center;
  256. border-radius: 50%;
  257. &.left {
  258. left: 16rpx;
  259. }
  260. &.right {
  261. right: 16rpx;
  262. }
  263. }
  264. .dateArr {
  265. display: flex;
  266. padding: 0 70rpx;
  267. // justify-content: space-between;
  268. &.oneDate {
  269. justify-content: center;
  270. }
  271. .dateWidth {
  272. width: 20%;
  273. display: flex;
  274. justify-content: center;
  275. }
  276. .date {
  277. width: 74rpx;
  278. height: 100rpx;
  279. border-radius: 16rpx;
  280. display: flex;
  281. flex-direction: column;
  282. align-items: center;
  283. justify-content: center;
  284. font-size: 28rpx;
  285. color: #333;
  286. .dian {
  287. width: 12rpx;
  288. height: 12rpx;
  289. background: #D8D8D8;
  290. border-radius: 50%;
  291. &.active {
  292. background: #1989FA;
  293. }
  294. }
  295. &.active {
  296. background: rgba(25,137,250,0.1);
  297. border: 2rpx solid #1989FA;
  298. color: $themC;
  299. }
  300. .week {
  301. }
  302. .num {
  303. margin-top: 4rpx;
  304. }
  305. }
  306. }
  307. }
  308. }
  309. }
  310. .card {
  311. .timeCon {
  312. padding: 0 24rpx 40rpx 24rpx;
  313. }
  314. .h2 {
  315. line-height: 90rpx;
  316. font-weight: 500;
  317. color: #333;
  318. }
  319. .time_box {
  320. display: flex;
  321. flex-wrap: wrap;
  322. justify-content: space-between;
  323. &::after{
  324. display:block;
  325. content:"";
  326. width: 32%;
  327. height:0px;
  328. }
  329. .time_item {
  330. width: 30%;
  331. height: 120rpx;
  332. background: #F8F8F8;
  333. border-radius: 12rpx;
  334. display: flex;
  335. flex-direction: column;
  336. justify-content: center;
  337. align-items: center;
  338. border-radius: 12rpx;
  339. margin-bottom: 20rpx;
  340. color: #333;
  341. &.active {
  342. background: rgba(25,137,250,0.1);
  343. border: 2rpx solid #1989FA;
  344. color: $themC;
  345. }
  346. &.disable {
  347. opacity: 0.4;
  348. }
  349. .lab {
  350. font-size: 28rpx;
  351. font-weight: 500;
  352. }
  353. .time {
  354. font-size: 24rpx;
  355. margin-top: 4rpx;
  356. }
  357. }
  358. }
  359. }
  360. .btn {
  361. width: 47%;
  362. height: 72rpx;
  363. background: #1989FA;
  364. border-radius: 8rpx;
  365. font-size: 28rpx;
  366. color: #fff;
  367. text-align: center;
  368. line-height: 72rpx;
  369. margin: 108rpx auto 50rpx auto;
  370. }
  371. .iconArrowBg {
  372. background: #D8D8D8;
  373. width: 26rpx;
  374. height: 26rpx;
  375. border-radius: 50%;
  376. display: flex;
  377. justify-content: center;
  378. align-items: center;
  379. margin-left: 4px;
  380. }
  381. .step2 {
  382. display: flex;
  383. justify-content: space-between;
  384. align-items: center;
  385. padding-bottom: 40px;
  386. .btnBg {
  387. width: 310rpx;
  388. }
  389. }
  390. </style>