<template>
  <div class="filter-container">
    <el-card>
      <el-input v-model="mediaName" placeholder="请输入媒体名称" class="filter-item"></el-input>
      <el-cascader
        v-model="provinceCity"
        :options="provinceCityDatas"
        :props="props"
        placeholder="请选择地区"
        class="form_select"
        clearable
        filterable
        change-on-select
      />
      <el-button type="primary" @click="btn_search">搜索</el-button>
      <el-button v-permission="'HY_add'" type="primary" @click="btn_add">添加</el-button>
      <el-table :data="dataLists" border stripe>
        <!-- <el-table-column type="selection" width="40"></el-table-column> -->
        <el-table-column prop="F_Name" label="媒体名称" align="center" fixed width></el-table-column>
        <el-table-column prop="F_RegioName" label="媒体地区" align="center" fixed width>
          <template slot-scope="scope">
            <span v-show="scope.row.F_Province==null ? false:true">{{scope.row.F_Province}}</span>
            <span v-show="scope.row.F_City==null ? false:true">{{scope.row.F_City}}</span>
            <span v-show="scope.row.F_County==null ? false:true">{{scope.row.F_County}}</span>
          </template>
        </el-table-column>
        <el-table-column prop="F_CreateTime" label="创建时间" align="center" fixed width></el-table-column>
        <el-table-column label="操作" width align="center" class-name="oparate_btn" fixed="right">
          <template slot-scope="scope">
            <!-- <el-button
              v-permission="'HY_detail'"
              type="text"
              @click="btn_detail(scope.row.F_ID.toString())"
            >详情</el-button> -->
            <el-button
              v-permission="'HY_edit'"
              type="text"
              @click="btn_edit(scope.row.F_ID.toString())"
            >编辑</el-button>
            <el-button
              v-permission="'HY_delete'"
              type="text"
              @click="btn_delete(scope.row.F_ID.toString())"
            >删除</el-button>
          </template>
        </el-table-column>
      </el-table>
      <pagination
        v-show="pageParams.total > 0"
        :total="pageParams.total"
        :pageindex.sync="pageParams.pageindex"
        :pagesize.sync="pageParams.pagesize"
        class="pagination"
        @pagination="getList"
      ></pagination>
    </el-card>
  </div>
</template>
<script>
import { getProviceCityTown } from "@/api/commonAPI";
import { getMedia ,deleteMedia} from "@/api/mediaCenter/mediaInformation";
import Pagination from "@/components/Pagination"; // 对el-pagination 二次封装
import detail from "./detail";
import addOrEdit from "./addOrEdit";
export default {
  components: {
    Pagination
  },
  data() {
    return {
      mediaName:'',//媒体名称
      provinceCityDatas: [], // 省市下拉数据
      provinceCity: [], // 省市下拉绑定的值
      props: {
        // 自定义省市下拉数据的key值
        value: "text",
        label: "text",
        children:'children'
      },
      pageParams: {
        pageindex: 1, // 当前第几页
        pagesize: Number(this.$store.getters.serverConfig.PAGESIZE), // 每页几条数据
        total: 0 // 总共多少数据
      },
      dataLists: [] //列表数据
    };
  },
  created() {
    this.getProCity();
    this.getList();
    document.onkeyup=(e)=>{
      if(e.keyCode==13){
        this.getList()
      }
    }
  },
  methods: {
    getList() {
      return new Promise(resolve => {
        const params = {
          name:this.mediaName.trim(),
          province:this.provinceCity&&this.provinceCity[0],
          city:this.provinceCity&&this.provinceCity[1],
          county:this.provinceCity&&this.provinceCity[2],
          pageindex: this.pageParams.pageindex, // int 第几页
          pagesize: this.pageParams.pagesize // int 每页几条信息
        };
        getMedia(params).then(response => {
          if (response.state.toLowerCase() === "success") {
            this.pageParams.total = response.total;
            this.dataLists = response.rows.Rows;
          }
        });
        resolve();
      });
    },
    btn_search() {
      this.pageParams.pageindex = 1;
      this.getList();
    },
    btn_detail(editId) {
      this.$layer.iframe({
        content: {
          content: detail, // 传递的组件对象
          parent: this, // 当前的vue对象
          data: { rowid: editId } // props
        },
        area: ["80%", "90%"],
        title: "详情"
      });
    },
    btn_edit(editId) {
      this.$layer.iframe({
        content: {
          content: addOrEdit, // 传递的组件对象
          parent: this, // 当前的vue对象
          data: { rowid: editId } // props
        },
        area: ["50%", "50%"],
        title: "编辑媒体信息"
      });
    },
    btn_add() {
      this.$layer.iframe({
        content: {
          content: addOrEdit, // 传递的组件对象
          parent: this, // 当前的vue对象
          data: { rowid: "" } // props
        },
        area: ["50%", "50%"],
        title: "添加媒体信息"
      });
    },
    //删除
    btn_delete(editId) {
      this.$confirm('您确定要将此媒体信息删除吗?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        deleteMedia(editId).then(response => {
          if (response.state.toLowerCase() === 'success') {
            this.getList()
            this.$message.success('删除成功!')
          }
        })
      }).catch(() => {
        this.$message.info('已取消删除')
      })
    },
    // 获取省市下拉数据
    getProCity() {
      return new Promise(resolve => {
        getProviceCityTown().then(response => {
          if (response.state.toLowerCase() === "success") {
            this.provinceCityDatas = response.data;
          }
        });
        resolve();
      });
    }
  }
};
</script>
<style lang="scss" scoped>
</style>