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

378 lines
9.4 KiB

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