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

375 lines
9.1 KiB

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