<template>
  <div>
    <div class="flex-row">
      <h3 class="font-size-16">{{detailInfo.bb_name}}</h3>
      <div>
        <!-- <el-button type="primary" @click="editData">编辑</el-button> -->
        <el-button type="primary" @click="exportAll">导出</el-button>
      </div>
    </div>
    <el-table :data="tableData" tooltip-effect="dark" style="width: 100%">

      <el-table-column label="序号" align="center" type="index" width="55">
      </el-table-column>
      <el-table-column label="年份" width="200" prop="year"></el-table-column>
      <el-table-column label="学校" width="150" prop="xs_school_name"></el-table-column>
      <el-table-column label="学生姓名" width="150" prop="xs_name"></el-table-column>
      <el-table-column label="比赛类型" width="150" prop="bs_type"></el-table-column>
      <el-table-column label="项目内容" width="150" prop="bs_name"></el-table-column>
      <el-table-column label="获得荣誉" width="" prop="ry_name"></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>
    <el-dialog title="编辑荣誉" :visible.sync="dialogFormVisible" width="580px" destory-on-close>
      <el-form :model="dialogForm" label-width="80px">
        <el-form-item label="" prop="ry_id">
          <el-radio-group v-model="dialogForm.ry_id" @change="handleChange">
            <el-radio v-for="item in ryData" :key="item.ry_id" :label="item.ry_id" :value="item.ry_name">{{item.ry_name}}</el-radio>
          </el-radio-group>
        </el-form-item>
      </el-form>
      <div slot="footer">
        <el-button @click="formCancel">取 消</el-button>
        <el-button type="primary" @click="formSubmit">确 定</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { useUserStore } from "@/stores/user";
const { real_name, token } = useUserStore();
import { xsxq_list, xsxq_detail, rygl_list, sjhz_edit } from './api'
export default {
  name: "index",
  data() {
    return {
      tableData: [],
      limit: 10,
      total: 12,
      cur_page: 1,
      bb_name: "",
      detailInfo: {},
      dialogFormVisible: false,
      ryData: [],
      dialogForm: {
        ry_id: 0,
        ry_name: ""
      },
    }
  },
  methods: {
    //学生列表
    getListData() {
      let data = {
        page: this.cur_page,
        limit: this.limit,
        keyword: this.keyword,
        bb_id: this.$route.params.bb_id,
        site: 'jnmf'
      };

      xsxq_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);
      });
    },
    //报表详情
    getDetailData() {
      let data = {
        bb_id: this.bb_id,
        site: 'jnmf'
      };
      xsxq_detail(data).then((res) => {
        this.detailInfo = res.data.one_info;

      });
    },
    //荣誉列表
    ryListData() {
      this.loading = true;
      let data = {
      };
      rygl_list(data).then((res) => {
        this.loading = false;
        this.ryData = res.data.page_data;
        console.log(this.ryData, 1344);
      });
    },
    handleCurrentChange(val) {
      this.cur_page = val;
    },
    handleChange() {
      this.ryData.map((item) => {
        if (item.ry_id == this.dialogForm.ry_id) {
          this.dialogForm.ry_name = item.ry_name;
        }
      })
    },
    editData() {
      this.dialogFormVisible = true;
      this.ryListData();
      this.dialogForm = {
        ry_id: this.dialogForm.ry_id,
        ry_name: this.dialogForm.ry_name,
      };
    },
    formCancel() {
      this.dialogFormVisible = false;
    },
    formSubmit() {

      let data = {
        site: "jnmf",
        issubmit: "1",
        bb_id: this.$route.params.bb_id,
        ry_id: this.dialogForm.ry_id,
        ry_name: this.dialogForm.ry_name,

      };
      sjhz_edit(data).then((res) => {
        if (res.code == 1) {
          this.$message({
            message: "荣誉编辑成功！",
            type: "success",
          });
          this.dialogFormVisible = false;
          this.getListData();
        }
      });
    },

    exportAll() {
      let link =
        window.globalVariables.api +
        "/jdbg/xsjs_xsgl/index?api=xls&page=1&limit=10000&token=" +
        token +
        "&bb_id=" +
        this.$route.params.bb_id
      window.open(link, "_blank");
    },
  },
  mounted() {
    if (this.$route.params.bb_id != "") {
      this.bb_id = this.$route.params.bb_id;
      this.getListData();
      this.getDetailData();
    }

  }
}
</script>

<style scoped>
::v-deep .el-radio {
  margin-right: 0px;
  width: 100%;
  padding: 15px 0;
}
::v-deep .el-dialog__body {
  padding: 30px 0px;
  border-top: 1px solid #f0f3f8;
}
</style>