index.vue 9.4 KB

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