question.vue 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. <template>
  2. <div id="question">
  3. <el-row>
  4. <el-col :span="24" class="question">
  5. <el-col :span="24" class="search">
  6. <van-search v-model="value" placeholder="请输入信息标题" @search="onSearch" />
  7. </el-col>
  8. <el-col :span="24" class="mess">
  9. <el-col :span="24" v-for="(item, index) in list" :key="index" class="list">
  10. <p class="title textOver">{{ item.title }}</p>
  11. <p>
  12. <span class="textOver">发布时间:{{ item.publish_time }}</span>
  13. <span class="textOver">来源:{{ item.orgin || '暂无' }}</span>
  14. </p>
  15. </el-col>
  16. </el-col>
  17. </el-col>
  18. </el-row>
  19. </div>
  20. </template>
  21. <script>
  22. const { mapActions: column } = createNamespacedHelpers('column');
  23. const { mapActions: news } = createNamespacedHelpers('news');
  24. import { mapState, createNamespacedHelpers } from 'vuex';
  25. export default {
  26. metaInfo() {
  27. return { title: this.$route.meta.title };
  28. },
  29. name: 'question',
  30. props: {},
  31. components: {},
  32. data: function() {
  33. return {
  34. //栏目列表
  35. columnList: [],
  36. colId: '',
  37. list: [],
  38. value: '',
  39. };
  40. },
  41. async created() {
  42. await this.search();
  43. await this.searchList();
  44. },
  45. methods: {
  46. ...column(['query', 'delete', 'update', 'create']),
  47. ...news({ newQuery: 'query' }),
  48. //查栏目
  49. async search() {
  50. const res = await this.query();
  51. if (this.$checkRes(res)) {
  52. this.$set(this, `columnList`, res.data);
  53. const colData = this.columnList.find(i => i.site == 'dcwj');
  54. this.colId = colData.id;
  55. }
  56. },
  57. //查列表
  58. async searchList() {
  59. const res = await this.newQuery({ column_id: this.colId });
  60. if (this.$checkRes(res)) {
  61. this.$set(this, `list`, res.data);
  62. // console.log(this.list);
  63. }
  64. },
  65. //搜索
  66. async onSearch({ ...info } = {}) {
  67. if (this.value) {
  68. info.title = this.value;
  69. info.column_id = this.colId;
  70. const res = await this.newQuery({ ...info });
  71. console.log(res.data);
  72. if (this.$checkRes(res)) {
  73. this.$set(this, `list`, res.data);
  74. }
  75. } else {
  76. this.searchList();
  77. }
  78. },
  79. },
  80. computed: {
  81. ...mapState(['user']),
  82. },
  83. watch: {},
  84. };
  85. </script>
  86. <style lang="less" scoped>
  87. .question {
  88. position: relative;
  89. .search {
  90. position: fixed;
  91. width: 100%;
  92. z-index: 999;
  93. border-bottom: 1px solid #ccc;
  94. background-color: #fff;
  95. .van-search {
  96. padding: 10px 12px 10px 12px;
  97. }
  98. }
  99. .mess {
  100. padding: 0px 10px;
  101. margin-top: 55px;
  102. .list {
  103. padding: 10px 0px;
  104. border-bottom: 1px dashed #ccc;
  105. .title {
  106. font-size: 18px;
  107. font-weight: bold;
  108. }
  109. p:nth-child(2) {
  110. margin-top: 5px;
  111. span {
  112. display: inline-block;
  113. width: 50%;
  114. height: 42px;
  115. line-height: 42px;
  116. color: #666;
  117. }
  118. }
  119. }
  120. }
  121. }
  122. </style>