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