Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

useOrderListItem.ts 3.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. /**
  2. * 订单列表业务逻辑
  3. */
  4. import { reactive, ref, watch,nextTick, onMounted } from "vue";
  5. import {request} from "@/utils/network/request.js";
  6. import { stringToJson } from "@/utils/network/encryption";
  7. import {onLoad,onUnload,onReachBottom,onPullDownRefresh} from "@dcloudio/uni-app";
  8. import { getItem, StorageKeys } from "@/utils/storage";
  9. import { hasLogin, msg } from "@/utils/utils";
  10. import { orderList } from "@/utils/network/api";
  11. import {PageData} from "@/datas/enum";
  12. export default function useOrderListItem(props) {
  13. //搜索关键字
  14. const searchKeyWords = ref('');
  15. //订单列表数据
  16. const ordersList = ref([]);
  17. const config = {
  18. emptyHint:{
  19. hint:'~ 暂无订单数据 ~',
  20. icon:'',
  21. mode:'order'
  22. },
  23. contentTxt:{
  24. contentdown: '~上拉加载更多~',
  25. contentrefresh: '努力加载中...',
  26. contentnomore: '-- 我是有底线的 --'
  27. }
  28. }
  29. //请求参数
  30. const params = reactive({
  31. pageNum: PageData.NUM,
  32. pageSize:PageData.SIZE,
  33. total: 0,
  34. status: 'more',
  35. reload: false,
  36. })
  37. //搜索
  38. const doSearch = () => {
  39. if(!searchKeyWords.value){
  40. msg('请输入需要搜索的车牌号!');
  41. return;
  42. }
  43. refreshList(true);
  44. }
  45. //订单车牌号输入
  46. const onKeyInput = (event) =>{
  47. searchKeyWords.value = event.target.value;
  48. if(searchKeyWords.value == ''){
  49. refreshList(true);
  50. }
  51. }
  52. /* 刷新列表 */
  53. const refreshList = (isLoading) =>{
  54. params.pageNum = 1;
  55. params.total = 0;
  56. params.status = 'more';
  57. params.reload = false;
  58. getList();
  59. }
  60. /* 加载更多 */
  61. const loadMore = () =>{
  62. if(params.total > ordersList.value.length){
  63. params.status = 'loading';
  64. params.pageNum++;
  65. getList();
  66. }else{
  67. params.status = 'noMore';
  68. }
  69. }
  70. /* 获取列表数据 */
  71. const getList = async(isLoading = true) =>{
  72. if(!hasLogin()){
  73. uni.stopPullDownRefresh();
  74. uni.$emit('refreshFinish');
  75. return;
  76. }
  77. let res: any = null;
  78. const options = {
  79. type:2,
  80. data:{
  81. "opId": getItem(StorageKeys.OpenId),
  82. "source":"WECHAT",
  83. "vehiclePlate":searchKeyWords.value,
  84. "tabIndex":props.index + '',
  85. "pageNo":params.pageNum,
  86. "pageSize":params.pageSize
  87. },
  88. method:'POST',
  89. // showLoading: isLoading ? (params.pageNum === 1 ? true : false) : false ,
  90. }
  91. try{
  92. res = await request(orderList,options);
  93. const data = stringToJson(res.bizContent);
  94. params.total = data.totalCount;
  95. if(params.pageNum === 1){
  96. ordersList.value = [];
  97. }
  98. if(params.total > 0){
  99. const curList = data.data || [];
  100. ordersList.value = params.reload ? curList : ordersList.value.concat(curList);
  101. params.reload = false;
  102. }
  103. if(params.total === ordersList.value.length){
  104. params.reload = false;
  105. params.status = 'noMore';
  106. }
  107. if(params.pageNum === 1){
  108. uni.stopPullDownRefresh();
  109. }
  110. uni.$emit('refreshFinish');
  111. }catch(e){
  112. uni.stopPullDownRefresh();
  113. uni.$emit('refreshFinish');
  114. }
  115. }
  116. watch(()=>props.index,()=>{
  117. refreshList(true);
  118. });
  119. watch(()=>props.refresh,(nv)=>{
  120. if(nv){
  121. refreshList(false);
  122. }
  123. });
  124. onMounted(()=>{
  125. if(props.refresh){
  126. refreshList(false);
  127. }
  128. })
  129. onPullDownRefresh(()=>{
  130. refreshList(true);
  131. });
  132. onReachBottom(()=>{
  133. loadMore();
  134. });
  135. return {
  136. config,
  137. params,
  138. ordersList,
  139. doSearch,
  140. onKeyInput
  141. };
  142. }