<template>
  <div class="casuallyaskDetail">
    <div class="detail">
      <div class="headerTitle" flex>
        <div class="temp">
          [{{ $dict.getLabel('leaveMessageType', detail.type) }}]
        </div>
        <span class="areaName">{{ detail.areaName }}</span>
        <span>{{ detail.title }}</span>
      </div>
      <div class="leaveName_leavePhone">
        <!-- 顶部圆形头像 -->
        <span class="icon">{{ detail.headPortrait || $formatName(detail.leaveName) }}</span>
        <span class="leaveName">{{ detail.leaveName }}</span>
        <span class="leavePhone" v-if="detail.leavePhone">({{ detail.leavePhone }})</span>
      </div>
      <!-- 编号 -->
      <div class="info-item">
        <span class="label">
          <u-icon name="order"></u-icon>
        </span>
        <span class="value">{{ detail.msgCode }}</span>
      </div>
      <!-- 日期 -->
      <div class="info-item">
        <span class="label">
          <u-icon name="clock"></u-icon>
        </span>
        <span class="value">{{ detail.createTime }}</span>
      </div>
      <!-- 进度-->
      <div class="info-item">
        <span class="label"><u-icon name="tags"/></span>
        <text class="status">{{
            $dict.getLabel('leaveMessageStatus', detail.status)
          }}
        </text>
      </div>
      <div class="content_text_img">
        <!-- 提问内容 -->
        <div class="content_text">
          {{ detail.content }}
        </div>
        <!-- 提问内容的图片 -->
        <div class="imageList">
          <ai-image preview :src="items.url" alt="" v-for="(items, i) in imgList" :key="i"/>
        </div>
      </div>
      <div class="reply_content" v-if="detail.status == 1 || detail.status == 2">
        <div class="reply_title">
          <img src="https://cdn.cunwuyun.cn/img/dialogue.svg" alt=""/>
          <p>沟通记录</p>
        </div>
        <div class="reply_list">
          <div class="item" v-for="(item, index) in appLeaveMessageReplyList" :key="index">
            <div class="item_top">
              <div class="item_left">
                <div class="icon">
                  {{ detail.headPortrait || $formatName(item.createUserName) }}
                </div>
                <div class="name fill">
                  <div class="createUserName_createUnitName">
                    <span v-if="item.createUserId == user.id" class="reply_font">我的回复</span>
                    <template v-else>
                      <span class="createUserName">{{ item.createUserName }}&nbsp;</span>
                      <span class="createUserName" v-if="item.createUserPhone">({{ item.createUserPhone }})</span>
                    </template>
                  </div>
                  <div flex v-if="item.createUserId != user.id">
                    <!-- 回复单位 -->
                    <span class="createUnitName">{{ item.createUnitName }}</span>
                    <span class="reply">回复</span>
                  </div>
                </div>
              </div>
              <div class="item_right">{{ item.createTime }}</div>
            </div>
            <!-- 回复内容 -->
            <div class="myreply_con">
              <div class="myreply_text">
                {{ item.content }}
              </div>
              <!-- 回复图片 -->
              <div class="imageList">
                <ai-image v-for="img in item.images" :key="img.id" preview :src="img.url"/>
              </div>
              <!--  -->
            </div>
          </div>
        </div>
      </div>
    </div>
    <div class="close_reply" v-if="detail.status == 0 || detail.status == 1">
      <div class="btn" @click="close">关闭留言</div>
      <div class="btn reply" @click="reply">回复</div>
    </div>
    <u-modal
        v-model="show"
        :content="content"
        cancel-color="#2979ff"
        title=""
        :async-close="true"
        :show-cancel-button="true"
        @confirm="handleCloseMessage"
        @cancel="show = false"/>
    <back/>
  </div>
</template>

<script>
import back from '../../components/AiBack'
import {mapState} from 'vuex'
import AiImage from "../../components/AiImage";
import UImage from "../../uview/components/u-image/u-image";

export default {
  name: 'casuallyaskDetail',
  components: {UImage, AiImage, back},
  props: {},
  computed: {
    ...mapState(['user'])
  },
  onLoad(options) {
    this.getDetail(options.id)
  },
  onShow() {
    this.$dict.load('leaveMessageStatus', 'leaveMessageType')
  },
  data() {
    return {
      objdie: '', // id
      appLeaveMessageReplyList: [], //遍历得到的数据
      show: false, // 默认关闭模态框
      content: '关闭留言后，双方都无法再进行回复，是否确定关闭本次留言？',
      msgCode: null,
      imgList: [],
      detail: {}
      // images:[]
    }
  },
  methods: {
    getDetail(id = this.detail.id) {
      this.$http.post(`/app/appleavemessage/queryDetailById?id=${id}`,).then(res => {
        if (res?.data) {
          this.detail = res.data
          this.imgList = JSON.parse(this.detail.images)
          this.appLeaveMessageReplyList = res.data.appLeaveMessageReplyList.map(item => ({
            ...item,
            images: JSON.parse(item.images).map(e => ({url: e.url || e?.file?.accessUrl, id: e.file?.id}))
          }))
        }
      })
    },
    // 关闭留言
    close() {
      this.show = true
      this.getDetail()
    },
    // 确定关闭留言
    handleCloseMessage() {
      this.$http.post(`/app/appleavemessage/release?id=${this.objdie}&status=2`).then(res => {
        if (res?.code == 0) {
          this.getDetail()
          uni.navigateTo({url: `./closemsg?flag=true`})
        }
      }).catch(() => {
        uni.navigateTo({url: `./closemsg?flag=false`})
      })
      this.show = false
    },
    // 去回复
    reply() {
      uni.navigateTo({url: `./reply?msgCode=${this.detail.msgCode}`})
    }
  },
}
</script>

