home.vue 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435
  1. <template>
  2. <view class="container">
  3. <image class="banner" src="@/static/images/home/banner.png" mode="aspectFill" />
  4. <view class="title" :style="{ top: `${paddingTop * 2}rpx` }"></view>
  5. <image class="people" src="@/static/images/home/people.png" mode="aspectFill" />
  6. <!-- 选择时间路线区域 -->
  7. <view class="path">
  8. <view class="path_box">
  9. <view>选择日期</view>
  10. <view class="box_time" @click="chooseDate">
  11. <wd-icon name="warning" color="#707070" size="10" />
  12. <view class="time" :class="currentTime ? '' : 'novalue'">
  13. <!-- 2025-8月-14日 星期五 -->
  14. {{ currentTime ? currentTime : '请选择日期' }}
  15. </view>
  16. <wd-icon name="calendar" color="#707070" size="26" />
  17. </view>
  18. <view>选择路线</view>
  19. <view
  20. v-for="(item, index) in pathList"
  21. :key="index"
  22. class="box_line"
  23. :class="currentIndex === index ? 'active' : ''"
  24. @click="handleChangeCurrentIndex(index, item)"
  25. >
  26. <image v-if="index % 2 === 1" style="width: 28rpx; height: 28rpx; margin-right: 20rpx" src="@/static/images/home/address.png" mode="aspectFill" />
  27. <image v-else style="width: 28rpx; height: 28rpx; margin-right: 20rpx" src="@/static/images/home/address2.png" mode="aspectFill" />
  28. {{ item.route }}
  29. </view>
  30. </view>
  31. </view>
  32. <!-- 选择车辆区域 -->
  33. <view class="car">
  34. 选择车辆
  35. <view class="car_list">
  36. <!-- 每一个车辆区域 -->
  37. <view v-for="(item, index) in busList" :key="index" :class="{ 'car_box': true, 'car_box1': item.isExpired,'car_box2': !item.isExpired }" @click="handleClickItem(item)">
  38. <view class="box_top">
  39. <view class="top_time">{{item.ci_time}}</view>
  40. <image class="top-line" src="../../static/images/home/line.png"></image>
  41. <view class="top_info">
  42. <view :class="{ 'info_box': true, 'top': index2 > 0 }" v-for="(item2, index2) in getRouteParts(item.route_end)" :key="index2">{{item2}}</view>
  43. <!-- <view class="info_box top">{{getRouteParts(item.route_end).suffix}}</view> -->
  44. </view>
  45. <view class="top_msg">
  46. <view class="msg_price">
  47. ¥
  48. <text class="text">{{ item.price }}</text>
  49. </view>
  50. <view class="msg_num">剩余{{ item.contain - item.boarde_num }}座</view>
  51. </view>
  52. </view>
  53. <image class="top-line2" src="../../static/images/home/line-bu.png" v-if="item.isExpired==false"></image>
  54. <view class="box_bottom">
  55. <view class="bottom_box">6点30分起售</view>
  56. <view class="bottom_box">车牌:{{ item.car_number }}</view>
  57. <view class="bottom_box">容量:{{ item.contain }}座</view>
  58. </view>
  59. </view>
  60. </view>
  61. <view v-if="!busList.length">
  62. <wd-status-tip image="content" tip="暂无数据" />
  63. </view>
  64. </view>
  65. <!-- 温馨提示区域 -->
  66. <view class="box_info">
  67. <view class="info_title">温馨提示</view>
  68. <view class="info_detail">
  69. 预约截止时间为发车前{{ yy_end }}分钟,车队长联系方式:
  70. <span @click="handlePhone('13576937506')">13576937506</span>
  71. ,技术支持联系方式:
  72. <span @click="handlePhone(`0791 - 82293574`)">0791-82293574</span>
  73. ,候补功能仅当日开放。
  74. </view>
  75. </view>
  76. </view>
  77. <!-- 授权手机号 -->
  78. <AuthorizePopup :show="show" @close="handleClose" />
  79. </template>
  80. <script setup>
  81. import { onLoad } from '@dcloudio/uni-app'
  82. import { onMounted, ref } from 'vue'
  83. import { myRequest } from '@/utils/api.ts'
  84. import dayjs from 'dayjs'
  85. const show = ref(false)
  86. // 胶囊按钮距离页面顶部的距离
  87. const paddingTop = ref(0)
  88. // 用户信息
  89. const userInfo = uni.getStorageSync('carUserInfo')
  90. // 当前日期
  91. const currentTime = ref('')
  92. // 发车路线列表
  93. const pathList = ref([])
  94. // 当前发车路线
  95. const currentPath = ref(null)
  96. // 当前路线
  97. const currentIndex = ref(0)
  98. // 发车车辆列表
  99. const busList = ref([])
  100. // 预约截止时间
  101. const yy_end = ref(0)
  102. // 截取箭头前后的文字
  103. const getRouteParts = (str) => {
  104. if (typeof str === 'string' && str.length > 0) {
  105. return str.split('→');
  106. }
  107. return [];
  108. // if (str && typeof str === 'string') {
  109. // const parts = str.split('→').slice(1); // 分割后取第2个及以后的元素
  110. // // return {
  111. // // prefix: parts[0] || '', // 箭头前的文字
  112. // // suffix: parts[parts.length - 1] || '' // 箭头最后的文字
  113. // // };
  114. // }
  115. // return { prefix: '', suffix: '' };
  116. };
  117. // 获取预约时间段数据
  118. async function getOrderConfig() {
  119. const res = await myRequest({
  120. url: '/appqueryConfig.action'
  121. })
  122. // console.log(res)
  123. yy_end.value = res.data.data.yy_end || 0
  124. }
  125. // 根据路线查询所有车次
  126. async function getBusList(route) {
  127. const res = await myRequest({
  128. url: '/tAppqueryCarNums.action',
  129. data: {
  130. date: currentTime.value,
  131. route: route || currentPath.value,
  132. mobile: userInfo.mobile
  133. }
  134. })
  135. // console.log(res)
  136. // ... 在获取到 res 数据之后
  137. if (res.data && res.data.data) {
  138. res.data.data.forEach(item => {
  139. // 1. 拼接目标时间字符串
  140. const targetDateStr = `${item.s_date} ${item.yy_end}`;
  141. // 2. 转换为时间戳并比较
  142. const targetTimestamp = new Date(targetDateStr).getTime();
  143. const nowTimestamp = new Date().getTime();
  144. // 3. 添加判断后的参数到 item 对象中
  145. // 这里我们添加一个叫 isExpired 的布尔值
  146. item.isExpired = nowTimestamp > targetTimestamp;
  147. });
  148. busList.value = res.data.data || []
  149. console.log(busList.value,'车次')
  150. }
  151. }
  152. // 获取所有的发车路线
  153. async function getPathList() {
  154. const res = await myRequest({
  155. url: '/appqueryRoute.action'
  156. })
  157. // console.log(res)
  158. pathList.value = res.data.data || []
  159. if (pathList.value.length) {
  160. currentPath.value = pathList.value[0]?.route
  161. getBusList(currentPath.value)
  162. }
  163. }
  164. onMounted(() => {
  165. const bus_date = uni.getStorageSync('bus_date')
  166. if (bus_date) {
  167. currentTime.value = bus_date
  168. } else {
  169. currentTime.value = dayjs(Date.now()).format('YYYY-MM-DD')
  170. }
  171. paddingTop.value = uni.getMenuButtonBoundingClientRect().top
  172. getOrderConfig()
  173. getPathList()
  174. })
  175. onLoad(() => {
  176. // uni.removeStorageSync('bus_date')
  177. })
  178. // 选择路线回调
  179. function handleChangeCurrentIndex(index, item) {
  180. currentIndex.value = index
  181. currentPath.value = item.route
  182. getBusList(currentPath.value)
  183. }
  184. // 点击跳转选择日期
  185. function chooseDate() {
  186. uni.navigateTo({
  187. url: '/pages/date/date'
  188. })
  189. }
  190. // 点击每一个车辆的回调
  191. function handleClickItem(item) {
  192. const info = encodeURIComponent(JSON.stringify(item),'l')
  193. uni.navigateTo({
  194. url: `/pages/chooseCar/chooseCar?info=${info}`
  195. })
  196. }
  197. // 点击拨打电话回调
  198. function handlePhone(phoneNumber) {
  199. uni.makePhoneCall({
  200. phoneNumber
  201. })
  202. }
  203. const handleClose = () => {
  204. show.value = false
  205. }
  206. </script>
  207. <style lang="scss" scoped>
  208. .container {
  209. position: relative;
  210. height: 100%;
  211. .banner {
  212. width: 100%;
  213. height: 680rpx;
  214. }
  215. .title {
  216. position: absolute;
  217. left: 314rpx;
  218. font-size: 40rpx;
  219. color: #001713;
  220. }
  221. .people {
  222. position: absolute;
  223. top: 274rpx;
  224. right: 18rpx;
  225. width: 234rpx;
  226. height: 298rpx;
  227. }
  228. .path {
  229. display: flex;
  230. margin: -266rpx auto 0;
  231. width: 706rpx;
  232. height: 410rpx;
  233. background: url(@/static/images/home/box.png);
  234. background-size: 100% 100%;
  235. .path_box {
  236. margin-top: 48rpx;
  237. margin-left: 50rpx;
  238. color: #707070;
  239. font-size: 24rpx;
  240. .box_time {
  241. display: flex;
  242. align-items: center;
  243. margin-top: 12rpx;
  244. margin-bottom: 14rpx;
  245. height: 64rpx;
  246. color: #001713;
  247. font-size: 28rpx;
  248. font-weight: bold;
  249. border-bottom: 2rpx solid #ebecf1;
  250. .time {
  251. margin: 0 56rpx 0 10rpx;
  252. }
  253. .novalue {
  254. color: #707070;
  255. }
  256. }
  257. .box_line {
  258. display: flex;
  259. align-items: center;
  260. height: 76rpx;
  261. font-size: 28rpx;
  262. }
  263. .active {
  264. color: #001713;
  265. font-weight: bold;
  266. transform: scale(1.08);
  267. }
  268. }
  269. }
  270. .car {
  271. margin: auto;
  272. width: 700rpx;
  273. color: #001713;
  274. font-size: 24rpx;
  275. .car_list {
  276. margin-top: 20rpx;
  277. .car_box1{
  278. /* 背景色调:浅灰色系,可根据需求微调 */
  279. background-color: rgba(0, 0, 0, 0.1);
  280. /* 阴影:轻微立体感,参数为 水平偏移 垂直偏移 模糊度 扩散度 颜色 */
  281. box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
  282. /* 可选:圆角优化视觉 */
  283. border-radius: 8px;
  284. }
  285. .car_box2{
  286. background-color: #FFFFFF;
  287. }
  288. .car_box {
  289. box-sizing: border-box;
  290. padding: 34rpx 34rpx 0;
  291. margin-bottom: 20rpx;
  292. width: 100%;
  293. height: 100%;
  294. background-color: #FFFFFF;
  295. // background: url(@/static/images/home/car-box.png);
  296. background-size: 100% 100%;
  297. .box_top {
  298. display: flex;
  299. align-items: center;
  300. // height: 110rpx;
  301. .top_time {
  302. margin-top: -30rpx;
  303. margin-right: 76rpx;
  304. font-size: 44rpx;
  305. }
  306. .top-line{
  307. width: 7px;
  308. height: 34px;
  309. background-size: 100%;
  310. }
  311. .top_info {
  312. margin-left: 2px;
  313. height: 100%;
  314. font-size: 28rpx;
  315. .info_box {
  316. width: 320rpx;
  317. overflow: hidden;
  318. text-overflow: ellipsis;
  319. white-space: nowrap;
  320. }
  321. .top {
  322. margin-top: 8rpx;
  323. }
  324. }
  325. .top_msg {
  326. // margin-left: 8rpx;
  327. height: 100%;
  328. color: #f86818;
  329. .msg_price {
  330. margin-top: -15rpx;
  331. font-size: 28rpx;
  332. .text {
  333. font-size: 48rpx;
  334. }
  335. }
  336. .msg_num {
  337. margin-top: 8rpx;
  338. }
  339. }
  340. }
  341. .top-line2{
  342. margin-left: -20px;
  343. width: 114%;
  344. height: 17px;
  345. background-size: 100%;
  346. }
  347. .box_bottom {
  348. display: flex;
  349. align-items: center;
  350. height: 58rpx;
  351. color: #f86818;
  352. .bottom_box {
  353. margin-right: 65rpx;
  354. }
  355. }
  356. }
  357. }
  358. }
  359. .box_info {
  360. padding: 30rpx 30rpx 40rpx;
  361. .info_title {
  362. height: 41rpx;
  363. font-size: 28rpx;
  364. color: #666666;
  365. }
  366. .info_detail {
  367. margin-top: 5rpx;
  368. color: #999999;
  369. font-size: 24rpx;
  370. }
  371. }
  372. }
  373. </style>