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

useOrderListItem.ts 7.0KB

2 年前
2 年前
1年前
1年前
2 年前
2 年前
1年前
2 年前
1年前
2 年前
2 年前
1年前
2 年前
1年前
2 年前
1年前
2 年前
1年前
2 年前
1年前
1年前
1年前
1年前
1年前
1年前
1年前
1年前
1年前
2 年前
1年前
2 年前
1年前
2 年前
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286
  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. //订单列表数据
  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. setItem('tab', tabOption)
  71. refreshList(true)
  72. }
  73. /* 加载更多 */
  74. const loadMore = () => {
  75. if (params.total > ordersList.value.length) {
  76. params.status = 'loading';
  77. params.pageNum++;
  78. getList();
  79. } else {
  80. params.status = 'noMore';
  81. }
  82. }
  83. /* 获取列表数据 */
  84. const getList = async () => {
  85. if (!hasLogin()) {
  86. uni.stopPullDownRefresh();
  87. uni.$emit('refreshFinish');
  88. return;
  89. }
  90. let res : any = null;
  91. let newsource = "WECHAT"
  92. // #ifdef MP-ALIPAY
  93. newsource = "ALI"
  94. // #endif
  95. let options = {}
  96. if (getItem('tab') == '线下网点') {
  97. options = {
  98. type: 2,
  99. data: {
  100. "opId": getItem(StorageKeys.OpenId),
  101. // "source": newsource,
  102. "vehiclePlate": searchKeyWords.value,
  103. "tabIndex": props.index + '',
  104. "pageNo": params.pageNum,
  105. "pageSize": params.pageSize,
  106. // "promotionModes": 1,
  107. },
  108. method: 'POST',
  109. showLoading: true
  110. }
  111. console.log("线下网点", ordersList.value)
  112. try {
  113. console.log('输出内容1111111')
  114. request(appPage, options).then((res) => {
  115. uni.hideLoading()
  116. var data = data = stringToJson(res.bizContent);
  117. console.log("ordersList.value", data)
  118. params.total = data.totalCount;
  119. if (params.pageNum === 1) {
  120. ordersList.value = [];
  121. }
  122. if (params.total > 0) {
  123. const curList = data.data || [];
  124. ordersList.value = params.reload ? curList : ordersList.value.concat(curList);
  125. params.reload = false;
  126. }
  127. if (params.total === ordersList.value.length) {
  128. params.reload = false;
  129. params.status = 'noMore';
  130. }
  131. if (params.pageNum === 1) {
  132. uni.stopPullDownRefresh();
  133. }
  134. // 订单发货后未激活 30天 以后 结束订单功能 insertTime >30 算出来距离今天是负数 updateTime<30(结束订单)
  135. for (var k = 0; k < ordersList.value.length; k++) {
  136. if (ordersList.value[k]['insertTime']) {
  137. if (timesDiff(ordersList.value[k]['insertTime'].replace("T", " ")).days > 30) {
  138. ordersList.value[k]['finishOrder'] = true //可以结束
  139. } else {
  140. ordersList.value[k]['finishOrder'] = false //不可以结束
  141. }
  142. }
  143. if (ordersList.value[k]['updateTime']) {
  144. if (timesDiff(ordersList.value[k]['updateTime'].replace("T", " ")).days <= 30) {
  145. ordersList.value[k]['isUseAgain'] = true //可以再次使用
  146. } else {
  147. ordersList.value[k]['isUseAgain'] = false //不可以再次使用
  148. }
  149. }
  150. }
  151. uni.$emit("refreshOrder");
  152. console.log('输出内容111111', ordersList)
  153. })
  154. .catch((err) => {
  155. console.log(err);
  156. });
  157. // uni.$emit('refreshFinish');
  158. } catch (e) {
  159. uni.stopPullDownRefresh();
  160. uni.$emit('refreshFinish');
  161. }
  162. } else {
  163. options = {
  164. type: 2,
  165. data: {
  166. "opId": getItem(StorageKeys.OpenId),
  167. "source": newsource,
  168. "vehiclePlate": searchKeyWords.value,
  169. "tabIndex": props.index + '',
  170. "pageNo": params.pageNum,
  171. "pageSize": params.pageSize,
  172. "promotionModes": 1,
  173. },
  174. method: 'POST',
  175. showLoading: true
  176. }
  177. try {
  178. console.log('输出内容1111111')
  179. request(orderList, options).then((res) => {
  180. uni.hideLoading()
  181. var data = data = stringToJson(res.bizContent);
  182. console.log("ordersList.value", data)
  183. params.total = data.totalCount;
  184. if (params.pageNum === 1) {
  185. ordersList.value = [];
  186. }
  187. if (params.total > 0) {
  188. const curList = data.data || [];
  189. ordersList.value = params.reload ? curList : ordersList.value.concat(curList);
  190. params.reload = false;
  191. }
  192. if (params.total === ordersList.value.length) {
  193. params.reload = false;
  194. params.status = 'noMore';
  195. }
  196. if (params.pageNum === 1) {
  197. uni.stopPullDownRefresh();
  198. }
  199. // 订单发货后未激活 30天 以后 结束订单功能 insertTime >30 算出来距离今天是负数 updateTime<30(结束订单)
  200. for (var k = 0; k < ordersList.value.length; k++) {
  201. if (ordersList.value[k]['insertTime']) {
  202. if (timesDiff(ordersList.value[k]['insertTime'].replace("T", " ")).days > 30) {
  203. ordersList.value[k]['finishOrder'] = true //可以结束
  204. } else {
  205. ordersList.value[k]['finishOrder'] = false //不可以结束
  206. }
  207. }
  208. if (ordersList.value[k]['updateTime']) {
  209. if (timesDiff(ordersList.value[k]['updateTime'].replace("T", " ")).days <= 30) {
  210. ordersList.value[k]['isUseAgain'] = true //可以再次使用
  211. } else {
  212. ordersList.value[k]['isUseAgain'] = false //不可以再次使用
  213. }
  214. }
  215. }
  216. console.log('输出内容222222', ordersList)
  217. })
  218. .catch((err) => {
  219. console.log(err);
  220. });
  221. uni.$emit('refreshFinish');
  222. } catch (e) {
  223. uni.stopPullDownRefresh();
  224. uni.$emit('refreshFinish');
  225. }
  226. }
  227. console.log("订单列表查询", options)
  228. }
  229. watch(() => props.index, () => {
  230. refreshList(true);
  231. });
  232. watch(() => props.refresh, (nv) => {
  233. if (nv) {
  234. refreshList(false);
  235. }
  236. });
  237. onMounted(() => {
  238. if (props.refresh) {
  239. refreshList(false);
  240. }
  241. })
  242. onPullDownRefresh(() => {
  243. refreshList(true);
  244. });
  245. onReachBottom(() => {
  246. loadMore();
  247. });
  248. return {
  249. config,
  250. params,
  251. ordersList,
  252. doSearch,
  253. onKeyInput,
  254. refreshList,
  255. changeTab
  256. };
  257. }