serviceOrder.vue 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367
  1. <template>
  2. <view class="container">
  3. <!-- 导航栏 -->
  4. <view class="navbar">
  5. <view class="nav-left" @click="goBack">
  6. <text class="back-icon"><</text>
  7. </view>
  8. <view class="nav-title">服务单</view>
  9. <view class="nav-right">
  10. <text class="more-icon">...</text>
  11. <text class="eye-icon">O</text>
  12. </view>
  13. </view>
  14. <!-- 标签页 -->
  15. <view class="tabs">
  16. <view class="tab-item" :class="{ active: activeTab === 'pending' }" @click="switchTab('pending')">
  17. <text>待确认</text>
  18. <view class="tab-indicator" v-if="activeTab === 'pending'"></view>
  19. </view>
  20. <view class="tab-item" :class="{ active: activeTab === 'confirmed' }" @click="switchTab('confirmed')">
  21. <text>已确认</text>
  22. <view class="tab-indicator" v-if="activeTab === 'confirmed'"></view>
  23. </view>
  24. </view>
  25. <!-- 内容区域 -->
  26. <scroll-view class="content" scroll-y @scrolltolower="loadMore">
  27. <view class="order-list">
  28. <view class="month-group" v-for="(group, groupIndex) in groupedOrders" :key="groupIndex">
  29. <view class="month-header">
  30. <view class="month-icon">○</view>
  31. <text class="month-text">{{ group.month }}</text>
  32. </view>
  33. <view class="order-items">
  34. <view class="order-item" v-for="(item, index) in group.items" :key="index" @click="goToDetail(item)">
  35. <view class="order-content">
  36. <view class="order-title">服务确认单</view>
  37. <view class="order-time">{{ item.createTime }}</view>
  38. </view>
  39. <view class="order-action" v-if="activeTab === 'pending'">
  40. <view class="confirm-btn" @click.stop="goToConfirm(item)">去确认</view>
  41. </view>
  42. </view>
  43. </view>
  44. </view>
  45. </view>
  46. <!-- 空状态 -->
  47. <view class="empty-state" v-if="groupedOrders.length === 0">
  48. <text>暂无数据</text>
  49. </view>
  50. </scroll-view>
  51. </view>
  52. </template>
  53. <script>
  54. import { getServiceOrderList } from '@/api-js/serviceOrder'
  55. export default {
  56. data() {
  57. return {
  58. activeTab: 'pending', // pending: 待确认, confirmed: 已确认
  59. orderList: [],
  60. page: 1,
  61. pageSize: 20,
  62. hasMore: true
  63. }
  64. },
  65. computed: {
  66. // 按月份分组订单
  67. groupedOrders() {
  68. const groups = {}
  69. this.orderList.forEach(item => {
  70. const month = item.createTime ? item.createTime.substring(0, 7) : '未知'
  71. if (!groups[month]) {
  72. groups[month] = {
  73. month: month,
  74. items: []
  75. }
  76. }
  77. groups[month].items.push(item)
  78. })
  79. // 转换为数组并按月份倒序排列
  80. return Object.values(groups).sort((a, b) => {
  81. return b.month.localeCompare(a.month)
  82. })
  83. }
  84. },
  85. onLoad() {
  86. this.loadData()
  87. },
  88. methods: {
  89. async loadData(refresh = false) {
  90. if (refresh) {
  91. this.page = 1
  92. this.hasMore = true
  93. }
  94. if (!this.hasMore) return
  95. try {
  96. uni.showLoading({ title: '加载中...' })
  97. const res = await getServiceOrderList({
  98. status: this.activeTab === 'pending' ? 0 : 1, // 0: 待确认, 1: 已确认
  99. page: this.page,
  100. pageSize: this.pageSize
  101. })
  102. uni.hideLoading()
  103. if (res.code === 200 && res.data) {
  104. const list = res.data.list || []
  105. if (refresh) {
  106. this.orderList = list
  107. } else {
  108. this.orderList = [...this.orderList, ...list]
  109. }
  110. this.hasMore = list.length >= this.pageSize
  111. if (this.hasMore) {
  112. this.page++
  113. }
  114. } else {
  115. // 使用示例数据
  116. this.orderList = this.getDefaultData()
  117. }
  118. } catch (e) {
  119. uni.hideLoading()
  120. console.error('加载服务单列表失败', e)
  121. this.orderList = this.getDefaultData()
  122. }
  123. },
  124. getDefaultData() {
  125. // 示例数据
  126. const list = []
  127. const currentDate = new Date()
  128. for (let i = 0; i < 3; i++) {
  129. const date1 = new Date(currentDate.getFullYear(), currentDate.getMonth() - 1, 23, 16, 0, 0)
  130. list.push({
  131. id: `order_${i + 1}`,
  132. title: '服务确认单',
  133. createTime: this.formatDate(date1),
  134. status: this.activeTab === 'pending' ? 0 : 1
  135. })
  136. }
  137. for (let i = 0; i < 3; i++) {
  138. const date2 = new Date(currentDate.getFullYear(), currentDate.getMonth() - 2, 23, 16, 0, 0)
  139. list.push({
  140. id: `order_${i + 4}`,
  141. title: '服务确认单',
  142. createTime: this.formatDate(date2),
  143. status: this.activeTab === 'pending' ? 0 : 1
  144. })
  145. }
  146. return list
  147. },
  148. formatDate(date) {
  149. const year = date.getFullYear()
  150. const month = String(date.getMonth() + 1).padStart(2, '0')
  151. const day = String(date.getDate()).padStart(2, '0')
  152. const hours = String(date.getHours()).padStart(2, '0')
  153. const minutes = String(date.getMinutes()).padStart(2, '0')
  154. const seconds = String(date.getSeconds()).padStart(2, '0')
  155. return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`
  156. },
  157. switchTab(tab) {
  158. if (this.activeTab === tab) return
  159. this.activeTab = tab
  160. this.loadData(true)
  161. },
  162. loadMore() {
  163. this.loadData(false)
  164. },
  165. goBack() {
  166. uni.navigateBack()
  167. },
  168. goToDetail(item) {
  169. uni.navigateTo({
  170. url: `/pages_user/serviceOrderDetail?id=${item.id}&status=${item.status}`
  171. })
  172. },
  173. goToConfirm(item) {
  174. uni.navigateTo({
  175. url: `/pages_user/serviceOrderDetail?id=${item.id}&status=0`
  176. })
  177. }
  178. }
  179. }
  180. </script>
  181. <style lang="scss" scoped>
  182. .container {
  183. min-height: 100vh;
  184. background: #f5f5f5;
  185. display: flex;
  186. flex-direction: column;
  187. }
  188. .navbar {
  189. display: flex;
  190. align-items: center;
  191. justify-content: space-between;
  192. padding: 20rpx 24rpx;
  193. background: #fff;
  194. border-bottom: 1rpx solid #f0f0f0;
  195. .nav-left {
  196. width: 60rpx;
  197. .back-icon {
  198. font-size: 36rpx;
  199. color: #333;
  200. font-weight: bold;
  201. }
  202. }
  203. .nav-title {
  204. flex: 1;
  205. text-align: center;
  206. font-size: 36rpx;
  207. font-weight: bold;
  208. color: #333;
  209. }
  210. .nav-right {
  211. display: flex;
  212. align-items: center;
  213. gap: 24rpx;
  214. width: 60rpx;
  215. justify-content: flex-end;
  216. .more-icon {
  217. font-size: 32rpx;
  218. color: #333;
  219. }
  220. .eye-icon {
  221. font-size: 32rpx;
  222. color: #333;
  223. }
  224. }
  225. }
  226. .tabs {
  227. display: flex;
  228. background: #fff;
  229. border-bottom: 1rpx solid #f0f0f0;
  230. .tab-item {
  231. flex: 1;
  232. display: flex;
  233. flex-direction: column;
  234. align-items: center;
  235. justify-content: center;
  236. padding: 24rpx 0;
  237. position: relative;
  238. text {
  239. font-size: 30rpx;
  240. color: #999;
  241. }
  242. &.active {
  243. text {
  244. color: #333;
  245. font-weight: 500;
  246. }
  247. .tab-indicator {
  248. position: absolute;
  249. bottom: 0;
  250. left: 50%;
  251. transform: translateX(-50%);
  252. width: 60rpx;
  253. height: 4rpx;
  254. background: #388BFF;
  255. border-radius: 2rpx;
  256. }
  257. }
  258. }
  259. }
  260. .content {
  261. flex: 1;
  262. }
  263. .order-list {
  264. padding: 24rpx;
  265. }
  266. .month-group {
  267. margin-bottom: 32rpx;
  268. &:last-child {
  269. margin-bottom: 0;
  270. }
  271. .month-header {
  272. display: flex;
  273. align-items: center;
  274. margin-bottom: 16rpx;
  275. .month-icon {
  276. width: 16rpx;
  277. height: 16rpx;
  278. border-radius: 50%;
  279. background: #ccc;
  280. margin-right: 16rpx;
  281. }
  282. .month-text {
  283. font-size: 28rpx;
  284. color: #666;
  285. }
  286. }
  287. .order-items {
  288. .order-item {
  289. background: #fff;
  290. border-radius: 16rpx;
  291. padding: 32rpx 24rpx;
  292. margin-bottom: 16rpx;
  293. display: flex;
  294. align-items: center;
  295. justify-content: space-between;
  296. &:last-child {
  297. margin-bottom: 0;
  298. }
  299. .order-content {
  300. flex: 1;
  301. .order-title {
  302. font-size: 32rpx;
  303. font-weight: 500;
  304. color: #333;
  305. margin-bottom: 12rpx;
  306. }
  307. .order-time {
  308. font-size: 24rpx;
  309. color: #999;
  310. }
  311. }
  312. .order-action {
  313. .confirm-btn {
  314. padding: 12rpx 32rpx;
  315. background: #388BFF;
  316. border-radius: 44rpx;
  317. font-size: 26rpx;
  318. color: #fff;
  319. }
  320. }
  321. }
  322. }
  323. }
  324. .empty-state {
  325. padding: 120rpx 24rpx;
  326. text-align: center;
  327. font-size: 28rpx;
  328. color: #999;
  329. }
  330. </style>