Home.vue 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248
  1. <template>
  2. <div class="report-home" ref="wrapper">
  3. <div v-if="listState.list.length && listState.list.length > 0">
  4. <van-pull-refresh v-model="isLoading" @refresh="onRefresh">
  5. <van-list
  6. v-model="listState.loading"
  7. :finished="listState.finished"
  8. :immediate-check="false"
  9. finished-text="没有更多了"
  10. @load="onLoad"
  11. :offset="50"
  12. >
  13. <ul class="list">
  14. <li class="item" v-for="item in listState.list" :key="item.id" @click="goDetail(item)">
  15. <div class="item-img">
  16. <img :src="item.img" alt="">
  17. </div>
  18. <div class="item-cont">
  19. <p class="ellipsis-2 title">{{item.title}}</p>
  20. <div class="desc">
  21. <div class="left">{{item.publishtime* 1000 | dateFormatter('yyyy/MM/dd')}}</div>
  22. <div class="right">
  23. <span class="before-price">&yen; <em>{{item.before_price}}</em></span>
  24. <span class="current-price">&yen; <em>{{item.price}}</em> </span>
  25. </div>
  26. </div>
  27. </div>
  28. </li>
  29. </ul>
  30. </van-list>
  31. </van-pull-refresh>
  32. </div>
  33. <Empty v-else>
  34. <div class="tip-sub-text">暂无数据</div>
  35. </Empty>
  36. </div>
  37. </template>
  38. <script lang="ts">
  39. import { Component, Vue } from 'vue-property-decorator'
  40. import { mapState, mapMutations, mapActions } from 'vuex'
  41. import { PullRefresh, List, Toast } from 'vant'
  42. import Empty from '@/components/common/Empty.vue'
  43. @Component({
  44. name: 'home',
  45. components: {
  46. [PullRefresh.name]: PullRefresh,
  47. [List.name]: List,
  48. Empty
  49. },
  50. methods: {
  51. ...mapState('home', {
  52. reportList: (state: any) => state.reportList
  53. }),
  54. ...mapMutations({
  55. saveList: 'home/saveReportList',
  56. clearList: 'home/clearReportList'
  57. }),
  58. ...mapActions({
  59. getList: 'home/getReportList'
  60. })
  61. }
  62. })
  63. export default class Home extends Vue {
  64. protected reportList!: any
  65. protected getList!: any
  66. protected saveList!: any
  67. protected clearList!: any
  68. isLoading = false
  69. listState = {
  70. list: [],
  71. loading: false,
  72. finished: false,
  73. currentPage: 1,
  74. totalPage: 0,
  75. scroll: 0
  76. }
  77. beforeRouteEnter (to, from, next) {
  78. if (from.name === 'detail') {
  79. to.meta.isBack = true
  80. } else {
  81. to.meta.isBack = false
  82. }
  83. next()
  84. }
  85. activated () {
  86. if (!this.$route.meta.isBack) {
  87. this.listState = {
  88. list: [],
  89. loading: false,
  90. finished: false,
  91. currentPage: 1,
  92. totalPage: 0,
  93. scroll: 0
  94. }
  95. this.getReportList()
  96. return
  97. }
  98. this.$route.meta.isBack = false
  99. this.listState = this.reportList()
  100. this.$nextTick(() => {
  101. ;(this.$refs.wrapper as any).scrollTop = this.reportList().scroll
  102. })
  103. }
  104. beforeRouteLeave (to, form, next) {
  105. this.listState.scroll = (this.$refs.wrapper as any).scrollTop
  106. this.saveList(this.listState)
  107. next()
  108. }
  109. getReportList () {
  110. this.listState.loading = true
  111. this.getList(`page_index=${this.listState.currentPage}`).then((res: any) => {
  112. if (res.error_code === 0 && res.data.list) {
  113. const rows = res.data.list
  114. this.listState.loading = false
  115. this.listState.totalPage = res.data.page_count
  116. if (rows === null || rows.length === 0) {
  117. this.listState.finished = true
  118. return
  119. }
  120. if (this.listState.currentPage >= this.listState.totalPage) {
  121. this.listState.finished = true
  122. }
  123. if (this.listState.currentPage === 1) {
  124. this.listState.list = rows
  125. } else {
  126. this.listState.list = this.listState.list.concat(rows)
  127. }
  128. } else {
  129. this.listState.finished = true
  130. }
  131. }).catch(() => {
  132. this.listState.finished = true
  133. })
  134. }
  135. onLoad () {
  136. this.listState.currentPage++
  137. this.getReportList()
  138. }
  139. goDetail (item) {
  140. this.$router.push(`/detail/${item.id}`)
  141. }
  142. onRefresh () {
  143. setTimeout(() => {
  144. this.isLoading = false
  145. this.clearList()
  146. this.$nextTick(() => {
  147. this.listState = {
  148. list: [],
  149. loading: false,
  150. finished: false,
  151. currentPage: 1,
  152. totalPage: 0,
  153. scroll: 0
  154. }
  155. this.getReportList()
  156. Toast('刷新成功')
  157. })
  158. }, 1000)
  159. }
  160. }
  161. </script>
  162. <style lang="scss">
  163. .report-home {
  164. .list{
  165. .item{
  166. position: relative;
  167. display: flex;
  168. padding: 20px 16px;
  169. background-color: #fff;
  170. &:after{
  171. position: absolute;
  172. box-sizing: border-box;
  173. content: ' ';
  174. pointer-events: none;
  175. right: 16px;
  176. bottom: 0;
  177. left: 16px;
  178. border-bottom: 1px solid rgba(0, 0, 0, 0.02);
  179. // -webkit-transform: scaleY(0.5);
  180. // transform: scaleY(0.5);
  181. }
  182. .item-img{
  183. width: 80px;
  184. height: 80px;
  185. border-radius: 4px;
  186. margin-right: 16px;
  187. overflow: hidden;
  188. img{
  189. width: 100%;
  190. height: 100%;
  191. }
  192. }
  193. .item-cont{
  194. flex: 1;
  195. .title{
  196. font-size: 16px;
  197. line-height: 24px;
  198. color: #171826;
  199. }
  200. .desc{
  201. display: flex;
  202. justify-content: space-between;
  203. align-items: center;
  204. margin-top: 13px;
  205. .left{
  206. font-size: 12px;
  207. line-height: 18px;
  208. color: #9B9CA3;
  209. }
  210. .right{
  211. display: flex;
  212. align-items: center;
  213. }
  214. .before-price{
  215. font-size: 12px;
  216. line-height: 18px;
  217. color: #9B9CA3;
  218. margin-right: 6px;
  219. em{
  220. text-decoration: line-through;
  221. }
  222. }
  223. .current-price{
  224. display: flex;
  225. align-items: center;
  226. color: #FB483D;
  227. font-size: 14px;
  228. line-height: 20px;
  229. em{
  230. margin-left: 2px;
  231. font-size: 16px;
  232. line-height: 24px;
  233. }
  234. }
  235. }
  236. }
  237. }
  238. }
  239. }
  240. </style>