classify.vue 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  1. <template>
  2. <view>
  3. <view class="classify-main">
  4. <up-tabs :list="column" :scrollable="false" @change="onChange" :activeStyle="{
  5. color: 'rgba(221, 94, 69, 1)',
  6. fontWeight: 'bold',
  7. transform: 'scale(1.05)',
  8. }" lineColor="rgba(221, 94, 69, 1)" v-model:current="tabKey">
  9. </up-tabs>
  10. <view class="list">
  11. <List :data="data" v-if="data && data.length > 0" @refresh="getList" ref="listRef" :total="pages.total" />
  12. <view v-else>
  13. <NoneView value="您还没有相关订单" />
  14. </view>
  15. </view>
  16. </view>
  17. <custom-tab-bar page="order" />
  18. </view>
  19. </template>
  20. <script setup>
  21. import { ref, computed } from 'vue'
  22. import List from '@/pages/common/orderList/index.vue'
  23. import { provide,inject } from 'vue'
  24. import { getVolunteerOrderList } from '@/api/volunteer.js'
  25. import { onMounted } from 'vue'
  26. import { useDict } from '@/utils/dict.js'
  27. import { onShow } from '@dcloudio/uni-app'
  28. import NoneView from '@/components/NoneView/index.vue'
  29. import { userMainOrderList } from '@/api/userList.js'
  30. import CustomTabBar from '@/components/CustomTabBar/index.vue'
  31. import { getToken } from '@/utils/auth'
  32. const userType = uni.getStorageSync('userType')|| 1; //读取本地存储
  33. const tab = ref('')
  34. const tabKey = ref(0)
  35. const data = ref([]) //志愿者
  36. const listRef = ref(null)
  37. /**
  38. * 0待支付 1已支付 2支付超时或取消 3进行中 4已完成 5申请退款中 6已退款 7部分退款 8 待确认
  39. */
  40. const admin = [
  41. {
  42. name: '全部',
  43. value: '',
  44. },
  45. {
  46. name: '待服务',
  47. value: '1',
  48. },
  49. {
  50. name: '进行中',
  51. value: '3',
  52. },
  53. {
  54. name: '已完成',
  55. value: '4',
  56. },
  57. {
  58. name: '已取消',
  59. value: '2',
  60. },
  61. ]
  62. const user = [
  63. {
  64. name: "全部",
  65. value: "",
  66. },
  67. {
  68. name: "待支付",
  69. value: "0",
  70. },
  71. {
  72. name: "待服务",
  73. value: "1",
  74. },
  75. {
  76. name: "进行中",
  77. value: "3",
  78. },
  79. {
  80. name: "已完成",
  81. value: "4",
  82. },
  83. {
  84. name: "售后",
  85. value: '2,5,6,7',
  86. }
  87. ]
  88. const column = computed(() => {
  89. return userType === 1 ? user : admin
  90. })
  91. const pages = ref({
  92. current: 1,
  93. pageSize: 10,
  94. total: null,
  95. })
  96. async function getList(type) {
  97. try {
  98. if (type === 'top') {
  99. data.value = [];
  100. pages.value.total = 0;
  101. }
  102. if (type === 'bottom') {
  103. if (data.value.length < pages.value.total) {
  104. listRef.value && listRef.value.handleBottom(true);
  105. pages.value.current++;
  106. } else {
  107. listRef.value && listRef.value.handleBottom(false)
  108. return;
  109. }
  110. } else {
  111. // uni.showLoading({
  112. // title: '数据加载中...',
  113. // })
  114. }
  115. const listApi = userType === 1 ? userMainOrderList : getVolunteerOrderList
  116. const res = await listApi({
  117. orderStatus: tab.value,
  118. pageNum: pages.value.current,
  119. pageSize: pages.value.pageSize,
  120. })
  121. data.value = [...data.value, ...res.rows];
  122. pages.value.total = res.total;
  123. type === 'bottom' && listRef.value && listRef.value.handleBottom(false);
  124. } catch (error) {
  125. console.log('error', error)
  126. uni.showToast({
  127. title: error.msg,
  128. icon: 'error',
  129. })
  130. } finally {
  131. if (listRef.value && listRef.value.handleRefreshing && type === 'top') {
  132. listRef.value.handleRefreshing(false)
  133. }
  134. setTimeout(() => {
  135. if (data.value.length === pages.value.total && pages.value.total > 0) {
  136. listRef.value && listRef.value.handleBottom(false)
  137. }
  138. }, 500)
  139. // type !== 'bottom' && uni.hideLoading()
  140. }
  141. }
  142. /**
  143. * 1: 查看
  144. * 2:沟通
  145. * 3:开始或结束服务
  146. */
  147. function btnClick(row, type) {
  148. uni.setStorageSync('tabKey', tabKey.value);//存储当前tab的下标
  149. if (type === 1) {
  150. uni.navigateTo({
  151. url: `/pages_classify/pages/order/index?secondOrderId=${row.secondOrderId}&type=details`,
  152. })
  153. return
  154. }
  155. if (type === 3) {
  156. uni.navigateTo({
  157. url: `/pages_classify/pages/handle/index?secondOrderId=${row.secondOrderId}`,
  158. })
  159. return
  160. }
  161. //前往沟通
  162. uni.navigateTo({
  163. url: `/pages_orderuser/pages/talk/pages/index/index?orderId=${row.mainOrderId}&conversationType=2`
  164. });
  165. }
  166. provide('onClick', btnClick)
  167. function onChange(tabItem) {
  168. tab.value = tabItem.value;
  169. pages.value.current = 1;
  170. data.value = [];
  171. getList()
  172. }
  173. onMounted(() => {
  174. })
  175. onShow(() => {
  176. const initIndex = userType === 1 ? 2 : 1;//默认选中待服务
  177. const params = getApp().globalData.switchTabParams || {}
  178. const storage_tabKey = uni.getStorageSync('tabKey'); //读取本地存储
  179. tabKey.value = params.tabKey || storage_tabKey || initIndex;//优先显示外部传入的tabKey,其次存储在本地的tabKey,最后默认选中待服务
  180. onChange(column.value[tabKey.value])
  181. // 使用后建议清除参数,避免重复读取
  182. getApp().globalData.switchTabParams = null
  183. const token = getToken();
  184. if (token) {
  185. const {
  186. order_status,
  187. } = useDict('order_status', 'lrr_service_status')
  188. provide('order_status', order_status) //订单/服务状态
  189. }
  190. })
  191. </script>
  192. <style lang="scss" scoped>
  193. .classify-main {
  194. height: 100vh;
  195. .list {
  196. position: fixed;
  197. top: 50px;
  198. // bottom: 150rpx;
  199. bottom: 0;
  200. left: 0px;
  201. right: 0px;
  202. background: rgba(245, 245, 245, 1);
  203. padding-bottom: 190rpx;
  204. }
  205. }
  206. </style>