<template>
  <common-header />
  <div class="content">
    <div class="title">
      <div>详情 <span>智慧教研-在线学习-</span><span>详情</span></div>
    </div>
    <div class="main">
      <p>{{ detailData.zz_name }}</p>
      <div style="display: flex; ">
        <div class="left">
          <img class="avatar" src="@/assets/img/zhjy/main_3.png" alt="" />

          <div class="left-top">
            <span>{{ detailData.zx_jsxx }}</span><img src="@/assets/img/zhjy/hot.png" alt="" /><span>{{
              detailData.zx_lll
            }}</span>
          </div>
          <div class="left-bottom"><span>金牌讲师</span> <span>YYDS</span></div>
        </div>
        <div class="nicBaseInfo_action">
          <div class="coverC" @click="finger">
            <img class="posiA posi1" v-if="fingerSwitch == '0'" src="@/assets/kczy/zanIcon.png" />
            <img class="posiA posi1" v-else src="@/assets/kczy/zanIcon_full.png" />
            <span class="posiA posi2">{{ fingerNum }}</span>
          </div>
          <div class="coverC" @click="loveIcon">
            <img class="posiA posi3" v-if="loveSwitch == '0'" src="@/assets/kczy/collectIcon.png" />
            <img class="posiA posi3" v-else src="@/assets/kczy/collectIcon_full.png" />
            <span class="posiA posi4">{{ loveNum }}</span>
          </div>
        </div>
        <div class="right">
          <el-button type="primary" :plain="isFocus" @click="handleFocus">{{
                !isFocus ? "关注" : "已关注"
              }}</el-button>
        </div>
        <!-- <div class="right" @click="handleFocus">
          <el-button type="primary" v-if="attentionSwitch == '0'">
            关注
          </el-button>
          <el-button :plain="isFocus" v-else>
            已关注
          </el-button>
        </div> -->
      </div>

      <div class=" docx">
        <div>{{ detailData.zz_fj_name }}</div>
        <span v-if="detailData.zz_fj" @click="download(detailData.zz_fj)">下载附件</span>
      </div>
      <p class="jieshao">
        {{ detailData.zz_content }}
      </p>

      <ul class="tp_list">
        <li><img :src="https + detailData.zz_img" alt="" /></li>
      </ul>
      <div class="pingjia">
        <el-rate v-model="pjInfo.ke_star"></el-rate>
        <div class="rateBtn" @click="formSubmit(detailData.zz_id)">评价</div>

        <div class="rate">
          <div class="rate-list" v-for="(e, i) in evaluateListData" :key="i" v-show="detailData.zz_id == e.kk_id">
            <p class="rate-list-title">
              <span class="rate-list-name">{{ e.ke_user_realname }}</span>
              <span class="rate-list-time">{{ e.create_dateline }}</span>
            </p>
            <div class="rate-list-star">
              <img class="rate-list-img" src="@/assets/img/zhjyzxxx/star.png" alt="" v-for="(item, index) in Number(e.ke_star)" :key="index" />
            </div>
          </div>
        </div>
      </div>
    </div>
    <!-- <div class="footer">
      <div style="width: 1400px; height: 50px; position: relative; margin: 0 auto">
        <el-pagination background layout="total,prev, pager, next" :total="total" style="position: absolute; top: 0; right: 200px" @current-change="handleCurrentChange" :page-size="limit">
        </el-pagination>
      </div>
    </div> -->
  </div>
</template>

