search.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308
  1. <template>
  2. <div class="help-center-container category">
  3. <!-- <div class="help-center-banner">
  4. <client-only>
  5. <swiper ref="mySwiper" :options="swiperOptions">
  6. <swiper-slide class="swiper-item" v-for="(item, index) in bannerList" :key="index">
  7. <ad-item :item="item"></ad-item>
  8. </swiper-slide>
  9. </swiper>
  10. </client-only>
  11. </div> -->
  12. <div class="category-hd bg-white">
  13. <div class="category-wrap">
  14. <div class="category-con flex" v-for="(item, oneIndex) in categoryList" :key="oneIndex">
  15. <div class="name muted">{{item.description}}:</div>
  16. <div class="category-list flex flex-wrap lighter">
  17. <div
  18. :class="[
  19. 'item line1',
  20. { active: oneIndex == index },
  21. ]"
  22. v-for="(category, index) in item.data"
  23. :key="index"
  24. @click="changeData(category.id)"
  25. >
  26. {{ category.name }}
  27. </div>
  28. </div>
  29. </div>
  30. </div>
  31. </div>
  32. <div class="help-center-box">
  33. <!-- <div class="help-center-aside bg-white">
  34. <ul class="nav flex-col col-center">
  35. <li class="flex" :class="{'active-item': currentId <= 0}" @click="changeList(0)">全部</li>
  36. <li class="flex" v-for="(item) in categoryList" :key="item.id"
  37. :class="{'active-item': item.id == currentId}" @click="changeList(item.id)">{{item.description}}</li>
  38. </ul>
  39. </div> -->
  40. <div class="article-lists-container m-l-16 bg-white">
  41. <div v-show="!dataNull">
  42. <div>
  43. <nuxt-link :to="'/policy/detail?id=' + item.id"
  44. class="article-item flex row-between bg-white" v-for="(item) in articleList" :key="item.id">
  45. <div>
  46. <div class="lg article-name line2">{{item.title}}</div>
  47. <div class="lighter" v-html="item.summary"></div>
  48. <div class="flex" style="margin-top: 56px;">
  49. <div class="sm muted m-r-20" v-if="item.author">{{item.author}}</div>
  50. <div class="sm muted">发布时间:{{timeFormat(item.created_at)}}</div>
  51. <!-- <div class="flex m-l-16">
  52. <i class="el-icon-view muted"></i>
  53. <div class="muted" style="margin-left: 3px;">{{item.visit}} 人浏览</div>
  54. </div> -->
  55. </div>
  56. </div>
  57. <!-- <el-image style="width: 200px; height: 150px;border-radius: 6px;" fit="cover"
  58. :src="item.image" /> -->
  59. </nuxt-link>
  60. </div>
  61. <div class="help-center-pagination row-center">
  62. <el-pagination background hide-on-single-page layout="prev, pager, next" :total="count"
  63. prev-text="上一页" next-text="下一页" :page-size="10" @current-change="changePage" />
  64. </div>
  65. </div>
  66. <div class="data-null column-center" v-show="dataNull">
  67. <img style="width: 150px;height: 150px;" src="~/static/images/news_null.png" />
  68. <div class="xs muted">
  69. 暂无数据~
  70. </div>
  71. </div>
  72. </div>
  73. </div>
  74. </div>
  75. </template>
  76. <script>
  77. import {
  78. timeFormat
  79. } from '@/utils/date'
  80. export default {
  81. head() {
  82. return {
  83. title: this.$store.getters.headTitle,
  84. link: [{
  85. rel: "icon",
  86. type: "image/x-icon",
  87. href: this.$store.getters.favicon
  88. }],
  89. };
  90. },
  91. async asyncData({
  92. $get,
  93. $post
  94. }) {
  95. let categoryList = [];
  96. let currentId = 0;
  97. let articleList = [];
  98. let count = 0;
  99. let dataNull = true;
  100. // const banner = $get("ad/lists", {
  101. // params: {
  102. // pid: 29,
  103. // terminal: 2
  104. // }
  105. // });
  106. let res = await $get("policy/category");
  107. // const {
  108. // data: bannerList
  109. // } = await banner;
  110. console.log(res)
  111. if (res.code == 1) {
  112. categoryList = res.data;
  113. currentId = 0
  114. let listsRes = await $get("policy", {
  115. params: {
  116. cid: currentId,
  117. page_size: 10
  118. }
  119. });
  120. console.log(listsRes)
  121. if (listsRes.code == 1) {
  122. articleList = listsRes.data;
  123. count = listsRes.data.length
  124. if (count <= 0) {
  125. dataNull = true;
  126. } else {
  127. dataNull = false
  128. }
  129. }
  130. console.log(listsRes)
  131. }
  132. return {
  133. categoryList,
  134. articleList,
  135. count,
  136. currentId,
  137. // bannerList,
  138. dataNull,
  139. }
  140. },
  141. data() {
  142. return {
  143. categoryList: [],
  144. articleList: [],
  145. currentId: -1,
  146. count: 0,
  147. swiperOptions: {
  148. width: 1180,
  149. }
  150. }
  151. },
  152. mounted() {
  153. // console.log(this.articleList, 'articleList')
  154. // console.log(this.articleList)
  155. },
  156. methods: {
  157. async changePage(current) {
  158. let res = await this.$get("policy", {
  159. params: {
  160. cid: this.currentId,
  161. page_no: current,
  162. page_size: 10
  163. }
  164. });
  165. if (res.code == 1) {
  166. this.articleList = res.data.list;
  167. if (this.articleList.length <= 0) {
  168. dataNull = true;
  169. } else {
  170. dataNull = false
  171. }
  172. }
  173. },
  174. changeList(id) {
  175. this.currentId = id;
  176. this.changePage(1)
  177. },
  178. timeFormat(time) {
  179. return timeFormat(time)
  180. },
  181. }
  182. }
  183. </script>
  184. <style lang="scss" scoped>
  185. .category {
  186. padding: 16px 0;
  187. .category-hd {
  188. .category-wrap {
  189. padding: 0 16px;
  190. }
  191. .category-con {
  192. border-bottom: 1px dashed #e5e5e5;
  193. align-items: flex-start;
  194. padding-top: 16px;
  195. .name {
  196. flex: none;
  197. }
  198. .item {
  199. margin-bottom: 16px;
  200. width: 84px;
  201. margin-left: 14px;
  202. cursor: pointer;
  203. &.active {
  204. color: $--color-primary;
  205. }
  206. &:hover {
  207. color: $--color-primary;
  208. }
  209. }
  210. }
  211. .sort {
  212. padding: 15px 16px;
  213. .sort-name {
  214. .item {
  215. margin-right: 30px;
  216. cursor: pointer;
  217. &.active {
  218. color: $--color-primary;
  219. }
  220. }
  221. }
  222. }
  223. }
  224. }
  225. .help-center-container {
  226. .help-center-banner {
  227. margin-top: 16px;
  228. }
  229. .help-center-box {
  230. margin-top: 16px;
  231. display: flex;
  232. flex-direction: row;
  233. .help-center-aside {
  234. width: 160px;
  235. // min-height: 635px;
  236. padding-top: 20px;
  237. padding-bottom: 20px;
  238. padding: 20px 30px;
  239. .nav {
  240. li {
  241. margin: 10px 0px;
  242. padding: 0px 30px;
  243. cursor: pointer;
  244. }
  245. .active-item {
  246. padding-left: 27px;
  247. color: $--color-primary;
  248. border-left: 3px solid $--color-primary;
  249. }
  250. }
  251. }
  252. .article-lists-container {
  253. width: 1004px;
  254. display: flex;
  255. flex-direction: column;
  256. justify-content: space-between;
  257. .article-item {
  258. margin: 0px 20px;
  259. padding: 15px 0px;
  260. border-bottom: 1px solid #E5E5E5;
  261. cursor: pointer;
  262. .article-name {
  263. margin-bottom: 11px;
  264. margin-top: 13px;
  265. max-width: 720px;
  266. }
  267. }
  268. .help-center-pagination {
  269. padding-top: 38px;
  270. margin-bottom: 30px;
  271. }
  272. .data-null {
  273. padding-top: 150px;
  274. }
  275. }
  276. }
  277. }
  278. ::v-deep .el-pagination.is-background .btn-prev {
  279. background: #fff;
  280. padding: 0 10px;
  281. }
  282. ::v-deep .el-pagination.is-background .btn-next {
  283. background: #fff;
  284. padding: 0 10px;
  285. }
  286. ::v-deep .el-pagination.is-background .el-pager li {
  287. background: #fff;
  288. padding: 0 10px;
  289. }
  290. </style>