You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

useOrderListItem.ts 4.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  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, timesDiff } 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. let newsource = "WECHAT"
  79. // #ifdef MP-ALIPAY
  80. newsource = "ALI"
  81. // #endif
  82. const options = {
  83. type: 2,
  84. data: {
  85. "opId": getItem(StorageKeys.OpenId),
  86. "source": newsource,
  87. "vehiclePlate": searchKeyWords.value,
  88. "tabIndex": props.index + '',
  89. "pageNo": params.pageNum,
  90. "pageSize": params.pageSize,
  91. "promotionModes": 1
  92. },
  93. method: 'POST',
  94. // showLoading: isLoading ? (params.pageNum === 1 ? true : false) : false ,
  95. }
  96. console.log("订单列表查询", options)
  97. try {
  98. res = await request(orderList, options);
  99. const data = stringToJson(res.bizContent);
  100. console.log("ordersList.value", ordersList.value)
  101. params.total = data.totalCount;
  102. if (params.pageNum === 1) {
  103. ordersList.value = [];
  104. }
  105. if (params.total > 0) {
  106. const curList = data.data || [];
  107. ordersList.value = params.reload ? curList : ordersList.value.concat(curList);
  108. params.reload = false;
  109. }
  110. if (params.total === ordersList.value.length) {
  111. params.reload = false;
  112. params.status = 'noMore';
  113. }
  114. if (params.pageNum === 1) {
  115. uni.stopPullDownRefresh();
  116. }
  117. // 订单发货后未激活 30天 以后 结束订单功能 insertTime >30 算出来距离今天是负数 updateTime<30(结束订单)
  118. for (var k = 0; k < ordersList.value.length; k++) {
  119. if (ordersList.value[k]['insertTime']) {
  120. if (timesDiff(ordersList.value[k]['insertTime'].replace("T", " ")).days > 30) {
  121. ordersList.value[k]['finishOrder'] = true //可以结束
  122. } else {
  123. ordersList.value[k]['finishOrder'] = false //不可以结束
  124. }
  125. }
  126. if (ordersList.value[k]['updateTime']) {
  127. if (timesDiff(ordersList.value[k]['updateTime'].replace("T", " ")).days <= 30) {
  128. ordersList.value[k]['isUseAgain'] = true //可以再次使用
  129. } else {
  130. ordersList.value[k]['isUseAgain'] = false //不可以再次使用
  131. }
  132. }
  133. }
  134. uni.$emit('refreshFinish');
  135. } catch (e) {
  136. console.log('输出内容', e)
  137. uni.stopPullDownRefresh();
  138. uni.$emit('refreshFinish');
  139. }
  140. }
  141. watch(() => props.index, () => {
  142. refreshList(true);
  143. });
  144. watch(() => props.refresh, (nv) => {
  145. if (nv) {
  146. refreshList(false);
  147. }
  148. });
  149. onMounted(() => {
  150. if (props.refresh) {
  151. refreshList(false);
  152. }
  153. })
  154. onPullDownRefresh(() => {
  155. refreshList(true);
  156. });
  157. onReachBottom(() => {
  158. loadMore();
  159. });
  160. return {
  161. config,
  162. params,
  163. ordersList,
  164. doSearch,
  165. onKeyInput
  166. };
  167. }