home.vue 15 KB

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