UserCollections.vue 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  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="bought" 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. window.open(`../content/${id}`) // 打开新窗口
  98. // window.open(`${process.env.VUE_APP_BASE_URL}/content/${id}`) // 打开新窗口
  99. },
  100. onPageChange (p) {
  101. this.listState.pageNum = p
  102. this.getList()
  103. },
  104. calcSubInfo (item) {
  105. const { DocPageSize, DocFileSize } = item
  106. const subInfoArr = []
  107. if (DocPageSize !== undefined) {
  108. subInfoArr.push(`共${DocPageSize}页`)
  109. }
  110. if (DocFileSize !== undefined) {
  111. subInfoArr.push(formatSize(DocFileSize))
  112. }
  113. return subInfoArr
  114. }
  115. }
  116. }
  117. </script>
  118. <style lang="scss" scoped>
  119. .user-collections {
  120. background-color: #fff;
  121. margin: 0 auto;
  122. .user-collections-header {
  123. padding-top: 48px;
  124. .u-d-title {
  125. font-size: 24px;
  126. line-height: 36px;
  127. color: #1D1D1D;
  128. }
  129. }
  130. .user-collections-content {
  131. margin-top: 48px;
  132. .u-d-header {
  133. display: flex;
  134. align-items: center;
  135. justify-content: space-between;
  136. padding: 0 28px;
  137. height: 48px;
  138. font-size: 14px;
  139. line-height: 24px;
  140. color: #686868;
  141. border-radius: 4px;
  142. background-color: #F5F6F7;
  143. }
  144. .user-d-list {
  145. border-top: 1px solid transparent;
  146. min-height: 500px;
  147. ::v-deep {
  148. .docs-card {
  149. margin-left: -18px;
  150. box-sizing: content-box;
  151. width: 1200px;
  152. }
  153. }
  154. }
  155. .bought {
  156. color: #686868;
  157. }
  158. .u-d-h-r {
  159. display: inline-block;
  160. width: 170px;
  161. .u-d-h-item {
  162. display: inline-block;
  163. width: 50%;
  164. &.size {
  165. text-align: center;
  166. }
  167. }
  168. }
  169. }
  170. .user-collections-pagination {
  171. margin-top: 28px;
  172. padding-bottom: 60px;
  173. text-align: right;
  174. }
  175. }
  176. </style>