<template>
  <div class="preview">
    <div class="title">{{ name }}</div>
    <div class="content">
      <div class="item" v-if="data.type === 0">
        <div class="msg" style="width: 100%">
          <div class="word">
            {{data.onlyText}}
          </div>
        </div>
      </div>
      <div class="item" v-if="data.type === 1">
        <div class="msg" style="width: 100%">
          <div class="word-title pd_0_12" v-if="data.title">
            {{ data.title }}
          </div>
          <div class="word-time">
            2024-01-29 10:10:11
          </div>
          <div class="word pd_0_12" v-if="data.textText1">
            {{ data.textText1 }}
          </div>
          <div class="word pd_0_12" v-if="textContext">
            <div v-for="val in textContext">
              {{val.n}} : {{val.v}}
            </div>
          </div>
          <div class="word pd_0_12" v-if="data.textText2">
            {{ data.textText2 }}
          </div>
        </div>
      </div>
      <div class="item" v-if="data.type === 2">
        <div class="msg" style="width: 100%">
          <div class="miniprogram">
            <div class='img_panel' style="position: relative;">
              <div class="img_title" v-if="data.oneImageTitleType === 1">
                <span>{{ data.title }}</span>
              </div>
              <div class="img-box">
                <img class="mini-img" :src="imageFunc(data.oneImageImage)" @click="goTo(data.oneImageLinkType,data.oneImageLinkUrl)"/>
              </div>
            </div>
            <div class="word-title" style="margin-top: 10px;font-weight: bold;" v-if="data.oneImageTitleType === 2">
              {{ data.title }}
            </div>
            <div class="word" v-if="data.oneImageTitleType === 2">
              {{ data.oneImageText }}
            </div>
          </div>
        </div>
      </div>
      <div class="item" v-if="data.type === 3">
        <div class="msg" style="width: 100%">
          <div class="miniprogram" >
            <div class='img_panel' style="position: relative;">
              <div class="img-box" style="position: relative;">
                <img class="mini-img" :src="imageFunc(imageContext[0]?imageContext[0].image:'')" alt="">
                <div class="img_desc">{{ imageContext[0]?imageContext[0].title:'' }}</div>
              </div>
              <div class="msg-list" v-for="(v,i) in imageContext">
                <div class="msg-list_item" v-if="i !== 0">
                  <div class="text" >{{v.title}}</div>
                  <img class="img" :src="imageFunc(v.image)" alt="" @click="goTo(v.linkType,v.linkUrl)">
                </div>
              </div>
            </div>
          </div>
        </div>
      </div>

      <div class="item" v-if="data.type === 4">
        <div class="msg">
          <div class="miniprogram">
            <div class='img_panel' style="position: relative;">
              <img class="mini-img" :src="imageFunc(data.onlyImage)" alt="">
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>
<script>
import store from "@/store";

export default {
  name: 'PreviewClient',
  props: {
    name: {
      type: String,
      default: '系统通知'
    },
    data: {
      type: Object,
      default: () => ({
      })
    },
    textContext: {
      type: Array,
      default: []
    },
    imageContext:{
      type: Array,
      default: []
    }
  },
  methods:{
    imageFunc(image){
      if(image){
        return store.getters.filePrefix + image;
      }
      return image;
    },
    goTo(linkType,linkUrl){
      if(linkType === 1 && linkUrl){
        window.open(linkUrl)
      }
    }
  }
}
</script>
<style lang="scss" scoped>
.pointer_img {
  cursor: pointer;
}


.pd_12 {
  padding: 12px!important;
}

.pd_0_12 {
  padding: 0 12px!important;
}

.pd_l_12 {
  padding-left: 12px!important;
}

.pd_r_12 {
  padding-left: 12px!important;
}

.preview {
  margin: 0 auto;
  position: relative;
  width: 300px;
  height: 500px;
  background: url(../../assets/drainageCode/preview-bg.png);
  background-repeat: no-repeat;
  background-size: 100% 100%;

  .title {
    position: absolute;
    top: 28px;
    left: 50%;
    transform: translateX(-50%);
    font-size: 14px;
    font-family: PingFangSC-Regular, PingFang SC;
    font-weight: 400;
    color: #333333;
  }

  .content {
    position: absolute;
    height: 405px;
    width: 280px;
    overflow-y: auto;
    top: 70px;
    left: 50%;
    transform: translateX(-50%);
    border-bottom-left-radius: 10px;
    border-bottom-right-radius: 10px;
    padding: 15px;

    .item {
      font-size: 12px;
      font-family: PingFangSC-Regular, PingFang SC;
      font-weight: 400;
      color: #666666;
      display: flex;
      margin-top: 20px;

      &:first-child {
        margin-top: 0;
      }

      .avatar222 {
        // align-self: center;
        margin-right: 5px;
      }

      .msg {
        position: relative;
        min-height: 26px;
        background: #ffffff;
        box-shadow: 0px 2px 6px 0px rgba(60, 136, 240, 0.1);
        border: 1px solid #e1edfc;
        display: inline-block;
        border-radius: 4px;
        box-sizing: border-box;
        word-break: break-all;
        margin-left: 5px;

        &:before {
          content: " ";
          display: block;
          position: absolute;
          left: -5px;
          box-shadow: 0px 2px 6px 0px rgba(60, 136, 240, 0.1);
          border-width: 5px;
          border-left: 0;
          width: 0;
          border-style: solid;
          border-color: transparent;
          border-right-color: #fff;
          top: 8px;
          z-index: 888;
        }

        .word-title {
          font-weight: bold;
          padding: 4px 0;
          font-size: 14px;
          color: #000;
        }
        .word-time{
          color: #99a9bf;
          padding: 0px 12px;
        }
        .word {
          margin-top: 3px;
        }

        .image {
          padding: 12px;

          img {
            width: 94px;
            height: 90px;
          }
        }

        .miniprogram {
          padding: 12px;
          .img-box {
            border-radius: 6px;
            width: 100%;
            height: 120px;
            background: #DCDFE6;
            overflow: hidden;
            .mini-img {
              height: 100%;
              width: 100%;
            }
            .img_desc {
              position: absolute;
              left: 18px;
              bottom: 18px;
              color: #fff;
              font-size: 14px;
            }
          }
          .img_panel {
            .img_title {
              padding: 0 10px;
              border-radius: 20px;
              line-height: 20px;
              position: absolute;
              right: 18px;
              top: 10px;
              background: #000000;
              opacity: 0.4;
              span {
                opacity: 1;
                color: #fff;
              }
            }
          }

          .msg-list {
            &_item {
              height: 80px;
              padding: 10px;
              line-height: 60px;
              box-sizing: border-box;
              display: flex;
              border-bottom: 1px solid #E4E7ED;
              .text {
                color: #000;
                flex-grow: 1;
              }
              .img {
                width: 60px;
                height: 60px;
                background:  #99a9bf;
              }
            }
          }
        }
      }
    }
  }
}
</style>
