home.vue 14 KB

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