<style lang="scss" scoped>
.casuallyaskDetail {
  padding-bottom: 80px;

  .detail {
    padding: 15px 32px 112px 32px;
    background-color: #fff;
    font-size: 30px;
    font-weight: 400;
    color: #343D65;

    .headerTitle {
      font-size: 40px;
      font-weight: bold;
      color: #333;
      line-height: 64px;
      letter-spacing: 2px;
      flex-wrap: wrap;
    }

    .leaveName_leavePhone {
      height: 56px;
      margin: 20px 0 36px 0;

      .icon {
        display: inline-block;
        width: 56px;
        height: 56px;
        line-height: 56px;
        border-radius: 50%;
        background-color: #2266ff;
        color: #fff;
        font-size: 22px;
        vertical-align: middle;
        text-align: center;
      }

      .leaveName {
        // display: block;
        margin-left: 20px;
        color: #343d65;
      }

      // .leavePhone {
      // }
    }

    .info-item {
      height: 40px;
      line-height: 40px;
      font-size: 28px;
      margin-bottom: 8px;

      .label {
        display: inline-block;
      }

      .value {
        display: inline-block;
        margin-left: 20px;
      }

      .status {
        display: inline-block;
        margin-left: 20px;
        // color: #999;
      }
    }

    .content_text_img {
      margin-top: 64px;
      max-height: 700px;
      color: #000;
      font-size: 32px;
      // font-weight: 800;
      overflow: hidden;

      .content_text {
        width: 100%;
        margin-bottom: 12px;
      }
    }

    .reply_content {
      margin-top: 25px;

      .reply_title {
        margin-top: 25px;
        width: 225px;
        height: 45px;
        line-height: 45px;

        img {
          vertical-align: middle;
        }

        p {
          display: inline-block;
          color: #333;
          // font-weight: 800;
          margin-left: 10px;
        }
      }

      .reply_list {
        .item {
          .item_top {
            display: flex;
            justify-content: space-between;
            margin-top: 10px;

            .item_left {
              display: flex;
              align-items: center;
              flex: 1;
              min-width: 0;

              .icon {
                display: block;
                flex-shrink: 0;
                width: 64px;
                height: 64px;
                line-height: 64px;
                border-radius: 50%;
                background-color: #2266ff;
                color: #fff;
                font-size: 23px;
                text-align: center;
                margin-right: 10px;
              }

              .name {
                display: flex;
                flex-direction: column;

                .createUnitName {
                  color: #135ab8;
                  margin-right: 8px;
                }

                .createUserName_createUnitName {
                  width: 100%;
                  display: flex;

                  .reply_font {
                    width: 120px;
                    color: #333333;
                    font-size: 28px;
                  }

                  .createUserName {
                    margin-bottom: 5px;
                    color: #135ab8;
                  }
                }
              }
            }

            .item_right {
              font-size: 26px;
              color: #999;
            }
          }

          .myreply_con {
            width: 570px;
            background-color: #f3f6f9;
            margin: 24px 0 0 80px;
            padding: 14px;

            .myreply_text {
              overflow: auto;
              word-wrap: break-word;
              word-break: break-all;
            }

            .imageList {
              display: flex;
              flex-wrap: wrap;

              .AiImage {
                margin: 0 12px 12px 0;
              }
            }
          }
        }

        .no_yes_reply {
          .con_title {
            display: flex;
            flex-direction: row;
            justify-content: space-between;
            margin-top: 16px;
            height: 64px;
            line-height: 64px;

            .icon {
              display: inline-block;
              width: 60px;
              height: 60px;
              line-height: 60px;
              border-radius: 50%;
              background-color: #2266ff;
              color: #fff;
              font-size: 23px;
              vertical-align: middle;
              text-align: center;
              // font-weight: 800;
            }

            .my_reply {
              width: 370px;
            }

            .right {
              color: #999;
            }
          }

          .myreply_content {
            width: 606px;
            height: 460px;
            background-color: #f3f6f9;
            margin: 24px 0 0 62px;
            padding: 16px;
          }
        }
      }
    }

    .no_more {
      padding: 44px 0;
      color: #999;
      font-size: 24px;
      text-align: center;
    }
  }

  .close_reply {
    position: fixed;
    bottom: 0;
    display: flex;
    height: 112px;
    width: 100%;
    border-top: 1px solid #ddd;
    z-index: 999;
    background: #fff;

    .btn {
      flex: 1;
      min-width: 0;
      background-color: #fff;
      display: flex;
      justify-content: center;
      align-items: center;

      &.reply {
        background-color: #1365dd;
        color: #fff;
      }
    }
  }
}
</style>
