
<template>
  <div class="menuManage app-container">
   <div class="search">
      <div>
        <el-input
          v-model="query.columnName"
          size="small"
          placeholder="请输入名称"
          class="item-width-200 "
        ></el-input>
        <el-button
        class="ml10"
        type="primary"
        size="small"
        icon="el-icon-search"
        @click="handleSearch"
      >
        搜索
      </el-button>
        <!-- <el-select
          v-model="query.columnId"
          size="small"
          clearable
          class="item-width-200 ml10"
          placeholder="请选择栏目"
        >
          <el-option
            v-for="item in options"
            :key="item.value"
            :label="item.label"
            :value="item.value"
          >
          </el-option>
        </el-select> -->
        
      </div>
      <el-button class="add-btn" type="primary" size="small" v-if="btnAuthObj.addColumn" @click="handleAdd"
        >添加</el-button
      >
    </div>

    <el-table
      :data="tableData"
      tooltip-effect="dark"
      border
      v-loading="loading"
      style="width: 100%"
    >
     
      <el-table-column
        prop="imgUrl"
        align="center"
        label="栏目背景图"
        show-overflow-tooltip
      >
      <template slot-scope="scope">
          <img class="icon" :src="scope.row.columnImg" alt="">
        </template>
      </el-table-column>
      <el-table-column
        prop="columnName"
        align="center"
        label="栏目名称"
        show-overflow-tooltip
      >
      </el-table-column>
      <el-table-column
        prop="columnMsg"
        align="center"
        label="栏目描述"
        show-overflow-tooltip
      >
      </el-table-column>
      <el-table-column
        align="center"
        label="小程序"
        show-overflow-tooltip
      >
       <template slot-scope="scope">
          <span>{{scope.row.belongType ==2?'慧研学':'贵大'}}</span>
        </template>
      </el-table-column>
      <el-table-column
        prop="sort"
        align="center"
        label="排序"
        show-overflow-tooltip
      >
      </el-table-column>
       <el-table-column
        prop="status"
        align="center"
        label="状态"
        show-overflow-tooltip
      >
      <template slot-scope="scope">
         <span :class="[scope.row.status == 2?'red':'green']">{{scope.row.status == 2?"隐藏 ":"显示"}}</span>
        </template>
      </el-table-column>

      <el-table-column prop="address" align="center" label="操作">
        <template slot-scope="scope">
          <el-button type="text" size="small" v-if="$route.query.title != '二级栏目'" @click="handle(scope.row.id)">查看下级</el-button>
          <el-button type="text" size="small" v-if="btnAuthObj.editColumn" @click="handleEdit(scope.row)">编辑</el-button>
          <el-button type="text" size="small" v-if="btnAuthObj.delColumn" @click="handleDel(scope.row.id)">删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    <div class="page-box">
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        background
        :current-page="query.currentPage"
        :page-sizes="[10, 20, 30, 40]"
        :page-size="query.pageSize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total"
      >
      </el-pagination>
    </div>
  </div>
</template>
  
  <script>
import { debounce } from "@/utils/index";
import {getList,del} from '@/api/study';
export default {
  name: "menuManage",
  data() {
    return {
      tableData: [],
      options:[],
      loading: false,
      query: {
        columnId: 0,
        columnName: "",
        currentPage: 1,
        pageSize: 10,
      },
      title: "",
      total: 0,
    };
  },
  // watch: {
  //   query: {
  //     handler: debounce(function (val) {
  //       this.getList()
  //     }),
  //     deep: true,
  //   },
  // },
  methods: {
    handleSearch(){
      this.query.currentPage = 1
      this.getList();

    },
    handle(id){
     
      let title,parentId
      if(!this.$route.query.title){
          title = '二级栏目'
          parentId = id
      }else if(this.$route.query.title == '二级栏目'){
        title = '三级栏目'
          parentId = this.$route.query.parentId
      }
       
         this.$router.push({
            path:'/studyManage/menuManage/index',
            query:{
                id,
                parentId,
                title
            }
         })
    },
    handleEdit(row){
      
      sessionStorage.setItem('studyMenu',JSON.stringify(row))
      this.$router.push({
        path:'/studyManage/menuManage/addMenu',
        query:{
            mode:'edit',
            title:'编辑栏目',
            id:this.$route.query.id,
            parentId:this.$route.query.parentId || 0,
            level:this.$route.query.title
        }
      })
    },
    handleAdd(){
      this.$router.push({
        path:'/studyManage/menuManage/addMenu',
        query:{
          id:this.$route.query.id,
          parentId:this.$route.query.parentId || 0,
          level:this.$route.query.title
        }
      })
    },
    // 点击删除
    handleDel(id) {
       this.$confirm(`此操作将删除该数据, 是否继续?`, '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          del({columnId:id}).then(res=>{
            if(res.state == 'Success'){
               this.$notify({
                title: '成功',
                message: '操作成功',
                type: 'success'
              });
              this.getList()
            }
          })
        })
    },
    handleSizeChange(val) {
      this.query.currentPage = 1;
      this.query.pageSize = val;
    this.getList()
    },
    handleCurrentChange(val) {
      this.query.currentPage = val;
    this.getList()
    },
    getList(){
      this.loading = true
      getList(this.query).then(res=>{
        this.loading = false
        if(res.state == 'Success'){
          this.tableData = res.content.records
          this.total = res.content.total
        }
      })
    }
  },
  created() {
    this.query.columnId = this.$route.query.id || 0
    this.getList()
  },
};
</script>
  
<style lang="scss" scoped>
.menuManage {
  .search{
    justify-content: space-between;
  }
  .icon{
    width: 80px;
    height: 80px;
  }
}
</style>
  