<template>
  <common-header />
  <div class="content">
    <div class="title">
      <div class="big">
        <div class="left">
          详情 <span>智慧教研-自主研学-</span><span>详情</span>
        </div>
        <div class="right" @click="goBack()">返回</div>
      </div>
    </div>
    <div class="main">
      <p class="top-title">{{ detailData.zz_name }}</p>

      <div class="vedioMainContent_left_top">
        <div class="nicBaseInfo_avator">
          <el-avatar
            :src="userInfoData.user_avatar"
            v-if="userInfoData.user_avatar"
          />
          <el-avatar
            src="https://cube.elemecdn.com/0/88/03b0d39583f48206768a7534e55bcpng.png"
            v-else
          />
        </div>
        <div class="nicBaseInfo_text">
          <div class="nicBaseInfo_text_top" style="height: 50%">
            <span class="fir">{{ detailData.zz_jsxx }}</span>
            <span class="middle"
              ><img src="@/assets/kczy/fireIcon.png" alt=""
            /></span>
            <span class="sec" v-if="userInfoData.ext">{{
              userInfoData.ext.ue_hot
            }}</span>
          </div>
          <div class="nicBaseInfo_text_bottom" style="height: 50%">
            <span class="markLableOne">金牌讲师</span>
            <span class="markLableTwo">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="nicBaseInfo_forceBtn">
          <div
            v-if="detailData.is_watch == 1"
            @click="delFollow(detailData.create_user_id)"
          >
            已关注
          </div>
          <div v-else @click="toFollow(detailData.create_user_id)">关注</div>
        </div>
      </div>
      <div class="flex justify-start">
        <div>
          <div
            class="docx mb-10px"
            v-for="(n, index) in filePathName"
            :key="index"
          >
            <a target="_blank">{{ n }}</a>
          </div>
        </div>
        <div>
          <div class="docx mb-10px" v-for="(f, index) in filePath" :key="index">
            <a class="down" :href="https + f" target="_blank"> 下载附件</a>
          </div>
        </div>
      </div>
      <p
        class="jieshao w-full min-h-65vh"
        v-for="(f, fi) in filePath"
        :key="fi"
      >
        <iframe
          v-if="typeKind[fi] == 'pdf' || typeKind[fi] == 'mp3'"
          class="w-full min-h-65vh"
          :src="https + f"
        ></iframe>
        <iframe
          v-else
          class="w-full min-h-65vh"
          :src="
            'https://view.officeapps.live.com/op/view.aspx?src=' + https + f
          "
        ></iframe>
      </p>
      <div class="pingjia">
        <el-rate v-model="pjInfo.ke_star"></el-rate>
        <button
          :disabled="disabled"
          :class="disabled ? 'add-gray' : 'rateBtn'"
          @click="formSubmit(detailData.zz_id)"
        >
          评价
        </button>
        <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>
  <common-footer />
</template>

<script>
import { getFullUrl } from "~/utils/helper";
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,
  userInfoDetail,
} from "./api";
import { download } from "~/utils/request";
import CommonHeader from "@/components/CommonHeader/index.vue";
import CommonFooter from "@/components/CommonFooter/index.vue";
import FilePreview from "@/components/FilePreview/index.vue";
import { user } from "@/store/user.js";
export default {
  name: "index",
  components: {
    CommonHeader,
    CommonFooter,
    download,
    FilePreview,
  },
  data() {
    return {
      userInfoData: {},
      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: "",
      disabled: false,
      filePathName: "",
      filePath: "",
      typeKind: [],
    };
  },
  methods: {
    goBack() {
      this.$router.go(-1);
    },
    initUserInfoDetail() {
      let transObj = {
        token: user?.token,
        user_id: user.user_id,
      };
      userInfoDetail(transObj)
        .then((res) => {
          if (res.code == "1") {
            this.userInfoData = res.data;
          }
        })
        .catch((error) => {
          console.log(error);
        });
    },
    //关注or已关注
    toFollow(e) {
      console.log(e, 123);
      let data = {
        site: "tyyx",
        issubmit: "1",
        user_watch: {
          uw_user_id: e,
        },
      };
      zxxx_attention_add(data).then((res) => {
        if (res.code == "1") {
          ElMessage({
            message: "关注成功!",
            type: "success",
          });
          this.detailData.is_watch = 1;
        }
      });
    },
    delFollow(e) {
      let data = {
        site: "tyyx",
        uw_user_id: e,
      };
      zxxx_attention_del(data).then((res) => {
        if (res.code == "1") {
          ElMessage({
            message: "已取消关注!",
            type: "success",
          });
          this.detailData.is_watch = 0;
        }
      });
    },
    /**增加赞或取消*/
    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);
          });
      } 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);
          });
      }
    },
    /**增加收藏或取消*/
    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);
          });
      }
    },

    getDetailData() {
      let data = {
        zz_id: this.zz_id,
      };
      zxxx_detail(data).then((res) => {
        this.detailData = res.data.one_info;
        this.filePath = this.detailData.zz_fj.split(";");
        this.filePath.map((item) => {
          console.log(item, 444);
          let a = item.substr(item.lastIndexOf(".") + 1);
          this.typeKind.push(a);
        });
        console.log(this.filePath, this.typeKind, 111);
        this.filePathName = this.detailData.zz_fj_name.split("|");
        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: user.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();
          this.pjInfo.ke_star = "";
          this.$forceUpdate(); //强制刷新
        }
      });
    },
    //评价列表
    getEvaluateListData() {
      let data = {
        kk_id: this.zz_id,
        kf_id: this.kf_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);
        if (res.template.check_myexist == 1) {
          this.disabled = true;
        }
      });
    },
    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.initUserInfoDetail();
    }
  },
};
</script>

