<template>
  <!-- 项目活动过程 -->
  <div class="pb_content">
    <div class="race_content_body">
      <div class="raceBox">
        <div class="stepBg">
          <div
            class="steps"
            v-for="(sta, staIndex) in raceAct.stageBox"
            :key="staIndex"
          >
            <div>
              <img src="../../../../assets/icon/race/progress.png" alt="" />
            </div>
            <div class="stepRightNav" @click="jump('jd' + staIndex + 1)">
              <div>阶段{{ staIndex + 1 }}</div>
              <div class="isFinishCss" v-if="sta.brief != ''">
                <div class="isFinish">
                  <img src="../../../../assets/icon/race/finish.png" alt="" />
                </div>
                <div>已填写</div>
              </div>
            </div>
          </div>
        </div>
        <div class="right">
          <div
            v-for="(sa, saIndex) in raceAct.stageBox"
            :key="saIndex"
            :id="'jd' + saIndex + 1"
          >
            <div class="right_title">阶段{{ saIndex + 1 }}</div>
            <div class="saBox">
              <div class="saLittleBox">
                <div style="position: relative">
                  <editor-bar
                    v-model="sa.brief"
                    @change="upRaceAct"
                  ></editor-bar>
                  <div
                    class="fullCss"
                    @click="fullTools(sa.brief, 1, '', saIndex)"
                  >
                    全屏编辑
                  </div>
                </div>
                <div>
                  <div class="basic_box">
                    <div>
                      <div
                        class="add_chapters_box"
                        v-if="sa.data && sa.data.length == 0"
                      ></div>
                      <div
                        v-else
                        class="add_chapters_box"
                        style="display: flex; flex-direction: column"
                      >
                        <div
                          class="chapter_upload"
                          v-for="(item, index) in sa.data"
                          :key="item.id"
                        >
                          <div class="chapter_upload_t"></div>
                          <div class="chapter_upload_o">
                            <div class="chapter_upload_l">
                              <div
                                v-if="item.type == 2"
                                class="chapter_upload_l_i1"
                              ></div>
                              <div
                                v-if="item.type == 1 || item.type == 3"
                                class="chapter_upload_l_i5"
                              ></div>
                            </div>
                            <div class="chapter_upload_ic">
                              <div class="chapter_upload_ic_l"></div>
                              <div
                                class="chapter_upload_ic_r"
                                @click.stop="
                                  deleteChapterData($event, saIndex, index)
                                "
                              >
                                <div></div>
                              </div>
                            </div>
                            <div class="chapter_upload_n">
                              <input
                                class="first"
                                v-if="item.type == 1 || item.type == 3"
                                :placeholder="item.name"
                              />
                              <input
                                class="first"
                                v-if="item.type == 2"
                                :placeholder="item.name"
                              />
                              <div class="chapter_upload_ud">
                                <div class="chapter_upload_up"></div>
                                <div class="chapter_upload_down"></div>
                              </div>
                            </div>
                          </div>
                        </div>
                      </div>
                    </div>
                    <div class="add_info_box">
                      <div class="upTips">
                        <button class="info_btn" @click="addImg($event)">
                          上传附件
                          <input
                            type="file"
                            accept="application/pdf, application/.ppt, .ppt, .pptx, .xlsx, .xls, application/msword, application/vnd.openxmlformats-officedocument.wordprocessingml.document,video/mp4, video/quicktime, video/x-msvideo,image/*"
                            style="display: none"
                            @change="beforeUpload($event, null, saIndex)"
                          />
                        </button>
                        <div>
                          上传文件PPT、Word大小限制为10M，Excel、PDF上传大小限制为5M，其他文件不限制大小。
                        </div>
                      </div>
                    </div>
                    <div v-if="sa.data.proVisible" class="mask">
                      <div class="progressBox">
                        <div class="lbox">
                          <img
                            src="../../../../assets/loading.gif"
                          />上传中，请稍后
                        </div>
                        <el-progress
                          :text-inside="true"
                          :stroke-width="20"
                          :percentage="sa.data.progress ? sa.data.progress : 0"
                          style="width: 80%"
                        ></el-progress>
                      </div>
                    </div>
                  </div>
                </div>
              </div>
            </div>
          </div>
        </div>
      </div>
    </div>
    <el-dialog
      title="编辑富文本"
      :visible.sync="full"
      :append-to-body="true"
      width="100%"
      :before-close="handleClose"
      class="dialog_diy fullEditor"
    >
      <editor-bar v-model="fullBrief" :placeholder="plaText"></editor-bar>
      <span slot="footer" class="dialog-footer">
        <el-button @click="full = false">取 消</el-button>
        <el-button type="primary" @click="addFullText">确定</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