<script>
import { getAvatarUrl } from "@/utils/helper";
import {
  zxxx_detail,
  zxxx_evaluate_add,
  zxxx_evaluate_list,
  user_avatar,
  zxxx_like_add,
  zxxx_like_del,
  zxxx_fav_add,
  zxxx_fav_del,
  zxxx_attention_add,
  zxxx_attention_del,
  wgzd_list

} from "./api";
import { download } from "~/utils/request";
import CommonHeader from "@/components/CommonHeader/index.vue";
export default {
  name: "index",
  components: {
    CommonHeader,
    download,
  },
  data() {
    return {
      isFocus: true,
      detailData: {},
      evaluateInfo: {},
      evaluateListData: [],
      https: window.GLOBAL_CONFIG.api,
      pjInfo: {
        ke_star: "",
        ke_user_realname: "",
        kk_id: "",
        kf_id: "",
      },
      zz_id: "",
      fingerNum: 0, //点赞数
      fingerSwitch: 0, //0：关 1：开
      loveNum: 0, //收藏
      loveSwitch: 0, //0：关 1：开
      attentionSwitch: 0,
      limit: 10,
      total: 0,
      cur_page: 1,
      listData: [],
      attention: "",
      uw_user_id: ""
    };
  },
  methods: {
    handleFocus() {
      this.isFocus = !this.isFocus;
      // // /**增加关注或取消*/
      // if (this.attentionSwitch == 1) {//关注
      //   let transObj = {
      //     uw_user_id: this.uw_user_id,
      //   };
      //   zxxx_attention_del(transObj)
      //     .then(res => {
      //       console.log(res);
      //     })
      //     .catch(error => {
      //       console.log(error)
      //     });
      // } else {
      //   let transObj = {
      //     uw_user_id: this.uw_user_id,
      //   };
      //   zxxx_attention_add(transObj)
      //     .then((res) => {
      //       if (res.code == "1") {
      //         ElMessage({
      //           message: res.msg,
      //           type: "success",
      //         });
      //         this.getListData();
      //       } else {
      //         ElMessage({
      //           message: res.msg,
      //           type: "waring",
      //         });
      //       }
      //     })
      //     .catch((error) => {
      //       console.log(error);
      //     });
      // }
      // this.getDetailData();

    },
    /**增加赞或取消*/
    finger() {
      if (this.fingerSwitch == "1") {//去掉赞
        let transObj = {
          zz_id: this.zz_id,
        };
        zxxx_like_del(transObj)
          .then(res => {
            if (res.code == "1") {
              ElMessage({
                message: res.msg,
                type: "success",
              });
              this.getDetailData();
            } else {
              ElMessage({
                message: res.msg,
                type: "waring",
              });
            }

          })
          .catch(error => { console.log(error) })
        this.getDetailData();
      } else {
        let transObj = {
          zz_id: this.zz_id,

        };
        zxxx_like_add(transObj)
          .then((res) => {
            if (res.code == "1") {
              ElMessage({
                message: res.msg,
                type: "success",
              });
              this.getDetailData();
            } else {
              ElMessage({
                message: res.msg,
                type: "waring",
              });
            }
          })
          .catch((error) => {
            console.log(error);
          });
      }
      this.getDetailData();
    },
    /**增加收藏或取消*/
    loveIcon() {
      if (this.loveSwitch == 1) {//去掉收藏
        let transObj = {
          zz_id: this.zz_id,
        };
        zxxx_fav_del(transObj)
          .then(res => {
            if (res.code == "1") {
              ElMessage({
                message: res.msg,
                type: "success",
              });
              this.getDetailData();
            } else {
              ElMessage({
                message: res.msg,
                type: "waring",
              });
            }
          })
          .catch(error => {
            console.log(error)
          });
      } else {
        let transObj = {
          zz_id: this.zz_id,

        };
        zxxx_fav_add(transObj)
          .then((res) => {
            if (res.code == "1") {
              ElMessage({
                message: res.msg,
                type: "success",
              });
              this.getDetailData();
            } else {
              ElMessage({
                message: res.msg,
                type: "waring",
              });
            }
          })
          .catch((error) => {
            console.log(error);
          });
      }
      this.getDetailData();
    },
    getListData() {
      let data = {
        page: this.cur_page,
        limit: this.limit,
        keyword: this.keyword,

      };

      wgzd_list(data).then((res) => {
        this.listData = res.data.page_data;
        console.log(this.keyword, 111);
        this.cur_page = Number(res.data.page_now);
        this.total = Number(res.data.total_rows);
      });
    },


    getDetailData() {
      let data = {
        zz_id: this.zz_id,
      };
      zxxx_detail(data).then((res) => {
        this.detailData = res.data.one_info;
        console.log(this.detailData.zz_id);
        this.fingerNum = res.data.one_info.zz_like_num; //点赞数
        this.fingerSwitch = res.data.one_info.is_like; //0：关 1：开
        this.loveNum = res.data.one_info.zz_fav_num; //收藏
        this.loveSwitch = res.data.one_info.is_fav; //0：关 1：开
        this.attentionSwitch = res.data.one_info.is_watch; //关注

      });
    },

    //评价
    evaluateData() {
      this.pjInfo = {
        ke_star: "",
        ke_user_realname: "",
        kk_id: "",
        kf_id: "",
      };
    },
    formSubmit(id) {
      let data = {
        ke_star: this.pjInfo.ke_star,
        ke_user_realname: this.pjInfo.ke_user_realname,
        kk_id: id,
        kf_id: this.pjInfo.kf_id,
      };
      zxxx_evaluate_add(data).then((res) => {
        this.evaluateInfo = res.data.one_info;
        if (res.code == 1) {
          this.getDetailData();
          this.getEvaluateListData();
        }
      });
    },
    //评价列表
    getEvaluateListData(id) {
      let data = { kk_id: id };
      zxxx_evaluate_list(data).then((res) => {
        this.evaluateListData = res.data.page_data;
        this.cur_page = Number(res.data.page_now);
        this.total = Number(res.data.total_rows);
        console.log(this.evaluateListData);
      });
    },
    handleCurrentChange(val) {
      this.cur_page = val;
      this.getEvaluateListData();
    },
    //头像数据
    AvatarData() {
      let data = {
        user_id: this.user_id,
      };
      user_avatar(data).then((res) => {
        if (res.code == 1) {
          this.avatarList = res.data;
        }
      });
    },
  },
  mounted() {
    if (this.$route.params.id != "") {
      this.zz_id = this.$route.params.id;
      this.getDetailData();
      this.getEvaluateListData();
      this.getListData();

    }
  },
};
</script>

