main.vue 7.0 KB

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