<template>
  <div class="share">
    <div class="preview">
      <div class="phone-top"></div>
      <div class="phone-center"></div>
      <div class="content">
        <div class="phone-status"></div>
        <div class="preview-area">
          <iframe :src="releaseUrl" frameborder="0"></iframe>
        </div>
      </div>
      <div class="phone-bottom"></div>
    </div>
    <div class="setting">
      <img class="share-close" src="../assets/images/share-close.png" alt="" @click="closeBtn">
      <div class="share-title">分享设置</div>
      <div class="share-titleBox">
        <div class="top">
          <el-input type="text" placeholder="h5测试分享标题" v-model="shareModel.shareTitle" maxlength="30" show-word-limit>
          </el-input>
        </div>
        <div class="content">
          <el-input class="input" type="textarea" :rows="3" placeholder="请输入内容" v-model="shareModel.shareContent"
            maxlength="30" show-word-limit>
          </el-input>
          <el-upload class="upload-demo" action="no_useing" accept="image/*" ref="my-upload" :http-request="uploadFile"
            :on-success="handleAvatarSuccess" :before-upload="beforeAvatarUpload" :show-file-list="false">
            <div class="changeCover">
              <img class="cover" :src="shareImg" alt="">
              <div class="cover-title">更换封面</div>
            </div>
          </el-upload>

        </div>
        <input type="text" id="releaseUrl" v-model="releaseUrl" style="height:0px;border: 0;">
      </div>
      <div class="mark">
        <div class="mark-title">添加备注</div>
        <div class="content">
          <el-input class="input" type="textarea" :rows="6" placeholder="请输入内容" v-model="shareModel.remark"
            maxlength="500" show-word-limit>
          </el-input>
        </div>
      </div>
      <div class="qrcode-title">渠道二维码
        <div class="qrcode-copy" @click="copy">
          <img class="qrcode-copy-img" src="../assets/images/qrcode-copy.png" alt="">
          复制链接
        </div>
      </div>

      <!-- <div class="qrcode">
        <el-input v-model="input" placeholder="请输入内容"></el-input>
        <img class="qrcode-img" src="" alt="">
        <div class="qrcode-btn">
          <div class="qrcode-download" @click="save">下载二维码</div>
          <div class="qrcode-copy" @click="save">
            <img class="qrcode-copy-img" src="../assets/images/qrcode-copy.png" alt="">
            复制链接</div>
        </div>
      </div>
      <div class="qrcode-add">添加渠道</div> -->
      <div class="share-save" @click="save">确定</div>
    </div>
  </div>
</template>

<script>
import appConst from "../util/appConst";
import editorApi from "../api/editor";
import * as http from "../util/http";
export default {
  data() {
    return {
      shareImg: this.shareModel.shareImg,
      releaseUrl:
        appConst.DIAOYANBAO_PATH +
        this.shareModel.id +
        "&testcaseId=" +
        this.shareModel.testcaseId
    };
  },
  props: {
    close: {
      type: Function,
      default: null
    },
    shareModel: ""
  },
  methods: {
    async uploadFile(file) {
      console.log("上传", file);
      var that = this;
      http.uploadMaterielFile(
        file.file,
        function(res) {
          that.shareImg = res;
          console.log("上传结果1", res);
        },
        function(res) {
          console.log("上传结果中", res);
        }
      );
    },
    handleAvatarSuccess() {
      console.log("成功");
    },
    beforeAvatarUpload() {
      console.log("失败");
    },
    copy() {
      document.querySelector("#releaseUrl").select();
      document.execCommand("copy");
      this.$message.success("复制成功");
    },
    closeBtn() {
      this.close();
    },
    save() {
      this.shareModel["updator"] = "admin";
      this.shareModel["shareImg"] = this.shareImg;
      editorApi.saveTheme(this.shareModel).then(res => {
        if (res.success) {
          this.$message.success("保存成功");
        } else {
          this.$message.error("数据加载失败,请重试");
        }
      });
      console.log("XXXX", this.currItem);
      this.saveRemarks();
    },
    saveRemarks() {
      let param = {
        id: this.shareModel.id,
        remark: this.shareModel.remark,
        updator: "admin"
      };
      editorApi.saveTheme(param).then(res => {
        if (res.success) {
          this.$emit("child-event", this.shareModel.remark);
        }
      });
    }
  },
  mounted() {
    console.log("XXXXXXXXXXX");
    console.log("shareModel", this.shareModel);
  }
};
</script>