<style lang="scss" scoped>
.nicBaseInfo_action {
  // border: 1px solid red;
  width: 20%;
  font-size: 16px;
  font-weight: 400;
  text-align: left;
  color: #00a3ff;
  position: relative;
  .coverC {
    cursor: pointer;
  }
  .posiA {
    position: absolute;
    z-index: 12;
  }
  .posi1 {
    left: 80px;
    top: 50%;
    transform: translate(0, -50%);
  }

  .posi2 {
    margin: 0 2px;
    left: 40%;
    top: 50%;
    transform: translate(0, -50%);
  }

  .posi3 {
    left: 65%;
    top: 50%;
    transform: translate(0, -50%);
  }

  .posi4 {
    margin: 0 2px;
    left: 75%;
    top: 50%;
    transform: translate(0, -50%);
    // border: 1px solid red;
  }

  .zan {
    background: url("../assets/kczy/zanIcon.png") no-repeat left center;
    background-size: 21px 20px;
    box-sizing: border-box;
    padding: 3px 0 3px 25px;
    cursor: pointer;
  }

  .collect {
    background: url("../assets/kczy/collectIcon.png") no-repeat left center;
    background-size: 21px 20px;
    box-sizing: border-box;
    padding: 3px 0 3px 25px;
    margin-left: 30px;
    cursor: pointer;
  }
}
.el-rate {
  --el-rate-icon-size: 22px;
  margin-top: 15px;
}
.content {
  width: 100%;
  min-width: 1400px;
  margin: 0 auto;
  background-image: url("@/assets/img/zhjy/xq_bg.png");
  background-repeat: no-repeat;
}
.title {
  width: 100%;

  height: 60px;
  line-height: 60px;
  font-size: 18px;
  font-family: PingFangSC, PingFangSC-Regular;
  font-weight: 400;
  color: #050026;
  background: #ffffff;
  margin-bottom: 20px;
  box-shadow: 0px 1px 10px 0px rgba(17, 46, 74, 0.1);
  div {
    width: 1400px;

    margin: 0 auto;
    span:first-of-type {
      width: 56px;
      height: 20px;
      font-size: 14px;
      font-family: PingFangSC, PingFangSC-Regular;
      font-weight: 400;
      text-align: left;
      color: #949494;
      line-height: 20px;
      margin-left: 30px;
    }
    span:last-of-type {
      width: 56px;
      height: 20px;
      font-size: 14px;
      font-family: PingFangSC, PingFangSC-Regular;
      font-weight: 400;
      text-align: left;
      color: #000000;
      line-height: 20px;
    }
  }
}

