
<template>
  <div class="bannerManage app-container">
    <div class="search">
      <div>
        <el-select
          v-model="query.advertsType"
          size="small"
          clearable
          class="item-width-200"
          placeholder="请选择广告类型"
        >
          <el-option
            v-for="item in options"
            :key="item.value"
            :label="item.label"
            :value="item.value"
          >
          </el-option>
        </el-select>
        <el-select
          v-model="query.belongType"
          size="small"
          clearable
          class="item-width-200 ml10"
          placeholder="请选择所属平台"
        >
          <el-option
            v-for="item in options1"
            :key="item.value"
            :label="item.label"
            :value="item.value"
          >
          </el-option>
        </el-select>
        <el-button
        class="ml10"
        type="primary"
        size="small"
        icon="el-icon-search"
        @click="handleSearch"
      >
        搜索
      </el-button>
      </div>
      <el-button class="add-btn" type="primary" size="small" @click="handleAdd"
        >添加</el-button
      >
    </div>

    <el-table
      :data="tableData"
      tooltip-effect="dark"
      border
      v-loading="loading"
      style="width: 100%"
    >

      <el-table-column
        prop="advertsName"
        align="center"
        label="名称"
        show-overflow-tooltip
      >
      </el-table-column>
      <el-table-column
        prop="createTime"
        align="center"
        label="广告图"
        show-overflow-tooltip
      >
      <template slot-scope="scope">
          <img class="icon" :src="scope.row.advertsImg" alt="">
        </template>
      </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="jumpUrl"
        align="center"
        label="跳转链接"
        show-overflow-tooltip
      >
      <template slot-scope="scope">
          <span>{{scope.row.jumpUrl || '-'}}</span>
        </template>
      </el-table-column>
      <el-table-column
        prop="sort"
        align="center"
        label="权重"
        show-overflow-tooltip
      >
      </el-table-column>
      <el-table-column
        prop="sort"
        align="center"
        label="状态"
        show-overflow-tooltip
      >
       <template slot-scope="scope">
          <span>{{scope.row.status == 1?'显示':'隐藏'}}</span>
        </template>
      </el-table-column>
      <el-table-column prop="address" align="center" label="操作">
        <template slot-scope="scope">
          <el-button type="text" size="small" @click="handleEdit(scope.row)">编辑</el-button>
          <el-button type="text" size="small" @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 {advList,delAdv} from '@/api/appConfig'
export default {
  name: "bannerManage",
  data() {
    return {
      tableData: [],
       options:[
        {
          label:'首页banner',
          value:1
        },
        {
          label:'首页广告位',
          value:2
        },
        {
          label:'贵大奶茶Banner',
          value:3
        },
        {
          label:'贵大奶茶广告位',
          value:4
        },
        {
          label:'首页弹窗',
          value:6
        }
      ],
      options1:[
         {
          label: "贵大",
          value: '1',
        },
        {
          label: "慧研学",
          value: '2',
        },
        {
          label: "生活宝",
          value: '3',
        },
      ],
      loading: false,
      query: {
        belongType:'',
        advertsType:'',
        currentPage: 1,
        pageSize: 10,
      },
      title: "",
      total: 0,
    };
  },
  // watch: {
  //   query: {
  //     handler: debounce(function (val) {
  //       this.advList()
  //     }),
  //     deep: true,
  //   },
  // },
  methods: {
    handleSearch(){
      this.query.currentPage = 1
      this.advList();

    },
    handleEdit(row){
      sessionStorage.setItem('advItem',JSON.stringify(row))
      this.$router.push({
        path:'/operationManage/advertisingManage/addAdv',
        query:{
          mode:'edit',
          title:'编辑广告位'
        }
      })
    },
    handleAdd(){
      this.$router.push('/operationManage/advertisingManage/addAdv')
    },
    // 删除
     handleDel(id) {
       this.$confirm(`此操作将删除该数据, 是否继续?`, '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          delAdv({id}).then(res=>{
            if(res.state == 'Success'){
               this.$notify({
                title: '成功',
                message: '操作成功',
                type: 'success'
              });
              this.advList()
            }
          })
        })
    },
    handleSizeChange(val) {
      this.query.currentPage = 1;
      this.query.pageSize = val;
    this.advList()
    },
    handleCurrentChange(val) {
      this.query.currentPage = val;
    this.advList()
    },
    advList(){
      this.loading = true
      advList(this.query).then(res=>{
        this.loading = false
        if(res.state == 'Success'){
          this.tableData = res.content.records
          this.total = res.content.total
        }
      })
    },

  },
  created() {
    this.advList()
  },
};
</script>

<style lang="scss" scoped>
.bannerManage {
  .search{
    justify-content: space-between;
  }
  .icon{
    width: 120px;
    height: 80px;
  }
}
</style>
