<template>
  <div class="Detail">
    <div class="header-top">
      <div class="avatars" v-if="data.name">{{ data.name.substring(data.name.length, data.name.length - 2) }}</div>
      <!-- v-if="data.eventStatus == 0 && data.eventStatus == 1" -->
      <span class="edit-btn" @click="toEdit()" v-if="data.eventStatus == 0">编辑</span>

      <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" :class="`status`+data.eventStatus" v-if="data.eventStatus"> {{ $dict.getLabel('qujingEventStatus', data.eventStatus) }}</span>

      <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">{{ $dict.getLabel('qujingEventType', data.type) }}</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">
        <span class="card-left" style="color:#999">照片</span>
      </div>

      <img :src="item.url" alt="" v-for="(item, i) in data.files" :key="i" @click="previewImage(data.files, item.url)"/>
      <span v-if="!data.files.length" style="display:inline-block;color:#999;padding-bottom: 16px;">暂无照片</span>
    </div>

    <div class="header-middle" v-if="result.doExplain">
      <div class="text-title">处理详情</div>
      <div class="card">
        <span class="card-left">处理结果</span>
        <span class="card-right">{{ result.doExplain }}</span>
      </div>
      <div class="cards">
        <span class="card-left" style="color:#999">照片</span>
      </div>
      <img :src="item.url" alt="" v-for="(item, i) in result.files" :key="i" @click="previewImage(result.files, item.url)"/>
      <span v-if="!result.files.length" style="display:inline-block;color:#999;padding-bottom: 16px;">暂无照片</span>
    </div>

    <div class="header-middle" v-if="data.judgeName">
      <div class="text-title">事件研判</div>
      <span class="risk-level" :class="`level`+data.judgeRiskLevel">{{ $dict.getLabel('qujingRiskLevel', data.judgeRiskLevel) }}</span>
      <div class="card">
        <span class="card-left">当事人姓名</span>
        <span class="card-right">{{ data.judgeName }}</span>
      </div>
      <div class="card">
        <span class="card-left">性别</span>
        <span class="card-right">{{ $dict.getLabel('sex', data.judgeSex) }}</span>
      </div>

      <div class="card">
        <span class="card-left">联系电话</span>
        <span class="card-right">{{ data.judgePhone }}</span>
      </div>

      <div class="card">
        <span class="card-left">家庭住址</span>
        <span class="card-right">{{data.judgeAddress}}</span>
      </div>

      <div class="card">
        <span class="card-left">纠纷类别</span>
        <span class="card-right">{{ $dict.getLabel('qujingDisputeCategory', data.judgeDisputeCategory) }}</span>
      </div>

      <div class="card not-line">
        <span class="card-left">排查内容</span>
        <span class="card-right">
          <span v-for="(item, index) in data.judgeRiskList" :key="index">
            <span v-if="index > 0">,</span>{{ $dict.getLabel('qujingRisk', item) }}
          </span>
        </span>
      </div>
    </div>

    <div class="header-middle" v-if="data.mediateAreaName">
      <div class="text-title">调解信息</div>
      <div class="card">
        <span class="card-left">调解主体</span>
        <span class="card-right">{{ data.mediateAreaName }}</span>
      </div>
      <div class="card">
        <span class="card-left">调解员</span>
        <span class="card-right">{{ data.mediatePerson }}</span>
      </div>
      <div class="card">
        <span class="card-left">调解时间</span>
        <span class="card-right">{{ data.mediateDate }}</span>
      </div>
      <div class="card">
        <span class="card-left">涉及金额</span>
        <span class="card-right">{{data.mediateAmount}}</span>
      </div>
      <div class="card">
        <span class="card-left">参加人</span>
        <span class="card-right">{{data.mediateMember || '无'}}</span>
      </div>
      <div class="card">
        <span class="card-left">调处思路、措施及主要经过</span>
        <span class="card-right">{{data.mediateInfo}}</span>
      </div>
      <div class="card not-line">
        <span class="card-left">调处结果</span>
        <span class="card-right">调解成功</span>
      </div>
    </div>

    <div class="header-bottom">
      <div class="line"></div>

      <div class="plan">
        <div class="nav">
          <div>办理进度</div>
          <!-- <span> ({{ detailStatus.label }})</span> -->
          <span :class="`status`+data.eventStatus" v-if="data.eventStatus"> ({{ $dict.getLabel('qujingEventStatus', data.eventStatus) }})</span>
        </div>

        <div class="cards" v-for="(item, index) in process" :key="index">
          <div class="cardss">
            <div class="cardss-left">
              <span v-text="formatName(item.systemExplain)"/>
            </div>
            <div class="cardss-right">
              <div class="cardsss-right-left">
                <div class="cardssss-right-left-top">
                  <span v-text="item.systemExplain"/>
                  <div style="color: #2ea222; font-size: 16px; margin-top: 5px" v-text="item.statusLabel"/>
                </div>
              </div>
              <div class="cardees-right-right">{{ item.doTime }}</div>
            </div>
            <div class="lines"/>
          </div>

          <div class="cardes-msg-top" v-if="item.doExplain">{{ item.doExplain }}</div>

          <div class="imgs">
            <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 class="fixedBtn" v-if="data.rightType < 4 && data.rightType !== null">
      <div class="flex-btn" v-if="data.rightType == 2">
        <div class="trans flex-3" @click="toContent(1)">转交事件</div>
        <div class="refuse flex-3" @click="toContent(4)">拒绝事件</div>
        <div class="confirm flex-4" @click="toContent(5)">前往办理</div>
      </div>
      <div class="flex-btn" v-else>
        <div class="refuse" @click="toContent(4)">拒绝受理</div>
        <div class="confirm" v-if="data.rightType == 0" @click="toContent(3)">我来受理</div>
        <div class="confirm" v-if="data.rightType == 1" @click="toContent(2)">前往办理</div>
        <div class="confirm" v-if="data.rightType == 3" @click="toContent(1)">转交事件</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',
  props: {},
  data() {
    return {
      data: {},
      id: '',
      doItShow: false,
      evaluation: {},
      isShowBtn: false,
      result: {}, //处理结果
    }
  },
  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('qujingEventStatus', v.data.eventStatus) : "已评价"
      }
    },
    process() {
      const getAvatar = str => str?.substring(str?.length, str?.length - 2)
      const list = this.data.processList.map(e => ({
        ...e,
        avatar: getAvatar(e.girdMemberName),
        statusLabel: this.$dict.getLabel('qujingDoStatus', 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('qujingEventStatus', 'qujingDoStatus', 'qujingEventType', 'sex', 'qujingRisk', 'qujingRiskLevel', 'qujingDisputeCategory').then(() => {
      this.getDetail()
    })

    uni.$on('updateDeatil', () => {
      this.getDetail()
    })
  },
  onShow() {
    document.title = '事件上报'
  },
  methods: {
    getDetail() {
      this.$http.post(`/app/appclapeventinfoqujing/queryDetailById?id=${this.id}`).then((res) => {
        if (res?.data) {
          this.data = res.data
          if(this.data.judgeRisk) {
            this.data.judgeRiskList = this.data.judgeRisk.split(',')
          }
          if (['3', '4'].includes(res.data.eventStatus) && res.data.groupName != '矛盾调解') {
            this.result = res.data.processList[0]
          }
        }
      })
    },

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

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

    toContent(status) {  // 1转交，2研判, 3办结, 4拒绝，5调解
      // if(status == 3 && !this.data.doRight) {
      //   return this.$u.toast('没有办理权限')
      // }
      if(status == 1 || status == 3 || status == 4) {
        uni.navigateTo({url: `./Content?status=${status}&groupId=${this.data.groupId}&groupName=${this.data.groupName}&id=${this.id}`})
      } 

      if(status == 2) {
        uni.navigateTo({url: `./JudgeContent?id=${this.id}`})
      } 

      if(status == 5) {
        uni.navigateTo({url: `./MediateContent?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)
    },
    toEdit() {
      uni.navigateTo({url: `./Edit?id=${this.id}`})
    }
  },
}
</script>

<style scoped lang="scss">
uni-page-body {
  height: 100%;
  padding-top: 26px;
}

.Detail {
  height: 100%;

  .header-top {
    display: flex;
    padding: 32px 32px 0;
    background-color: #fff;
    position: relative;

    .edit-btn {
      position: absolute;
      color: #197df0;
      top: 16px;
      right: 32px;
      width: 150px;
      height: 44px;
      line-height: 44px;
      text-align: right;
    }

    .avatars {
      width: 80px;
      height: 80px;
      line-height: 80px;
      background: #3975c6;
      border-radius: 50%;
      color: #fff;
      text-align: center;
      font-size: 28px;
      font-weight: 500;
      margin-right: 16px;
    }

    .right {
      .names {
        font-size: 32px;
        font-weight: 500;
      }

      .times {
        margin-top: 10px;
        font-size: 28px;
        color: #999999;
      }
    }
  }

  .header-middle {
    padding: 0 32px 10px 32px;
    position: relative;
    background-color: #fff;
    margin-bottom: 32px;

    .titles {
      padding: 32px 0;
      line-height: 56px;
      word-break: break-all;
      font-size: 40px;
      font-weight: 600;
    }
    .text-title {
      line-height: 44px;
      font-family: PingFangSC-SNaNpxibold;
      font-weight: 600;
      font-size: 32px;
      color: #333;
      letter-spacing: 0;
      padding: 26px 0;
    }
    .risk-level {
      position: absolute;
      top: 28px;
      right: 32px;
      line-height: 40px;
      font-family: PingFangSC-Regular;
      font-size: 28px;
    }

    .level1 {
      color: #3D88F5;
    }
    .level2 {
      color: #52C75B;
    }
    .level3 {
      color: #FF883C;
    }
    .level4 {
      color: #FF3C3C;
    }

    .status {
      display: inline-block;
      margin-bottom: 14px;
      padding: 4px 8px;
      font-size: 26px;
      color: #ffffff;
      border-radius: 8px;
    }

    .status0 {
      background: #ff883c;
    }

    .status1, .status2 {
      background: #1aaaff;
    }

    .status3 {
      background: #42d784;
    }

    .status4 {
      background: #ff4466;
    }

    .card {
      display: flex;
      justify-content: space-between;
      padding: 34px 0;
      border-bottom: 1px solid #ddd;

      .card-left {
        width: 210px;
        font-size: 32px;
        color: #999;
        word-break: break-all;
      }

      .card-right {
        font-size: 32px;
        width: calc(100% - 228px);
        text-align: right;
        word-break: break-all;
        .u-icon {
          margin-left: 8px;
        }
      }
    }

    .not-line {
      border-bottom: none;
    }

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

    .cards {
      padding: 34px 0;
    }

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

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

  .header-bottom {
    padding-bottom: 80px;

    .line {
      height: 16px;
      background: #f3f6f9;
    }

    .plan {
      padding: 0 32px;
      background-color: #fff;

      .nav {
        padding: 26px 0;
        div {
          display: inline-block;
          line-height: 44px;
          font-family: PingFangSC-SNaNpxibold;
          font-weight: 600;
          font-size: 32px;
          color: #333;
        }
        span {
          display: inline-block;
          line-height: 44px;
          margin-left: 8px;
        }
        .status0 {
          color: #ff883c;
        }

        .status1, .status2 {
          color: #1aaaff;
        }

        .status3 {
          color: #42d784;
        }

        .status4 {
          color: #ff4466;
        }
      }

      .cards {
        position: relative;
        padding-bottom: 80px;
        background-color: #fff;

        .cardss {
          display: flex;
          justify-content: space-between;

          .cardss-left {
            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;
            // img {
            //   width: 100%;
            //   height: 100%;
            //   border-radius: 50%;
            // }
            .avatarIcon {
              position: absolute;
              bottom: 0;
              right: 0;
              width: 38px;
              height: 38px;
            }
          }

          .cardss-right {
            width: calc(100% - 110px);
            display: flex;
            justify-content: space-between;

            .cardsss-right-left {
              .cardssss-right-left-top {
                width: 300px;
                overflow: hidden;
                text-overflow: ellipsis;
                font-size: 32px;
              }

              .cardssss-right-left-bottom {
                margin-top: 10px;
                font-size: 28px;
                color: #666666;
              }
            }

            .cardees-right-right {
              font-size: 28px;
              color: #999999;
            }
          }

          .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;
          }
        }
      }

      .cards:last-child {
        .lines {
          width: 0;
          height: 0;
        }
      }
    }
  }

  .fixedBtn {
    background: #fff;
    position: fixed;
    bottom: 0;
    width: 100%;
    box-sizing: border-box;
    z-index: 999;

    .flex-btn {
      display: flex;
      justify-content: space-between;
      line-height: 112px;
      div {
        flex: 1;
        font-family: PingFangSC-Regular;
        font-size: 36px;
        text-align: center;
        color: #333;
      }
      .refuse {
        color: #FF3C3C;
      }
      .confirm {
        color: #fff;
        background-color: #3975c6;
      }
      .trans {
        border-right: 1px solid #ddd;
      }
      .flex-3 {
        flex: 3;
      }
      .flex-4 {
        flex: 4;
      }
    }

    .change-btn {
      background: #3975c6;
      text-align: center;
      padding: 34px 0;
      font-size: 32px;
      font-weight: 500;
      color: #ffffff;
    }

    .status00 {
      display: flex;

      .columns {
        display: flex;
        flex-direction: column;
        align-items: center;
        width: 22%;
        padding: 16px 0;
        border-top: 1px solid #ddd;

        img {
          width: 44px;
          height: 42px;
        }

        .hint {
          margin-top: 4px;
          font-size: 28px;
          color: #666666;
        }
      }

      .border-r {
        border-right: 1px solid #ddd;
      }

      .doIt {
        width: 56%;
        background: #3975c6;
        text-align: center;
        line-height: 112px;
        font-size: 36px;
        font-weight: 500;
        color: #fff;
      }

    }

    
  }
}
</style>
