UserCollections.vue 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  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. :productType="item.productType"
  15. :subInfo="calcSubInfo(item)"
  16. @onClick="toDocDetail(item)"
  17. >
  18. <template slot="price">
  19. <div class="bought" v-if="item.Cost === '已购买'">已购买</div>
  20. <!-- <Price v-else :price="item.Cost" /> -->
  21. </template>
  22. </doc-card>
  23. <no-data v-if="listState.list.length === 0 && listState.loaded">
  24. 暂无文库收藏
  25. <div class="go-collect-box">
  26. <el-button type="primary" @click="goCollect">前往收藏</el-button>
  27. </div>
  28. </no-data>
  29. </div>
  30. <div class="user-collections-pagination" v-if="listState.total > 0">
  31. <el-pagination
  32. popper-class="pagination-custom-select"
  33. background
  34. layout="prev, pager, next, sizes, jumper"
  35. :current-page="listState.pageNum"
  36. :page-size="listState.pageSize"
  37. :page-sizes="[5, 10, 50, 100]"
  38. :total="listState.total"
  39. :show-confirm-btn="true"
  40. @current-change="onPageChange"
  41. @size-change="onSizeChange"
  42. >
  43. </el-pagination>
  44. </div>
  45. </div>
  46. </div>
  47. </template>
  48. <script>
  49. import { Pagination, Button } from 'element-ui'
  50. import DocCard from '@/components/doc-item-card/Card'
  51. import Price from '@/components/doc-item-card/Price'
  52. import NoData from '@/components/NoData'
  53. import { getUserDocs } from '../api/modules/user'
  54. import { formatSize } from '@/utils/'
  55. import { mixinBackground } from '@/utils/mixins'
  56. export default {
  57. name: 'user-collections',
  58. mixins: [mixinBackground],
  59. components: {
  60. [Pagination.name]: Pagination,
  61. [Button.name]: Button,
  62. DocCard,
  63. Price,
  64. NoData
  65. },
  66. data () {
  67. return {
  68. title: '文库收藏',
  69. listState: {
  70. loaded: false, // 是否已经搜索过
  71. loading: false,
  72. pageNum: 1, // 当前页
  73. pageSize: 10, // 每页多少条数据
  74. total: 0, // 一共多少条数据
  75. list: [] // 查询请求返回的数据
  76. }
  77. }
  78. },
  79. created () {
  80. this.getList()
  81. },
  82. methods: {
  83. async getList () {
  84. const query = {
  85. sign: 1,
  86. num: this.listState.pageNum,
  87. size: this.listState.pageSize
  88. }
  89. console.log(query)
  90. this.listState.loading = true
  91. this.listState.loaded = false
  92. const r = await getUserDocs(query)
  93. this.listState.loading = false
  94. this.listState.loaded = true
  95. const res = r.data
  96. if (res.error_code === 0) {
  97. this.listState.total = res.data.total
  98. this.listState.list = res.data.list || []
  99. }
  100. },
  101. toDocDetail (item) {
  102. const { DocId: id } = item
  103. // this.$router.push({
  104. // name: 'content',
  105. // params: { id }
  106. // })
  107. window.open(`../content/${id}`) // 打开新窗口
  108. // window.open(`${process.env.VUE_APP_BASE_URL}/content/${id}`) // 打开新窗口
  109. },
  110. onPageChange (p) {
  111. this.listState.pageNum = p
  112. this.getList()
  113. },
  114. onSizeChange (size) {
  115. this.listState.pageSize = size
  116. this.listState.pageNum = 1
  117. this.getList()
  118. },
  119. calcSubInfo (item) {
  120. const { DocPageSize, DocFileSize } = item
  121. const subInfoArr = []
  122. if (DocPageSize !== undefined) {
  123. subInfoArr.push(`共${DocPageSize}页`)
  124. }
  125. if (DocFileSize !== undefined) {
  126. subInfoArr.push(formatSize(DocFileSize))
  127. }
  128. return subInfoArr
  129. },
  130. goCollect () {
  131. this.$router.push('/')
  132. }
  133. }
  134. }
  135. </script>
  136. <style lang="scss" scoped>
  137. .user-collections {
  138. background-color: #fff;
  139. margin: 0 auto;
  140. .user-collections-header {
  141. padding-top: 48px;
  142. .u-d-title {
  143. font-size: 24px;
  144. line-height: 36px;
  145. color: #1D1D1D;
  146. }
  147. }
  148. .user-collections-content {
  149. margin-top: 48px;
  150. .u-d-header {
  151. display: flex;
  152. align-items: center;
  153. justify-content: space-between;
  154. padding: 0 28px;
  155. height: 48px;
  156. font-size: 14px;
  157. line-height: 24px;
  158. color: #686868;
  159. border-radius: 4px;
  160. background-color: #F5F6F7;
  161. }
  162. .user-d-list {
  163. border-top: 1px solid transparent;
  164. min-height: 500px;
  165. ::v-deep {
  166. .docs-card {
  167. margin-left: -18px;
  168. box-sizing: content-box;
  169. width: 1200px;
  170. }
  171. }
  172. }
  173. .bought {
  174. color: #686868;
  175. }
  176. .u-d-h-r {
  177. display: inline-block;
  178. width: 170px;
  179. .u-d-h-item {
  180. display: inline-block;
  181. width: 50%;
  182. &.size {
  183. text-align: center;
  184. }
  185. }
  186. }
  187. }
  188. .user-collections-pagination {
  189. margin-top: 28px;
  190. padding-bottom: 60px;
  191. text-align: right;
  192. }
  193. .go-collect-box{
  194. margin-top: 24px;
  195. .el-button{
  196. width: 108px;
  197. height: 30px;
  198. padding: 0;
  199. border-radius: 4px;
  200. font-size: 14px;
  201. }
  202. }
  203. }
  204. .in-app{
  205. .user-d-list{
  206. ::v-deep{
  207. .docs-card{
  208. width: auto!important;
  209. }
  210. }
  211. }
  212. .user-collections{
  213. padding: 0 18px;
  214. }
  215. }
  216. </style>