index.vue 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300
  1. <template>
  2. <div class="return-container">
  3. <div
  4. class="wrapper"
  5. ref="returnWrapper">
  6. <ul>
  7. <li
  8. :class="{'static': isRefresh}"
  9. class="pulldown-wrapper">
  10. <van-loading
  11. v-show="isRefresh"
  12. size="24px"
  13. type="spinner">加载中...
  14. </van-loading>
  15. <div
  16. v-show="!isRefresh"
  17. class="van-loading">
  18. <span
  19. class="van-loading__text">下拉刷新</span>
  20. </div>
  21. </li>
  22. <li
  23. v-for="(item, index) in list"
  24. :key="index"
  25. class="list-item">
  26. <div class="wrap">
  27. <div>
  28. <p class="avatar">
  29. <img
  30. :src="item.user_head_img_url"
  31. alt="">
  32. </p>
  33. <p class="user">{{ item.user_nickname }}</p>
  34. <p class="shop">{{ item.order_title }}</p>
  35. </div>
  36. <p class="money">¥{{ item.order_commission | fen2Yuan }}</p>
  37. </div>
  38. <p class="date">佣金状态:{{ ['未结算', '已结算', '已退款'][item.commission_status] }}</p>
  39. <p class="date">创建时间:{{ item.created_at }}</p>
  40. </li>
  41. <li class="pullup-wrapper">
  42. <van-loading
  43. v-show="!finished"
  44. size="24px"
  45. type="spinner">加载中...
  46. </van-loading>
  47. <div
  48. v-show="finished"
  49. class="van-loading">
  50. <span
  51. class="van-loading__text">没有更多了</span>
  52. </div>
  53. </li>
  54. </ul>
  55. </div>
  56. </div>
  57. </template>
  58. <script>
  59. import BScroll from 'better-scroll'
  60. import { Toast, Loading } from 'vant'
  61. import { apiMakeList } from './api'
  62. export default {
  63. components: {
  64. 'van-loading': Loading
  65. },
  66. data () {
  67. return {
  68. finished: false, // 所有数据是否加载完
  69. isRefresh: false, // 是否下拉刷新
  70. isFetchLock: false, // 接口调用加锁
  71. pagenum: 0,
  72. pagesize: 20,
  73. list: [],
  74. scroll: null
  75. }
  76. },
  77. activated () {
  78. if (!this.$route.meta.isUseCache) {
  79. this.finished = false
  80. this.isRefresh = false
  81. this.isFetchLock = false
  82. this.pagenum = 0
  83. this.pagesize = 20
  84. this.list = []
  85. this.scroll = null
  86. this.getList()
  87. } else {
  88. this.scroll && this.scroll.refresh()
  89. }
  90. this.$route.meta.isUseCache = false
  91. },
  92. methods: {
  93. goDetail (id) {},
  94. onRefresh () {
  95. this.pagenum = 0
  96. this.pagesize = 20
  97. this.finished = false
  98. this.isRefresh = true
  99. this.getList()
  100. },
  101. async getList () {
  102. if (this.finished) {
  103. return
  104. }
  105. if (this.isFetchLock) {
  106. return
  107. }
  108. this.isFetchLock = true
  109. this.pagenum++
  110. try {
  111. const { status, data, msg } = await apiMakeList({ page: this.pagenum, page_size: this.pagesize })
  112. if (status) {
  113. const { list } = data
  114. // 下拉刷新数据清空
  115. if (this.isRefresh) {
  116. this.isRefresh = false
  117. this.list = []
  118. }
  119. // 没有数据返回了
  120. if (Array.isArray(list) && !list.length) {
  121. this.finished = true
  122. }
  123. if (Array.isArray(list) && list.length) {
  124. // 总页数小于等于1页时
  125. if (list.length < this.pagesize) {
  126. this.finished = true
  127. }
  128. this.list = this.list.concat(list)
  129. this.$nextTick(() => {
  130. if (!this.scroll) {
  131. this.scroll = new BScroll(this.$refs.returnWrapper, {
  132. click: true,
  133. pullDownRefresh: {
  134. threshold: 50, // 顶部下拉的距离
  135. stop: 20 // 回弹停留的距离
  136. },
  137. pullUpLoad: {
  138. threshold: -20
  139. },
  140. scrollbar: true
  141. })
  142. this.scroll.on('pullingDown', () => {
  143. this.onRefresh()
  144. })
  145. this.scroll.on('pullingUp', () => {
  146. this.getList()
  147. })
  148. } else {
  149. this.scroll.finishPullDown()
  150. this.scroll.finishPullUp()
  151. this.scroll.refresh()
  152. }
  153. })
  154. }
  155. } else {
  156. Toast(msg)
  157. }
  158. this.isFetchLock = false
  159. } catch (err) {
  160. this.isFetchLock = false
  161. }
  162. }
  163. },
  164. beforeDestroy () {
  165. this.scroll && this.scroll.destroy()
  166. },
  167. beforeRouteLeave (to, form, next) {
  168. if (['MarketingSave', 'MarketingReturn'].findIndex(item => item === to.name) > -1) {
  169. form.meta.isUseCache = true
  170. }
  171. next()
  172. }
  173. }
  174. </script>
  175. <style lang="scss" scoped>
  176. .return-container {
  177. position: absolute;
  178. left: 0;
  179. top: 56px;
  180. right: 0;
  181. bottom: 50px;
  182. background: #F7F6F9;
  183. overflow: hidden;
  184. }
  185. .wrapper {
  186. width: 100%;
  187. height: 100%;
  188. overflow: hidden;
  189. ul {
  190. display: flex;
  191. flex-direction: column;
  192. align-items: center;
  193. width: 100%;
  194. padding: 15px 0 102px;
  195. }
  196. }
  197. .pulldown-wrapper {
  198. position: absolute;
  199. left: 0;
  200. top: -43px;
  201. width: 100%;
  202. text-align: center;
  203. margin-bottom: 10px;
  204. &.static {
  205. position: static;
  206. left: 0;
  207. top: 0;
  208. }
  209. }
  210. .pullup-wrapper {
  211. width: 100%;
  212. text-align: center;
  213. }
  214. .list-item {
  215. width: 335px;
  216. background: #FFFFFF;
  217. box-shadow: 0 2px 4px 0 rgba(31, 49, 74, 0.12);
  218. border-radius: 10px;
  219. padding: 15px;
  220. margin-bottom: 16px;
  221. .wrap {
  222. display: flex;
  223. align-items: center;
  224. & > div {
  225. display: flex;
  226. align-items: center;
  227. width: 205px;
  228. }
  229. }
  230. .avatar {
  231. flex: 0 0 28px;
  232. width: 28px;
  233. height: 28px;
  234. border: 2px solid #FFFFFF;
  235. border-radius: 50%;
  236. overflow: hidden;
  237. img {
  238. display: block;
  239. width: 100%;
  240. }
  241. }
  242. .user,
  243. .shop {
  244. font-size: 20px;
  245. color: #1F314A;
  246. line-height: 28px;
  247. white-space: nowrap;
  248. }
  249. .user {
  250. max-width: 90px;
  251. margin: 0 8px 0 10px;
  252. overflow: hidden;
  253. text-overflow: ellipsis;
  254. white-space: nowrap;
  255. }
  256. .shop {
  257. max-width: 69px;
  258. overflow: hidden;
  259. text-overflow: ellipsis;
  260. white-space: nowrap;
  261. }
  262. .money {
  263. width: 100px;
  264. font-size: 18px;
  265. font-family: PingFangSC-Semibold, PingFang SC;
  266. font-weight: 600;
  267. color: #FA4A4A;
  268. line-height: 25px;
  269. white-space: nowrap;
  270. text-align: right;
  271. }
  272. .date {
  273. margin-top: 12px;
  274. font-size: 16px;
  275. color: #1F314A;
  276. line-height: 19px;
  277. }
  278. }
  279. </style>