<template>
  <div>
    <header>
      <div class="flex title">
        <h3>{{ detailInfo.bs_name }}</h3>
      </div>
      <p><span class="blank">比赛类型</span> {{ detailInfo.bs_type_name }}</p>
      <p><span class="blank">报名时间</span> {{ detailInfo.bs_bmsj }}-{{detailInfo.bs_end_bmsj}}</p>
      <div class="bs-content" v-html="detailInfo.bs_content"></div>
      <div class="font-size-14 text-blue" v-for="f in filePath">
        <a :href="https+f.split('|')[0]" target="_blank">{{f.split('|')[1]}}</a>
      </div>
    </header>
    <el-table :data="tableData" tooltip-effect="dark" style="width: 100%">
      <el-table-column label="序号" align="center" type="index" width="50">
      </el-table-column>
      <el-table-column label="学生姓名" width="80" prop="xs_name"></el-table-column>
      <el-table-column label="性别" width="80" prop="xs_sex"></el-table-column>
      <el-table-column label="学校" width="" prop="xs_school_name"></el-table-column>
      <el-table-column label="年级" width="100" prop="xs_grade"></el-table-column>
      <el-table-column label="身份证" width="" prop="xs_sfz_code"></el-table-column>
      <el-table-column label="比赛类型" width="" prop="bs_type"></el-table-column>
      <el-table-column label="项目名称" width="" prop="bs_name"></el-table-column>
      <el-table-column label="操作" width="150" align="center">
        <template slot-scope="scope">
          <el-button type="text" @click="toSet(scope.row)">设置 </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>
    <el-dialog title="设置荣誉" :visible.sync="dialogFormVisible" width="680px" 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 { cjbs_detail, xsxq_list, xsxq_edit, rygl_list } from "./api";
import { useUserStore } from "@/stores/user";
const { token } = useUserStore();
export default {

  data() {
    return {
      detailInfo: {},
      limit: 10,
      total: 0,
      cur_page: 1,
      tableData: [],
      ryData: [],
      dialogForm: {
        ry_id: 0,
        ry_name: "",
        bs_id: ""
      },
      dialogFormVisible: false,
      filePath: "",
      https: window.globalVariables.api,

    };
  },
  methods: {
    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);
      });
    },
    handleChange() {
      this.ryData.map((item) => {
        if (item.ry_id == this.dialogForm.ry_id) {
          this.dialogForm.ry_name = item.ry_name;
        }
      })
    },
    detailData() {
      let data = {
        bs_id: this.bs_id
      };
      cjbs_detail(data).then((res) => {
        if (res.code == 1) {
          this.detailInfo = res.data.one_info;
          this.filePath = this.detailInfo.bs_file.split(";");

        }
      });
    },

    getListData() {
      let data = {
        page: this.cur_page,
        limit: this.limit,
        keyword: this.keyword,
        bs_id: this.bs_id
      };

      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);
      });
    },
    handleCurrentChange(val) {
      this.cur_page = val;
      this.getListData();
    },
    toSet(item) {
      console.log(item, 1232);
      this.dialogFormVisible = true;
      this.id = item.xs_id;
      this.dialogForm.ry_id = item.ry_id;
      this.dialogForm.ry_name = item.ry_name;
      this.dialogForm.bs_id = item.bs_id
    },

    formSubmit() {
      let data = {
        ry_id: this.dialogForm.ry_id,
        ry_name: this.dialogForm.ry_name,
        bs_id: this.dialogForm.bs_id,
      };
      data.xs_id = this.id;
      xsxq_edit(data).then((res) => {
        if (res.code == 1) {
          this.$message({
            message: "设置成功！",
            type: "success",
          });
          this.dialogFormVisible = false;
          this.getListData();
        } else {
          this.$message({
            message: res.msg,
            type: "error",
          });
        }
      });
    },
    formCancel() {
      this.dialogFormVisible = false;
    },

  },
  mounted() {
    if (this.$route.params.id != "") {
      this.bs_id = this.$route.params.id;
      this.detailData();
      this.getListData();
      this.ryListData();
    }

  }
};
</script>
<style lang="scss" scoped>
.flex {
  display: flex;
}
header {
  padding: 30px 20px;
  font-family: PingFangSC-Regular;
  box-sizing: border-box;
  font-size: 14px;
  border-bottom: 1px solid #f0f3f8;
  .title {
    justify-content: space-between;
    h3 {
      color: #000;
      font-size: 16px;
    }
  }
}
.blank {
  display: inline-block;
  color: #000;
  width: 65px;
}
.bs-content {
  width: 100%;
  height: 124px;
  font-size: 14px;
  font-family: PingFangSC-Regular;
  text-align: left;
  color: #969696;
  line-height: 21px;
  overflow-y: scroll;
}
::-webkit-scrollbar {
  width: 0;
  height: 0;
  color: transparent;
}
::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>