classify.vue 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  1. <template>
  2. <!-- 志愿者 -->
  3. <view class="classify-main" v-if="userType == '2'">
  4. <up-tabs :list="column" :scrollable="false" @change="onChange" :activeStyle="{
  5. color: 'rgba(255, 87, 4, 1)',
  6. fontWeight: 'bold',
  7. transform: 'scale(1.05)'
  8. }" lineColor="rgba(255, 87, 4, 1)" :current="tabKey">
  9. </up-tabs>
  10. <view class="list">
  11. <List :data="data" v-if="data.length > 0" />
  12. <view v-else class="empty-null">
  13. <img src="/static/empty/订单为空.png" alt="">
  14. </view>
  15. </view>
  16. </view>
  17. <!-- 用户 -->
  18. <OrderList :dataList="dataList" @fetchData="getListData"/>
  19. </template>
  20. <script setup>
  21. import {
  22. ref
  23. } from 'vue';
  24. import List from './order/list/index.vue';
  25. import {
  26. provide
  27. } from 'vue';
  28. import {
  29. getVolunteerOrderList
  30. } from '@/api/volunteer.js'
  31. import {
  32. onMounted
  33. } from 'vue';
  34. import {
  35. useDict
  36. } from '@/utils/dict.js';
  37. import {
  38. onLoad,
  39. onShow
  40. } from '@dcloudio/uni-app';
  41. import OrderList from '@/components/pages/classify/orderlist.vue'
  42. import {
  43. userMainOrderList
  44. } from "@/api/userList.js"
  45. const {
  46. order_status
  47. } = useDict('order_status');
  48. provide('order_status', order_status); //订单/服务状态
  49. const userType = uni.getStorageSync('userType') //读取本地存储
  50. // 用户/志愿者 识别标识
  51. const userOrWorker = uni.getStorageSync('storage_data').vuex_userOrWorker //读取本地存储
  52. const tab = ref('');
  53. const tabKey = ref(0);
  54. const dataList = ref([]) //用户
  55. const data = ref([]); //志愿者
  56. /**
  57. * 0待支付 1已支付 2支付超时或取消 3进行中 4已完成 5申请退款中 6已退款 7部分退款 8 待确认
  58. */
  59. const column = [{
  60. name: "全部",
  61. value: "",
  62. },
  63. {
  64. name: "待服务",
  65. value: "1",
  66. },
  67. {
  68. name: "进行中",
  69. value: "3",
  70. },
  71. {
  72. name: "已完成",
  73. value: "4",
  74. },
  75. {
  76. name: "已取消",
  77. value: "2",
  78. }
  79. ]
  80. const column2 = [{
  81. name: "全部",
  82. value: "",
  83. },
  84. {
  85. name: "待支付",
  86. value: "1",
  87. },
  88. {
  89. name: "待服务",
  90. value: "2",
  91. },
  92. {
  93. name: "进行中",
  94. value: "3",
  95. },
  96. {
  97. name: "已完成",
  98. value: "4",
  99. },
  100. {
  101. name: "已取消",
  102. value: "5",
  103. }
  104. ]
  105. async function getList() {
  106. console.log(userType, '>>>>>>userType');
  107. try {
  108. uni.hideLoading();
  109. uni.showLoading({
  110. title: '数据加载中...'
  111. });
  112. // 判断 userType 来决定调用哪个接口
  113. let res;
  114. if (userType === 1) {
  115. // 如果 userType 是 1,调用 userMainOrderList 接口
  116. res = await getListData();
  117. } else if (userType === 2) {
  118. // 如果 userType 是 2,调用 getVolunteerOrderList 接口
  119. res = await getVolunteerOrderList({
  120. orderStatus: tab.value
  121. });
  122. data.value = res.data;
  123. }
  124. } catch (error) {
  125. console.log('error', error);
  126. uni.showToast({
  127. title: error.msg,
  128. icon: 'error',
  129. });
  130. } finally {
  131. uni.hideLoading();
  132. }
  133. }
  134. const getListData = async (orderStatus = tab.value) => {
  135. const res = await userMainOrderList({
  136. orderStatus: orderStatus
  137. });
  138. dataList.value = res.data
  139. }
  140. /**
  141. * 1: 查看
  142. * 2:沟通
  143. * 3:上传照片
  144. */
  145. function btnClick(row, type) {
  146. console.log('btnClick', type, row);
  147. if (type === 1) {
  148. uni.navigateTo({
  149. url: `/pages/order/order?orderId=${row.secondOrderId}`
  150. });
  151. return
  152. }
  153. uni.navigateTo({
  154. url: `/pages/order/handle?orderId=${row.secondOrderId}`
  155. });
  156. }
  157. provide('onClick', btnClick);
  158. function onChange(tabItem) {
  159. console.log('onChange called with tabItem:', tabItem); // 确认是否进入 onChange
  160. tab.value = tabItem.value;
  161. getList();
  162. console.log('change', tabItem, tab.value);
  163. }
  164. onMounted(() => {
  165. getList()
  166. getListData()
  167. })
  168. onShow(() => {
  169. const params = getApp().globalData.switchTabParams || {};
  170. if (!params.tabKey) return;
  171. tabKey.value = params.tabKey;
  172. console.log(params); // { id: 123, type: "test" }
  173. onChange(column[tabKey.value])
  174. // 使用后建议清除参数,避免重复读取
  175. getApp().globalData.switchTabParams = null;
  176. })
  177. </script>
  178. <style lang="scss" scoped>
  179. .classify-main {
  180. height: 100vh;
  181. .list {
  182. position: fixed;
  183. top: 50px;
  184. bottom: 0px;
  185. left: 0px;
  186. right: 0px;
  187. }
  188. }
  189. </style>