import EditorBar from "../../../tools/wangEnduit";
export default {
  components: { EditorBar },
  props: ["raceProcess"],
  data() {
    return {
      raceAct: {
        stageBox: [
          {
            staTitle: "",
            allTime: "",
            brief: "",
            data: [],
            actBox: [
              {
                actName: "",
                actTime: "",
                driQuestion: { brief: "", data: [] },
                tarDesign: { brief: "", data: [] },
                actiDesign: { brief: "", data: [] },
                evaDesign: { brief: "", data: [] },
              },
            ],
          },
        ],
      },
      fullBrief: "",
      plaText: "",
      isBrief: 0,
      full: false,
      jdIndex: 0,
      stage: 0,
    };
  },
  methods: {
    upRaceAct() {
      this.$emit("upRaceAct", this.raceAct);
    },
    handleClose(done) {
      done();
    },
    addImg(e) {
      var el = e.currentTarget;
      el.getElementsByTagName("input")[0].click();
    },
    jump(t) {
      var a = document.getElementById(t);
      var b = document.getElementsByClassName("right")[0];
      b.scrollTop = a.offsetTop;
    },
    imgChange(file, fileList, type, sindex) {
      var _tmp = this.raceAct.stageBox[sindex].data;
      this.noneBtnImg = _tmp.length >= 1;
    },
    deleteChapterData(e, si, i) {
      e.stopPropagation();
      this.raceAct.stageBox[si].data.splice(i, 1);
      this.upRaceAct();
    },
    beforeUpload(event, type, sindex) {
      var file = event.target.files[0];
      var credentials = {
        accessKeyId: "AKIATLPEDU37QV5CHLMH",
        secretAccessKey: "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",
      }; //秘钥形式的登录上传
      window.AWS.config.update(credentials);
      window.AWS.config.region = "cn-northwest-1"; //设置区域
      var type1 = type;
      var bucket = new window.AWS.S3({ params: { Bucket: "ccrb" } }); //选择桶
      var _this = this;
      var b = [
        "DOC",
        "DOCX",
        "DOCM",
        "DOTM",
        "DOTX",
        "PPTX",
        "PPSX",
        "PPT",
        "PPS",
        "PPTM",
        "POTM",
        "PPAM",
        "POTX",
        "PPSM",
      ];
      var c = ["PDF", "DOT", "DOC", "DOCX", "PPT", "PPTX", "XLSX", "XLS"];
      var d = [
        "BMP",
        "PJP",
        "APNG",
        "PNG",
        "JPG",
        "GIF",
        "SVG",
        "JPEG",
        "JPG",
        "ICO",
        "PGPEG",
        "AVIF",
      ];
      if (
        b.indexOf(
          file.name
            .split(".")
            [file.name.split(".").length - 1].toLocaleUpperCase()
        ) != -1
      ) {
        if (file.size / 1024 / 1024 > 10) {
          this.$message.error("上传文件大于10M，请重新选择文件！");
          return;
        }
      } else if (
        c.indexOf(
          file.name
            .split(".")
            [file.name.split(".").length - 1].toLocaleUpperCase()
        ) != -1
      ) {
        if (file.size / 1024 / 1024 > 5) {
          this.$message.error("添加的上传文件大于5M，请重新选择文件！");
          return;
        }
      }

      if (
        c.indexOf(
          file.name
            .split(".")
            [file.name.split(".").length - 1].toLocaleUpperCase()
        ) != -1
      ) {
        type1 = 1;
      } else if (
        d.indexOf(
          file.name
            .split(".")
            [file.name.split(".").length - 1].toLocaleUpperCase()
        ) != -1
      ) {
        type1 = 3;
      } else {
        type1 = 2;
      }

      _this.raceAct.stageBox[sindex].data.progress = 0;
      _this.raceAct.stageBox[sindex].data.proVisible = true;
      _this.$forceUpdate();
      if (file) {
        var params = {
          Key:
            file.name.split(".")[0] +
            new Date().getTime() +
            "." +
            file.name.split(".")[file.name.split(".").length - 1],
          ContentType: file.type,
          Body: file,
          "Access-Control-Allow-Credentials": "*",
          ACL: "public-read",
        }; //key可以设置为桶的相抵路径，Body为文件， ACL最好要设置
        var options = {
          partSize: 2048 * 1024 * 1024,
          queueSize: 2,
          leavePartsOnError: true,
        };
        bucket
          .upload(params, options)
          .on("httpUploadProgress", function (evt) {
            //这里可以写进度条
            // console.log("Uploaded : " + parseInt((evt.loaded * 80) / evt.total) + '%');
            _this.raceAct.stageBox[sindex].data.progress = parseInt(
              (evt.loaded * 80) / evt.total
            );
          })
          .send(function (err, data) {
            _this.raceAct.stageBox[sindex].data.progress = 100;
            setTimeout(() => {
              _this.raceAct.stageBox[sindex].data.proVisible = false;
              _this.$forceUpdate();
            }, 1000);
            if (err) {
              _this.$message.error("上传失败");
            } else {
              _this.raceAct.stageBox[sindex].data.push({
                name: file.name,
                url: data.Location,
                type: type1,
              });
              _this.imgChange(null, null, type1, sindex);
              _this.upRaceAct();
              console.log(data.Location);
            }
          });
      }
    },
    fullTools(b, t, text,i) {
      this.fullBrief = b;
      this.isBrief = t;
      this.plaText = text;
      this.jdIndex = i;
      this.full = !this.full;
    },
    addFullText() {
      if (this.isBrief == 1) {
        this.raceAct.stageBox[this.jdIndex].brief = this.fullBrief;
      } else if (this.isBrief == 2) {
        this.raceAct.stageBox[this.jdIndex].brief = this.fullBrief;
      } else if (this.isBrief == 3) {
        this.raceAct.stageBox[this.jdIndex].brief = this.fullBrief;
      } else if (this.isBrief == 4) {
        this.raceAct.stageBox[this.jdIndex].brief = this.fullBrief;
      }
      this.isBrief = 0;
      this.fullBrief = "";
      this.plaText = "";
      this.jdIndex = 0;
      this.full = !this.full;
      this.upRaceAct();
    },
  },
  created() {
    this.raceAct = this.raceProcess;
  },
};
</script>

