<template>
  <div>
    <div class="d-flex flex-between">
      <div>
        <el-button type="primary" size="medium" @click="exportAll">
          <span class="d-in-block v-mid font-size-16">导出</span>
        </el-button>
      </div>
      <el-form label-width="100px" :inline="true">
        <el-form-item>
          <el-select class="mr10" v-model="xxx_bjbm" placeholder="全部" @change="getListData">
            <el-option v-for="(item,index) in schoolData" :key='index' :value="item.xxx_bjbm">
              {{item.xxx_bjbm}}
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item prop="keyword">
          <el-input placeholder="请输入搜索关键字" v-model="keyword" clearable @clear="getListData">
          </el-input>
        </el-form-item>
        <el-button type="primary" class="ml5" @click="getListData">搜索
        </el-button>
      </el-form>
    </div>
    <el-table :data="tableData" tooltip-effect="dark" style="width: 100%">
      <el-table-column type="selection" align="center" width="55">
      </el-table-column>
      <el-table-column label="序号" align="center" type="index" width="50">
      </el-table-column>
      <el-table-column label="学校名称" show-overflow-tooltip prop="school_name" width="auto">
      </el-table-column>
      <el-table-column label="荣誉名称" width="200" prop="xxx_shrymc"></el-table-column>
      <el-table-column label="荣获称号时间" width="220" prop="xxx_rhchsj"></el-table-column>

      <el-table-column prop=" xxx_zs" label="证书" v-for="z in zs">
        <template slot-scope="scope">
          <img v-if="scope.row.xxx_zs!=null&&scope.row.xxx_zs!=''" style="width: 46px; height: 30px;display: block;" :src="prefix+ z.url" />
        </template>
      </el-table-column>
      <el-table-column label="操作" width="180" align="right">
        <template slot-scope="scope">
          <el-button type="text" @click="toDetail(scope.row.xxx_id)">详情
          </el-button>
        </template>
      </el-table-column>
    </el-table>
    <footer class="flex-item-none" style="display: flex; justify-content: flex-end; margin-top: 30px">
      <el-pagination background layout="total,prev, pager, next" :page-size="limit" :total="total" :current-page.sync="cur_page" @current-change="handleCurrentChange"></el-pagination>
    </footer>

  </div>
</template>
<script>
import { useUserStore } from "@/stores/user";
const { real_name, token } = useUserStore();
import { xxry_list, school_list } from './api';

export default {
  name: "index",
  data() {
    return {
      keyword: "",
      title: "",
      limit: 10,
      total: 0,
      cur_page: 1,
      dialogFormVisible: false,
      tableData: [],
      schoolData: [],
      xxx_bjbm: "",
      zs: [],
      prefix: window.globalVariables.api,
    };
  },
  methods: {
    schoolListData() {
      school_list().then((res) => {
        this.schoolData = res.data.data;
        console.log(this.schoolData, 333);
      });
    },
    getListData() {
      let data = {
        page: this.cur_page,
        limit: this.limit,
        keyword: this.keyword,
        school_name: this.xxx_bjbm
      };
      xxry_list(data).then((res) => {
        this.tableData = res.data.page_data;
        this.cur_page = Number(res.data.page_now);
        this.total = Number(res.data.total_rows);
        this.tableData.map(item => {
          this.zs = JSON.parse(item.xxx_zs);
        })

      });
    },
    handleCurrentChange(val) {
      this.cur_page = val;
      this.getListData();
    },
    toDetail(id) {
      this.$router.push({ name: "xxrygl_detail", params: { id: id } });
    },
    exportAll() {
      let link =
        window.globalVariables.api +
        "/xdbg/xxry_xxry/index?api=xls&page=1&limit=10000&token=" +
        token;
      window.open(link, "_blank");
    },
  },
  mounted() {
    this.getListData();
    this.schoolListData();
  },
};
</script>