home.vue 14 KB

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