<script>
import {downFileBase64, reminderDetails} from "@/api/commitment";

export default {
  watch: {
    /* 提醒uuid */
    'router.query.uuid': {
      handler() {
        this.handleGetDetail()
      },
      immediate: true,
      deep: true
    }
  },
  data() {
    return {}
  },
  computed:{
    noDownload(){
      return this.$router.query.noDownload === true
    }
  },
  methods: {
    handleGetDetail() {
      reminderDetails({
        uuid: this.$route.query.uuid,
        type: this.$route.query.type // 0:整改提醒 1:系统提醒
      }).then(res => {
        if (res.code === 0) {
          this.enterpriseDetail = res.data
        }
      })
    },
    /* 附件下载 */
    handleFileDown(uuid) {
      downFileBase64({
        uuid: uuid
      }).then(res => {
        if (res.code === 0) {
          const a = document.createElement('a')
          a.href = res.data
          a.download = '附件'
          a.click()
        }
      })
    },
    handleClose() {
      window.history.go(-1)
    },
  }
}

</script>

<template>
  <view class="remind-page">
    <view class="top">
      <view class="title">整改提醒：{{ item.code }}</view>
      <view class="status">
        <span v-if="$router.query.type === '0'" style="color: #1492FF">待核查</span>
        <span v-if="$router.query.type === '1'" style="color: #FF6B00">已核查</span>
      </view>
    </view>

    <view class="remind">
      {{ enterpriseDetail.content }}
    </view>
    <el-divider></el-divider>
    <view>
      <view class="indicator-body">
        {{ item.indicatorInputBody }}
      </view>
      <view>
        <view class="other-title">
          监管核查
          <view style="color: #FF6B00" v-if="enterpriseDetail.approvalStatus === 0">
            审批状态：待审批
          </view>
          <view style="color: #15BE50" v-if="enterpriseDetail.approvalStatus === 1">
            审批状态：已通过
          </view>
          <view style="color: #D40000" v-if="enterpriseDetail.approvalStatus === 2">
            审批状态：已拒绝
          </view>
        </view>
        <van-divider/>
        <van-form>
          <!--核查结果-->
          <van-field
              name="auditResult"
              label="核查结果"
          >
            <template #input>
              <view v-if="enterpriseDetail.auditResult === 0">符合</view>
              <view v-if="enterpriseDetail.auditResult === 1">整改</view>
              <view v-if="enterpriseDetail.auditResult === 2">整改扣分</view>
            </template>
          </van-field>
          <!--核查得分-->
          <van-field
              name="auditScore"
              label="核查得分"
          >
            <template #input>
              <view v-if="enterpriseDetail.auditScore === 0">0分</view>
              <view v-if="enterpriseDetail.auditScore === -10">-10分</view>
            </template>
          </van-field>
          <!--核查说明-->
          <van-field
              name="auditRemark"
              label="核查说明"
          >
            <template #input>
              <view>{{ enterpriseDetail.auditRemark }}</view>
            </template>
          </van-field>
          <van-field
              name="expandStr"
              label="附件"
          >
            <template #input>
              <view class="file-style">
                <view v-for="(item,index) in item.expandStr.split(',')" @click="handleFileDown(item.uuid)" :key="index">
                  附件{{ index + 1 }}
                </view>
              </view>
            </template>
          </van-field>
        </van-form>
      </view>
    </view>
    <view class="page-bottom">
      <van-button plain type="primary" @click="handleClose">关闭</van-button>
      <van-button  v-if="!noDownload" type="info" @click="handleFileDown(enterpriseDetail.attachmentId)">下载PDF</van-button>
    </view>
  </view>
</template>

<style scoped lang="scss">
.remind-page {
  min-height: 100vh;
  background-color: #fff;
}

.remind-page .top {
  padding: 20rpx;
  display: flex;
  justify-content: space-between;
  align-items: center;

  .title {
    font-size: 32rpx;
    color: #333333;
  }

  .status {
    font-size: 28rpx;
  }
}

.indicator-body {
  background: #F6F6F6;
  border-radius: 4px;
  font-weight: 400;
  font-size: 15px;
  color: #666666;
  text-align: justify;
  padding: 5px;
  min-height: 40px;
}

.other-title {
  font-size: 14px;
  font-weight: bold;
  color: #333;
  margin-top: 10px;
  display: flex;
  justify-content: space-between;

  view {
    font-size: 12px;
  }
}

.file-style {
  font-size: 14px;
  font-weight: 400;
  color: #1492FF;
  margin-top: 10px;
  display: flex;
  flex-direction: column;
  cursor: pointer;
}
.page-bottom {
  height: 48px;
}
</style>