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.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  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. const tools = require("../../static/etcUtil/tools.js");
  13. export default function useOrderListItem(props) {
  14. //搜索关键字
  15. const searchKeyWords = ref('');
  16. //订单列表数据
  17. const ordersList = ref([]);
  18. const config = {
  19. emptyHint: {
  20. hint: '~ 暂无订单数据 ~',
  21. icon: '',
  22. mode: 'order'
  23. },
  24. contentTxt: {
  25. contentdown: '~上拉加载更多~',
  26. contentrefresh: '努力加载中...',
  27. contentnomore: '-- 我是有底线的 --'
  28. }
  29. }
  30. //请求参数
  31. const params = reactive({
  32. pageNum: PageData.NUM,
  33. pageSize: PageData.SIZE,
  34. total: 0,
  35. status: 'more',
  36. reload: false,
  37. })
  38. //搜索
  39. const doSearch = () => {
  40. // #ifdef MP-WEIXIN
  41. if (!searchKeyWords.value) {
  42. msg('请输入需要搜索的车牌号!');
  43. return;
  44. }
  45. refreshList(true);
  46. // #endif
  47. // #ifdef MP-ALIPAY
  48. tools.showLoadingAlert("加载中");
  49. refreshList(true);
  50. tools.hideLoadingAlert();
  51. // #endif
  52. }
  53. //订单车牌号输入
  54. const onKeyInput = (event) => {
  55. searchKeyWords.value = event.target.value;
  56. if (searchKeyWords.value == '') {
  57. refreshList(true);
  58. }
  59. }
  60. /* 刷新列表 */
  61. const refreshList = (isLoading) => {
  62. params.pageNum = 1;
  63. params.total = 0;
  64. params.status = 'more';
  65. params.reload = false;
  66. getList();
  67. }
  68. /* 加载更多 */
  69. const loadMore = () => {
  70. if (params.total > ordersList.value.length) {
  71. params.status = 'loading';
  72. params.pageNum++;
  73. getList();
  74. } else {
  75. params.status = 'noMore';
  76. }
  77. }
  78. /* 获取列表数据 */
  79. const getList = async (isLoading = true) => {
  80. if (!hasLogin()) {
  81. uni.stopPullDownRefresh();
  82. uni.$emit('refreshFinish');
  83. return;
  84. }
  85. let res : any = null;
  86. let newsource = "WECHAT"
  87. // #ifdef MP-ALIPAY
  88. newsource = "ALI"
  89. // #endif
  90. const options = {
  91. type: 2,
  92. data: {
  93. "opId": getItem(StorageKeys.OpenId),
  94. "source": newsource,
  95. "vehiclePlate": searchKeyWords.value,
  96. "tabIndex": props.index + '',
  97. "pageNo": params.pageNum,
  98. "pageSize": params.pageSize,
  99. "promotionModes": 1,
  100. "isAfter": true
  101. },
  102. method: 'POST',
  103. // showLoading: isLoading ? (params.pageNum === 1 ? true : false) : false ,
  104. }
  105. console.log("订单列表查询", options)
  106. try {
  107. // res = await request(orderList, options);
  108. console.log('输出内容1111111')
  109. request(orderList, options).then((res) => {
  110. const data = stringToJson(res.bizContent);
  111. console.log("ordersList.value", ordersList.value)
  112. params.total = data.totalCount;
  113. if (params.pageNum === 1) {
  114. ordersList.value = [];
  115. }
  116. if (params.total > 0) {
  117. const curList = data.data || [];
  118. ordersList.value = params.reload ? curList : ordersList.value.concat(curList);
  119. params.reload = false;
  120. }
  121. if (params.total === ordersList.value.length) {
  122. params.reload = false;
  123. params.status = 'noMore';
  124. }
  125. if (params.pageNum === 1) {
  126. uni.stopPullDownRefresh();
  127. }
  128. // 订单发货后未激活 30天 以后 结束订单功能 insertTime >30 算出来距离今天是负数 updateTime<30(结束订单)
  129. for (var k = 0; k < ordersList.value.length; k++) {
  130. if (ordersList.value[k]['insertTime']) {
  131. if (timesDiff(ordersList.value[k]['insertTime'].replace("T", " ")).days > 30) {
  132. ordersList.value[k]['finishOrder'] = true //可以结束
  133. } else {
  134. ordersList.value[k]['finishOrder'] = false //不可以结束
  135. }
  136. }
  137. if (ordersList.value[k]['updateTime']) {
  138. if (timesDiff(ordersList.value[k]['updateTime'].replace("T", " ")).days <= 30) {
  139. ordersList.value[k]['isUseAgain'] = true //可以再次使用
  140. } else {
  141. ordersList.value[k]['isUseAgain'] = false //不可以再次使用
  142. }
  143. }
  144. }
  145. console.log('输出内容222222', ordersList)
  146. })
  147. .catch((err) => {
  148. console.log(err);
  149. });
  150. uni.$emit('refreshFinish');
  151. } catch (e) {
  152. uni.stopPullDownRefresh();
  153. uni.$emit('refreshFinish');
  154. }
  155. }
  156. watch(() => props.index, () => {
  157. refreshList(true);
  158. });
  159. watch(() => props.refresh, (nv) => {
  160. if (nv) {
  161. refreshList(false);
  162. }
  163. });
  164. onMounted(() => {
  165. if (props.refresh) {
  166. refreshList(false);
  167. }
  168. })
  169. onPullDownRefresh(() => {
  170. refreshList(true);
  171. });
  172. onReachBottom(() => {
  173. loadMore();
  174. });
  175. return {
  176. config,
  177. params,
  178. ordersList,
  179. doSearch,
  180. onKeyInput,
  181. refreshList
  182. };
  183. }