当前位置:   article > 正文

vue 后台返回列表H5点击按钮加载更多分页数据与van-tab记住选中状态_vue点击加载更多请求

vue点击加载更多请求

效果图(点击更多订单加载,一次加载10条):

  1. <template>
  2. <div id="order" class="wap-el page-container wap-com-page">
  3. <section>
  4. <com-header></com-header>
  5. </section>
  6. <div class="com-top-blue-bg">
  7. <div class="com-top-blue-bg-cont"></div>
  8. </div>
  9. <div class="order-box">
  10. <div class="com-title-box">
  11. <!-- 返回按钮 -->
  12. <div class="wap-page-return" @click="$router.go(-1)"></div>
  13. <div class="com-page-title">我的订单</div>
  14. </div>
  15. <van-tabs v-model="activeStatus" @change="changeTab" animated>
  16. <van-tab
  17. v-for="item in orderTitle"
  18. :key="item.orderStatus"
  19. :title="item.name"
  20. >
  21. <div class="order-cont" v-show="isData">
  22. <div
  23. class="order-tab-content"
  24. v-for="(item1, index1) in list"
  25. :key="index1"
  26. @click="goDetail(item1)"
  27. >
  28. <div class="order-tab-box">
  29. <div class="order-tab-title-box">
  30. <div class="order-tab-title flex-center-start">
  31. <img
  32. class="order-tab-title-img"
  33. :src="item1.toolApplicationIcon"
  34. alt=""
  35. />
  36. <div class="order-tab-title-text">
  37. {{ item1.toolApplicationName }}
  38. </div>
  39. </div>
  40. <div class="order-status-box">
  41. <div
  42. class="order-status 1"
  43. :class="`order-status${item1.orderStatus == 1 ? 1 : 0}`"
  44. >
  45. {{ orderStatusVal[item1.orderStatus] }}
  46. </div>
  47. </div>
  48. </div>
  49. <div class="order-tab-item-box">
  50. <div class="order-tab-item flex-center-between">
  51. <div class="order-tab-item-name">订单总金额</div>
  52. <div class="order-tab-item-cont">
  53. ¥{{ item1.totalPrice }}
  54. </div>
  55. </div>
  56. <div class="order-tab-item flex-center-between">
  57. <div class="order-tab-item-name">实付金额</div>
  58. <div class="order-tab-item-cont">
  59. ¥{{ item1.realPrice }}
  60. </div>
  61. </div>
  62. <div class="order-tab-item flex-center-between">
  63. <div class="order-tab-item-name">下单时间</div>
  64. <div class="order-tab-item-cont">
  65. {{ item1.createDate }}
  66. </div>
  67. </div>
  68. </div>
  69. </div>
  70. </div>
  71. <div class="flex-center-center" v-if="list.length < total">
  72. <div class="more-order flex-center-center" @click="moreOrder">
  73. <span>更多订单</span>
  74. <img
  75. class="blue-double-right-arrow"
  76. :src="`${NEW_ASSET_IMG}/common/blue_double_right_arrow.png`"
  77. alt=""
  78. />
  79. </div>
  80. </div>
  81. </div>
  82. <!-- 无订单 -->
  83. <div
  84. class="wap-not-data-box flex-column-center-center"
  85. v-show="!isData"
  86. >
  87. <img
  88. class="wap-not-data-img"
  89. :src="`${NEW_ASSET_IMG}/common/wap_not_data.png`"
  90. />
  91. <p class="wap-not-data-text">暂无订单</p>
  92. </div>
  93. </van-tab>
  94. </van-tabs>
  95. </div>
  96. </div>
  97. </template>
  98. <script>
  99. export default {
  100. name: "order",
  101. components: {
  102. "com-header": () => import("@/components/common/com-header"),
  103. },
  104. data() {
  105. return {
  106. page: 1,
  107. pageSize: 10,
  108. total: "", //页总数
  109. nav_index: 0,
  110. activeStatus: this.$route.query.orderStatus
  111. ? Number(this.$route.query.orderStatus)
  112. : "", //订单状态(-3 已退款-2 退款申请中-1:已取消 0:待支付 1:已支付)
  113. orderStatus: "",
  114. orderStatusVal: {
  115. "-3": "已退款",
  116. "-2": "退款申请中",
  117. "-1": "已取消",
  118. 0: "待支付",
  119. 1: "已支付",
  120. }, //订单状态
  121. orderTitle: [
  122. { orderStatus: "", name: "全部" }, //status自定义
  123. { orderStatus: "1", name: "已支付" },
  124. { orderStatus: "0", name: "待支付" },
  125. { orderStatus: "-2", name: "退款申请中" },
  126. { orderStatus: "-3", name: "已退款" },
  127. { orderStatus: "-1", name: "已取消" },
  128. ],
  129. list: [], //订单数据
  130. isData: true, //是否有数据
  131. };
  132. },
  133. computed: {},
  134. watch: {},
  135. methods: {
  136. getOrderList(isMore, orderStatus) {
  137. const params = `?page=${this.page}&pageSize=${this.pageSize}&orderStatus=${orderStatus}`;
  138. this.$orderAPI.getOrders(params).then(({ code, msg, data }) => {
  139. if (code) {
  140. this.$message.warning(msg);
  141. return;
  142. }
  143. this.total = Number(data.pageNumVO.total);
  144. if (isMore) {
  145. if (data.list.length <= this.total) {
  146. this.list.push(...data.list);
  147. } else {
  148. this.list = data.list;
  149. }
  150. } else {
  151. this.list = data.list;
  152. }
  153. this.isData = data.list.length <= 0 ? false : true; //是否显示无数据
  154. });
  155. },
  156. changeTab(e) {
  157. this.nav_index = e;
  158. let data = {
  159. 0: "",
  160. 1: 1,
  161. 2: 0,
  162. 3: -2,
  163. 4: -3,
  164. 5: -1,
  165. };
  166. this.orderStatus = data[e];
  167. this.getOrderList(0, data[e]);
  168. window.sessionStorage.setItem("order_idx", `${this.nav_index}`);
  169. },
  170. goDetail(item) {
  171. this.$router.push({
  172. path: `/order-detail?toolOrderId=${item.toolOrderId}&orderStatus=${item.orderStatus}`,
  173. });
  174. },
  175. moreOrder() {
  176. this.page++;
  177. this.getOrderList(1, this.orderStatus);
  178. },
  179. },
  180. created() {},
  181. mounted() {
  182. let order_idx = window.sessionStorage.getItem("order_idx") || "";
  183. if (order_idx != "") {
  184. this.activeStatus = Number(order_idx);
  185. let statusVal =
  186. this.activeStatus == 1
  187. ? 1
  188. : this.activeStatus == 2
  189. ? 0
  190. : this.activeStatus == 3
  191. ? -2
  192. : this.activeStatus == 4
  193. ? -3
  194. : this.activeStatus == 5
  195. ? -1
  196. : "";
  197. this.$nextTick(() => {
  198. this.getOrderList(0, statusVal);
  199. });
  200. }else{
  201. this.getOrderList(0,this.orderStatus);
  202. }
  203. },
  204. beforeCreate() {},
  205. beforeMount() {},
  206. beforeUpdate() {},
  207. updated() {},
  208. beforeDestroy() {},
  209. destroyed() {},
  210. activated() {},
  211. };
  212. </script>
  213. <style lang='scss' scoped>
  214. #order {
  215. ::v-deep .van-tab {
  216. padding: 0;
  217. }
  218. ::v-deep .van-tabs__nav {
  219. background-color: transparent;
  220. }
  221. .order-box {
  222. position: relative;
  223. z-index: 10;
  224. }
  225. .order-tab-title-box {
  226. padding: 0.31rem 0.33rem;
  227. background: linear-gradient(310deg, #ddebff 0%, #ece8ff 48%, #f3f1fd 100%);
  228. border-radius: 0.16rem 0.16rem 0 0;
  229. position: relative;
  230. }
  231. .order-status-box {
  232. position: absolute;
  233. top: 0;
  234. right: -0.11rem;
  235. }
  236. .order-status {
  237. width: fit-content;
  238. position: relative;
  239. padding: 0.06rem 0.15rem;
  240. font-size: 0.16rem;
  241. font-family: SourceHanSansCN-Medium, SourceHanSansCN;
  242. font-weight: 500;
  243. line-height: 0.27rem;
  244. letter-spacing: 0.02rem;
  245. border-radius: 0.06rem 0.06rem 0px 0.06rem;
  246. }
  247. .order-status1 {
  248. background: linear-gradient(315deg, #4265fe 0%, #10f7ff 100%);
  249. color: #ffffff;
  250. }
  251. .order-status0 {
  252. background: linear-gradient(315deg, #8e8e8e 0%, #d7d7d7 100%);
  253. color: #ffffff;
  254. }
  255. .clip-triangle {
  256. -webkit-clip-path: polygon(50% 40%, 0% 100%, 100% 100%);
  257. clip-path: polygon(50% 40%, 0% 100%, 100% 100%);
  258. }
  259. .order-status0,
  260. .order-status1 {
  261. &::after {
  262. content: "";
  263. position: absolute;
  264. bottom: -0.08rem;
  265. right: 0.0178rem;
  266. width: 0.16rem;
  267. height: 0.14rem;
  268. transform: rotate(-45deg);
  269. @extend .clip-triangle;
  270. }
  271. }
  272. .order-status0::after {
  273. background-color: rgba(123, 123, 123, 1);
  274. }
  275. .order-status1::after {
  276. background-color: rgba(8, 53, 182, 1);
  277. }
  278. .order-cont {
  279. padding: 0 0.32rem 0.7rem 0.32rem;
  280. }
  281. .order-tab-title-img {
  282. width: 0.64rem;
  283. height: 0.64rem;
  284. }
  285. .order-tab-content {
  286. margin-top: 0.32rem;
  287. }
  288. .order-tab-title-text {
  289. font-size: 0.32rem;
  290. font-family: SourceHanSansCN-Medium, SourceHanSansCN;
  291. font-weight: 500;
  292. color: #000000;
  293. line-height: 0.48rem;
  294. letter-spacing: 0.02rem;
  295. margin-left: 0.16rem;
  296. }
  297. .order-tab-item-box {
  298. padding: 0 0.32rem 0.4rem 0.32rem;
  299. background: rgba(255, 255, 255, 1);
  300. border-radius: 0 0 0.16rem 0.16rem;
  301. border: 1px solid #979797;
  302. border-top: none;
  303. }
  304. .order-tab-item {
  305. font-size: 0.28rem;
  306. font-family: PingFangSC-Regular, PingFang SC;
  307. font-weight: 400;
  308. color: #242424;
  309. line-height: 0.36rem;
  310. letter-spacing: 0.01rem;
  311. padding-top: 0.32rem;
  312. }
  313. // 暂无数据
  314. .wap-not-data-box {
  315. padding: 1.74rem 0 0 0;
  316. .wap-not-data-img {
  317. width: 2.58rem;
  318. height: 2.52rem;
  319. }
  320. .wap-not-data-text {
  321. font-size: 0.26rem;
  322. font-family: PingFangSC-Regular, PingFang SC;
  323. font-weight: 400;
  324. color: #242424;
  325. line-height: 0.37rem;
  326. letter-spacing: 1px;
  327. margin-top: 0.32rem;
  328. }
  329. }
  330. .more-order {
  331. font-size: 0.26rem;
  332. font-family: PingFangSC-Medium, PingFang SC;
  333. font-weight: 500;
  334. color: #0064ff;
  335. line-height: 0.26rem;
  336. margin-top: 0.4rem;
  337. .blue-double-right-arrow {
  338. width: 0.27rem;
  339. height: 0.27rem;
  340. }
  341. }
  342. }
  343. </style>

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/AllinToyou/article/detail/97370
推荐阅读
相关标签
  

闽ICP备14008679号