home.vue 15 KB

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