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

380 lines
9.4 KiB

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