<template>
  <div class="Detail">
    <u-navbar back-icon-color="#000" title="事件上报" title-color="#000" title-width="300" title-size="32" 
      :title-bold="true" :background="backgroundNavbar" :is-fixed="true" height="44"></u-navbar>
    <div class="header-content-bg">
      <img src="https://cdn.sinoecare.com/i/2024/07/12/6690a1303d423.png" alt="">
    </div>
    <div class="border-r">
      <div class="header-top">
        <div class="avatars" v-if="data.name">{{ data.name.substring(data.name.length, data.name.length - 2) }}</div>
        <div class="right">
          <div class="names">{{ data.name }}的上报</div>
          <div class="times">{{ data.createTime }}</div>
        </div>
      </div>
      <div class="header-middle">
        <div class="titles">{{ data.content }}</div>
        <span class="status status0" :class="detailStatus.cls" v-if="data.eventStatus"> {{ detailStatus.label }}</span>
        <div class="card">
          <span class="card-left">事件来源</span>
          <span class="card-right">{{ $dict.getLabel('residentEventSource', data.eventSource) }}</span>
        </div>
        <div class="card">
          <span class="card-left">事件类型</span>
          <span class="card-right">{{ data.groupName }}</span>
        </div>
        <div class="card">
          <span class="card-left">所属网格</span>
          <span class="card-right">{{ data.girdName }}</span>
        </div>
        <div class="card">
          <span class="card-left">联系方式</span>
          <span class="card-right">
            <span> {{ data.phone }}</span>
            <u-icon name="phone-fill" color="#3D94FB" @click="callPhone(data.phone)"></u-icon>
          </span>
        </div>
        <div class="card">
          <span class="card-left">上报地址</span>
          <span class="card-right">
            <span>{{ data.address }}</span>
          </span>
        </div>

        <!-- 暂时先去掉 -->

        <!-- <div class="card">
          <span class="card-left">上报来源</span>
          <span class="card-right">三角湖居民社群 李毅 小程序填报三角湖居民社群 李毅 小程序填报三角湖居民社群 李毅 小程序填报</span>
        </div> -->

        <div class="cards" v-if="data.files && data.files.length">
          <span class="card-left">照片</span>
        </div>

        <img :src="item.url" alt="" v-for="(item, i) in data.files" :key="i" @click="previewImage(data.files, item.url)"/>
      </div>
    </div>

    <div class="border-r">
      <div class="header-bottom">
        <div class="plain">
          <div class="nav">
            <span>办理进度</span>
            <span> ({{ detailStatus.label }})</span>
          </div>
          <div class="plain-item" v-for="(item, index) in process" :key="index">
            <div class="item-content">
              <div class="user-name-bg">
                <span v-text="formatName(item.systemExplain)"/>
              </div>
              <div class="content-right">
                <p class="explain">{{item.systemExplain}}</p>
                <p class="time">{{ item.doTime }}</p>
                <p class="status">{{item.statusLabel}}</p>
              </div>
              <div class="lines"/>
            </div>
            <div class="cardes-msg-top" v-if="item.doExplain">{{ item.doExplain }}</div>
            <div class="imgs" v-if="item.files && item.files.length">
              <img :src="e.url" alt="" v-for="(e, index) in item.files" :key="index" @click="previewImage(item.files, e.url)"/>
            </div>
          </div>
        </div>
      </div>
    </div>
    <div class="footer" v-if="data.eventStatus == 0">
      <div class="btn">
        <div class="flex trans" v-if="data.powerTransmit" @click="toContent(1)">转交事件</div>
        <div class="flex cancel" v-if="data.powerHandle" @click="toContent(2)">
          <div>拒绝受理</div>
        </div>
        <div class="flex confirm" @click="toContent(3)">
          <div>我来受理</div>
        </div>
      </div>
    </div>
    <div class="footer" v-if="data.eventStatus == 1">
      <div class="btn">
        <div class="flex trans" v-if="data.powerTransmit" @click="toContent(1)">转交事件</div>
        <div class="flex cancel" v-if="data.powerHandle" @click="toContent(2)">
          <div>拒绝受理</div>
        </div>
        <div class="flex confirm" v-if="data.powerHandle" @click="toContent(3)">
          <div>我来受理</div>
        </div>
      </div>
    </div>
    <AiEvaluation v-show="false" v-model="evaluation" :bid="data.id"/>
    <u-modal v-model="doItShow" :mask-close-able="true" z-index="99" content="确定受理该事件?" :show-cancel-button="true" @confirm="doThings"></u-modal>
  </div>
