PushList.vue 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269
  1. <template>
  2. <el-card class="info-list-card">
  3. <div slot="header" class="clearfix">
  4. <span class="card-title">订阅推送</span>
  5. <el-button @click="goManage" class="sub-manager" type="plain" icon="el-icon-jy-edit">订阅管理</el-button>
  6. </div>
  7. <div class="info-list" v-loading="listState.loading">
  8. <article-item
  9. v-for="(item, index) in listState.list"
  10. :key="index"
  11. :index="index + 1"
  12. :article="item"
  13. @onClick="toDetail(item)"
  14. />
  15. <empty v-if="showEmpty">
  16. <div v-if="isAllFirst">
  17. <span>订阅关键词,接收最新招投标信息</span>
  18. <div class="add-key-button">
  19. <span class="icon-chahao"></span>
  20. <span class="button-text">订阅关键词</span>
  21. </div>
  22. </div>
  23. <div v-else>
  24. <span>暂时无历史推送记录</span>
  25. </div>
  26. </empty>
  27. </div>
  28. <div class="el-pagination-container" :class="showMore ? 'center' : ''">
  29. <el-pagination
  30. background
  31. layout="prev, pager, next, ->"
  32. :hide-on-single-page="true"
  33. :current-page="listState.pageNum"
  34. :page-size="listState.pageSize"
  35. :total="listState.total"
  36. @current-change="onPageChange"
  37. >
  38. </el-pagination>
  39. <div class="p-right" v-if="showMore && !showEmpty">
  40. <el-button size="mini" class="get-more" type="plain" icon="el-icon-arrow-right" @click="getMore">更多</el-button>
  41. </div>
  42. </div>
  43. </el-card>
  44. </template>
  45. <script>
  46. import { Pagination, Card, Button } from 'element-ui'
  47. import Empty from '@/components/common/Empty.vue'
  48. import ArticleItem from '@/components/article-item/ArticleItem.vue'
  49. import { getPushList } from '@/api/modules/'
  50. export default {
  51. name: 'push-list',
  52. components: {
  53. [Pagination.name]: Pagination,
  54. [Card.name]: Card,
  55. [Button.name]: Button,
  56. ArticleItem,
  57. Empty
  58. },
  59. props: {
  60. showMore: {
  61. type: Boolean,
  62. default: true
  63. },
  64. filters: {
  65. type: Object,
  66. default () {
  67. return {
  68. area: '',
  69. time: ''
  70. }
  71. }
  72. }
  73. },
  74. computed: {
  75. showEmpty () {
  76. return this.listState.list.length === 0 && this.listState.loaded
  77. },
  78. getFilters () {
  79. return this.filters
  80. }
  81. },
  82. data () {
  83. return {
  84. isAllFirst: false,
  85. listState: {
  86. loaded: true, // 是否已经搜索过
  87. loading: false,
  88. pageNum: 1, // 当前页
  89. pageSize: 10, // 每页多少条数据
  90. total: 0, // 一共多少条数据
  91. list: [] // 查询请求返回的数据
  92. }
  93. }
  94. },
  95. created () {
  96. this.doQuery()
  97. },
  98. methods: {
  99. goManage () {
  100. alert('订阅管理')
  101. // this.$router.push('')
  102. },
  103. // 恢复数据至第一次请求的状态(页码等)
  104. resetListState () {
  105. const state = {
  106. loaded: false,
  107. loading: false,
  108. pageNum: 1,
  109. total: 0,
  110. list: []
  111. }
  112. Object.assign(this.listState, state)
  113. },
  114. doQuery (filters) {
  115. this.resetListState()
  116. this.getList(filters)
  117. },
  118. async getList (filters) {
  119. const query = {
  120. pagenum: this.listState.pageNum,
  121. pageSize: this.listState.pageSize,
  122. area: this.getFilters.area,
  123. time: this.getFilters.time
  124. }
  125. if (filters && Object.keys(filters).length > 0) {
  126. filters.area && (query.area = filters.area)
  127. filters.time && (query.time = filters.time)
  128. }
  129. this.listState.loading = true
  130. this.listState.loaded = false
  131. // 判断是否无筛选条件
  132. this.isAllFirst = false
  133. if (query.pagenum === 1 && query.area === '' && query.time === '') {
  134. this.isAllFirst = true
  135. }
  136. const res = await getPushList(query)
  137. this.listState.loading = false
  138. this.listState.loaded = true
  139. if (res.error_code === 0) {
  140. this.listState.total = res.data.total
  141. this.listState.list = res.data.list || []
  142. } else {
  143. this.listState.total = 0
  144. this.listState.list = []
  145. }
  146. },
  147. toDetail (item) {
  148. const { _id } = item
  149. window.open(`/article/content/${_id}.html`)
  150. },
  151. onPageChange (p) {
  152. this.listState.pageNum = p
  153. this.getList()
  154. },
  155. getMore () {
  156. this.$emit('getMore')
  157. }
  158. }
  159. }
  160. </script>
  161. <style lang="scss" scoped>
  162. @include diy-icon('edit', 20, 20);
  163. // card样式重置
  164. ::v-deep {
  165. .el-card__header {
  166. margin: 0 40px;
  167. padding-left: 0;
  168. padding-right: 0;
  169. }
  170. .el-card__body {
  171. padding: 20px 40px;
  172. }
  173. .empty-container {
  174. margin-top: 60px;
  175. }
  176. .get-more {
  177. display: flex;
  178. .el-icon-arrow-right {
  179. margin-left: 4px;
  180. order: 2;
  181. }
  182. }
  183. }
  184. .sub-manager {
  185. display: flex;
  186. align-items: center;
  187. padding: 8px 16px;
  188. font-size: 14px;
  189. line-height: 24px;
  190. color: #1d1d1d;
  191. border-color: #E0E0E0;
  192. &.el-button:focus,
  193. &.el-button:hover {
  194. color: inherit;
  195. background-color: inherit;
  196. }
  197. }
  198. .info-list-card {
  199. .card-title {
  200. font-size: 24px;
  201. color: #1d1d1d;
  202. line-height: 36px;
  203. }
  204. .sub-manager {
  205. float: right;
  206. }
  207. .info-list {
  208. min-height: 545px;
  209. border-top: 1px solid transparent;
  210. }
  211. .add-key-button {
  212. display: flex;
  213. align-items: center;
  214. justify-content: center;
  215. margin-top: 32px;
  216. padding: 8px 16px;
  217. color: #F7F9FA;
  218. border-radius: 6px;
  219. background-color: #2ABED1;
  220. cursor: pointer;
  221. .icon-chahao {
  222. margin-right: 4px;
  223. transform: rotate(-45deg);
  224. }
  225. .button-text {
  226. margin-left: 4px;
  227. white-space: nowrap;
  228. }
  229. }
  230. .icon-chahao {
  231. position: relative;
  232. display: inline-block;
  233. width: 14px;
  234. height: 14px;
  235. &:before,
  236. &:after {
  237. position: absolute;
  238. content: '';
  239. background-color: #fff;
  240. top: 50%;
  241. left: 50%;
  242. width: 14px;
  243. height: 2px;
  244. border-radius: 2px;
  245. }
  246. &:before {
  247. transform: translate(-50%,-50%) rotate(45deg);
  248. }
  249. &:after {
  250. transform: translate(-50%,-50%) rotate(-45deg);
  251. }
  252. }
  253. .el-pagination-container.center {
  254. .el-pagination {
  255. left: 50%;
  256. right: unset;
  257. transform: translateX(-50%);
  258. }
  259. }
  260. }
  261. </style>