<style scoped>
@media screen and (max-width: 1280px) {
  .right_title {
    padding: 20px 0 20px 10px !important;
  }
  .saLittleBox {
    padding: 20px 0 10px 10px !important;
  }
  .upTips {
    align-items: flex-start !important;
  }
  .fullCss {
    right: 1% !important;
  }
  .fullEditor >>> .el-dialog__footer {
    padding: 4% 20px 20px !important;
  }
}
.dialog_diy >>> .el-dialog__header {
  background: #3c3c3c !important;
  padding: 15px 20px;
}
.dialog_diy >>> .el-dialog__title {
  color: #fff;
}
.pb_content {
  width: 100%;
  height: 100%;
}
.race_content_body {
  width: 100%;
  position: relative;
  margin: 0;
  height: 100%;
}

.raceBox {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: row;
  flex-wrap: nowrap;
  align-items: flex-start;
}

.stepBg {
  padding: 80px 0 0 0;
  margin: 0 25px 0 0;
  width: 20%;
  display: flex;
  justify-content: flex-start;
  align-items: center;
  flex-wrap: nowrap;
  background: #fff;
  /* min-height: 800px; */
  height: calc(100% - 80px);
  border-radius: 15px;
  overflow: auto;
  min-width: 260px;
  flex-direction: column;
  font-size: 14px;
}
.steps {
  display: flex;
  flex-direction: row;
  flex-wrap: nowrap;
  position: relative;
  width: 145px;
  height: 130px;
}
.steps > div:nth-child(1) > img {
  z-index: 9;
  position: relative;
}
.stepRightNav {
  display: flex;
  flex-direction: column;
  flex-wrap: nowrap;
  justify-content: space-between;
  align-items: flex-start;
  margin: 8px 0 0 10px;
  height: 40px;
  cursor: pointer;
}
.stepRightNav:hover {
  color: #999;
}
.stepBg .steps::after {
  content: "";
  height: 100%;
  background: #eee;
  width: 4px;
  position: absolute;
  left: 15px;
  top: calc(50% + (35px / 2));
  transform: translateY(-50%);
  z-index: 1;
}

