home.vue 14 KB

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