home.vue 14 KB

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