您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

useOrderListItem.ts 4.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  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. // 订单发货后未激活 30天 以后 结束订单功能 insertTime >30 算出来距离今天是负数
  102. for (var k = 0; k < ordersList.value.length; k++) {
  103. console.log("ordersList.value1111", ordersList.value[k]['insertTime'].replace("T", " "))
  104. console.log("ordersList.value1111", timesDiff(ordersList.value[k]['insertTime'].replace("T", " ")))
  105. if (ordersList.value[k]['insertTime']) {
  106. if (timesDiff(ordersList.value[k]['insertTime'].replace("T", " ")).days > 30) {
  107. ordersList.value[k]['finishOrder'] = true //可以结束
  108. } else {
  109. ordersList.value[k]['finishOrder'] = false //不可以结束
  110. }
  111. }
  112. if (ordersList.value[k]['updateTime']) {
  113. if (timesDiff(ordersList.value[k]['updateTime'].replace("T", " ")).days <= 30) {
  114. ordersList.value[k]['isUseAgain'] = true //可以再次使用
  115. } else {
  116. ordersList.value[k]['isUseAgain'] = false //不可以再次使用
  117. }
  118. }
  119. }
  120. params.total = data.totalCount;
  121. if (params.pageNum === 1) {
  122. ordersList.value = [];
  123. }
  124. if (params.total > 0) {
  125. const curList = data.data || [];
  126. ordersList.value = params.reload ? curList : ordersList.value.concat(curList);
  127. params.reload = false;
  128. }
  129. if (params.total === ordersList.value.length) {
  130. params.reload = false;
  131. params.status = 'noMore';
  132. }
  133. if (params.pageNum === 1) {
  134. uni.stopPullDownRefresh();
  135. }
  136. uni.$emit('refreshFinish');
  137. } catch (e) {
  138. console.log('输出内容', e)
  139. uni.stopPullDownRefresh();
  140. uni.$emit('refreshFinish');
  141. }
  142. }
  143. watch(() => props.index, () => {
  144. refreshList(true);
  145. });
  146. watch(() => props.refresh, (nv) => {
  147. if (nv) {
  148. refreshList(false);
  149. }
  150. });
  151. onMounted(() => {
  152. if (props.refresh) {
  153. refreshList(false);
  154. }
  155. })
  156. onPullDownRefresh(() => {
  157. refreshList(true);
  158. });
  159. onReachBottom(() => {
  160. loadMore();
  161. });
  162. return {
  163. config,
  164. params,
  165. ordersList,
  166. doSearch,
  167. onKeyInput
  168. };
  169. }