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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  1. /**
  2. * 订单列表业务逻辑
  3. */
  4. import { reactive, ref, watch, nextTick } from "vue";
  5. import { requestNew } from "@/utils/network/request.js";
  6. import { onReachBottom, onPullDownRefresh, onShow } from "@dcloudio/uni-app";
  7. import { getItem, StorageKeys } from "@/utils/storage";
  8. import { hasLogin, msg, timesDiff } from "@/utils/utils";
  9. import { queryPage } from "@/utils/network/api";
  10. import { PageData } from "@/datas/enum";
  11. const tools = require("../../static/etcUtil/tools.js");
  12. const searchKeyWords = ref('');
  13. export default function useOrderListItem(props) {
  14. //搜索关键字
  15. const tabName = 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. console.log("========", isLoading)
  63. params.pageNum = 1;
  64. params.total = 0;
  65. params.status = 'more';
  66. params.reload = false;
  67. getList();
  68. }
  69. const changeTab = (tabOption) => {
  70. console.log("tabOption", tabOption)
  71. tabName.value = tabOption
  72. refreshList(true)
  73. }
  74. /* 加载更多 */
  75. const loadMore = () => {
  76. if (params.total > ordersList.value.length) {
  77. params.status = 'loading';
  78. params.pageNum++;
  79. getList();
  80. } else {
  81. params.status = 'noMore';
  82. }
  83. }
  84. /* 获取列表数据 */
  85. const getList = async () => {
  86. console.log("props.refresh", props.refresh)
  87. if (!hasLogin()) {
  88. uni.stopPullDownRefresh();
  89. uni.$emit('refreshFinish');
  90. return;
  91. }
  92. let res : any = null;
  93. let newsource = "WECHAT"
  94. // #ifdef MP-ALIPAY
  95. newsource = "ALI"
  96. // #endif
  97. let options = {}
  98. console.log("tabName.value", tabName.value)
  99. options = {
  100. type: 2,
  101. data: {
  102. // "opId": getItem(StorageKeys.OpenId),
  103. // "source": newsource,
  104. // "vehiclePlate": searchKeyWords.value,
  105. "tabIndex": props.index + '',
  106. "pageNo": params.pageNum,
  107. "pageSize": params.pageSize,
  108. // "promotionModes": 1,
  109. "customerId": "",
  110. },
  111. method: 'POST',
  112. showLoading: true
  113. }
  114. try {
  115. requestNew(queryPage, options).then((res) => {
  116. uni.hideLoading()
  117. console.log("订单", res)
  118. var data = res;
  119. console.log("ordersList.value", data)
  120. params.total = data.totalCount;
  121. if (params.pageNum === 1) {
  122. ordersList.value = [];
  123. }
  124. if (params.total > 0) {
  125. const curList = data.result || [];
  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. // 订单发货后未激活 30天 以后 结束订单功能 insertTime >30 算出来距离今天是负数 updateTime<30(结束订单)
  137. console.log("处理前列表数据", ordersList.value)
  138. for (var k = 0; k < ordersList.value.length; k++) {
  139. if (ordersList.value[k]['insertTime']) {
  140. if (timesDiff(ordersList.value[k]['insertTime'].replace("T", " ")).days > 30) {
  141. ordersList.value[k]['finishOrder'] = true //可以结束
  142. } else {
  143. ordersList.value[k]['finishOrder'] = false //不可以结束
  144. }
  145. }
  146. if (ordersList.value[k]['updateTime']) {
  147. if (timesDiff(ordersList.value[k]['updateTime'].replace("T", " ")).days <= 30) {
  148. ordersList.value[k]['isUseAgain'] = true //可以再次使用
  149. } else {
  150. ordersList.value[k]['isUseAgain'] = false //不可以再次使用
  151. }
  152. }
  153. // 收货日期超过7个自然日不允许申请退货
  154. if (ordersList.value[k]['receivingTime']) {
  155. if (timesDiff(ordersList.value[k]['receivingTime'].replace("T", " ")).days > 7) {
  156. ordersList.value[k]['applyReturn'] = false //不展示申请退货
  157. } else {
  158. ordersList.value[k]['applyReturn'] = true //展示申请退货
  159. }
  160. }
  161. }
  162. uni.$emit("refreshOrder");
  163. console.log('输出内容小程序', ordersList)
  164. })
  165. .catch((err) => {
  166. console.log(err);
  167. });
  168. } catch (e) {
  169. uni.stopPullDownRefresh();
  170. }
  171. console.log("订单列表查询", options)
  172. }
  173. watch(() => props.index, () => {
  174. console.log("watch1111")
  175. refreshList(true);
  176. });
  177. onPullDownRefresh(() => {
  178. refreshList(true);
  179. });
  180. onReachBottom(() => {
  181. loadMore();
  182. });
  183. onShow(() => {
  184. console.log("一进页面就刷新", searchKeyWords.value)
  185. if (props.index == 0) {
  186. refreshList(true);
  187. }
  188. })
  189. return {
  190. config,
  191. params,
  192. ordersList,
  193. doSearch,
  194. onKeyInput,
  195. refreshList,
  196. changeTab,
  197. tabName,
  198. searchKeyWords
  199. };
  200. }