明梦爽
2022-01-19 b80d0c5dd5ca242427a07f4891e8a0dc354889b3
src/components/page/introduce.vue
@@ -7,41 +7,20 @@
      <!-- 小标题 -->
      <el-col :span="4" class="marr10">
        <ul>
          <li
            v-for="(item, index) in menuList"
            :key="index"
            class="liStylenone liPointer marb10"
            @click="changeMenu(item)"
          >
            <b :class="cont == item.categoryName ? 'ft-blue' : 'ft-black'">{{
              item.categoryName
            }}</b>
          <li v-for="(item, index) in menuList" :key="index" class="liStylenone liPointer marb10" @click="changeMenu(item)">
            <b :class="cont == item.name ? 'ft-blue' : 'ft-black'">{{item.name}}</b>
          </li>
        </ul>
      </el-col>
       <!-- 新闻内容 -->
      <el-card class="box-card">
        <el-col :span="18">
          <div>
            <el-row
              class="marb10"
              :key="index"
              v-for="(item, index) in newsList"
            >
          <!-- <div v-if="newsList.length > 0">
            <el-row class="marb10" :key="index" v-for="(item, index) in newsList">
              {{ item.title }}
            </el-row>
          </div>
          <!-- 分页 -->
          <div>
            <el-pagination
              @current-change="handleCurrentChange"
              :current-page.sync="currentPage"
              :page-size="20"
              layout="total, pager, next"
              :total="total"
            >
            </el-pagination>
          </div>
          </div> -->
          <div>{{ content }}</div>
        </el-col>
      </el-card>
    </el-row>
@@ -50,7 +29,7 @@
<script>
import globalTitle from '../globalTitle.vue'
import { getMinTitle, getNewsList } from '../../api/api'
import {getMinTitle,getNewsList,getnew} from '../../api/api'
export default {
  name: 'introduce',
  components: {
@@ -60,62 +39,66 @@
    return {
      cont: '',
      menuList: [],
      newsList: [],
      total: 0,
      currentPage: 1
      newsList:[],
      content:'',
    }
  },
  created() {
    this.getMinTitleList()
  },
  mounted() {},
  mounted() {
    this.getTitle();
  },
  watch: {
    menuList(newval, oldval) {
      this.getAllNewsList(this.menuList[0])
      this.cont = this.menuList[0].categoryName
    menuList(n,o){
      this.cont =  this.menuList[0].name;
      this.getnews(this.menuList[0]);
      this.getalone(this.newsList);
    }
  },
  methods: {
    handleCurrentChange(val) {
      console.log(`当前页: ${val}`)
    getTitle(){
      const data = Number(this.$route.query.id);
      getMinTitle(data).then(res => {
        console.log(res);
        if(res.code == 200){
          this.menuList = res.data
        }
      }).catch(err => {
        console.log(err);
      })
    },
    changeMenu(val) {
      this.getAllNewsList(val)
      this.cont = val.categoryName
      this.cont = val.name;
      this.getnews(val)
    },
    getMinTitleList() {
    getnews(item){
      const data = {
        contypeId: this.$route.query.id,
        p: 1
      }
      getMinTitle(data)
        .then((res) => {
          console.log('res', res)
          if (res.code == 200) {
            this.menuList = res.data.records
          }
        })
        .catch((err) => {
          console.log('err', err)
        })
        current:1,
        newsCategoryId:item.id,
        size:5
      };
      getNewsList(data).then(res => {
        console.log(res);
        if(res.code == 200){
          // if(res.data.records.length == 1){
            this.newsList = [];
            this.getalone(res.data.records[0]);
          // }else{
          //   this.content = '';
          //   this.newsList = res.data.records
          // }
        }
      }).catch(error => {
        console.log(error);
      })
    },
    getAllNewsList(item) {
      const data = {
        categoryId: item.id,
        contypeId: item.contypeId,
        p: this.currentPage
      }
      getNewsList(data)
        .then((res) => {
          console.log('res', res)
          if (res.code == 200) {
            this.newsList = res.data.records
            this.total = Number(res.data.total)
          }
        })
        .catch((err) => {
          console.log('err', err)
        })
    getalone(item){
      const data = item.id;
      getnew(data).then(res => {
        console.log(">>>>",res);
        this.content = res.data.content;
        this.data = res.data;
      })
    }
  }
}