<style lang="scss" scoped>
.el-button {
  background: #0083c5;
  color: #fff;
}
.nicBaseInfo_action {
  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%);
  }

  .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);

  .big {
    display: flex;
    justify-content: space-between;
    width: 1400px;
    margin: 0 auto;
    padding-right: 30px;
    .left {
      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;
      }
    }
    .right {
      width: 100px;
      height: 40px;
      background: rgba(0, 163, 255, 0.8);
      border-radius: 6px;
      font-size: 14px;
      font-family: PingFang SC, PingFang SC-Regular;
      font-weight: 400;
      text-align: center;
      color: #ffffff;
      line-height: 40px;
      margin-top: 10px;
    }
  }
}

.main {
  width: 1400px;
  margin: 0 auto;
  background: #ffffff;
  border-radius: 12px;
  padding: 30px;

  .top-title {
    font-size: 20px;
    font-family: PingFangSC, PingFangSC-Semibold;
    font-weight: 600;
    text-align: left;
    color: #333333;
    word-wrap: break-word;
    text-overflow: ellipsis;
    display: -webkit-box;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 1;
    overflow: hidden;
  }

  .jieshao {
    font-size: 16px;
    font-family: PingFang, PingFang-Medium;
    font-weight: 500;
    text-align: left;
    color: #333333;
    line-height: 31px;
    margin-bottom: 30px;
  }
}
.vedioMainContent_left_top {
  display: flex;
  height: 100px;
  background: #ffffff;
  border-radius: 10px;
  box-shadow: 2px 10px 24px 0px rgba(161, 153, 168, 0.18);
  margin-bottom: 10px;
  justify-content: space-between;

  .nicBaseInfo_avator {
    width: 10%;
    line-height: 100px;
    position: relative;

    span {
      width: 77px;
      height: 77px;
      border-radius: 50%;
      display: inline-block;
      background-color: #cacaca;
      position: absolute;
      left: 50%;
      top: 50%;
      z-index: 13;
      transform: translate(-50%, -50%);
    }
  }

  .nicBaseInfo_text {
    width: 50%;

    .nicBaseInfo_text_top {
      line-height: 70px;
      display: flex;

      span.middle {
        display: inline-block;
        margin-left: 10px;
        margin-right: 3px;
        box-sizing: border-box;
        padding-top: 4%;

        img {
          width: 19px;
          height: 22px;
        }
      }

      span.fir {
        font-size: 16px;
        font-weight: 800;
        text-align: left;
        color: #000000;
      }

      span.sec {
        font-size: 14px;
        font-weight: 400;
        text-align: left;
        color: #949494;
        background: url("../assets/images/kczy/fireIcon1.png");
        background-size: 100% 100%;
      }
    }

    .nicBaseInfo_text_bottom {
      line-height: 30px;

      .markLableOne {
        background: #190006;
        border: 1px solid #f1c342;
        border-radius: 12px;
        font-size: 12px;
        font-weight: 400;
        text-align: center;
        color: #ffffff;
        padding: 5px 8px;
        margin-right: 10px;
      }

      .markLableTwo {
        background: linear-gradient(90deg, #00a3ff 1%, #57c38f);
        border-radius: 12px;
        font-size: 12px;
        font-weight: 400;
        text-align: center;
        color: #ffffff;
        padding: 5px 8px;
      }
    }
  }

  .nicBaseInfo_action {
    width: 30%;
    font-size: 16px;
    font-weight: 400;
    text-align: left;
    color: #00a3ff;
    position: relative;

    .coverC {
      cursor: pointer;
    }

    .posiA {
      position: absolute;
      z-index: 12;
    }

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

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

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

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

    .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;
    }
  }

  .nicBaseInfo_forceBtn {
    width: 10%;
    text-align: left;
    position: relative;
    div {
      position: absolute;
      right: 43%;
      top: 50%;
      transform: translate(0, -50%);
      width: 100px;
      height: 40px;
      font-size: 16px;
      font-weight: 400;
      text-align: center;
      color: #ffffff;
      background: rgba(0, 131, 197, 0.8);
      border-radius: 6px;
      padding: 7px 20px;
      cursor: pointer;
    }
  }
}

.docx {
  a {
    display: inline-block;
    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;
  }
  .down {
    display: inline-block;
    width: 56px;
    height: 30px;
    font-size: 14px;
    font-family: PingFangSC, PingFangSC-Regular;
    font-weight: 400;
    text-decoration: underline;
    text-align: left;
    color: #4d60fc;
    line-height: 30px;
    cursor: pointer;
    background: transparent;
  }
}

.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;
  }
  .add-gray {
    width: 111px;
    height: 32px;
    background: #ccc;
    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 {
    height: 300px;
    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;
}
.z-footer {
  width: 100%;
  height: 50px;
  margin-top: 100px;
  display: inline-block;
}
</style>

