classify.vue 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  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. console.log("TCL: getList -> type", type)
  98. try {
  99. console.log(data.value.length, pages.value.total);
  100. if (type === 'top') {
  101. data.value = [];
  102. pages.value.total = 0;
  103. }
  104. if (type === 'bottom') {
  105. if (data.value.length < pages.value.total) {
  106. listRef.value && listRef.value.handleBottom(true);
  107. pages.value.current++;
  108. } else {
  109. listRef.value && listRef.value.handleBottom(false)
  110. return;
  111. }
  112. } else {
  113. uni.showLoading({
  114. title: '数据加载中...',
  115. })
  116. }
  117. const listApi = userType === 1 ? userMainOrderList : getVolunteerOrderList
  118. const res = await listApi({
  119. orderStatus: tab.value,
  120. pageNum: pages.value.current,
  121. pageSize: pages.value.pageSize,
  122. })
  123. data.value = [...data.value, ...res.rows];
  124. pages.value.total = res.total;
  125. type === 'bottom' && listRef.value && listRef.value.handleBottom(false);
  126. } catch (error) {
  127. console.log('error', error)
  128. uni.showToast({
  129. title: error.msg,
  130. icon: 'error',
  131. })
  132. } finally {
  133. if (listRef.value && listRef.value.handleRefreshing && type === 'top') {
  134. listRef.value.handleRefreshing(false)
  135. }
  136. setTimeout(() => {
  137. if (data.value.length === pages.value.total && pages.value.total > 0) {
  138. listRef.value && listRef.value.handleBottom(false)
  139. }
  140. }, 500)
  141. type !== 'bottom' && uni.hideLoading()
  142. }
  143. }
  144. /**
  145. * 1: 查看
  146. * 2:沟通
  147. * 3:开始或结束服务
  148. */
  149. function btnClick(row, type) {
  150. if (type === 1) {
  151. uni.navigateTo({
  152. url: `/pages_classify/pages/order/index?secondOrderId=${row.secondOrderId}`,
  153. })
  154. return
  155. }
  156. if (type === 3) {
  157. uni.navigateTo({
  158. url: `/pages_classify/pages/handle/index?secondOrderId=${row.secondOrderId}`,
  159. })
  160. return
  161. }
  162. //前往沟通
  163. uni.navigateTo({
  164. url: `/pages_orderuser/pages/talk/pages/index/index?orderId=${row.mainOrderId}`
  165. });
  166. }
  167. provide('onClick', btnClick)
  168. function onChange(tabItem) {
  169. tab.value = tabItem.value;
  170. pages.value.current = 1;
  171. data.value = [];
  172. getList()
  173. }
  174. onMounted(() => {
  175. })
  176. onShow(() => {
  177. const initIndex = userType === 1 ? 2 : 1;//默认选中待服务
  178. const params = getApp().globalData.switchTabParams || {}
  179. tabKey.value = params.tabKey || initIndex;
  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: 150rpx;
  204. }
  205. }
  206. </style>