UserCollections.vue 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. <template>
  2. <div class="user-collections">
  3. <div class="user-collections-header">
  4. <span class="u-d-title">{{ title }}</span>
  5. </div>
  6. <div class="user-collections-content">
  7. <div class="user-d-list" v-loading="listState.loading">
  8. <doc-card
  9. v-for="(item, index) in listState.list"
  10. :key="index"
  11. :title="item.DocName"
  12. :desc="item.DocSummary"
  13. :docType="item.DocFileType"
  14. :subInfo="calcSubInfo(item)"
  15. @onClick="toDocDetail(item)"
  16. >
  17. <template slot="price">
  18. <div class="highlight-text" v-if="item.Cost === '已购买'">已购买</div>
  19. <Price v-else :price="item.Cost" />
  20. </template>
  21. </doc-card>
  22. <no-data v-if="listState.list.length === 0 && listState.loaded">暂无文库收藏</no-data>
  23. </div>
  24. <div class="user-collections-pagination">
  25. <el-pagination
  26. background
  27. layout="prev, pager, next, ->, total"
  28. :hide-on-single-page="true"
  29. :current-page="listState.pageNum"
  30. :page-size="listState.pageSize"
  31. :total="listState.total"
  32. @current-change="onPageChange"
  33. >
  34. </el-pagination>
  35. </div>
  36. </div>
  37. </div>
  38. </template>
  39. <script>
  40. import { Pagination } from 'element-ui'
  41. import DocCard from '@/components/doc-item-card/Card'
  42. import Price from '@/components/doc-item-card/Price'
  43. import NoData from '@/components/NoData'
  44. import { getUserDocs } from '../api/modules/user'
  45. import { formatSize } from '@/utils/'
  46. import { mixinBackground } from '@/utils/mixins'
  47. export default {
  48. name: 'user-collections',
  49. mixins: [mixinBackground],
  50. components: {
  51. [Pagination.name]: Pagination,
  52. DocCard,
  53. Price,
  54. NoData
  55. },
  56. data () {
  57. return {
  58. title: '文库收藏',
  59. listState: {
  60. loaded: false, // 是否已经搜索过
  61. loading: false,
  62. pageNum: 1, // 当前页
  63. pageSize: 10, // 每页多少条数据
  64. total: 0, // 一共多少条数据
  65. list: [] // 查询请求返回的数据
  66. }
  67. }
  68. },
  69. created () {
  70. this.getList()
  71. },
  72. methods: {
  73. async getList () {
  74. const query = {
  75. sign: 1,
  76. num: this.listState.pageNum,
  77. size: this.listState.pageSize
  78. }
  79. console.log(query)
  80. this.listState.loading = true
  81. this.listState.loaded = false
  82. const r = await getUserDocs(query)
  83. this.listState.loading = false
  84. this.listState.loaded = true
  85. const res = r.data
  86. if (res.error_code === 0) {
  87. this.listState.total = res.data.total
  88. this.listState.list = res.data.list || []
  89. }
  90. },
  91. toDocDetail (item) {
  92. const { DocId: id } = item
  93. this.$router.push({
  94. name: 'content',
  95. params: { id }
  96. })
  97. },
  98. onPageChange (p) {
  99. this.listState.pageNum = p
  100. this.getList()
  101. },
  102. calcSubInfo (item) {
  103. const { DocPageSize, DocFileSize } = item
  104. const subInfoArr = []
  105. if (DocPageSize !== undefined) {
  106. subInfoArr.push(`共${DocPageSize}页`)
  107. }
  108. if (DocFileSize !== undefined) {
  109. subInfoArr.push(formatSize(DocFileSize))
  110. }
  111. return subInfoArr
  112. }
  113. }
  114. }
  115. </script>
  116. <style lang="scss" scoped>
  117. .user-collections {
  118. background-color: #fff;
  119. margin: 0 auto;
  120. .user-collections-header {
  121. padding-top: 48px;
  122. .u-d-title {
  123. font-size: 24px;
  124. line-height: 36px;
  125. color: #1D1D1D;
  126. }
  127. }
  128. .user-collections-content {
  129. margin-top: 48px;
  130. .u-d-header {
  131. display: flex;
  132. align-items: center;
  133. justify-content: space-between;
  134. padding: 0 28px;
  135. height: 48px;
  136. font-size: 14px;
  137. line-height: 24px;
  138. color: #686868;
  139. border-radius: 4px;
  140. background-color: #F5F6F7;
  141. }
  142. .user-d-list {
  143. border-top: 1px solid transparent;
  144. min-height: 500px;
  145. }
  146. .u-d-h-r {
  147. display: inline-block;
  148. width: 170px;
  149. .u-d-h-item {
  150. display: inline-block;
  151. width: 50%;
  152. &.size {
  153. text-align: center;
  154. }
  155. }
  156. }
  157. }
  158. .user-collections-pagination {
  159. margin-top: 28px;
  160. padding-bottom: 60px;
  161. text-align: right;
  162. }
  163. }
  164. </style>