<template>
  <div class="detail">
    <div class="detail-list">
      <div class="detail-info">
        <div class="detail-name">申请人:<span>{{form.residentName}}</span></div>
        <div class="detail-type">{{ $dict.getLabel('atWillReportType',form.applyIntegralType) }}</div>
      </div>
      <div class="detail-area">
        <div class="time">{{ form.createTime }}</div>
        <div class="address" v-if="form.areaId">
          <img src="./img/address.png" alt="">
          <span>{{ form.areaName }}</span>
        </div>
      </div>
      <div class="detail-text">
        {{ form.description }}
      </div>
      <div class="detail-img">
        <img :src="item.url" alt="" v-for="(item, i) in form.applyFiles" :key="i" @click="previewImage(form.applyFiles, item.url)" />
      </div>
    </div>

    <!-- 待审核 -->
    <div class="integral" v-if="form.auditStatus == 0">
      <div class="result">
        <div><span  style="color: #FF4466;">*</span>积分审核结果</div>
        <div class="options">
          <div class="opts-item" :class="opts? 'current': ''" @click="opts = 1">通过</div>
          <div class="opts-item" :class="!opts? 'current': ''" @click="opts = 0">不通过</div>
        </div>
      </div>

      <!-- 通过 -->
      <div class="integral-select" v-if="opts === 1">
        <div class="integral-item" @click="isShowType = true">
          <div class="label"><span>*</span>积分类别</div>
          <div class="value">
            <span :style="{color:data.auditIntegralType ? '' : '#999'}">{{ $dict.getLabel('atWillReportType',data.auditIntegralType) || '请选择' }}</span>
            <u-icon name="arrow-right" color="#E1E2E3"/>
          </div>
        </div>
        <div class="integral-item" @click="getType()">
          <div class="label"><span>*</span>积分事项</div>
          <div class="value">
            <span :style="{color:data.ruleName ? '' : '#999'}">{{ data.ruleName || '请选择' }}</span>
            <u-icon name="arrow-right" color="#E1E2E3"/>
          </div>
        </div>
        <div class="integral-item last mode">
          <div class="label"><span style="margin-right: 8px;"></span>积分方式</div>
          <div style="color: #E6736E;margin-right: 8px; font-weight: 600;" class="value">{{ data.integral }}</div>
        </div>
      </div>
      <!-- 不通过 -->
      <div class="reject" v-else>
        <div><span style="color:#FF4466;">*</span>不通过理由</div>
        <textarea class="reasons" placeholder="请输入不通过理由" :maxlength="500" 
                    v-model="data.auditOpinion"></textarea>
        <div class="tips">{{ data.auditOpinion.length }}/500</div>
      </div>

      <u-select :list="$dict.getDict('atWillReportType')" value-name="dictValue" label-name="dictName"
              v-model="isShowType" @confirm="integralType"></u-select>

      <u-select :list="typeList" value-name="id" label-name="ruleName"
              v-model="isShowOption" @confirm="typeChange"></u-select>
    </div>


    <!-- 已审核 -->
    <div class="readOnly" v-else>
      <!-- 通过 -->
      <div v-if="form.auditStatus==1">  
        <div class="item">
          <div>积分审核</div>
          <div>通过</div>
        </div>
        <div class="item">
          <div>积分类别</div>
          <div>{{ form.auditIntegralType }}</div>
        </div>
        <div class="item">
          <div>积分事项</div>
          <div>{{ form.auditRuleName }}</div>
        </div>
        <div class="item">
          <div>积分方式</div>
          <div style="color: #E6736E;">{{ form.auditIntegral }}</div>
        </div>
      </div>
      <!-- 不通过 -->
      <div v-if="form.auditStatus==2">
        <div class="item">
          <div>积分审核</div>
          <div>不通过</div>
        </div>
        <div class="item nopass">
          <div>不通过的理由</div>
          <div class="textarea">{{ form.auditOpinion }}</div>
        </div>
      </div>
      <div class="item">
        <div>审核人</div>
        <div>{{ form.auditUserName }}</div>
      </div>
      <div class="item last">
        <div>审核时间</div>
        <div>{{ form.auditTime }}</div>
      </div>
    </div>

    <div style="height: 70px"></div>
    <div class="saveBtn" v-if="form.auditStatus == 0" @click="submit">保存</div>
  </div>
</template>