.right {
  width: calc(100% - 20%);
  background: rgb(255, 255, 255);
  border-radius: 10px;
  overflow: auto;
  height: 100%;
  border-radius: 15px;
  overflow-x: hidden;
  /* max-height: 800px; */
}
.basic_box {
  position: relative;
  margin: 0;
  min-height: 0;
  width: 90%;
}
.add_info_box {
  margin: 20px 0;
}

.add_info_box button {
  margin: 0 10px 10px 0;
}

.add_chapters_box {
  text-align: left;
  background-color: rgb(232 234 237);
  width: 100%;
  padding: 0px 15px;
  border-radius: 15px;
  font-size: 16px;
  box-sizing: border-box;
  position: relative;
  padding: 0 10px 5px 10px;
  height: 125px;
  overflow-y: auto;
  overflow-x: hidden;
}

.chapter_upload {
  height: 50px;
  margin-top: 8px;
  position: relative;
  display: flex;
  align-items: center;
  width: 100%;
  min-height: 50px;
}

.chapter_upload_t {
  background-color: #fff;
  position: absolute;
  height: 100%;
  top: 0px;
  left: 0px;
  border-radius: 40px;
  box-sizing: border-box;
  box-shadow: 0 0 3px 3px #dfdfdf;
  width: 100%;
}

.chapter_upload_o {
  width: 100%;
  height: 100%;
  position: relative;
  z-index: 1;
  display: flex;
  align-items: center;
}

.chapter_upload_ic {
  height: 30px;
  float: right;
  cursor: pointer;
  position: absolute;
  width: 45px;
  right: 0;
  top: 0;
}

.chapter_upload_ic_l {
  width: 50px;
  height: 50px;
  float: left;
}

.chapter_upload_ic_l div {
  width: 30px;
  height: 35px;
  background: url("../../../../assets/icon/icon.png");
}

.chapter_upload_ic_r {
  width: 50px;
  height: 50px;
  float: left;
  margin-left: 0px;
  display: flex;
  align-items: center;
  position: absolute;
}

.chapter_upload_ic_r div {
  width: 25px;
  height: 25px;
  background-image: url("../../../../assets/delete.png");
  background-size: 100% 100%;
}

.chapter_upload_n {
  display: flex;
  text-indent: 10px;
  text-decoration: none;
  text-overflow: ellipsis;
  white-space: nowrap;
  overflow: hidden;
  width: 55%;
  margin-left: 10px;
  cursor: pointer;
  margin-top: 2px;
}

.chapter_upload_l_i1 {
  background-image: url("../../../../assets/icon/video.png");
  width: 28px;
  height: 28px;
  background-size: 100% 100%;
}

.chapter_upload_l_i5 {
  background-image: url("../../../../assets/icon/word.png");
  width: 24px;
  height: 24px;
  background-size: 100% 100%;
  margin-left: 1px;
}

.chapter_upload_l_i8 {
  background-image: url("../../../../assets/icon/line.png");
  width: 24px;
  height: 24px;
  background-size: 100% 100%;
  margin-left: 1px;
}

