home.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463
  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(workTele)">{{workTele}}</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 workTele = ref('')
  104. // 截取箭头前后的文字
  105. const getRouteParts = (str) => {
  106. if (typeof str === 'string' && str.length > 0) {
  107. return str.split('→');
  108. }
  109. return [];
  110. // if (str && typeof str === 'string') {
  111. // const parts = str.split('→').slice(1); // 分割后取第2个及以后的元素
  112. // // return {
  113. // // prefix: parts[0] || '', // 箭头前的文字
  114. // // suffix: parts[parts.length - 1] || '' // 箭头最后的文字
  115. // // };
  116. // }
  117. // return { prefix: '', suffix: '' };
  118. };
  119. // 获取预约时间段数据
  120. async function getOrderConfig() {
  121. const res = await myRequest({
  122. url: '/appqueryConfig.action'
  123. })
  124. // console.log(res)
  125. yy_end.value = res.data.data.yy_end || 0
  126. }
  127. // 根据路线查询所有车次
  128. async function getBusList(route) {
  129. const res = await myRequest({
  130. url: '/tAppqueryCarNums.action',
  131. data: {
  132. date: currentTime.value,
  133. route: route || currentPath.value,
  134. mobile: userInfo.mobile
  135. }
  136. })
  137. // console.log(res)
  138. // ... 在获取到 res 数据之后
  139. if (res.data && res.data.data) {
  140. res.data.data.forEach(item => {
  141. // 1. 拼接目标时间字符串
  142. const targetDateStr = `${item.s_date} ${item.yy_end}`;
  143. // 2. 转换为时间戳并比较
  144. const targetTimestamp = new Date(targetDateStr).getTime();
  145. const nowTimestamp = new Date().getTime();
  146. // 3. 添加判断后的参数到 item 对象中
  147. // 这里我们添加一个叫 isExpired 的布尔值
  148. item.isExpired = nowTimestamp > targetTimestamp;
  149. });
  150. busList.value = res.data.data || []
  151. console.log(busList.value,'车次')
  152. }
  153. }
  154. //客服电话
  155. async function getTuigai() {
  156. const res = await myRequest({
  157. url: '/carBook/cnqueryHb.action',
  158. data: {
  159. }
  160. })
  161. if(res.code==200){
  162. workTele.value=res.data.workMobile
  163. }else{
  164. uni.showToast({
  165. title: res.message,
  166. icon: 'none'
  167. });
  168. }
  169. }
  170. // 获取所有的发车路线
  171. async function getPathList() {
  172. const res = await myRequest({
  173. url: '/appqueryRoute.action'
  174. })
  175. // console.log(res)
  176. pathList.value = res.data.data || []
  177. if (pathList.value.length) {
  178. currentPath.value = pathList.value[0]?.route
  179. getBusList(currentPath.value)
  180. }
  181. }
  182. onMounted(() => {
  183. const bus_date = uni.getStorageSync('bus_date')
  184. if (bus_date) {
  185. currentTime.value = bus_date
  186. } else {
  187. currentTime.value = dayjs(Date.now()).format('YYYY-MM-DD')
  188. }
  189. paddingTop.value = uni.getMenuButtonBoundingClientRect().top
  190. getTuigai()
  191. getOrderConfig()
  192. getPathList()
  193. })
  194. onLoad(() => {
  195. // uni.removeStorageSync('bus_date')
  196. })
  197. // 选择路线回调
  198. function handleChangeCurrentIndex(index, item) {
  199. currentIndex.value = index
  200. currentPath.value = item.route
  201. getBusList(currentPath.value)
  202. }
  203. // 点击跳转选择日期
  204. function chooseDate() {
  205. uni.navigateTo({
  206. url: '/pages/date/date'
  207. })
  208. }
  209. // 点击每一个车辆的回调
  210. function handleClickItem(item) {
  211. const info = encodeURIComponent(JSON.stringify(item),'l')
  212. uni.navigateTo({
  213. url: `/pages/chooseCar/chooseCar?info=${info}`
  214. })
  215. }
  216. // 点击拨打电话回调
  217. function handlePhone(phoneNumber) {
  218. uni.makePhoneCall({
  219. phoneNumber
  220. })
  221. }
  222. const handleClose = () => {
  223. show.value = false
  224. }
  225. const onShareAppMessage = (res) => { //发送给朋友
  226. return {
  227. // title: this.tuiguang,
  228. path: '/pages/home/home',
  229. // imageUrl: this.tuiguangImg,
  230. }
  231. }
  232. </script>
  233. <style lang="scss" scoped>
  234. .container {
  235. position: relative;
  236. height: 100%;
  237. .banner {
  238. width: 100%;
  239. height: 680rpx;
  240. }
  241. .title {
  242. position: absolute;
  243. left: 314rpx;
  244. font-size: 40rpx;
  245. color: #001713;
  246. }
  247. .people {
  248. position: absolute;
  249. top: 274rpx;
  250. right: 18rpx;
  251. width: 234rpx;
  252. height: 298rpx;
  253. }
  254. .path {
  255. display: flex;
  256. margin: -266rpx auto 0;
  257. width: 706rpx;
  258. height: 410rpx;
  259. background: url(@/static/images/home/box.png);
  260. background-size: 100% 100%;
  261. .path_box {
  262. margin-top: 48rpx;
  263. margin-left: 50rpx;
  264. color: #707070;
  265. font-size: 24rpx;
  266. .box_time {
  267. display: flex;
  268. align-items: center;
  269. margin-top: 12rpx;
  270. margin-bottom: 14rpx;
  271. height: 64rpx;
  272. color: #001713;
  273. font-size: 28rpx;
  274. font-weight: bold;
  275. border-bottom: 2rpx solid #ebecf1;
  276. .time {
  277. margin: 0 56rpx 0 10rpx;
  278. }
  279. .novalue {
  280. color: #707070;
  281. }
  282. }
  283. .box_line {
  284. display: flex;
  285. align-items: center;
  286. height: 76rpx;
  287. font-size: 28rpx;
  288. }
  289. .active {
  290. color: #001713;
  291. font-weight: bold;
  292. transform: scale(1.08);
  293. }
  294. }
  295. }
  296. .car {
  297. margin: auto;
  298. width: 700rpx;
  299. color: #001713;
  300. font-size: 24rpx;
  301. .car_list {
  302. margin-top: 20rpx;
  303. .car_box1{
  304. /* 背景色调:浅灰色系,可根据需求微调 */
  305. background-color: rgba(0, 0, 0, 0.1);
  306. /* 阴影:轻微立体感,参数为 水平偏移 垂直偏移 模糊度 扩散度 颜色 */
  307. box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
  308. /* 可选:圆角优化视觉 */
  309. border-radius: 8px;
  310. }
  311. .car_box2{
  312. background-color: #FFFFFF;
  313. }
  314. .car_box {
  315. box-sizing: border-box;
  316. padding: 34rpx 34rpx 0;
  317. margin-bottom: 20rpx;
  318. width: 100%;
  319. height: 100%;
  320. background-color: #FFFFFF;
  321. // background: url(@/static/images/home/car-box.png);
  322. background-size: 100% 100%;
  323. .box_top {
  324. display: flex;
  325. align-items: center;
  326. // height: 110rpx;
  327. .top_time {
  328. margin-top: -30rpx;
  329. margin-right: 76rpx;
  330. font-size: 44rpx;
  331. }
  332. .top-line{
  333. width: 7px;
  334. height: 34px;
  335. background-size: 100%;
  336. }
  337. .top_info {
  338. margin-left: 2px;
  339. height: 100%;
  340. font-size: 28rpx;
  341. .info_box {
  342. width: 320rpx;
  343. overflow: hidden;
  344. text-overflow: ellipsis;
  345. white-space: nowrap;
  346. }
  347. .top {
  348. margin-top: 8rpx;
  349. }
  350. }
  351. .top_msg {
  352. // margin-left: 8rpx;
  353. height: 100%;
  354. color: #f86818;
  355. .msg_price {
  356. margin-top: -15rpx;
  357. font-size: 28rpx;
  358. .text {
  359. font-size: 48rpx;
  360. }
  361. }
  362. .msg_num {
  363. margin-top: 8rpx;
  364. }
  365. }
  366. }
  367. .top-line2{
  368. margin-left: -20px;
  369. width: 114%;
  370. height: 17px;
  371. background-size: 100%;
  372. }
  373. .box_bottom {
  374. display: flex;
  375. align-items: center;
  376. height: 58rpx;
  377. color: #f86818;
  378. .bottom_box {
  379. margin-right: 65rpx;
  380. }
  381. }
  382. }
  383. }
  384. }
  385. .box_info {
  386. padding: 30rpx 30rpx 40rpx;
  387. .info_title {
  388. height: 41rpx;
  389. font-size: 28rpx;
  390. color: #666666;
  391. }
  392. .info_detail {
  393. margin-top: 5rpx;
  394. color: #999999;
  395. font-size: 24rpx;
  396. }
  397. }
  398. }
  399. </style>