index.vue 6.8 KB

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