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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292
  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, setItem } from "@/utils/storage";
  9. import { hasLogin, msg, timesDiff } from "@/utils/utils";
  10. import { orderList, appPage } 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. const tabName = ref('小程序');
  17. //订单列表数据
  18. const ordersList = ref([]);
  19. const config = {
  20. emptyHint: {
  21. hint: '~ 暂无订单数据 ~',
  22. icon: '',
  23. mode: 'order'
  24. },
  25. contentTxt: {
  26. contentdown: '~上拉加载更多~',
  27. contentrefresh: '努力加载中...',
  28. contentnomore: '-- 我是有底线的 --'
  29. }
  30. }
  31. //请求参数
  32. const params = reactive({
  33. pageNum: PageData.NUM,
  34. pageSize: PageData.SIZE,
  35. total: 0,
  36. status: 'more',
  37. reload: false,
  38. })
  39. //搜索
  40. const doSearch = () => {
  41. // #ifdef MP-WEIXIN
  42. if (!searchKeyWords.value) {
  43. msg('请输入需要搜索的车牌号!');
  44. return;
  45. }
  46. refreshList(true);
  47. // #endif
  48. // #ifdef MP-ALIPAY
  49. tools.showLoadingAlert("加载中");
  50. refreshList(true);
  51. tools.hideLoadingAlert();
  52. // #endif
  53. }
  54. //订单车牌号输入
  55. const onKeyInput = (event) => {
  56. searchKeyWords.value = event.target.value;
  57. if (searchKeyWords.value == '') {
  58. refreshList(true);
  59. }
  60. }
  61. /* 刷新列表 */
  62. const refreshList = (isLoading) => {
  63. console.log("========", isLoading)
  64. params.pageNum = 1;
  65. params.total = 0;
  66. params.status = 'more';
  67. params.reload = false;
  68. getList();
  69. }
  70. const changeTab = (tabOption) => {
  71. // setItem('tab', tabOption)
  72. console.log("tabOption", tabOption)
  73. tabName.value = tabOption
  74. refreshList(true)
  75. }
  76. /* 加载更多 */
  77. const loadMore = () => {
  78. if (params.total > ordersList.value.length) {
  79. params.status = 'loading';
  80. params.pageNum++;
  81. getList();
  82. } else {
  83. params.status = 'noMore';
  84. }
  85. }
  86. /* 获取列表数据 */
  87. const getList = async () => {
  88. console.log("props.refresh", props.refresh)
  89. if (!hasLogin()) {
  90. uni.stopPullDownRefresh();
  91. uni.$emit('refreshFinish');
  92. return;
  93. }
  94. let res : any = null;
  95. let newsource = "WECHAT"
  96. // #ifdef MP-ALIPAY
  97. newsource = "ALI"
  98. // #endif
  99. let options = {}
  100. console.log("tabName.value", tabName.value)
  101. if (tabName.value == '线下网点') {
  102. options = {
  103. type: 2,
  104. data: {
  105. "opId": getItem(StorageKeys.OpenId),
  106. "vehiclePlate": searchKeyWords.value,
  107. "tabIndex": props.index + '',
  108. "pageNo": params.pageNum,
  109. "pageSize": params.pageSize,
  110. },
  111. method: 'POST',
  112. showLoading: true
  113. }
  114. console.log("线下网点", ordersList.value)
  115. try {
  116. request(appPage, options).then((res) => {
  117. uni.hideLoading()
  118. var data = stringToJson(res.bizContent);
  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.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. // 订单发货后未激活 30天 以后 结束订单功能 insertTime >30 算出来距离今天是负数 updateTime<30(结束订单)
  137. for (var k = 0; k < ordersList.value.length; k++) {
  138. if (ordersList.value[k]['insertTime']) {
  139. if (timesDiff(ordersList.value[k]['insertTime'].replace("T", " ")).days > 30) {
  140. ordersList.value[k]['finishOrder'] = true //可以结束
  141. } else {
  142. ordersList.value[k]['finishOrder'] = false //不可以结束
  143. }
  144. }
  145. if (ordersList.value[k]['updateTime']) {
  146. if (timesDiff(ordersList.value[k]['updateTime'].replace("T", " ")).days <= 30) {
  147. ordersList.value[k]['isUseAgain'] = true //可以再次使用
  148. } else {
  149. ordersList.value[k]['isUseAgain'] = false //不可以再次使用
  150. }
  151. }
  152. }
  153. // uni.$emit('refreshFinish');
  154. uni.$emit("refreshOrder");
  155. console.log("data.refresh", props.refresh)
  156. console.log('输出内容app', ordersList)
  157. })
  158. .catch((err) => {
  159. console.log(err);
  160. });
  161. uni.$emit('refreshFinish');
  162. } catch (e) {
  163. uni.stopPullDownRefresh();
  164. }
  165. } else {
  166. options = {
  167. type: 2,
  168. data: {
  169. "opId": getItem(StorageKeys.OpenId),
  170. "source": newsource,
  171. "vehiclePlate": searchKeyWords.value,
  172. "tabIndex": props.index + '',
  173. "pageNo": params.pageNum,
  174. "pageSize": params.pageSize,
  175. "promotionModes": 1,
  176. },
  177. method: 'POST',
  178. showLoading: true
  179. }
  180. try {
  181. request(orderList, options).then((res) => {
  182. uni.hideLoading()
  183. var data = stringToJson(res.bizContent);
  184. console.log("ordersList.value", data)
  185. params.total = data.totalCount;
  186. if (params.pageNum === 1) {
  187. ordersList.value = [];
  188. }
  189. if (params.total > 0) {
  190. const curList = data.data || [];
  191. ordersList.value = params.reload ? curList : ordersList.value.concat(curList);
  192. params.reload = false;
  193. }
  194. if (params.total === ordersList.value.length) {
  195. params.reload = false;
  196. params.status = 'noMore';
  197. }
  198. if (params.pageNum === 1) {
  199. uni.stopPullDownRefresh();
  200. }
  201. // 订单发货后未激活 30天 以后 结束订单功能 insertTime >30 算出来距离今天是负数 updateTime<30(结束订单)
  202. for (var k = 0; k < ordersList.value.length; k++) {
  203. if (ordersList.value[k]['insertTime']) {
  204. if (timesDiff(ordersList.value[k]['insertTime'].replace("T", " ")).days > 30) {
  205. ordersList.value[k]['finishOrder'] = true //可以结束
  206. } else {
  207. ordersList.value[k]['finishOrder'] = false //不可以结束
  208. }
  209. }
  210. if (ordersList.value[k]['updateTime']) {
  211. if (timesDiff(ordersList.value[k]['updateTime'].replace("T", " ")).days <= 30) {
  212. ordersList.value[k]['isUseAgain'] = true //可以再次使用
  213. } else {
  214. ordersList.value[k]['isUseAgain'] = false //不可以再次使用
  215. }
  216. }
  217. }
  218. // uni.$emit('refreshFinish');
  219. // uni.$emit("refreshOrder");
  220. console.log('输出内容小程序', ordersList)
  221. })
  222. .catch((err) => {
  223. console.log(err);
  224. });
  225. } catch (e) {
  226. uni.stopPullDownRefresh();
  227. }
  228. }
  229. console.log("订单列表查询", options)
  230. }
  231. watch(() => props.index, () => {
  232. console.log("watch1111")
  233. refreshList(true);
  234. });
  235. // watch(() => props.refresh, (nv) => {
  236. // console.log("watch222222221", props.refresh)
  237. // if (nv) {
  238. // refreshList(false);
  239. // }
  240. // });
  241. onMounted(() => {
  242. if (props.refresh) {
  243. refreshList(false);
  244. }
  245. })
  246. onPullDownRefresh(() => {
  247. refreshList(true);
  248. });
  249. onReachBottom(() => {
  250. loadMore();
  251. });
  252. return {
  253. config,
  254. params,
  255. ordersList,
  256. doSearch,
  257. onKeyInput,
  258. refreshList,
  259. changeTab,
  260. tabName
  261. };
  262. }