</template>

<script>
import {mapState} from 'vuex'
export default {
  name: 'Detail',
  customNavigation: true,
  props: {},
  data() {
    return {
      data: {},
      id: '',
      doItShow: false,
      evaluation: {},
      isShowBtn: false, //统计列表进页面不显示操作按钮
      backgroundNavbar: {
        background: 'url(https://cdn.sinoecare.com/i/2024/07/12/6690a1309c7d3.png) no-repeat',
        backgroundSize: 'cover',
      },
    }
  },
  computed: {
    ...mapState(['user']),
    detailStatus: v => {
      const status = !v.evaluation.id ? v.data.eventStatus : 'evaluation'
      return {
        cls: 'status' + status,
        label: !v.evaluation.id ? v.$dict.getLabel('clapEventStatus', v.data.eventStatus) : "已评价"
      }
    },
    process() {
      const getAvatar = str => str?.substring(str?.length, str?.length - 2)
      var list = []
      if(this.data.processList && this.data.processList.length) {
        list = this.data.processList.map(e => ({
          ...e,
          avatar: getAvatar(e.girdMemberName),
          statusLabel: this.$dict.getLabel('residentReportDoStatus', e.doStatus)
        }))
        if (this.evaluation.id) {
          const {id, createUserName, score, files, createTime: doTime, content: doExplain} = this.evaluation
          list.splice(0, 0, {
            id, doTime, doExplain,
            statusLabel: `${score}星评价`,
            avatar: getAvatar(createUserName),
            systemExplain: `${createUserName}完成评价`,
            files: files
          })
        }
      }
      return list
    }
  },
  watch: {},
  onLoad(o) {
    this.isShowBtn = o.isShowBtn == 1 ? true : false
    this.id = o.id
    this.$dict.load('clapEventStatus','residentEventSource', 'residentReportDoStatus').then(() => {
      this.getDetail()
    })

    uni.$on('updateDeatil', () => {
      this.getDetail()
    })
  },
  methods: {
    getDetail() {
      this.$instance.post(`/app/apppatrolreportinfov2/queryDetailById?id=${this.id}`).then((res) => {
        if (res?.data) {
          this.data = res.data
        }
      })
    },

    callPhone(phone) {
      uni.makePhoneCall({phoneNumber: phone})
    },

    doThings() {
      this.$instance.post(`/app/appresidentreportinfov2/finivsh`, {
        id: this.id,
        eventStatus: 1
      }).then((res) => {
        if (res.code == 0) {
          this.$u.toast('受理成功')
          this.getDetail()
        }
      })
    },

    toContent(status) {
      // if(status == 3 && !this.data.doRight) {
      //   return this.$u.toast('没有办理权限')
      // }
      uni.navigateTo({url: `./Content?status=${status}&groupId=${this.data.groupId}&groupName=${this.data.groupName}&id=${this.id}`})
    },
    previewImage(images, img) {
      uni.previewImage({
        urls: images.map(v => v.url),
        current: img
      })
    },
    formatName(name) {
      if (name == undefined) {
        return
      }
      return name.substr(0, 2)
    },
  },
}
</script>

<style scoped lang="scss">
uni-page-body {
  height: 100%;
  background: #F4F5FA;
}

