<template>
  <div class="showModel" v-if="disjunctor">
    <div class="showModel__wrap">
      <div class="showModel__header" v-if="title">
        {{ title }}
      </div>
      <div class="showModel__article">
        <div v-if="content" class="showModel__content" v-html="content"></div>
        <div class="imgs-container">
          <img :src="img.previewUrl" v-for="(img, index) in repairImgs" :key="index" class="imgs" @click="showImgs(repairImgs)" />
        </div>
      </div>
      <div class="showModel__footer">
        <div v-if="operate.know" class="showModel__know" @click.stop="know">
          {{ operate.know || "" }}
        </div>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      loginUser: JSON.parse(localStorage.getItem("loginUser")),
      repairImgs: [], //报修图片
    };
  },
  props: {
    // 显示隐藏
    disjunctor: {
      type: Boolean,
      default: false
    },
    // 标题
    title: {
      type: String,
      default: "提示"
    },
    // 内容
    content: {
      type: String,
      default: ""
    },
    // 报修单id
    wxIncidentId: {
      type: Number,
    },
    // 操作按钮文字
    operate: {
      type: Object,
      default: () => {
        return {
          know: "知道了"
        };
      }
    }
  },
  methods: {
    // 知道了
    know() {
      this.$emit("know");
    },
    // 获取报修图片
    getRepairImgs() {
      const toast = this.$createToast({
        txt: "Loading...",
        mask: true
      });
      toast.show();
      this.$http
        .get(
          "service/common/common/listAttachment/wechatRequesterIncident/" +
            this.wxIncidentId,
          {}
        )
        .then((res) => {
          toast.hide();
          console.log(res.data);
          res.data.data = res.data.data || [];
          res.data.data.forEach(v => {
            v.previewUrl = location.origin + "/file" + v.relativeFilePath;
          })
          this.repairImgs = res.data.data;
        });
    },
    //展示图片
    showImgs(imgs){
      this.$createImagePreview({
        imgs:imgs.map(v=>v.previewUrl)
      }).show()
    },
  },
  mounted() {
    this.getRepairImgs();
  }
};
</script>

<style lang="less">
.showModel {
  position: fixed;
  left: 0;
  right: 0;
  top: 0;
  bottom: 0;
  background-color: rgba(0, 0, 0, 0.2);
  z-index: 99;
  margin: 0 auto;
  .red{
    color: red;
  }

  .imgs-container {
    display: flex;
    justify-content: space-between;
    flex-wrap: wrap;
    img {
      width: 1.5rem;
      height: 1.5rem;
      margin: 0.2rem 0.1rem;
    }
  }

  .tipsAll {
    .tips {
      word-break: break-all;
      margin-bottom: 0.1rem;
    }
  }

  .showModel__wrap {
    width: 6rem;
    position: absolute;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
    background-color: #fff;
    border-radius: 0.12rem;

    .showModel__header {
      font-size: 0.28rem;
      color: #000;
      height: 0.84rem;
      display: flex;
      justify-content: center;
      align-items: center;
      font-weight: bold;
    }

    .showModel__article {
      margin: 0 auto 0.2rem;
      width: 5.28rem;
      padding: 0.2rem 0 0;
      background-color: rgb(249, 250, 251);
      border: 0.02rem solid rgb(229, 233, 237);
      border-radius: 0.12rem;
      box-sizing: border-box;
      display: flex;
      flex-direction: column;
      justify-content: center;
      align-items: center;

      .showModel__icon {
        font-size: 1.38rem;
        margin-bottom: 0.32rem;

        &.showModel__icon--success {
          color: rgb(52, 179, 73);
        }

        &.showModel__icon--warn {
          color: rgb(245, 165, 35);
        }

        &.showModel__icon--error {
          color: rgb(255, 58, 82);
        }
      }

      .showModel__content {
        width: 100%;
        font-size: 0.26rem;
        padding: 0 0 0.2rem;
        border-bottom: 0.02rem solid #B7B7B7;
        text-align: center;
      }

      .showModel__info {
        font-size: 0.32rem;
        color: rgb(102, 102, 102);
      }
      .select-wrap {
        width: 80%;
        margin: 0 auto;
        &.hc{
          font-size: 0.32rem;
          .hc_item{
            margin-bottom: 0.1rem;
            display: flex;
            align-items: center;
          }
        }
      }
      .specialCloseFlag {
        width: 90%;
        height: 100%;
        padding: 0.16rem;
      }
    }

    .showModel__footer {
      box-sizing: border-box;
      height: 1rem;
      border-top: 0.02rem solid rgb(229, 233, 237);
      display: flex;
      align-items: center;

      div {
        height: 100%;
        display: flex;
        align-items: center;
        justify-content: center;
        font-size: 0.36rem;
        color: rgb(102, 102, 102);
        position: relative;

        &:nth-of-type(2)::before {
          content: "";
          position: absolute;
          left: 0;
          bottom: 0;
          width: 0.02rem;
          height: 0.87rem;
          background-color: rgb(229, 233, 237);
        }
        &:nth-of-type(3)::before {
          content: "";
          position: absolute;
          left: 0;
          bottom: 0;
          width: 0.02rem;
          height: 0.87rem;
          background-color: rgb(229, 233, 237);
        }
      }

      .showModel__ok {
        flex: 1;
        color: #005395;
      }

      .showModel__remove {
        flex: 1;
        color: #f30922;
      }

      .showModel__cancel {
        flex: 1;
      }

      .showModel__know {
        flex: 1;
        color: #005395;
        font-size: 0.28rem;
      }
    }
  }
}
</style>