<style lang="less" scoped>
.share {
  z-index: 1000;
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  background: rgba(0, 0, 0, 0.6);
  display: flex;
  flex-direction: row;
  .preview {
    flex-grow: 2;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    .phone-top {
      width: 341px;
      height: 83px;
      background: url(../assets/images/phone-model-top.png) center no-repeat;
      background-size: cover;
    }
    .phone-center {
      position: relative;
      width: 346px;
      height: 530px;
      background: url(../assets/images/phone-model-center.png) repeat-y;
      background-size: cover;
    }
    .content {
      position: absolute;
      width: 298px;
      height: 530px;
      .phone-status {
        margin-left: -2px;
        margin-top: -2px;
        width: 300px;
        height: 50px;
        background: url(../assets/images/phone-model-status.png) repeat-y;
        background-size: cover;
      }
      .preview-area {
        position: relative;
        margin-left: -3px;
        width: 302px;
        height: 480px;
        border: 1px solid #000;
        border-top: 0px;
        background: #fff;
        iframe {
          width: 100%;
          height: 100%;
        }
      }
    }

    .phone-bottom {
      width: 342px;
      height: 87px;
      background: url(../assets/images/phone-model-bottom.png) center no-repeat;
      background-size: cover;
    }
  }
  .setting {
    overflow: auto;
    width: 446px;
    height: 100%;
    background: #fff;
    .share-close {
      z-index: 1001;
      position: absolute;
      top: 0px;
      right: 0px;
      width: 63px;
      height: 57px;
      cursor: pointer;
    }
    .share-title {
      margin: 80px 0px 10px 18px;
      font-size: 16px;
      font-family: PingFangSC-Regular;
      font-weight: 400;
      color: rgba(0, 0, 0, 1);
      line-height: 22px;
    }
    .share-titleBox {
      margin: 0px 12px;
      height: 150px;
      border-radius: 4px;
      border: 1px solid rgba(204, 204, 204, 1);
      .top {
        display: flex;
        flex-direction: row;
        justify-content: space-between;
        margin: 10px;
      }
      .content {
        display: flex;
        position: relative;
        .input {
          width: 326px;
          margin-left: 10px;
        }

        .changeCover {
          margin: 0px 10px;
          width: 70px;
          height: 70px;
          background: rgba(239, 239, 239, 1);
          cursor: pointer;
          .cover {
            width: 100%;
            height: 100%;
          }
        }
        .cover-title {
          position: absolute;
          bottom: 0px;
          right: 10px;
          width: 70px;
          height: 20px;
          background: rgba(0, 0, 0, 0.8);
          color: #fff;
          font-size: 12px;
          line-height: 20px;
          text-align: center;
        }
      }
    }
    .qrcode-title {
      margin: 28px 0px 10px 18px;
      font-size: 16px;
      font-family: PingFangSC-Regular;
      font-weight: 400;
      color: rgba(0, 0, 0, 1);
      line-height: 22px;
      position: relative;
      .qrcode-copy {
        position: absolute;
        top: -5px;
        left: 100px;
        font-size: 14px;
        font-family: PingFangSC-Regular;
        font-weight: 400;
        color: rgba(78, 93, 255, 1);
        line-height: 30px;
        text-align: center;
        width: 125px;
        height: 30px;
        background: rgba(230, 237, 255, 1);
        border-radius: 15px;
        cursor: pointer;
        .qrcode-copy-img {
          width: 16px;
          height: 16px;
          vertical-align: middle;
        }
      }
    }
    .qrcode {
      margin-left: 18px;
      margin-bottom: 10px;
      width: 408px;
      height: 283px;
      border: 1px solid rgba(204, 204, 204, 1);
      display: flex;
      flex-direction: column;
      align-items: center;
      .el-input {
        margin-top: 16px;
        width: 265px;
      }
      .qrcode-img {
        margin-top: 16px;
        width: 140px;
        height: 140px;
        background: rgba(239, 239, 239, 1);
      }
      .qrcode-btn {
        display: flex;
        justify-content: space-between;
        width: 250px;
        height: 31px;
        margin-top: 20px;
        font-size: 14px;
        font-family: PingFangSC-Regular;
        font-weight: 400;
        color: rgba(78, 93, 255, 1);
        line-height: 30px;
        text-align: center;
        .qrcode-download {
          width: 91px;
          height: 30px;
          background: rgba(230, 237, 255, 1);
          border-radius: 15px;
          cursor: pointer;
        }
        .qrcode-copy {
          width: 125px;
          height: 30px;
          background: rgba(230, 237, 255, 1);
          border-radius: 15px;
          cursor: pointer;
          .qrcode-copy-img {
            width: 16px;
            height: 16px;
            vertical-align: middle;
          }
        }
      }
    }

    .qrcode-add {
      margin-left: 18px;
      margin-top: 20px;
      width: 408px;
      height: 44px;
      background: rgba(241, 241, 241, 1);
      border: 1px dotted rgba(192, 192, 192, 1);
      line-height: 44px;
      text-align: center;
      font-size: 14px;
      font-weight: 400;
      color: rgba(78, 93, 255, 1);
      cursor: pointer;
    }
    .share-save {
      text-align: center;
      width: 105px;
      height: 34px;
      background: rgba(78, 93, 255, 1);
      border-radius: 19px;
      margin-top: 167px;
      margin-bottom: 94px;
      margin-left: 174px;
      font-weight: 500;
      color: rgba(255, 255, 255, 1);
      line-height: 34px;
      font-size: 14px;
      cursor: pointer;
    }
  }
  .mark {
    overflow: auto;
    width: 446px;
    background: #fff;
    .mark-title {
      margin: 20px 0px 10px 18px;
      font-size: 16px;
      font-family: PingFangSC-Regular;
      font-weight: 400;
      color: rgba(0, 0, 0, 1);
      line-height: 22px;
    }
    .content {
      display: flex;
      position: relative;
      .input {
        width: 415px;
        margin-left: 15px;
      }
    }
  }
}
</style>