.Detail {
  height: 100%;
  padding-bottom: 220px;
  .header-content-bg {
    width: 100%;
    position: fixed;
    z-index: -1;
    img {
      width: 100%;
      height: 592px;
    }
  }
  .border-r {
    width: calc(100% - 64px);
    margin: 0 0 32px 32px;
    background-color: #fff;
    border-radius: 16px;
  }
  .header-top {
    display: flex;
    margin: 16px 0 30px 0;
    padding: 32px 32px 0;
    .avatars {
      width: 80px;
      height: 80px;
      line-height: 80px;
      background-color: #4E8EEE;
      border-radius: 50%;
      color: #fff;
      text-align: center;
      font-size: 28px;
      font-weight: 500;
      margin-right: 16px;
    }
    .right {
      .names {
        line-height: 24px;
        font-family: PingFangSC-Medium;
        font-weight: 500;
        font-size: 32px;
        color: #333;
        margin-bottom: 16px;
      }
      .times {
        font-family: PingFangSC-Regular;
        font-size: 28px;
        color: #999;
        line-height: 22px;
      }
    }
  }
  .header-middle {
    padding: 0 0 32px 32px;
    .titles {
      width: calc(100% - 32px);
      word-break: break-all;
      font-family: PingFangSC-SNaNpxibold;
      font-weight: 600;
      font-size: 36px;
      color: #333;
      line-height: 56px;
      margin-bottom: 20px;
    }
    .status {
      display: inline-block;
      margin-bottom: 14px;
      padding: 4px 8px;
      font-size: 26px;
      color: #fff;
      border-radius: 8px;
    }
    .status0 {
      background: #ff883c;
    }
    .status1, .statusevaluation {
      background: #1aaaff;
    }
    .status2 {
      background: #42d784;
    }
    .status3 {
      background: #ff4466;
    }
    .card {
      display: flex;
      padding: 34px 32px 34px 0;
      border-bottom: 1px solid #ddd;
      box-sizing: border-box;
      line-height: 44px;
      font-family: PingFangSC-Regular;
      font-size: 32px;

      .card-left {
        width: 136px;
        color: #999;
      }

      .card-right {
        width: calc(100% - 136px);
        text-align: right;

        ::v-deep u-icon {
          margin-left: 8px;
        }
      }
    }

    // .card:last-child {
    //   border-bottom: none;
    // }

    .cards {
      padding: 34px 0;
    }

    img {
      width: 225px;
      height: 226px;
      margin: 0 8px 8px 0;
    }

    img:nth-of-type(3n) {
      margin-right: 0;
    }
  }
  .header-bottom {
    padding-bottom: 32px;
    .nav {
      padding: 26px 0;
    }
    .plain {
      padding: 0 32px;
      .plain-item {
        position: relative;
        padding-bottom: 80px;
        .item-content {
          display: flex;
          justify-content: space-between;

          .user-name-bg {
            position: relative;
            width: 80px;
            height: 80px;
            text-align: center;
            line-height: 80px;
            color: #fff;
            background: #197df0;
            border: 1px solid #dddddd;
            border-radius: 50%;
            font-size: 28px;
            z-index: 9;
          }

          .content-right {
            width: calc(100% - 110px);
            font-family: PingFangSC-Regular;
            .explain {
              line-height: 44px;
              font-size: 32px;
              color: #333;
              margin-bottom: 8px;
              font-size: 32px;
              word-break: break-all;
            }
            .time {
              line-height: 40px;
              font-size: 28px;
              color: #999;
              margin-bottom: 16px;
            }
            .status {
              line-height: 40px;
              font-size: 28px;
              color: #4CB364;
            }
            
          }
          .lines {
            position: absolute;
            top: 0;
            left: 40px;
            width: 4px;
            height: 100%;
            background: #eeeeee;
          }
        }

        .cardes-msg-top {
          font-size: 28px;
          color: #343d65;
          margin-top: 10px;
          margin-left: 110px;
        }

        .imgs {
          margin-top: 10px;
          margin-left: 110px;

          img {
            width: 136px;
            height: 136px;
            border-radius: 4px;
            margin-right: 12px;
          }

          img:nth-of-type(3n) {
            margin-right: 0;
          }
        }
      }

      .plain-item:last-child {
        .lines {
          width: 0;
          height: 0;
        }
      }
    }
  }
  .footer {
    padding: 32px 32px 68px;
    width: 100%;
    box-sizing: border-box;
    background-color: #F4F5FA;
    position: fixed;
    bottom: 0;
    left: 0;
    z-index: 99;
    .btn {
      width: 100%;
      display: flex;
      padding: 30px 28px;
      box-sizing: border-box;
      background-color: #fff;
      border-radius: 16px;
      .flex {
        flex: 1;
        line-height: 88px;
        font-family: PingFangSC-Regular;
        font-size: 34px;
        box-sizing: border-box;
      }
      .trans {
        color: #222;
        border-right: 1px solid #ddd;
      }
      .cancel {
        color: #FF3C3C;
        div {
          width: 100%;
          padding-left: 28px;
        }
      }
      .confirm {
        flex: 1.2;
        div {
          width: 100%;
          background-color: #026AF2;
          color: #fff;
          border-radius: 44px;
          text-align: center;
        }
      }
    }
  }
}
</style>
