classify.vue 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239
  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 { wxMakePhoneCall } from '@/utils/wxRequest.js'
  39. import { getToken } from '@/utils/auth'
  40. const userType = uni.getStorageSync('userType') //读取本地存储
  41. const tab = ref('')
  42. const tabKey = ref(0)
  43. const data = ref([]) //志愿者
  44. const listRef =ref(null)
  45. /**
  46. * 0待支付 1已支付 2支付超时或取消 3进行中 4已完成 5申请退款中 6已退款 7部分退款 8 待确认
  47. */
  48. const admin = [
  49. {
  50. name: '全部',
  51. value: '',
  52. },
  53. {
  54. name: '待服务',
  55. value: '1',
  56. },
  57. {
  58. name: '进行中',
  59. value: '3',
  60. },
  61. {
  62. name: '已完成',
  63. value: '4',
  64. },
  65. {
  66. name: '已取消',
  67. value: '2',
  68. },
  69. ]
  70. const user = [
  71. {
  72. name: "全部",
  73. value: "",
  74. },
  75. {
  76. name: "待支付",
  77. value: "0",
  78. },
  79. {
  80. name: "待服务",
  81. value: "1",
  82. },
  83. {
  84. name: "进行中",
  85. value: "3",
  86. },
  87. {
  88. name: "已完成",
  89. value: "4",
  90. },
  91. {
  92. name: "售后",
  93. value: '2,5,6,7',
  94. }
  95. ]
  96. const column = computed(() => {
  97. return userType === 1 ? user : admin
  98. })
  99. const pages = ref({
  100. current: 1,
  101. pageSize: 10,
  102. total: null,
  103. })
  104. async function getList(type) {
  105. console.log("TCL: getList -> type", type)
  106. try {
  107. console.log(data.value.length, pages.value.total);
  108. if(type === 'top'){
  109. data.value = [];
  110. pages.value.total = 0;
  111. }
  112. if(type ==='bottom' ){
  113. if(data.value.length < pages.value.total){
  114. listRef.value && listRef.value.handleBottom(true);
  115. pages.value.current++;
  116. }else {
  117. listRef.value && listRef.value.handleBottom(false)
  118. return;
  119. }
  120. }else{
  121. uni.showLoading({
  122. title: '数据加载中...',
  123. })
  124. }
  125. const listApi = userType === 1 ? userMainOrderList : getVolunteerOrderList
  126. const res = await listApi({
  127. orderStatus: tab.value,
  128. pageNum: pages.value.current,
  129. pageSize: pages.value.pageSize,
  130. })
  131. data.value =[...data.value,...res.rows];
  132. pages.value.total = res.total;
  133. type ==='bottom'&& listRef.value && listRef.value.handleBottom(false);
  134. } catch (error) {
  135. console.log('error', error)
  136. uni.showToast({
  137. title: error.msg,
  138. icon: 'error',
  139. })
  140. } finally {
  141. if(listRef.value && listRef.value.handleRefreshing && type ==='top'){
  142. listRef.value.handleRefreshing(false)
  143. }
  144. setTimeout(() => {
  145. if (data.value.length === pages.value.total && pages.value.total > 0) {
  146. listRef.value && listRef.value.handleBottom(false)
  147. }
  148. }, 500)
  149. type !=='bottom' && uni.hideLoading()
  150. }
  151. }
  152. /**
  153. * 1: 查看
  154. * 2:沟通
  155. * 3:开始或结束服务
  156. */
  157. function btnClick(row, type) {
  158. if (type === 1) {
  159. uni.navigateTo({
  160. url: `/pages_classify/pages/order/index?secondOrderId=${row.secondOrderId}`,
  161. })
  162. return
  163. }
  164. if (type === 3) {
  165. uni.navigateTo({
  166. url: `/pages_classify/pages/handle/index?secondOrderId=${row.secondOrderId}`,
  167. })
  168. return
  169. }
  170. //前往沟通
  171. uni.navigateTo({
  172. url: `/pages_orderuser/pages/talk/pages/index/index?orderId=${row.mainOrderId}`
  173. });
  174. }
  175. provide('onClick', btnClick)
  176. function onChange(tabItem) {
  177. tab.value = tabItem.value;
  178. pages.value.current = 1;
  179. data.value = [];
  180. getList()
  181. }
  182. onMounted(() => {
  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. onShow(() => {
  192. const initIndex = userType === 1? 2:1;//默认选中待服务
  193. const params = getApp().globalData.switchTabParams || {}
  194. tabKey.value = params.tabKey || initIndex;
  195. onChange(column.value[tabKey.value])
  196. // 使用后建议清除参数,避免重复读取
  197. getApp().globalData.switchTabParams = null
  198. })
  199. </script>
  200. <style lang="scss" scoped>
  201. .classify-main {
  202. height: 100vh;
  203. .list {
  204. position: fixed;
  205. top: 50px;
  206. // bottom: 150rpx;
  207. bottom: 0;
  208. left: 0px;
  209. right: 0px;
  210. background: rgba(245, 245, 245, 1);
  211. padding-bottom: 150rpx;
  212. }
  213. }
  214. </style>