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