<template>
  <div class="result" v-loading="loading">
    <Header :projectShow="true" />
    <div class="main">
      <div
        class="hanzi_list"
        :style="{
          overflowY: unfold ? 'scroll' : 'hidden',
        }"
      >
        <div class="top_jf">
          <div class="j_f">
            <div :class="[JFIndex == 0 ? 'sele' : '']" @click="jfEvent(0)">
              简
            </div>
            <div :class="[JFIndex == 1 ? 'sele' : '']" @click="jfEvent(1)">
              繁
            </div>
          </div>
        </div>
        <div
          class="list_one"
          v-for="(item, index) in ShowHzData"
          :key="'index' + index"
        >
          <Strockplayredline
            v-if="item.hzDetail.hz_json"
            :Book_text="JFIndex == 0 ? item.con : item.fanti"
            :playStorkes="true"
            :curItem="item.hzDetail"
            :targetDiv="'bwcHanziIntp' + index + item.con"
            :isHighlight="false"
            :judgeAnswer="2"
          />
          <div class="Highlight" v-if="item.hzDetail.hz_json">
            <div class="play_audio">
              <img src="../../assets/teacherdev/speaker-one.png" alt="" />
              <span>{{ item.pinyin }}</span>
            </div>
            <div
              v-for="(items, indexs) in item.hzDetail.hz_json.medians.length"
              :key="'row' + indexs"
              class="row"
            >
              <Strockplayredline
                :Book_text="JFIndex == 0 ? item.con : item.fanti"
                :playStorkes="false"
                :curItem="item.hzDetail"
                :targetDiv="'bwcHanziIntp_height' + index + item.con + indexs"
                :isHighlight="true"
                :judgeAnswer="indexs + 1"
              />
              <div class="number">{{ indexs + 1 }}</div>
            </div>
          </div>
        </div>

        <div class="shouqi">
          <span @click="updownHz">
            <template v-if="unfold">
              <img src="../../assets/teacherdev/up.png" alt="" />
              收起
            </template>
            <template v-else>
              <img src="../../assets/teacherdev/down.png" alt="" />
              展开
            </template>
          </span>
        </div>
      </div>
      <div class="txt_imgtable">
        <div class="left">
          <div class="top">
            <div class="pattern">
              <div
                :class="[patternIndex == 0 ? 'sele' : '']"
                @click="cutPattern(0)"
              >
                引语模式
              </div>
              <div
                :class="[patternIndex == 1 ? 'sele' : '']"
                @click="cutPattern(1)"
              >
                KWIC模式
              </div>
            </div>
            <div class="lang_sort">
              长度
              <img src="" alt="" />
            </div>
            <div class="refresh">
              <img src="../../assets/teacherdev/refresh.png" alt="" />
            </div>
            <el-switch
              v-model="pinyinShow"
              active-text="拼音"
              active-color="#424242"
              style="margin-left: 32px"
            >
            </el-switch>
            <el-switch
              v-model="shiyiShow"
              active-text="释义"
              active-color="#424242"
              style="margin-left: 16px"
            >
            </el-switch>
          </div>
        </div>
        <div class="right">
          <div class="top">
            <div>
              <div
                :class="[rightTopIndex == 0 ? 'sele' : '']"
                @click="cutsyly(0)"
              >
                释义
              </div>
              <div
                :class="[rightTopIndex == 1 ? 'sele' : '']"
                @click="cutsyly(1)"
              >
                来源
              </div>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
