home.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714
  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="handleSub">{{ 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 }}分钟,如当月爽约{{ black_count }}次,账号会被锁定,锁定后联系车队长解锁。车队长联系方式:
  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. onLoad(() => {
  91. if (isWeixin()) {
  92. filterIdentity()
  93. card_number.value = uni.getStorageSync('bus_card_number')
  94. } else {
  95. uni.redirectTo({
  96. url: '/pages/404/404?message=请在微信客户端打开链接'
  97. })
  98. }
  99. })
  100. onShow(() => {
  101. dateType.value == '今天' ? getTimeFormat() : getTimeFormat(1)
  102. getPathList()
  103. getOrderConfig()
  104. currentIndex1.value = 0
  105. currentIndex2.value = null
  106. currentBusId.value = null
  107. busList.value = []
  108. setTimeout(() => {
  109. currentPath.value = pathList.value[0].route
  110. getBusList(pathList.value[0].route)
  111. }, 300)
  112. })
  113. // 页面下拉触发刷新回调
  114. onPullDownRefresh(() => {
  115. dateType.value == '今天' ? getTimeFormat() : getTimeFormat(1)
  116. getPathList()
  117. getOrderConfig()
  118. currentIndex1.value = 0
  119. currentIndex2.value = null
  120. currentBusId.value = null
  121. busList.value = []
  122. setTimeout(function () {
  123. currentPath.value = pathList.value[0].route
  124. getBusList(pathList.value[0].route)
  125. uni.stopPullDownRefresh()
  126. }, 500)
  127. })
  128. // 用户card_number
  129. const card_number = ref('')
  130. // 判断是今天还是明天
  131. const dateType = ref('今天')
  132. // 当前年份
  133. const currentYear = ref('')
  134. // 当前月份
  135. const currentMonth = ref('')
  136. // 当前日期
  137. const currentDay = ref('')
  138. // 当前星期
  139. const currentWeek = ref('')
  140. // 发车路线列表
  141. const pathList = ref([])
  142. // 发车路线当前选中项
  143. const currentIndex1 = ref(0)
  144. // 当前发车路线
  145. const currentPath = ref(null)
  146. // 发车车辆列表
  147. const busList = ref([])
  148. // 预约车辆当前选中项
  149. const currentIndex2 = ref(null)
  150. // 当前预约车辆ID
  151. const currentBusId = ref(null)
  152. // 开始预约时间段
  153. const yy_duration = ref('')
  154. // 预约截止时间
  155. const yy_end = ref('')
  156. // 南昌-靖安 候补截止时间
  157. const hjh_end = ref('')
  158. // 靖安-南昌 候补截止时间
  159. const mxh_end = ref('')
  160. // 爽约次数
  161. const black_count = ref('')
  162. // 候补预约状态 true表示预约 false表示候补
  163. const status = ref(true)
  164. // 监听车辆列表更改候补预约状态
  165. watch(
  166. () => busList.value,
  167. (newValue) => {
  168. if (newValue.length) {
  169. let flag = newValue.some((item) => item.can_order == 1)
  170. let count = newValue.length
  171. let LastObj = newValue[count - 1]
  172. if (LastObj.boarde_num == LastObj.contain && !flag) {
  173. status.value = false
  174. } else {
  175. status.value = true
  176. }
  177. }
  178. }
  179. )
  180. // 获取所有的发车路线
  181. const getPathList = async () => {
  182. const res = await myRequest({
  183. url: '/appqueryRoute.action'
  184. })
  185. // console.log(res);
  186. pathList.value = res.data
  187. }
  188. // 根据路线查询所有车次
  189. const getBusList = async (route) => {
  190. busList.value = []
  191. const res = await myRequest({
  192. url: '/appqueryCarNums.action',
  193. data: {
  194. date: `${currentYear.value}-${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. const res = await myRequest({
  278. url: '/appmakeAppointment.action',
  279. data: {
  280. date: `${currentYear.value}-${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 year = date.getFullYear()
  371. let month = (date.getMonth() + 1 + '').padStart(2, '0')
  372. let day = (date.getDate() + '').padStart(2, '0')
  373. let week = date.getDay()
  374. let weekArr = ['星期日', '星期一', '星期二', '星期三', '星期四', '星期五', '星期六']
  375. currentYear.value = year
  376. currentMonth.value = month
  377. currentDay.value = day
  378. currentWeek.value = weekArr[week]
  379. }
  380. // 点击电话回调
  381. const handlePhone = (phone) => {
  382. uni.makePhoneCall({
  383. phoneNumber: phone
  384. })
  385. }
  386. </script>
  387. <style lang="scss" scoped>
  388. .container {
  389. background-color: #ebeced;
  390. .header-time {
  391. display: flex;
  392. align-items: center;
  393. padding: 0 30rpx;
  394. height: 118rpx;
  395. background-color: #fff;
  396. .today,
  397. .tomorrow {
  398. width: 72rpx;
  399. font-size: 24rpx;
  400. color: #999999;
  401. }
  402. .time-info {
  403. flex: 1;
  404. display: flex;
  405. justify-content: center;
  406. align-items: center;
  407. font-size: 34rpx;
  408. span {
  409. margin: 0 15rpx;
  410. font-size: 24rpx;
  411. color: #3d51e8;
  412. }
  413. }
  414. }
  415. .header-path {
  416. margin-top: 20rpx;
  417. padding: 0 30rpx;
  418. background-color: #fff;
  419. .path-title {
  420. line-height: 95rpx;
  421. font-size: 34rpx;
  422. font-weight: bold;
  423. }
  424. .path-list {
  425. display: flex;
  426. justify-content: space-between;
  427. flex-wrap: wrap;
  428. .path-item {
  429. box-sizing: border-box;
  430. margin-bottom: 20rpx;
  431. padding: 0 8rpx;
  432. min-width: 45%;
  433. line-height: 96rpx;
  434. text-align: center;
  435. font-size: 40rpx;
  436. font-weight: bold;
  437. border-radius: 14rpx;
  438. background-color: #ffdb6e;
  439. }
  440. .scale {
  441. transform: scale(1.08);
  442. }
  443. .active {
  444. color: #fff;
  445. background-color: #3d51e8;
  446. .item-info {
  447. .item-info-detail {
  448. color: #fff;
  449. }
  450. }
  451. }
  452. .unactive {
  453. color: #a6a6a6;
  454. .item-info {
  455. .item-info-detail {
  456. color: #a6a6a6;
  457. }
  458. }
  459. }
  460. }
  461. .path-list-nodata {
  462. text-align: center;
  463. color: #999999;
  464. padding-bottom: 20rpx;
  465. }
  466. }
  467. .carList {
  468. margin-top: 20rpx;
  469. padding-bottom: 30rpx;
  470. min-height: 508rpx;
  471. background-color: #fff;
  472. .carList-title {
  473. padding-left: 30rpx;
  474. line-height: 95rpx;
  475. font-size: 34rpx;
  476. font-weight: bold;
  477. }
  478. .carList-item {
  479. position: relative;
  480. display: flex;
  481. align-items: center;
  482. box-sizing: border-box;
  483. padding: 37rpx 100rpx 32rpx 30rpx;
  484. margin: 0 auto 20rpx;
  485. width: 690rpx;
  486. min-height: 224rpx;
  487. border-radius: 24rpx;
  488. .item-time {
  489. position: relative;
  490. width: 128rpx;
  491. font-weight: bold;
  492. }
  493. .item-time::after {
  494. content: '';
  495. height: 77rpx;
  496. position: absolute;
  497. top: -15rpx;
  498. right: 0rpx;
  499. border-right: 1px solid #a6a6a6;
  500. }
  501. .item-info {
  502. flex: 1;
  503. display: flex;
  504. flex-direction: column;
  505. justify-content: space-around;
  506. margin-left: 50rpx;
  507. height: 100%;
  508. .item-info-place {
  509. font-weight: bold;
  510. }
  511. .item-info-detail {
  512. font-size: 26rpx;
  513. span {
  514. margin-left: 20rpx;
  515. }
  516. }
  517. }
  518. .item-check {
  519. position: absolute;
  520. right: 2rpx;
  521. bottom: 2rpx;
  522. display: flex;
  523. justify-content: center;
  524. width: 100rpx;
  525. height: 70rpx;
  526. font-size: 50rpx;
  527. border-radius: 24rpx 0 22rpx 0;
  528. }
  529. .type {
  530. color: #fff;
  531. background-color: #d43030;
  532. }
  533. .type2 {
  534. color: #3d51e8;
  535. background-color: #fff;
  536. }
  537. }
  538. .yellow {
  539. color: #e01f1f;
  540. background-color: #ffdb6e;
  541. }
  542. .blue {
  543. color: #fff;
  544. background-color: #3d51e8;
  545. }
  546. .unactive {
  547. color: #a6a6a6;
  548. .item-info {
  549. .item-info-detail {
  550. color: #a6a6a6;
  551. }
  552. }
  553. }
  554. .carList-nodata {
  555. padding: 0 30rpx;
  556. text-align: center;
  557. img {
  558. height: 508rpx;
  559. }
  560. .nodata-info {
  561. padding-bottom: 10rpx;
  562. color: #999999;
  563. }
  564. }
  565. }
  566. .btn-box {
  567. padding: 0 30rpx;
  568. background-color: #fff;
  569. .btn {
  570. position: relative;
  571. display: flex;
  572. align-items: center;
  573. width: 690rpx;
  574. height: 95rpx;
  575. border-radius: 15rpx;
  576. box-shadow: 0px 0px 12rpx rgba(0, 0, 0, 0.12);
  577. .btn-clock {
  578. margin-left: 30rpx;
  579. width: 61rpx;
  580. height: 61rpx;
  581. img {
  582. width: 100%;
  583. }
  584. }
  585. .btn-info {
  586. margin-left: 18rpx;
  587. flex: 1;
  588. display: flex;
  589. flex-direction: column;
  590. justify-content: center;
  591. font-size: 24rpx;
  592. color: #d43030;
  593. .btn-info-title {
  594. margin-bottom: 8rpx;
  595. }
  596. .btn-info-title2 {
  597. font-size: 28rpx;
  598. margin-bottom: 8rpx;
  599. }
  600. .btn-info-time {
  601. color: #b3b3b3;
  602. }
  603. }
  604. .btn-button {
  605. position: absolute;
  606. right: 0;
  607. top: -7rpx;
  608. width: 257rpx;
  609. height: 113rpx;
  610. line-height: 113rpx;
  611. text-align: center;
  612. font-size: 30rpx;
  613. color: #fff;
  614. background: url(../../static/box.png);
  615. background-size: 100% 100%;
  616. }
  617. }
  618. }
  619. .box-info {
  620. padding: 30rpx 30rpx 40rpx;
  621. background-color: #fff;
  622. .info-title {
  623. height: 41rpx;
  624. font-size: 28rpx;
  625. color: #666666;
  626. }
  627. .info-detail {
  628. margin-top: 5rpx;
  629. color: #999999;
  630. font-size: 24rpx;
  631. }
  632. }
  633. }
  634. </style>