index.vue 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371
  1. <template>
  2. <view>
  3. <view class="my-order">
  4. <view class="nav">
  5. <up-tabs :scrollable="false" lineColor="#F8C008" :activeStyle="{color:'#F8C008',fontSize:'28rpx'}"
  6. :inactiveStyle="{color:'#333333',fontSize:'28rpx'}" :list="list" @click="statusClick"
  7. :current="oldOrderStatus"></up-tabs>
  8. </view>
  9. <view class="list" v-if="orderList.length">
  10. <OrderListCard v-for="(item, index) in orderList" :key="index" :order="item" :index="index"
  11. @cancelOrder="cancelOrder" @goPay="goPay" @goOrderDetails="goOrderDetails" :mallType="0"
  12. @delOrder="delOrder" />
  13. </view>
  14. <view class="loadingicon acea-row row-center-wrapper" v-if="orderList.length > 0">
  15. <text class="loading iconfont icon-jiazai" :hidden="loading == false"></text>{{ loadTitle }}
  16. </view>
  17. <view class="empty" v-if="orderList.length == 0">
  18. <uni-empty-view />
  19. </view>
  20. </view>
  21. <payment @closePopup="closePayPopup" :payMode="payMode" :showPopup="showPopup" @payComplete="payComplete"
  22. @payFail="payFail" @onChangeFun="onChangeFun" :order_id="pay_order_id" :totalPrice="totalPrice"></payment>
  23. </view>
  24. </template>
  25. <script setup>
  26. import {
  27. ref,
  28. onMounted
  29. } from "vue";
  30. import {
  31. onLoad,
  32. onShow,
  33. onReachBottom
  34. } from "@dcloudio/uni-app";
  35. import OrderListCard from "@/components/OrderListCard";
  36. import {
  37. useAppStore
  38. } from "@/stores/app";
  39. import {
  40. getOrderList,
  41. orderData,
  42. orderCancel,
  43. orderDel
  44. } from "@/api/order.js";
  45. import payment from "@/components/payment";
  46. import {
  47. toLogin
  48. } from "@/libs/login.js";
  49. import emptyPage from "@/components/emptyPage.vue";
  50. import {
  51. useToast
  52. } from "@/hooks/useToast";
  53. const appStore = useAppStore();
  54. const {
  55. Toast
  56. } = useToast();
  57. // 状态
  58. const loading = ref(false);
  59. const loadend = ref(false);
  60. const loadTitle = ref("加载更多");
  61. const orderList = ref([]);
  62. const orderDataState = ref({});
  63. const orderStatus = ref(0);
  64. const oldOrderStatus = ref(0); //老数据
  65. const page = ref(1);
  66. const limit = ref(10);
  67. const payMode = ref([{
  68. name: "微信支付",
  69. icon: "icon-weixinzhifu",
  70. value: "weixin",
  71. title: "微信快捷支付",
  72. },
  73. {
  74. name: "余额支付",
  75. icon: "icon-yuezhifu",
  76. value: "yue",
  77. title: "可用余额:",
  78. number: 0,
  79. },
  80. ]);
  81. const showPopup = ref(false);
  82. const pay_order_id = ref("");
  83. const totalPrice = ref("0");
  84. const list = ref([{
  85. name: '待付款',
  86. orderStatus: 0,
  87. value: 0
  88. },
  89. {
  90. name: '待发货',
  91. orderStatus: 1,
  92. value: 1
  93. },
  94. {
  95. name: '待收货',
  96. orderStatus: 2,
  97. value: 2
  98. },
  99. {
  100. name: '退款/换货',
  101. orderStatus: -3,
  102. value: 3
  103. },
  104. {
  105. name: '已完成',
  106. orderStatus: 4,
  107. value: 4
  108. },
  109. ]) //头部导航
  110. // 生命周期
  111. onMounted(() => {
  112. if (appStore.isLogin) {
  113. loadend.value = false;
  114. page.value = 1;
  115. orderList.value = [];
  116. getOrderData();
  117. getOrderListFn();
  118. } else {
  119. toLogin();
  120. }
  121. });
  122. // 页面显示时
  123. onShow(() => {
  124. if (appStore.isLogin) {
  125. loadend.value = false;
  126. page.value = 1;
  127. orderList.value = [];
  128. getOrderData();
  129. getOrderListFn();
  130. } else {
  131. toLogin();
  132. }
  133. });
  134. onLoad((options) => {
  135. if (options.status) {
  136. const statusValue = parseInt(options.status);
  137. // 验证状态是否有效
  138. const validStatuses = [0, 1, 2, 4, -3];
  139. if (validStatuses.includes(statusValue)) {
  140. // 设置状态
  141. orderStatus.value = statusValue;
  142. // 找到对应的索引
  143. const index = list.value.findIndex(item => item.orderStatus === statusValue);
  144. if (index !== -1) {
  145. oldOrderStatus.value = index; // 设置索引值
  146. }
  147. console.log("设置订单状态为:", statusValue, "索引为:", index);
  148. } else {
  149. console.warn("无效的状态参数:", statusValue);
  150. }
  151. }
  152. })
  153. // 下拉加载
  154. onReachBottom(() => {
  155. getOrderListFn();
  156. });
  157. function onChangeFun(state) {
  158. let action = state.action || null;
  159. let value = state.value !== undefined ? state.value : null;
  160. if (action && typeof [action] === "function") {
  161. [action](value);
  162. }
  163. }
  164. function getOrderData() {
  165. orderData().then((res) => {
  166. orderDataState.value = res.data;
  167. });
  168. }
  169. function cancelOrder(index, order_id) {
  170. if (!order_id) return Toast({
  171. title: "缺少订单号无法取消订单"
  172. });
  173. uni.showLoading({
  174. title: "正在删除中"
  175. });
  176. orderCancel(order_id)
  177. .then((res) => {
  178. uni.hideLoading();
  179. Toast({
  180. title: "删除成功",
  181. icon: "success"
  182. }, () => {
  183. orderList.value.splice(index, 1);
  184. orderDataState.value.unpaid_count--;
  185. getOrderData();
  186. });
  187. })
  188. .catch((err) => {
  189. Toast({
  190. title: err
  191. });
  192. });
  193. }
  194. function goPay(pay_price, order_id) {
  195. appStore.USERINFO().then((res) => {
  196. if (res.nowMoney) {
  197. showPopup.value = true;
  198. pay_order_id.value = order_id;
  199. totalPrice.value = pay_price;
  200. }
  201. });
  202. }
  203. const closePayPopup = () => {
  204. console.log("payClose");
  205. showPopup.value = false;
  206. };
  207. function payComplete() {
  208. console.log("payComplete");
  209. loadend.value = false;
  210. page.value = 1;
  211. orderList.value = [];
  212. showPopup.value = false;
  213. getOrderData();
  214. getOrderListFn();
  215. }
  216. function payFail() {
  217. showPopup.value = false;
  218. }
  219. function goOrderDetails(order_id) {
  220. if (!order_id) return Toast({
  221. title: "缺少订单号无法查看订单详情"
  222. });
  223. uni.navigateTo({
  224. url: "/pages/order_details/index?order_id=" + order_id
  225. });
  226. }
  227. function toReturnList() {
  228. uni.navigateTo({
  229. url: "/pages/users/user_return_list/index"
  230. });
  231. }
  232. const changeStatus = (item) => {
  233. // oldOrderStatus.value = item.index;
  234. }
  235. function statusClick(item) {
  236. console.log(item)
  237. if (item.orderStatus === orderStatus.value) return;
  238. orderStatus.value = item.orderStatus;
  239. loadend.value = false;
  240. page.value = 1;
  241. orderList.value = [];
  242. getOrderListFn();
  243. }
  244. function getOrderListFn() {
  245. if (loadend.value || loading.value) return;
  246. loading.value = true;
  247. loadTitle.value = "加载更多";
  248. getOrderList({
  249. type: orderStatus.value,
  250. page: page.value,
  251. limit: limit.value,
  252. mallType: 0,
  253. })
  254. .then((res) => {
  255. let list = res.data.list || [];
  256. let isLoadend = list.length < limit.value;
  257. // orderList.value = uni.$util.SplitArray(list, orderList.value)
  258. orderList.value = [...list, ...orderList.value];
  259. loadend.value = isLoadend;
  260. loading.value = false;
  261. loadTitle.value = isLoadend ? "我也是有底线的" : "加载更多";
  262. page.value += 1;
  263. })
  264. .catch(() => {
  265. loading.value = false;
  266. loadTitle.value = "加载更多";
  267. });
  268. }
  269. function delOrder(order_id, index) {
  270. orderDel(order_id)
  271. .then((res) => {
  272. orderList.value.splice(index, 1);
  273. orderDataState.value.unpaid_count--;
  274. getOrderData();
  275. Toast({
  276. title: "删除成功",
  277. icon: "success"
  278. });
  279. })
  280. .catch((err) => {
  281. Toast({
  282. title: err
  283. });
  284. });
  285. }
  286. </script>
  287. <style>
  288. page {
  289. background: #F9F7F0;
  290. }
  291. </style>
  292. <style scoped lang="scss">
  293. .empty {
  294. height: calc(100vh - 44px);
  295. /* #ifdef H5 */
  296. height: calc(100vh - 88px);
  297. /* #endif */
  298. display: flex;
  299. align-items: center;
  300. justify-content: center;
  301. }
  302. .my-order {
  303. .nav {
  304. background: #FFFFFF;
  305. // height: 140rpx;
  306. background-color: #fff;
  307. .item {
  308. text-align: center;
  309. font-size: 26rpx;
  310. color: #282828;
  311. padding: 26rpx 0;
  312. &.on {
  313. font-weight: bold;
  314. border-bottom: 5rpx solid $border-color;
  315. }
  316. .num {
  317. margin-top: 18rpx;
  318. }
  319. }
  320. }
  321. .list {
  322. width: 690rpx;
  323. margin: 16rpx auto 0 auto;
  324. }
  325. }
  326. .noCart {
  327. margin-top: 171rpx;
  328. padding-top: 0.1rpx;
  329. .pictrue {
  330. width: 414rpx;
  331. height: 336rpx;
  332. margin: 78rpx auto 56rpx auto;
  333. image {
  334. width: 100%;
  335. height: 100%;
  336. }
  337. }
  338. }
  339. </style>