.main {
  width: 1400px;
  margin: 0 auto;

  background: #ffffff;
  border-radius: 12px;
  padding: 30px;

  p {
    font-size: 20px;
    font-family: PingFangSC, PingFangSC-Semibold;
    font-weight: 600;
    text-align: left;
    color: #333333;
  }

  .jieshao {
    font-size: 16px;
    font-family: PingFang, PingFang-Medium;
    font-weight: 500;
    text-align: left;
    color: #333333;
    line-height: 31px;
    margin-bottom: 30px;
  }
}
.left {
  width: 700px;
  height: 100px;
  border-bottom: 1px solid #eeeeee;
  position: relative;
  .avatar {
    width: 75px;
    height: 77px;
    border-radius: 50%;
    display: inline-block;
  }
  .left-top {
    display: inline-block;
    width: 150px;
    height: 22px;

    margin-left: 10px;
    img {
      display: inline-block;
    }
    span:first-of-type {
      display: inline-block;
      width: 48px;
      height: 22px;
      font-size: 16px;
      font-family: PingFang, PingFang-Heavy;
      font-weight: 800;
      text-align: left;
      color: #000000;
      line-height: 22px;
      margin-right: 10px;
    }
    span:last-of-type {
      display: inline-block;
      width: 40px;
      height: 20px;
      font-size: 14px;
      font-family: PingFangSC, PingFangSC-Regular;
      font-weight: 400;
      text-align: left;
      color: #949494;
      line-height: 20px;
    }
  }
  .left-bottom {
    width: 150px;
    height: 22px;
    margin-left: 10px;
    position: absolute;
    bottom: 20px;
    left: 70px;
    span:first-of-type {
      display: inline-block;
      width: 63px;
      height: 23px;
      line-height: 23px;
      background: #190006;
      border: 1px solid #f1c342;
      border-radius: 12px;
      font-size: 12px;
      font-family: PingFangSC, PingFangSC-Regular;
      font-weight: 400;
      text-align: center;
      color: #ffffff;
    }
    span:last-of-type {
      display: inline-block;
      width: 63px;
      height: 24px;
      background: linear-gradient(90deg, #00a3ff 1%, #57c38f);
      border-radius: 12px;
      font-size: 14px;
      font-family: PingFangSC, PingFangSC-Regular;
      font-weight: 400;
      text-align: center;
      color: #ffffff;
      line-height: 24px;
      letter-spacing: 0.6px;
    }
  }
}
.right {
  height: 100px;
  line-height: 100px;
  .el-button {
    width: 100px;
    height: 40px;
    text-align: center;

    &.el-button--primary.is-plain {
      background: transparent;
      color: #409eff;
    }
  }
}
.docx {
  margin: 10px;
  div {
    display: inline-block;
    // width: 281px;
    height: 30px;
    background: rgba(#00a3ff, 0.1);
    border-radius: 15px;
    font-size: 14px;
    font-family: PingFangSC, PingFangSC-Regular;
    font-weight: 400;
    text-align: center;
    color: #00a3ff;
    line-height: 30px;
    margin-right: 10px;
  }
  span {
    display: inline-block;
    width: 56px;
    height: 20px;
    font-size: 14px;
    font-family: PingFangSC, PingFangSC-Regular;
    font-weight: 400;
    text-decoration: underline;
    text-align: left;
    color: #4d60fc;
    line-height: 20px;
    cursor: pointer;
  }
}

.tp_list {
  display: flex;
  flex-wrap: wrap;
  margin: 0 auto;
  padding: 0 200px;
  li {
    width: 250px;
    height: 250px;
    margin-right: 20px;
    img {
      width: 250px;
      height: 250px;
    }
  }
}
.pingjia {
  width: 1220px;
  height: 400px;
  padding: 30px 50px;
  border-top: 1px solid rgba(#00a3ff, 0.3);
  margin-top: 30px;
  .rateBtn {
    width: 111px;
    height: 32px;
    background: linear-gradient(90deg, #00a3ff 1%, #57c38f);
    border-radius: 38px;
    font-family: PingFangSC, PingFangSC-Regular;
    font-weight: 400;
    text-align: center;
    color: #ffffff;
    line-height: 32px;
    letter-spacing: 0.6px;
    margin-top: 15px;
    cursor: pointer;
  }
  .rate {
    // border: 1px solid red;
    height: 400px;
    overflow-y: scroll;
    .rate-list {
      width: 100%;
      height: 80px;
      padding: 15px;
      border-bottom: 1px dashed rgba(#6e58c5, 0.5);
      .rate-list-title {
        .rate-list-name {
          display: inline-block;
          font-size: 14px;
          font-family: PingFangSC, PingFangSC-Semibold;
          font-weight: 600;
          text-align: left;
          color: #171721;
          line-height: 18px;
          margin-right: 8px;
        }
        .rate-list-time {
          display: inline-block;

          font-size: 12px;
          font-family: PingFangSC, PingFangSC-Regular;
          font-weight: 400;
          text-align: left;
          color: #8083a3;
          line-height: 18px;
        }
      }
      .rate-list-star {
        .rate-list-img {
          display: inline-block;
          width: 21px;
          height: 20px;
          margin-left: 14px;
        }
      }
    }
  }
}
::-webkit-scrollbar {
  width: 0;
  height: 0;
  color: transparent;
}
.footer {
  width: 100%;
  height: 50px;
  margin-top: 100px;
  display: inline-block;
}
</style>

