猫妈狗爸伴宠师小程序前端代码
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

297 lines
8.1 KiB

2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
  1. <template>
  2. <view>
  3. <view class="header-buts flex flex-center">
  4. <view class="flex buts-box">
  5. <view class="buts" :class="{'buts-active':activeIndex===1}" @click="clickTab(1)">总订单</view>
  6. <view class="buts" :class="{'buts-active':activeIndex===2}" @click="clickTab(2)">日订单</view>
  7. </view>
  8. </view>
  9. <up-sticky bgColor="#fff" v-if="activeIndex == 1">
  10. <view class="container-tabs">
  11. <up-tabs @click="classIfyClickTab" :list="tabList1" lineWidth="68rpx" :activeStyle="{
  12. color: '#FFFFFF',
  13. fontWeight: 'bold',
  14. transform: 'scale(1.05)'
  15. }" :inactiveStyle="{
  16. color: '#FFFFFF',
  17. transform: 'scale(1)'
  18. }" :itemStyle="{height:'88rpx',width : '33%'}"
  19. lineColor="#FFFFFF"></up-tabs>
  20. </view>
  21. </up-sticky>
  22. <up-sticky bgColor="#fff" v-else>
  23. <view class="container-tabs">
  24. <up-tabs :list="tabList2" lineWidth="68rpx" :activeStyle="{
  25. color: '#FFFFFF',
  26. fontWeight: 'bold',
  27. transform: 'scale(1.05)'
  28. }" :inactiveStyle="{
  29. color: '#FFFFFF',
  30. transform: 'scale(1)'
  31. }" :itemStyle="{height:'88rpx',padding:'0 52rpx', width : '400rpx'}"
  32. @click="classIfyClickTab"
  33. lineColor="#FFFFFF"></up-tabs>
  34. </view>
  35. </up-sticky>
  36. <view class="container">
  37. <!-- 加载中状态 -->
  38. <view v-if="loading" class="loading-container">
  39. <up-loading-icon size="36" mode="circle" color="#FFAA48"></up-loading-icon>
  40. <text class="loading-text">加载中...</text>
  41. </view>
  42. <!-- 总订单内容 -->
  43. <systemOrder :list="list" :current="current" v-else-if="activeIndex == 1" />
  44. <!-- 日订单内容 -->
  45. <view v-else>
  46. <view v-if="dateOrderList && dateOrderList.length > 0">
  47. <timelineService
  48. v-for="(item,index) in dateOrderList"
  49. :key="index"
  50. :date="item.date"
  51. :status="current == 0"
  52. :list="item.list"
  53. :current="current"
  54. />
  55. </view>
  56. <view v-else class="empty-state">
  57. <image src="/static/images/ydd/empty.png" mode="aspectFit" class="empty-image"></image>
  58. <text class="empty-text">暂无订单数据</text>
  59. </view>
  60. </view>
  61. <!-- <orderListByData :list="list" v-else /> -->
  62. </view>
  63. </view>
  64. </template>
  65. <script setup>
  66. import {
  67. computed,
  68. reactive,
  69. ref
  70. } from "vue";
  71. import systemOrder from "./components/systemOrder.vue";
  72. import orderListByData from "./components/orderListByData.vue";
  73. import timelineService from "./components/timelineService.vue";
  74. import {
  75. onShow,
  76. onLoad,
  77. } from "@dcloudio/uni-app"
  78. import {
  79. getLoginStatus
  80. } from "@/utils/useMixin.js"
  81. // import personOrder from "./components/personOrder.vue";
  82. // import lossOrder from "./components/lossOrder.vue";
  83. import {
  84. myList
  85. } from "@/api/receivingHall/index.js"
  86. import {
  87. getOrderDateList,
  88. } from "@/api/order/order.js"
  89. import {
  90. appletOrderDateFrequencyList,
  91. } from "@/api/order/frequency.js"
  92. import {
  93. useStore
  94. } from "vuex"
  95. import { getOrderServiceText, getProductNameText } from '@/utils/serviceTime.js'
  96. onLoad(() => {
  97. requestId.value = 0;
  98. activeIndex.value = 1;
  99. })
  100. onShow(() => {
  101. if (!getLoginStatus()) return;
  102. getList();
  103. })
  104. const current = ref(0)
  105. const activeIndex = ref(1)
  106. const list = ref([])
  107. const dateOrderList = ref([])
  108. const loading = ref(false) // 添加loading状态
  109. const requestId = ref(0) // 添加请求序列号
  110. const store = useStore();
  111. const userInfo = computed(() => {
  112. return store.getters.userInfo;
  113. })
  114. const tabList1 = reactive([{
  115. name: '待服务',
  116. badge: {
  117. value: 0,
  118. }
  119. },
  120. {
  121. name: '进行中',
  122. badge: {
  123. value: 0,
  124. }
  125. },
  126. {
  127. name: '已完成',
  128. badge: {
  129. value: 0,
  130. }
  131. },
  132. ])
  133. const tabList2 = reactive([{
  134. name: '待上门',
  135. badge: {
  136. value: 0,
  137. }
  138. },
  139. {
  140. name: '已完成',
  141. badge: {
  142. value: 0,
  143. }
  144. },
  145. ])
  146. function getList() {
  147. loading.value = true; // 开始加载
  148. requestId.value++; // 递增请求序列号
  149. const currentRequestId = requestId.value; // 保存当前请求的ID
  150. let index = current.value;
  151. if (activeIndex.value == 1) {
  152. myList({
  153. orderStatus: index,
  154. userId: userInfo.value.userId
  155. })
  156. .then(res => {
  157. // 检查请求是否是最新的
  158. if (currentRequestId !== requestId.value) {
  159. return; // 如果不是最新请求,忽略响应
  160. }
  161. if (res.code == 200) {
  162. list.value = res.data.rows
  163. tabList1[index].badge.value = res.data.total
  164. list.value.forEach(item => {
  165. item.h5OrderVO.petVOList.forEach(pet => {
  166. pet.orderServiceText = getOrderServiceText(pet.id, item.h5OrderVO.orderServiceList)
  167. pet.productNameText = getProductNameText(pet.id, item.h5OrderVO.orderItemList, item.h5OrderVO.orderServiceList)
  168. })
  169. })
  170. }
  171. })
  172. .finally(() => {
  173. // 只有最新请求才能关闭loading
  174. if(activeIndex.value == 1 && currentRequestId === requestId.value){
  175. loading.value = false; // 结束加载
  176. }
  177. })
  178. }else{
  179. dateOrderList.value = []
  180. appletOrderDateFrequencyList({
  181. status: index == 0 ? '0,1' : '2',
  182. masterId: userInfo.value.userId
  183. })
  184. .then(res => {
  185. // 检查请求是否是最新的
  186. if (currentRequestId !== requestId.value) {
  187. return; // 如果不是最新请求,忽略响应
  188. }
  189. if (res.code == 200) {
  190. dateOrderList.value = res.data
  191. // 更新标签数量显示
  192. let totalOrders = 0;
  193. dateOrderList.value.forEach(item => {
  194. totalOrders += item.list.length || 0;
  195. });
  196. tabList2[index].badge.value = totalOrders;
  197. }
  198. })
  199. .finally(() => {
  200. // 只有最新请求才能关闭loading
  201. if(activeIndex.value == 2 && currentRequestId === requestId.value){
  202. loading.value = false; // 结束加载
  203. }
  204. })
  205. // getOrderDateList({
  206. // status: index,
  207. // userId: userInfo.value.userId
  208. // })
  209. // .then(res => {
  210. // if (res.code == 200) {
  211. // dateOrderList.value = res.data
  212. // // 更新标签数量显示
  213. // let totalOrders = 0;
  214. // dateOrderList.value.forEach(item => {
  215. // totalOrders += item.num || 0;
  216. // });
  217. // tabList2[index].badge.value = totalOrders;
  218. // }
  219. // })
  220. // .finally(() => {
  221. // if(activeIndex.value == 2){
  222. // loading.value = false; // 结束加载
  223. // }
  224. // })
  225. }
  226. }
  227. function clickTab(index) {
  228. current.value = 0;
  229. activeIndex.value = index;
  230. getList();
  231. }
  232. const classIfyClickTab = (item) => {
  233. current.value = item.index;
  234. getList();
  235. }
  236. </script>
  237. <style scoped lang="scss">
  238. @import "index.scss";
  239. .loading-container {
  240. display: flex;
  241. flex-direction: column;
  242. align-items: center;
  243. justify-content: center;
  244. padding: 40rpx;
  245. .loading-text {
  246. margin-top: 20rpx;
  247. color: #999;
  248. font-size: 28rpx;
  249. }
  250. }
  251. .empty-state {
  252. display: flex;
  253. flex-direction: column;
  254. align-items: center;
  255. justify-content: center;
  256. padding: 80rpx 40rpx;
  257. .empty-image {
  258. width: 200rpx;
  259. height: 200rpx;
  260. margin-bottom: 20rpx;
  261. }
  262. .empty-text {
  263. color: #999;
  264. font-size: 28rpx;
  265. }
  266. }
  267. </style>