classify.vue 5.0 KB

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