home.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688
  1. <template>
  2. <view class="container">
  3. <!-- 头部时间信息区域 -->
  4. <view class="header-time">
  5. <view class="today" @click="handleChangeTime">{{ dateType == '明天' ? '今天' : '' }}</view>
  6. <view class="time-info">
  7. {{ currentMonth }}月{{ currentDay }}日
  8. <span>{{ dateType }}</span>
  9. {{ currentWeek }}
  10. </view>
  11. <view class="tomorrow" @click="handleChangeTime">{{ dateType == '今天' ? '明天' : '' }}</view>
  12. </view>
  13. <!-- 头部路线信息区域 -->
  14. <view class="header-path">
  15. <view class="path-title">请选择路线</view>
  16. <view class="path-list" v-if="pathList.length">
  17. <view
  18. :class="currentIndex1 === index ? 'active path-item' : 'path-item'"
  19. v-for="(item, index) in pathList"
  20. :key="index"
  21. @click="handleChangeCurrentIndex(1, index, item)"
  22. >
  23. {{ item.route }}
  24. </view>
  25. </view>
  26. <view class="path-list-nodata" v-else>暂无数据</view>
  27. </view>
  28. <!-- 车辆列表区域 -->
  29. <view class="carList">
  30. <view class="carList-title">请选择车辆</view>
  31. <view
  32. :class="[currentIndex2 === index ? 'active ' : '', item.can_order == 0 ? 'unactive' : '', 'carList-item']"
  33. v-for="(item, index) in busList"
  34. :key="index"
  35. @click="handleChangeCurrentIndex(2, index, item)"
  36. >
  37. <view class="item-time">{{ item.ci_time }}</view>
  38. <view class="item-info">
  39. <view class="item-info-place">{{ item.route_end }}</view>
  40. <view class="item-info-detail">
  41. 车牌:{{ item.car_number }}
  42. <span>容量:{{ item.boarde_num + '/' + item.contain }}</span>
  43. </view>
  44. </view>
  45. </view>
  46. <!-- 没有数据时展示的区域 -->
  47. <view class="carList-nodata" v-if="busList.length == 0">
  48. <img src="../../static/no-bus.png" />
  49. <view class="nodata-info">暂无数据</view>
  50. </view>
  51. </view>
  52. <!-- 立即预约按钮区域 -->
  53. <view class="btn-box" v-if="busList.length">
  54. <view class="btn">
  55. <view class="btn-clock"><img src="../../static/clock.png" /></view>
  56. <view class="btn-info" v-if="status">
  57. <view class="btn-info-title">开始预约时间段</view>
  58. <view>{{ yy_duration }}</view>
  59. </view>
  60. <view class="btn-info" v-else>
  61. <view class="btn-info-title2">候补截止时间</view>
  62. <view class="btn-info-time">{{ currentPath == '墨轩湖校区-黄家湖校区' ? mxh_end : hjh_end }}</view>
  63. </view>
  64. <view class="btn-button" @click="handleSub">{{ status ? '立即预约' : dateType == '今天' ? '候补预约' : '立即预约' }}</view>
  65. </view>
  66. </view>
  67. <!-- 温馨提示区域 -->
  68. <view class="box-info">
  69. <view class="info-title">温馨提示</view>
  70. <view class="info-detail">
  71. 预约截止时间为发车前{{ yy_end }}分钟,如当月爽约{{ black_count }}次,账号会被锁定,锁定后联系车队长解锁。车队长联系方式:
  72. <span @click="handlePhone(13576937506)">13576937506</span>
  73. ,候补功能仅当日开放。
  74. </view>
  75. </view>
  76. </view>
  77. </template>
  78. <script setup>
  79. import { ref, computed, watch } from 'vue'
  80. import { onLoad, onPullDownRefresh, onShow } from '@dcloudio/uni-app'
  81. import { myRequest } from '../../util/api.js'
  82. import { isWeixin } from '../../util/isWeixin.js'
  83. onLoad(() => {
  84. if (isWeixin()) {
  85. card_number.value = uni.getStorageSync('bus_card_number')
  86. getUserInfo()
  87. } else {
  88. uni.redirectTo({
  89. url: '/pages/404/404?message=请在微信客户端打开链接'
  90. })
  91. }
  92. })
  93. onShow(() => {
  94. getTimeFormat()
  95. getPathList()
  96. getOrderConfig()
  97. currentIndex1.value = 0
  98. currentIndex2.value = null
  99. currentBusId.value = null
  100. busList.value = []
  101. setTimeout(() => {
  102. currentPath.value = pathList.value[0].route
  103. getBusList(pathList.value[0].route)
  104. }, 200)
  105. })
  106. // 页面下拉触发刷新回调
  107. onPullDownRefresh(() => {
  108. getUserInfo()
  109. dateType.value == '今天' ? getTimeFormat() : getTimeFormat(1)
  110. getPathList()
  111. getOrderConfig()
  112. currentIndex1.value = 0
  113. currentIndex2.value = null
  114. currentBusId.value = null
  115. busList.value = []
  116. setTimeout(function() {
  117. currentPath.value = pathList.value[0].route
  118. getBusList(pathList.value[0].route)
  119. uni.stopPullDownRefresh()
  120. }, 500)
  121. })
  122. // 用户card_number
  123. const card_number = ref('')
  124. // 判断是今天还是明天
  125. const dateType = ref('今天')
  126. // 当前月份
  127. const currentMonth = ref('')
  128. // 当前日期
  129. const currentDay = ref('')
  130. // 当前星期
  131. const currentWeek = ref('')
  132. // 发车路线列表
  133. const pathList = ref([])
  134. // 发车路线当前选中项
  135. const currentIndex1 = ref(0)
  136. // 当前发车路线
  137. const currentPath = ref(null)
  138. // 发车车辆列表
  139. const busList = ref([])
  140. // 预约车辆当前选中项
  141. const currentIndex2 = ref(null)
  142. // 当前预约车辆ID
  143. const currentBusId = ref(null)
  144. // 开始预约时间段
  145. const yy_duration = ref('')
  146. // 预约截止时间
  147. const yy_end = ref('')
  148. // 黄家湖校区-墨轩湖校区 候补截止时间
  149. const hjh_end = ref('')
  150. // 墨轩湖校区-黄家湖校区 候补截止时间
  151. const mxh_end = ref('')
  152. // 爽约次数
  153. const black_count = ref('')
  154. // 候补预约状态 true表示预约 false表示候补
  155. const status = ref(true)
  156. // 监听车辆列表更改候补预约状态
  157. // watch(
  158. // () => busList.value,
  159. // newValue => {
  160. // status.value = newValue.some(item => item.can_order == 1)
  161. // }
  162. // )
  163. // 获取用户信息
  164. const getUserInfo = async () => {
  165. const res = await myRequest({
  166. url: '/appget_user.action',
  167. data: {
  168. card_number: card_number.value
  169. }
  170. })
  171. // console.log(res);
  172. uni.setStorageSync('bus-userInfo', JSON.stringify(res.data))
  173. if (res.data && res.data.user_zz !== '教师') {
  174. uni.reLaunch({
  175. url: '/pages/record/record'
  176. })
  177. }
  178. }
  179. // 获取所有的发车路线
  180. const getPathList = async () => {
  181. const res = await myRequest({
  182. url: '/appqueryRoute.action'
  183. })
  184. // console.log(res);
  185. pathList.value = res.data
  186. }
  187. // 根据路线查询所有车次
  188. const getBusList = async route => {
  189. busList.value = []
  190. // 处理时间参数
  191. let date = new Date()
  192. let year = date.getFullYear()
  193. const res = await myRequest({
  194. url: '/appqueryCarNums.action',
  195. data: {
  196. date: `${year}-${currentMonth.value}-${currentDay.value}`,
  197. route: route || currentPath.value
  198. }
  199. })
  200. // console.log(res)
  201. busList.value = res.data || []
  202. if (res.data.length) {
  203. const count = res.data.length
  204. const LastObj = res.data[count - 1]
  205. if (LastObj.boarde_num == LastObj.contain) {
  206. status.value = false
  207. }
  208. }
  209. }
  210. // 获取预约时间段数据
  211. const getOrderConfig = async () => {
  212. const res = await myRequest({
  213. url: '/appqueryConfig.action'
  214. })
  215. // console.log(res);
  216. yy_duration.value = res.data.yy_duration
  217. yy_end.value = res.data.yy_end
  218. hjh_end.value = res.data.hjh_end
  219. mxh_end.value = res.data.mxh_end
  220. black_count.value = res.data.black_count
  221. }
  222. // 立即预约按钮回调
  223. const handleSub = () => {
  224. if (status.value) {
  225. if (!currentPath.value) {
  226. uni.showToast({
  227. title: '请选择路线',
  228. icon: 'none'
  229. })
  230. return
  231. }
  232. if (!currentBusId.value) {
  233. uni.showToast({
  234. title: '请选择车辆',
  235. icon: 'none'
  236. })
  237. return
  238. }
  239. uni.showModal({
  240. title: '提示',
  241. content: '确定预约吗?',
  242. success: res => {
  243. if (res.confirm) {
  244. handleSubscribe()
  245. } else if (res.cancel) {
  246. }
  247. }
  248. })
  249. } else {
  250. if (dateType.value == '明天') {
  251. uni.showToast({
  252. title: '候补功能仅当日开放',
  253. icon: 'none'
  254. })
  255. return
  256. }
  257. if (!currentPath.value) {
  258. uni.showToast({
  259. title: '请选择路线',
  260. icon: 'none'
  261. })
  262. return
  263. }
  264. if (pathList.value[currentIndex1.value].is_repair == 0) {
  265. uni.showToast({
  266. title: '当前路线不可候补',
  267. icon: 'none'
  268. })
  269. return
  270. }
  271. uni.showModal({
  272. title: '提示',
  273. content: '确定候补预约吗?',
  274. success: res => {
  275. if (res.confirm) {
  276. handleStandby()
  277. } else if (res.cancel) {
  278. }
  279. }
  280. })
  281. }
  282. }
  283. // 预约请求
  284. const handleSubscribe = async () => {
  285. // 处理时间参数
  286. let date = new Date()
  287. let year = date.getFullYear()
  288. const res = await myRequest({
  289. url: '/appmakeAppointment.action',
  290. data: {
  291. date: `${year}-${currentMonth.value}-${currentDay.value}`,
  292. card_number: card_number.value,
  293. id: currentBusId.value,
  294. yyEnd: yy_end.value
  295. }
  296. })
  297. // console.log(res);
  298. if (res) {
  299. uni.showToast({
  300. title: res.message
  301. })
  302. currentIndex1.value = null
  303. currentIndex2.value = null
  304. currentPath.value = null
  305. currentBusId.value = null
  306. busList.value = []
  307. uni.switchTab({
  308. url: '/pages/my/my'
  309. })
  310. }
  311. }
  312. // 候补预约请求
  313. const handleStandby = async () => {
  314. const res = await myRequest({
  315. url: '/appwait_appointment.action',
  316. data: {
  317. route: currentPath.value,
  318. card_number: card_number.value,
  319. hh_end: currentPath.value == '墨轩湖校区-黄家湖校区' ? mxh_end.value : hjh_end.value
  320. }
  321. })
  322. // console.log(res);
  323. if (res) {
  324. uni.showToast({
  325. title: res.message
  326. })
  327. currentIndex1.value = null
  328. currentIndex2.value = null
  329. currentPath.value = null
  330. currentBusId.value = null
  331. uni.switchTab({
  332. url: '/pages/my/my'
  333. })
  334. }
  335. }
  336. // 改变选中项回调
  337. const handleChangeCurrentIndex = (type, index, item) => {
  338. if (type === 1) {
  339. currentIndex2.value = null
  340. currentBusId.value = null
  341. currentIndex1.value = index
  342. currentPath.value = item.route
  343. getBusList()
  344. } else {
  345. // 如果车辆不能预约则不进行任何操作
  346. if (item.can_order == 0) {
  347. } else {
  348. currentIndex2.value = index
  349. currentBusId.value = item.id
  350. }
  351. }
  352. }
  353. // 切换日期回调
  354. const handleChangeTime = () => {
  355. if (dateType.value == '今天') {
  356. dateType.value = '明天'
  357. getTimeFormat(1)
  358. } else {
  359. dateType.value = '今天'
  360. getTimeFormat()
  361. }
  362. // currentIndex1.value = null
  363. // currentPath.value = null
  364. // currentIndex2.value = null
  365. // currentBusId.value = null
  366. // busList.value = []
  367. currentIndex1.value = 0
  368. currentPath.value = pathList.value[0].route
  369. currentIndex2.value = null
  370. currentBusId.value = null
  371. busList.value = []
  372. getBusList()
  373. }
  374. // 获取格式化时间 日期 和 星期
  375. const getTimeFormat = dayType => {
  376. let date = new Date()
  377. if (dayType) {
  378. let targetday = date.getTime() + 1000 * 60 * 60 * 24
  379. date.setTime(targetday)
  380. }
  381. let month = (date.getMonth() + 1 + '').padStart(2, '0')
  382. let day = (date.getDate() + '').padStart(2, '0')
  383. let week = date.getDay()
  384. let weekArr = ['星期日', '星期一', '星期二', '星期三', '星期四', '星期五', '星期六']
  385. currentMonth.value = month
  386. currentDay.value = day
  387. currentWeek.value = weekArr[week]
  388. }
  389. // 点击电话回调
  390. const handlePhone = phone => {
  391. uni.makePhoneCall({
  392. phoneNumber: phone
  393. })
  394. }
  395. </script>
  396. <style lang="scss" scoped>
  397. .container {
  398. background-color: #ebeced;
  399. .header-time {
  400. display: flex;
  401. align-items: center;
  402. padding: 0 30rpx;
  403. height: 118rpx;
  404. background-color: #fff;
  405. .today,
  406. .tomorrow {
  407. width: 72rpx;
  408. font-size: 24rpx;
  409. color: #999999;
  410. }
  411. .time-info {
  412. flex: 1;
  413. display: flex;
  414. justify-content: center;
  415. align-items: center;
  416. font-size: 34rpx;
  417. span {
  418. margin: 0 15rpx;
  419. font-size: 24rpx;
  420. color: #3d51e8;
  421. }
  422. }
  423. }
  424. .header-path {
  425. margin-top: 20rpx;
  426. padding: 0 30rpx;
  427. background-color: #fff;
  428. .path-title {
  429. line-height: 95rpx;
  430. font-size: 34rpx;
  431. font-weight: bold;
  432. }
  433. .path-list {
  434. display: flex;
  435. justify-content: space-between;
  436. flex-wrap: wrap;
  437. .path-item {
  438. margin-bottom: 20rpx;
  439. padding: 0 8rpx;
  440. min-width: 45%;
  441. line-height: 96rpx;
  442. text-align: center;
  443. font-size: 27rpx;
  444. border-radius: 14rpx;
  445. background-color: #ebebeb;
  446. }
  447. .active {
  448. color: #fff;
  449. background-color: #5c60f3;
  450. .item-info {
  451. .item-info-detail {
  452. color: #fff;
  453. }
  454. }
  455. }
  456. .unactive {
  457. color: #a6a6a6;
  458. .item-info {
  459. .item-info-detail {
  460. color: #a6a6a6;
  461. }
  462. }
  463. }
  464. }
  465. .path-list-nodata {
  466. text-align: center;
  467. color: #999999;
  468. padding-bottom: 20rpx;
  469. }
  470. }
  471. .carList {
  472. margin-top: 20rpx;
  473. padding-bottom: 30rpx;
  474. min-height: 508rpx;
  475. background-color: #fff;
  476. .carList-title {
  477. padding-left: 30rpx;
  478. line-height: 95rpx;
  479. font-size: 34rpx;
  480. font-weight: bold;
  481. }
  482. .carList-item {
  483. display: flex;
  484. align-items: center;
  485. box-sizing: border-box;
  486. padding: 37rpx 30rpx 32rpx;
  487. height: 163rpx;
  488. .item-time {
  489. position: relative;
  490. width: 128rpx;
  491. font-weight: bold;
  492. }
  493. .item-time::after {
  494. content: '';
  495. height: 77rpx;
  496. position: absolute;
  497. top: -15rpx;
  498. right: 0;
  499. border-right: 1px solid #a6a6a6;
  500. }
  501. .item-info {
  502. display: flex;
  503. flex-direction: column;
  504. justify-content: space-around;
  505. margin-left: 50rpx;
  506. height: 100%;
  507. .item-info-place {
  508. font-weight: bold;
  509. }
  510. .item-info-detail {
  511. color: #999999;
  512. font-size: 26rpx;
  513. span {
  514. margin-left: 20rpx;
  515. }
  516. }
  517. }
  518. }
  519. .active {
  520. color: #fff;
  521. background-color: #5c60f3;
  522. .item-info {
  523. .item-info-detail {
  524. color: #fff;
  525. }
  526. }
  527. }
  528. .unactive {
  529. color: #a6a6a6;
  530. .item-info {
  531. .item-info-detail {
  532. color: #a6a6a6;
  533. }
  534. }
  535. }
  536. .carList-nodata {
  537. padding: 0 30rpx;
  538. text-align: center;
  539. img {
  540. height: 508rpx;
  541. }
  542. .nodata-info {
  543. padding-bottom: 10rpx;
  544. color: #999999;
  545. }
  546. }
  547. }
  548. .btn-box {
  549. padding: 0 30rpx;
  550. background-color: #fff;
  551. .btn {
  552. position: relative;
  553. display: flex;
  554. align-items: center;
  555. width: 690rpx;
  556. height: 95rpx;
  557. border-radius: 15rpx;
  558. box-shadow: 0px 0px 12rpx rgba(0, 0, 0, 0.12);
  559. .btn-clock {
  560. margin-left: 30rpx;
  561. width: 61rpx;
  562. height: 61rpx;
  563. img {
  564. width: 100%;
  565. }
  566. }
  567. .btn-info {
  568. margin-left: 18rpx;
  569. flex: 1;
  570. display: flex;
  571. flex-direction: column;
  572. justify-content: center;
  573. font-size: 24rpx;
  574. color: #5863f1;
  575. .btn-info-title {
  576. margin-bottom: 8rpx;
  577. }
  578. .btn-info-title2 {
  579. font-size: 28rpx;
  580. margin-bottom: 8rpx;
  581. }
  582. .btn-info-time {
  583. color: #b3b3b3;
  584. }
  585. }
  586. .btn-button {
  587. position: absolute;
  588. right: 0;
  589. top: -7rpx;
  590. width: 257rpx;
  591. height: 113rpx;
  592. line-height: 113rpx;
  593. text-align: center;
  594. font-size: 30rpx;
  595. color: #fff;
  596. background: url(../../static/box.png);
  597. background-size: 100% 100%;
  598. }
  599. }
  600. }
  601. .box-info {
  602. padding: 30rpx 30rpx 40rpx;
  603. background-color: #fff;
  604. .info-title {
  605. height: 41rpx;
  606. font-size: 28rpx;
  607. color: #666666;
  608. }
  609. .info-detail {
  610. margin-top: 5rpx;
  611. color: #999999;
  612. font-size: 24rpx;
  613. }
  614. }
  615. }
  616. </style>