学员端小程序
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.

379 lines
9.5 KiB

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