.chapter_upload_ud {
  display: flex;
  flex-direction: column;
  margin-left: 5px;
  justify-content: center;
  z-index: 99;
}

.chapter_upload_up {
  background-image: url("../../../../assets/icon/up.png");
  width: 17px;
  height: 15px;
  background-size: 100% 100%;
  cursor: pointer;
}

.chapter_upload_down {
  background-image: url("../../../../assets/icon/down.png");
  width: 17px;
  height: 15px;
  margin: 2px auto 0 auto;
  background-size: 100% 100%;
  cursor: pointer;
}

.chapter_upload_l {
  padding: 1px 0 0 10px;
}

.first {
  border: none;
  outline: none;
  width: 80%;
  min-width: 215px;
  z-index: 99;
  font-size: 14px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.info_btn {
  color: #fff;
  background-color: #0f7eff;
  padding: 8px 24px;
  font-size: 0.9375rem;
  box-shadow: 0px 1px 3px 0px rgb(0 0 0 / 20%), 0px 2px 2px 0px rgb(0 0 0 / 14%),
    0px 3px 1px -2px rgb(0 0 0 / 12%);
  min-width: 64px;
  font-weight: 500;
  border-radius: 4px;
  box-sizing: border-box;
  border: none;
  cursor: pointer;
}

.info_btn:hover {
  background-color: #4f7cd5 !important;
}
.mask {
  background-color: rgb(0 0 0 / 30%);
  /* position: fixed; */
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 20000;
  display: flex;
  align-items: center;
  justify-content: center;
}

.progressBox {
  width: 300px;
  height: 150px;
  background: #fff;
  border-radius: 10px;
  box-shadow: 0 0 6px 1px #bfbfbf;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
}

.progressBox .lbox {
  height: 100px;
  font-size: 16px;
  display: flex;
  align-items: center;
}

.progressBox .lbox img {
  width: 40px;
  margin-right: 20px;
}

.progressBox >>> .el-progress-bar__outer {
  background-color: #d1dfff !important;
}

.progressBox .lbox {
  height: 100px;
  font-size: 19px;
  display: flex;
  align-items: center;
}

.progressBox .lbox img {
  width: 40px;
  margin-right: 20px;
}
.saBox {
  width: 96%;
  margin: 0 auto;
  background: #fbfbfb;
  border-radius: 10px;
}
.saLittleBox {
  width: 100%;
  padding: 25px 0 10px 25px;
}
.saLittleBox > div:nth-child(1) {
  width: 85%;
}
.saLittleBox > div:nth-child(2) {
  width: 90%;
  margin-top: 25px;
}
.right_title {
  height: 30px;
  font-size: 1.5em;
  font-weight: bold;
  color: #0f7eff;
  width: 80px;
  padding: 20px 0 20px 30px;
}
.isFinishCss {
  display: flex;
  flex-direction: row;
  flex-wrap: nowrap;
  align-items: flex-end;
}
.isFinishCss > div:nth-child(2) {
  margin-left: 5px;
  color: #939393;
}
.isFinish {
  width: 16px;
  height: 16px;
  margin-top: 5px;
}
.isFinish > img {
  width: 100%;
  height: 100%;
}
.upTips {
  display: flex;
  flex-direction: row;
  flex-wrap: nowrap;
  align-items: baseline;
}
.upTips > div {
  margin-left: 10px;
  color: #999;
  font-size: 14px;
}
.fullCss {
  font-size: 12px;
  position: absolute;
  right: 4%;
  top: 12px;
  cursor: pointer;
}
.fullEditor >>> .text {
  height: 100% !important;
}
.fullEditor >>> .el-dialog {
  margin: 0 !important;
  height: 100%;
}
.fullEditor >>> .el-dialog__body {
  height: 70%;
}
.fullEditor >>> .editor {
  height: 100%;
}
.fullEditor >>> .el-dialog__footer {
  padding: 2% 20px 20px !important;
}
</style>