<template>
  <div class="major-page">
    <div class="breadcrumb">
      <el-breadcrumb separator="/">
        <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
        <el-breadcrumb-item :to="{ path: '/career/plan/index' }"
          >生涯·志愿</el-breadcrumb-item
        >
        <el-breadcrumb-item :to="{ path: '/career/subject/index' }"
          >选科查询</el-breadcrumb-item
        >
        <el-breadcrumb-item>由专业选科目</el-breadcrumb-item>
      </el-breadcrumb>
    </div>
    <div class="content-box">
      <div class="content-top-box">
        <div class="content-box-title">招生专业的选科要求</div>
        <div class="my-subject-button" @click="toMyPage()">我的选科方案</div>
      </div>
      <div class="content-msg">
        新高考改革方案，志愿填报将采取“专业+学校”的填报方式，由学校平行志愿转变为专业平行志愿，每个招生专业都有相应的选考科目要求。您可以通过此功能查询各学校各专业的选考科目要求。
      </div>

      <div class="table-box">
        <mx-table
          :rows="dataList"
          :propDefines="propDefines"
          @selection-change="handleSelectionChange"
        >
          <template #select="{ row }">
            <img
              class="college-icon"
              v-if="row.collect"
              @click="httpCollectRemove(row)"
              src="@/assets/images/subject/icon_shoucang_pre.png"
            />
            <img
              class="college-icon"
              v-else
              @click="httpCollectAdd(row)"
              src="@/assets/images/subject/icon_shoucang_n.png"
            />
          </template>
        </mx-table>
        <pagination
          v-show="total > 0"
          :total="total"
          :page.sync="pageNum"
          :limit.sync="pageSize"
          :page-size="20"
          @pagination="onChangePage"
        />
      </div>
      <div class="button-box">
        <el-button @click="httpXkcxScheme">提交选科方案</el-button>
      </div>
    </div>
    <div class="major-list-box" v-if="xkcxSchemeTotal>0">
      <div class="major-list-title">
        如需填报以上专业，您有以下<span>{{ xkcxSchemeTotal }}</span
        >种选科组合可以选择
      </div>
      <div class="major-card-list">
        <div
          class="divide-equally-box"
          v-for="(item, index) in xkcxSchemeList"
          :key="index"
        >
          <div class="major-card-item">
            <div class="major-card-title">{{ item.course }}</div>
            <div class="major-progress-box">
              <el-progress
                type="circle"
                stroke-width="14"
                width="96"
                color="#c8eee3"
                :percentage="item.marjorRate"
              ></el-progress>
              <div class="major-progress-text">
                可报{{ item.marjorRate }}%的专业
              </div>
            </div>
            <div class="major-card-bottom-box">
              <div class="major-card-msg" v-if="item.collect">
                <i class="el-icon-circle-check"></i> 已加入我的选科方案
              </div>
              <div v-else class="major-card-button" @click="onClickJoin(item)">
                加入我的选科方案
              </div>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import { xkcxScheme, schemeAdd,xkcxlist } from "@/api/webApi/webQue";

export default {
  data() {
    return {
      dataList: [
      ],
      propDefines: {
        selection: {
          type: "selection"
        },
        universityName: {
          label: "院校名称",
        },
        marjorName: {
          label: "专业（类）名称",
        },
        resourcesName: {
          label: "类中所含专业",
          align: "left",
        },
        level: {
          label: "专业层次",
        },
        courseRemark0: {
          label: "首选科目",
          align: "left",
        },
        courseRemark1: {
          label: "再选科目",
          align: "left",
        },
        collect: {
          label: "选择",
          align: "left",
          slot: "select",
          width: "100px",
        },
      },
      selectIds: [],
      pageNum: 1,
      pageSize: 10,
      total: 0,
      xkcxSchemeTotal: 0,
      xkcxSchemeList: [],
    };
  },
  created() {
    this.httpGetXkcxList();
  },
  methods: {
    onChangePage(page) {
      this.pageSize = page.limit;
      this.pageNum = page.page;
      this.httpGetXkcxList();
    },
    handleSelectionChange(list) {
      let ids = [];
      let len = list.length;
      for (let i = 0; i < len; i++) {
        ids.push(list[i]["id"]);
      }
      this.selectIds = ids;
    },
    onClickJoin(item) {
      this.httpSchemeAdd(item.id);
    },
    httpSchemeAdd(id) {
      schemeAdd({
        groupId: id,
        df: 0,
      }).then((res) => {
        this.httpXkcxScheme();
        console.log(res);
      });
    },
    toMyPage() {
      this.$router.push("/career/subject/myChoice");
    },
    httpXkcxScheme() {
      if (this.selectIds.length == 0) {
        this.$message.error("请选择专业");
        return;
      }
      xkcxScheme({
        ids: this.selectIds.toString(),
      }).then((res) => {
        this.xkcxSchemeList = res.rows;
        this.xkcxSchemeTotal = res.total;
      });
    },
    httpGetXkcxList() {
      xkcxlist({
        collect:true,
        pageNum: this.pageNum,
        pageSize: this.pageSize,
      })
        .then((res) => {
          this.dataList = res.rows;
          this.total = res.total;
        })
        .catch((err) => {
          console.log("请求出错！");
        });
    },
  },
};
</script>


<style scoped>
.breadcrumb {
  padding: 15px 30px;
  margin: 15px 0;
  border-bottom: 1px solid #eee;
  border-radius: 2px;
  background-color: #fff;
  box-shadow: 0 1px 2px 0 rgb(0 0 0 / 5%);
}
.el-breadcrumb {
  font-size: 16px !important;
}
.content-box {
  padding: 60px 40px 60px 50px;
}
.content-box-title {
  color: #47c6a2;
  font-size: 24px;
}
.content-top-box {
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.my-subject-button {
  color: #47c6a2;
  cursor: pointer;
  font-size: 14px;
  border: 1px solid #47c6a2;
  padding: 13px 110px;
}
.content-msg {
  margin: 32px 0;
  font-size: 16px;
}
.button-box {
  padding: 30px;
  display: flex;
  justify-content: center;
}
.major-list-title {
  color: #4c4c4c;
  font-size: 24px;
  text-align: center;
  margin-top: 100px;
}
.major-list-title span {
  color: #d28140;
}
.major-card-list {
  margin-top: 30px;
  display: flex;
  flex-wrap: wrap;
}
.divide-equally-box {
  width: 33%;
  margin: 0px auto;
}
.major-card-item {
  width: 320px;
  margin: 20px auto;
  background: rgba(255, 255, 255, 1);
  box-shadow: 2px 2px 10px 0px rgb(0 0 0 / 10%);
  margin-top: 20px;
}
.major-card-title {
  text-align: center;
  background: #47c6a2;
  color: #fff;
  font-size: 24px;
  font-weight: 600;
  padding: 25px 0px;
}
.major-progress-box {
  padding: 40px 0 20px 0;
  display: flex;
  flex-direction: column;
  align-items: center;
}
.major-progress-text {
  margin-top: 20px;
}
.major-card-bottom-box {
  border-top: 1px solid #eee;
  margin: 0 auto;
  width: 80%;
  padding: 20px 0;
  display: flex;
  flex-direction: column;
  align-items: center;
}
.major-card-button {
  width: 100%;
  background: #47c6a2;
  color: #fff;
  height: 48px;
  text-align: center;
  line-height: 48px;
  cursor: pointer;
}
.major-card-msg {
  height: 48px;
  line-height: 48px;
  color: #73a0fa;
}
/deep/ .el-progress__text {
  font-size: 18px !important;
  color: #73a0fa;
}
</style>
