hexiaolist.vue 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310
  1. <template>
  2. <!-- 页面容器 -->
  3. <view class="page-container">
  4. <!-- 搜索区域:点击跳转时间选择页 -->
  5. <view class="search-bar" @click="jumpToDateSelect">
  6. <view class="search-input-wrap">
  7. <text class="search-input">
  8. {{ searchTime || '开始时间 ~ 结束时间' }}
  9. </text>
  10. </view>
  11. <!-- 取消按钮:仅在已选择时间时显示 -->
  12. <text
  13. class="cancel-btn"
  14. v-if="searchTime"
  15. @click.stop="cancelSearch"
  16. >
  17. 取消
  18. </text>
  19. </view>
  20. <!-- 核销记录列表 -->
  21. <view class="record-list">
  22. <view
  23. class="record-item"
  24. v-for="(item, index) in recordList"
  25. :key="index"
  26. >
  27. <!-- 已乘车标签 -->
  28. <view class="status-tag">
  29. <text v-if="item.payState==0">待支付</text>
  30. <text v-if="item.payState==2">退款中</text>
  31. <text v-if="item.payState==3">已取消</text>
  32. <text v-if="item.payState==1">
  33. <text v-if="item.byState==1">预约成功</text>
  34. <text v-if="item.byState==2">已乘车</text>
  35. <text v-if="item.byState==3">未乘车</text>
  36. </text>
  37. </view>
  38. <!-- 记录内容 -->
  39. <view class="record-content">
  40. <text class="record-text">发车日期:{{ item.ciDate }}</text>
  41. <text class="record-text">发车时间:{{ item.ciTime }}</text>
  42. <text class="record-text">车次:{{ item.carNumber }}</text>
  43. <text class="record-text">预约人:{{ item.username }}</text>
  44. <text class="record-text" @click.stop="bindphone(item.mobile)">手机号码:{{ item.mobile }}</text>
  45. <text class="record-text">核销专员号码:{{ item.vertifyManMobile }}</text>
  46. <text class="record-text">核销时间:{{ item.vertifyTime }}</text>
  47. </view>
  48. </view>
  49. </view>
  50. <!-- 无数据提示 -->
  51. <view v-if="recordList.length === 0" class="empty-tip">
  52. 暂无核销记录
  53. </view>
  54. </view>
  55. </template>
  56. <script setup>
  57. import { ref } from 'vue'
  58. import { onLoad, onReachBottom, onShow, onUnload } from '@dcloudio/uni-app'
  59. import { myRequest } from '@/utils/api.ts'
  60. // 搜索时间显示文本
  61. const searchTime = ref('')
  62. // 接收时间选择页的参数(用于页面栈传递)
  63. const selectedDate = ref(null)
  64. // 用户信息
  65. const userInfo = ref()
  66. const startT=ref('')
  67. const endT=ref('')
  68. // 每页多少条
  69. const pageSize = ref(10)
  70. // 当前页
  71. const currentPage = ref(1)
  72. // 总条数
  73. const total = ref(0)
  74. // 核销记录数据
  75. const recordList = ref([]) // 初始化空数组,避免本地测试数据干扰
  76. // 跳转至时间选择页
  77. const jumpToDateSelect = () => {
  78. uni.navigateTo({
  79. url: '/pages/select/select'
  80. })
  81. }
  82. // 取消搜索(清空时间筛选)
  83. const cancelSearch = () => {
  84. // 清空时间相关参数
  85. searchTime.value = ''
  86. startT.value = ''
  87. endT.value = ''
  88. selectedDate.value = null
  89. // 重置页码并重新加载全部数据
  90. currentPage.value = 1
  91. getCommonData()
  92. // 提示用户
  93. uni.showToast({ title: '已清空时间筛选', icon: 'none' })
  94. }
  95. // 拨打电话
  96. const bindphone = (e) => {
  97. uni.makePhoneCall({
  98. phoneNumber: e,
  99. fail: (err) => {
  100. uni.showToast({ title: '拨打电话失败', icon: 'none' })
  101. }
  102. })
  103. }
  104. onLoad(() => {
  105. userInfo.value = uni.getStorageSync('carUserInfo')
  106. console.log(userInfo.value)
  107. getCommonData()
  108. })
  109. // 页面显示时(从时间选择页返回后触发)
  110. onShow(() => {
  111. // 方式1:从storage获取参数
  112. const dateRange = uni.getStorageSync('selectedDateRange')
  113. // 方式2:从页面栈参数获取(优先级更高)
  114. if (selectedDate.value) {
  115. startT.value = selectedDate.value.startTime
  116. endT.value = selectedDate.value.endTime
  117. searchTime.value = selectedDate.value.showText
  118. } else if (dateRange) {
  119. startT.value = dateRange.startTime
  120. endT.value = dateRange.endTime
  121. searchTime.value = dateRange.showText
  122. // 清空storage,避免重复读取
  123. uni.removeStorageSync('selectedDateRange')
  124. }
  125. // 有选中时间则重新查询数据
  126. if (startT.value && endT.value) {
  127. currentPage.value = 1 // 重置页码
  128. getCommonData()
  129. }
  130. })
  131. // 页面卸载时清空参数(避免缓存)
  132. onUnload(() => {
  133. uni.removeStorageSync('selectedDateRange')
  134. })
  135. // 页面触底触发的回调
  136. onReachBottom(() => {
  137. if (recordList.value.length < total.value) {
  138. currentPage.value++
  139. getCommonData()
  140. } else {
  141. uni.showToast({
  142. title: '没有更多数据了',
  143. icon: 'none'
  144. })
  145. }
  146. })
  147. // 获取常用旅客列表数据
  148. const getCommonData = async () => {
  149. // 核心:根据时间参数是否存在动态组装请求数据
  150. let data = {}
  151. if (startT.value && endT.value) {
  152. data = {
  153. page: currentPage.value,
  154. rows: pageSize.value,
  155. startTime: startT.value,
  156. endTime: endT.value
  157. }
  158. } else {
  159. data = {
  160. page: currentPage.value,
  161. rows: pageSize.value
  162. }
  163. }
  164. try {
  165. const res = await myRequest({
  166. url: '/carBook/brecblist.action',
  167. data
  168. })
  169. // 分页加载:第一页清空原有数据,后续页追加
  170. if (currentPage.value === 1) {
  171. recordList.value = res.rows
  172. } else {
  173. recordList.value = [...recordList.value, ...res.rows]
  174. }
  175. total.value = res.total
  176. } catch (err) {
  177. uni.showToast({ title: '数据加载失败', icon: 'none' })
  178. }
  179. }
  180. // 打开时间选择弹窗
  181. const openTimePopup = async () => {
  182. await nextTick(); // 等待组件渲染完成
  183. if (timePopupRef.value) {
  184. timePopupRef.value.open();
  185. }
  186. };
  187. // 关闭时间选择弹窗
  188. const closeTimePopup = () => {
  189. timePopupRef.value.close()
  190. }
  191. // 确认选择时间(触发接口查询)
  192. const confirmTime = () => {
  193. if (selectedTime.value.length < 2) {
  194. uni.showToast({ title: '请选择完整时间范围', icon: 'none' })
  195. return
  196. }
  197. // 格式化时间并更新参数
  198. startT.value = formatDate(selectedTime.value[0])
  199. endT.value = formatDate(selectedTime.value[1])
  200. searchTime.value = `${startT.value} ~ ${endT.value}`
  201. // 重置页码,重新查询
  202. currentPage.value = 1
  203. getCommonData()
  204. // 关闭弹窗
  205. closeTimePopup()
  206. }
  207. // 日期格式化工具函数
  208. const formatDate = (date) => {
  209. const d = new Date(date)
  210. const year = d.getFullYear()
  211. const month = (d.getMonth() + 1).toString().padStart(2, '0')
  212. const day = d.getDate().toString().padStart(2, '0')
  213. return `${year}-${month}-${day}`
  214. }
  215. </script>
  216. <style scoped>
  217. /* 页面容器 */
  218. .page-container {
  219. min-height: 100vh;
  220. background-color: #f5f5f5;
  221. }
  222. /* 搜索区域 */
  223. .search-bar {
  224. display: flex;
  225. align-items: center;
  226. padding: 15rpx;
  227. background-color: #fff;
  228. margin-bottom: 10rpx;
  229. }
  230. .search-input-wrap {
  231. flex: 1;
  232. display: flex;
  233. align-items: center;
  234. background-color: #f5f5f5;
  235. border-radius: 20rpx;
  236. padding: 0 15rpx;
  237. height: 35px;
  238. /* 点击区域cursor */
  239. cursor: pointer;
  240. }
  241. .search-icon {
  242. color: #999;
  243. margin-right: 10rpx;
  244. }
  245. .search-input {
  246. flex: 1;
  247. height: 100%;
  248. font-size: 14px;
  249. background-color: transparent;
  250. line-height: 35px;
  251. }
  252. /* 占位符样式 */
  253. .placeholder {
  254. color: #999;
  255. }
  256. .cancel-btn {
  257. color: #007aff;
  258. font-size: 16px;
  259. margin-left: 15rpx;
  260. }
  261. /* 记录列表 */
  262. .record-list {
  263. padding: 0 15rpx;
  264. }
  265. .record-item {
  266. background-color: #fff;
  267. border-radius: 10rpx;
  268. padding: 20rpx;
  269. margin-bottom: 15rpx;
  270. position: relative;
  271. border: 1px solid #eee;
  272. }
  273. /* 第一条记录高亮边框 */
  274. .active-item {
  275. border: 2px solid #ffd700;
  276. }
  277. /* 已乘车标签 */
  278. .status-tag {
  279. position: absolute;
  280. top: 20rpx;
  281. right: 20rpx;
  282. background-color: #4cd964;
  283. color: #fff;
  284. font-size: 12px;
  285. padding: 2rpx 8rpx;
  286. border-radius: 4rpx;
  287. }
  288. /* 记录内容 */
  289. .record-content {
  290. margin-top: 5rpx;
  291. }
  292. .record-text {
  293. display: block;
  294. font-size: 14px;
  295. color: #333;
  296. line-height: 45rpx;
  297. }
  298. </style>