//这里可以导入其它文件（比如：组件，工具js，第三方插件js，json文件，图片文件等等）
//例如：import 《组件名称》from ‘《组件路径》';
import Header from "@/components/Header";
import { getLogin } from "@/api/api";
import Strockplayredline from "@/components/corpus/Strockplayredline";
import "@/utils/pinyin_dict_withtone";
import "@/utils/pinyinUtil";
import seekWord from "@/utils/lang.js";
const OpenCC = require("opencc-js");
const converter = OpenCC.Converter({ from: "cn", to: "tw" });
export default {
  //import引入的组件需要注入到对象中才能使用
  components: {
    Header,
    Strockplayredline,
  },
  props: {},
  data() {
    //这里存放数据
    return {
      shiyiShow: false,
      pinyinShow: false,
      JFIndex: 0,
      hzData: [],
      ShowHzData: [],
      loading: true,
      lang: null,
      unfold: true,
      patternIndex: 0,
      rightTopIndex: 0,
      rightList: [
        {
          name: "",
          value: "",
          ratio: "",
        },
      ],
    };
  },
  //计算属性 类似于data概念
  computed: {},
  //监控data中数据变化
  watch: {},
  //方法集合
  methods: {
    // 切换模式
    cutPattern(index) {
      this.patternIndex = index;
    },
    // 切换释义来源
    cutsyly(index) {
      this.rightTopIndex = index;
    },
    updownHz() {
      this.unfold = !this.unfold;
      if (this.unfold) {
        this.ShowHzData = JSON.parse(JSON.stringify(this.hzData));
      } else {
        this.ShowHzData.splice(2);
      }
    },
    jfEvent(index) {
      this.JFIndex = index;
      if (index == 0) {
        //简体
      } else {
        //繁体
        this.hzData.forEach((item) => {
          // let a = seekWord(item.con);
          // item.fanti = a;
          let a = converter(item.con);
          item.fanti = a;
        });
        this.gethzJSON();
      }
    },
    // 获取汉字josn
    gethzJSON() {
      this.loading = true;
      let MethodName = "hz_resource_manager-GetHZStrokesContent";
      this.hzData.forEach((item, i) => {
        let data = {
          hz: this.JFIndex == 0 ? item.con : item.fanti,
        };
        item.hzDetail = {
          hz_json: null,
        };
        this.$forceUpdate();
        getLogin(MethodName, data)
          .then((res) => {
            this.$set(item.hzDetail, "hz_json", res);
            this.$forceUpdate();
            this.ShowHzData = JSON.parse(JSON.stringify(this.hzData));
            if (i == this.hzData.length - 1) {
              this.loading = false;
            }
          })
          .catch(() => {
            this.loading = false;
          });
      });
    },
  },
  //生命周期 - 创建完成（可以访问当前this实例）
  created() {
    if (this.$route.query.keyword) {
      let arr = this.$route.query.keyword.split("");
      arr.forEach((item) => {
        let result = pinyinUtil.getPinyin(item);
        let obj = {
          con: item,
          pinyin: result,
          hzDetail: {
            hz_json: null,
          },
        };
        this.hzData.push(obj);
        this.ShowHzData = JSON.parse(JSON.stringify(this.hzData));
      });
      this.gethzJSON();
    }
  },
  //生命周期 - 挂载完成（可以访问DOM元素）
  mounted() {},
  //生命周期-创建之前
  beforeCreated() {},
  //生命周期-挂载之前
  beforeMount() {},
  //生命周期-更新之前
  beforUpdate() {},
  //生命周期-更新之后
  updated() {},
  //生命周期-销毁之前
  beforeDestory() {},
  //生命周期-销毁完成
  destoryed() {},
  //如果页面有keep-alive缓存功能，这个函数会触发
  activated() {},
};
</script>
<style lang="scss" scoped>
/* @import url(); 引入css类 */
.result {
  min-height: 100%;
  .main {
    min-height: 100%;
    background: #f2f2f2;
    padding-top: 33px;
    padding-bottom: 66px;
  }
  .hanzi_list {
    width: 1120px;
    max-height: 858px;
    margin: 0 auto;
    background: #ffffff;
    border-radius: 8px;
    padding: 40px;
    .top_jf {
      width: 128px;
    }
    .j_f {
      display: flex;
      width: 60px;
      height: 24px;
      margin-bottom: 16px;
      margin-left: 33px;
      > :nth-child(1) {
        border-top-left-radius: 2px;
        border-bottom-left-radius: 2px;
        border-right: none;
      }
      > :nth-child(2) {
        border-top-right-radius: 2px;
        border-bottom-right-radius: 2px;
        border-left: none;
      }
      div {
        width: 30px;
        height: 24px;
        font-weight: 400;
        font-size: 14px;
        line-height: 24px;
        text-align: center;
        color: #de4444;
        cursor: pointer;
        border: 2px solid #de4444;
      }
      .sele {
        color: #ffffff;
        background: #de4444;
      }
    }
    .list_one {
      margin-bottom: 20px;
      display: flex;
      align-items: flex-start;
      .Highlight {
        flex: 1;
        margin-left: 22px;
        display: flex;
        flex-wrap: wrap;
        .play_audio {
          width: 100%;
          display: flex;
          align-items: center;
          margin-bottom: 13px;
          img {
            width: 16px;
            height: 16px;
            cursor: pointer;
          }
          span {
            font-family: "GB-PINYINOK-B";
            font-weight: 400;
            font-size: 12px;
            margin-left: 5px;
            color: #000000;
          }
        }
      }
      .row {
        margin-right: 8px;
        margin-bottom: 8px;
        .number {
          margin-top: 9px;
          width: 64px;
          height: 20px;
          background: #e9e9e9;
          border-radius: 22px;
          text-align: center;
          line-height: 20px;
        }
      }
    }
    .shouqi {
      margin-top: 21;
      display: flex;
      justify-content: flex-end;
      span {
        cursor: pointer;
        display: flex;
        align-items: center;
      }
      img {
        width: 24px;
        height: 24px;
        margin-right: 4px;
      }
    }
  }
  .txt_imgtable {
    width: 1200px;
    margin: 0 auto;
    margin-top: 8px;
    display: flex;
    .left {
      width: 562px;
      background: #ffffff;
      border-bottom: 1px solid rgba(0, 0, 0, 0.08);
      border-radius: 8px;
      margin-right: 8px;
      .top {
        border-bottom: 1px solid rgba(0, 0, 0, 0.08);
        height: 44px;
        display: flex;
        align-items: center;
        font-weight: 400;
        font-size: 12px;
        .pattern {
          margin-left: 16px;
          width: 144px;
          height: 28px;
          background: #eeeeee;
          border-radius: 4px;
          display: flex;
          justify-content: center;
          align-items: center;
          > div {
            width: 64px;
            height: 24px;
            text-align: center;
            line-height: 24px;
            color: #888888;
            cursor: pointer;
            font-weight: 400;
            font-size: 12px;
            border-radius: 2px;
          }
          .sele {
            background: #ffffff;
            box-shadow: 0px 2px 2px rgba(0, 0, 0, 0.08);
            color: #000000;
          }
        }
        .lang_sort {
          width: 54px;
          height: 28px;
          background: #eeeeee;
          border-radius: 4px;
          margin-left: 24px;
          display: flex;
          justify-content: center;
          align-items: center;
        }
        .refresh {
          width: 28px;
          height: 28px;
          background: #eeeeee;
          border-radius: 4px;
          display: flex;
          justify-content: center;
          align-items: center;
          margin-left: 8px;
          cursor: pointer;
          img {
            width: 16px;
            height: 16px;
          }
        }
      }
    }
    .right {
      width: 630px;
      height: 100px;
      background: #ffffff;
      border-bottom: 1px solid rgba(0, 0, 0, 0.08);
      border-radius: 8px;
      .top {
        border-bottom: 1px solid rgba(0, 0, 0, 0.08);
        height: 44px;
        display: flex;
        align-items: center;
        > div {
          margin-left: 16px;
          width: 84px;
          height: 28px;
          background: #eeeeee;
          border-radius: 4px;
          display: flex;
          justify-content: center;
          align-items: center;
          > div {
            border-radius: 2px;
            width: 40px;
            height: 24px;
            text-align: center;
            line-height: 24px;
            color: #888888;
            cursor: pointer;
            font-weight: 400;
            font-size: 12px;
          }
          .sele {
            background: #ffffff;
            box-shadow: 0px 2px 2px rgba(0, 0, 0, 0.08);
            color: #000000;
          }
        }
      }
    }
  }
}
</style>
<style lang="scss">
.result {
  .el-switch__core {
    width: 26px !important;
    height: 16px;
  }
  .el-switch__core:after {
    width: 8px;
    height: 8px;
    top: 2px;
  }
  .el-switch.is-checked .el-switch__core::after {
    margin-left: -10px;
  }
}
</style>