<script>
export default {
  name: 'detail',
  data () {
    return {
      id: '',
      auditType: 1,
      opts: 1,
      isShowType: false,
      isShowOption: false,
      getList: [],
      reason: '',
      form: {},
      data: {
        id: '',
        auditIntegralType: '',
        auditOpinion: '',   // 不通过理由
        ruleName: '',
        integral: '',
        integralType: ''
      },
      typeList: [],
    }
  },
  onLoad(o) {
    this.$dict.load('atWillReportType','integralDeclareStatus').then(()=>{
      this.id = o.id
      this.nopass = o.nopass
      this.getDetail()
    })
  },
  methods: {
    previewImage(images, img) {
      uni.previewImage({
        urls: images.map(v => v.url),
        current: img
      })
    },
    getDetail() {
      this.$http.post(`/app/appvillagerintegraldeclare/queryDetailById?id=${this.id}`).then(res => {
        if(res.code==0) {
          this.form = res.data
          this.$forceUpdate()
        }
      })
    },
    getType() {
      if(!this.data.auditIntegralType) {
        return this.$u.toast('请选择积分类别')
      } else {
        this.$http.post(`/app/appvillagerintegralrule/list?current=1&size=10&auditIntegralType=${this.data.auditIntegralType}`).then(res=>{
          if(res.code == 0){
            this.typeList = res.data.records
            this.isShowOption=true
          }
        })
      }
    },
    typeChange(e) {
      this.data.ruleName = e[0].label
      this.data.id = e[0].value
      this.data.integral = e[0].value
      this.typeList.map((item) => {
        if(item.id == e[0].value) {
          this.data.integral = item.integral
          this.data.integralType = item.integralType
        }
      })
    },
    integralType(e) {
      this.data.auditIntegralType = e[0].value
    },
    submit() {
      if(this.opts==1){
        if(!this.data.auditIntegralType) {
        return this.$u.toast('请选择积分类别')
        }
        if(!this.data.ruleName) {
          return this.$u.toast('请选择积分事项')
        }
      }
      if(this.opts==0){
        if(!this.data.auditOpinion) {
          return this.$u.toast('请输入不通过理由')
        }
      }
      this.$http.post('/app/appvillagerintegraldeclare/examine',null,{
        params: {
          id: this.id,
          pass: this.opts,
          auditRuleId: this.data.id,
          auditIntegralType: this.data.auditIntegralType,
          auditIntegral: audithis.data.integralTypetIntegral,
          opinion: this.data.auditOpinion,
          auditRuleName: this.data.ruleName,
        }
      }).then(()=>{
        this.$u.toast('保存成功')
        uni.$emit('update')
        setTimeout(()=>{
          uni.navigateBack()
        },600)
      })
    }
  },
  onShow() {
    document.title = '积分审核详情'
  },
  

}
</script>

<style lang="scss" scoped>
.detail {

  .detail-list {
    padding: 20px 30px;
    box-sizing: border-box;
    background-color: #FFFFFF;
    margin-bottom: 16px;

    .detail-info {
      display: flex;
      justify-content: space-between;
      height: 50px;
      line-height: 50px;
      .detail-name {
        font-size: 30px;
        font-weight: 600;
        color: #333333;
      }

      .detail-type {
        height: 50px;
        line-height: 50px;
        color: #135AB8;
        font-size: 24px;
        background-color: #e6edf7;
        padding: 0 25px;
        border-radius: 16px;
      }

    }

    .detail-area {
      display: flex;
      color: #333333;
      font-size: 22px;
      margin: 15px 0;

      .address {
        display: flex;
        margin-left: 30px;

        img {
          width: 32px;
          height: 32px;
        }
      }
    }

    .detail-text {
      color: #333333;
      font-size: 30px;
      margin-bottom: 30px;
    }

    .detail-img {
      
      img {
      width: 220px;
      height: 220px;
      margin-right: 8px;
      }
      img:nth-child(3n) {
        margin-right: 0;
      }
    }
  }

  .integral {
    font-size: 32px;
    
    .result {
      padding: 20px 30px;
      box-sizing: border-box;
      background-color: #FFFFFF;
      border-bottom: 1px solid #D8DDE6;
      .options {
        display: flex;
        justify-content: space-between;
        
        .opts-item {
          width: 45%;
          height: 112px;
          line-height: 112px;
          background: #F5F5F5;
          text-align: center;
          margin-top: 30px;
          border-radius: 6px;
        }
      }
    }

    .current {
      color: #1174fe;
      background: #e7f1fe !important;
      position: relative;
    }

    .integral-select {
      padding: 0px 30px;
      box-sizing: border-box;
      background: #FFFFFF;

      .integral-item {
        width: 100%;
        display: flex;
        justify-content: space-between;
        box-sizing: border-box;
        padding: 34px 0;
        border-bottom: 1px solid #D8DDE6;

        .label {
          width: 30%;
          span {
            color: #FF4466;
          }
        }
        .value {
          width: 70%;
          text-align: right;
        }
      }

      .integral-item:last-child {
        border-bottom: none;
      }
    }

    .reject {
      padding: 30px 30px;
      background: #FFFFFF;

      .reasons {
        margin-top: 30px;
        width: 100%;
        height: 200px;
        color: #333333;
      }

      .tips {
        margin-top: 30px;
        text-align: right;
        font-size: 30px;
        color: #999;
      }

    }

  }

  .readOnly {
    padding: 20px 30px;
    box-sizing: border-box;
    background: #FFFFFF;

    .item {
      display: flex;
      justify-content: space-between;
      padding: 30px 0;
      font-size: 32px;
      color: #333333;
      border-bottom: 1px solid #D8DDE6;

      .textarea {
        margin-top: 30px;
        color: #333333;
      }
    }

    .nopass {
      flex-direction: column;
      border-bottom: 1px solid #D8DDE6;
    }

    .last {
      border-bottom: none;
    }
  }
  
  .saveBtn {
    position: fixed;
    bottom: 0;
    height: 112px;
    width: 100%;
    line-height: 112px;
    background-color: #3975C6;
    font-size: 32px;
    color: #FFFFFF;
    text-align: center;
  }
  
}
</style>