index.vue 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375
  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. name: '已取消',
  111. orderStatus: 6,
  112. value: 6
  113. },
  114. ]) //头部导航
  115. // 生命周期
  116. onMounted(() => {
  117. if (appStore.isLogin) {
  118. loadend.value = false;
  119. page.value = 1;
  120. orderList.value = [];
  121. getOrderData();
  122. getOrderListFn();
  123. } else {
  124. toLogin();
  125. }
  126. });
  127. // 页面显示时
  128. onShow(() => {
  129. if (appStore.isLogin) {
  130. loadend.value = false;
  131. page.value = 1;
  132. orderList.value = [];
  133. getOrderData();
  134. getOrderListFn();
  135. } else {
  136. toLogin();
  137. }
  138. });
  139. onLoad((options) => {
  140. if (options.status) {
  141. const statusValue = parseInt(options.status);
  142. // 验证状态是否有效
  143. const validStatuses = [0, 1, 2, 4, -3];
  144. if (validStatuses.includes(statusValue)) {
  145. // 设置状态
  146. orderStatus.value = statusValue;
  147. // 找到对应的索引
  148. const index = list.value.findIndex(item => item.orderStatus === statusValue);
  149. if (index !== -1) {
  150. oldOrderStatus.value = index; // 设置索引值
  151. }
  152. console.log("设置订单状态为:", statusValue, "索引为:", index);
  153. } else {
  154. console.warn("无效的状态参数:", statusValue);
  155. }
  156. }
  157. })
  158. // 下拉加载
  159. onReachBottom(() => {
  160. getOrderListFn();
  161. });
  162. function onChangeFun(state) {
  163. let action = state.action || null;
  164. let value = state.value !== undefined ? state.value : null;
  165. if (action && typeof [action] === "function") {
  166. [action](value);
  167. }
  168. }
  169. function getOrderData() {
  170. orderData().then((res) => {
  171. orderDataState.value = res.data;
  172. });
  173. }
  174. function cancelOrder(index, order_id) {
  175. if (!order_id) return Toast({
  176. title: "缺少订单号无法取消订单"
  177. });
  178. uni.showLoading({
  179. title: "正在删除中"
  180. });
  181. orderCancel(order_id)
  182. .then((res) => {
  183. uni.hideLoading();
  184. Toast({
  185. title: "删除成功",
  186. icon: "success"
  187. }, () => {
  188. orderList.value.splice(index, 1);
  189. orderDataState.value.unpaid_count--;
  190. getOrderData();
  191. });
  192. })
  193. .catch((err) => {
  194. Toast({
  195. title: err
  196. });
  197. });
  198. }
  199. function goPay(pay_price, order_id) {
  200. appStore.USERINFO().then((res) => {
  201. if (res.nowMoney) {
  202. showPopup.value = true;
  203. pay_order_id.value = order_id;
  204. totalPrice.value = pay_price;
  205. }
  206. });
  207. }
  208. const closePayPopup = () => {
  209. console.log("payClose");
  210. showPopup.value = false;
  211. };
  212. function payComplete() {
  213. console.log("payComplete");
  214. loadend.value = false;
  215. page.value = 1;
  216. orderList.value = [];
  217. showPopup.value = false;
  218. getOrderData();
  219. getOrderListFn();
  220. }
  221. function payFail() {
  222. showPopup.value = false;
  223. }
  224. function goOrderDetails(order_id) {
  225. if (!order_id) return Toast({
  226. title: "缺少订单号无法查看订单详情"
  227. });
  228. uni.navigateTo({
  229. url: "/pages/order_details/index?order_id=" + order_id
  230. });
  231. }
  232. function toReturnList() {
  233. uni.navigateTo({
  234. url: "/pages/users/user_return_list/index"
  235. });
  236. }
  237. const changeStatus = (item) => {
  238. // oldOrderStatus.value = item.index;
  239. }
  240. function statusClick(item) {
  241. console.log(item)
  242. if (item.orderStatus === orderStatus.value) return;
  243. orderStatus.value = item.orderStatus;
  244. loadend.value = false;
  245. page.value = 1;
  246. orderList.value = [];
  247. getOrderListFn();
  248. }
  249. function getOrderListFn() {
  250. if (loadend.value || loading.value) return;
  251. loading.value = true;
  252. loadTitle.value = "加载更多";
  253. getOrderList({
  254. type: orderStatus.value,
  255. page: page.value,
  256. limit: limit.value,
  257. mallType: 0,
  258. })
  259. .then((res) => {
  260. let list = res.data.list || [];
  261. let isLoadend = list.length < limit.value;
  262. // orderList.value = uni.$util.SplitArray(list, orderList.value)
  263. orderList.value = [...list, ...orderList.value];
  264. loadend.value = isLoadend;
  265. loading.value = false;
  266. loadTitle.value = isLoadend ? "我也是有底线的" : "加载更多";
  267. page.value += 1;
  268. })
  269. .catch(() => {
  270. loading.value = false;
  271. loadTitle.value = "加载更多";
  272. });
  273. }
  274. function delOrder(order_id, index) {
  275. orderDel(order_id)
  276. .then((res) => {
  277. orderList.value.splice(index, 1);
  278. orderDataState.value.unpaid_count--;
  279. getOrderData();
  280. Toast({
  281. title: "删除成功",
  282. icon: "success"
  283. });
  284. })
  285. .catch((err) => {
  286. Toast({
  287. title: err
  288. });
  289. });
  290. }
  291. </script>
  292. <style>
  293. page {
  294. background: #F9F7F0;
  295. }
  296. </style>
  297. <style scoped lang="scss">
  298. .empty {
  299. height: calc(100vh - 44px);
  300. /* #ifdef H5 */
  301. height: calc(100vh - 88px);
  302. /* #endif */
  303. display: flex;
  304. align-items: center;
  305. justify-content: center;
  306. }
  307. .my-order {
  308. .nav {
  309. background: #FFFFFF;
  310. // height: 140rpx;
  311. background-color: #fff;
  312. .item {
  313. text-align: center;
  314. font-size: 26rpx;
  315. color: #282828;
  316. padding: 26rpx 0;
  317. &.on {
  318. font-weight: bold;
  319. border-bottom: 5rpx solid $border-color;
  320. }
  321. .num {
  322. margin-top: 18rpx;
  323. }
  324. }
  325. }
  326. .list {
  327. width: 690rpx;
  328. margin: 16rpx auto 0 auto;
  329. }
  330. }
  331. .noCart {
  332. margin-top: 171rpx;
  333. padding-top: 0.1rpx;
  334. .pictrue {
  335. width: 414rpx;
  336. height: 336rpx;
  337. margin: 78rpx auto 56rpx auto;
  338. image {
  339. width: 100%;
  340. height: 100%;
  341. }
  342. }
  343. }
  344. </style>