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

export default {
  watch: {
    /* 提醒uuid */
    '$route.query.uuid': {
      handler() {
        if (this.$route.query.uuid && this.$route.path === '/subPages/pages/commitment/remindDetail/index') {
          this.handleGetDetail()
        }
      },
      immediate: true,
      deep: true
    }
  },
  activated() {
    this.handleGetDetail()
  },
  data() {
    return {
      reminderDetail: {},
    }
  },
  onLoad(){
    buriedPoint('提醒详情','3-2','subPages/pages/commitment/remindDetail/index')
  },
  methods: {
    handleGetDetail() {
      reminderDetails({
        uuid: this.$route.query.uuid,
        type: this.$route.query.type // 0:整改提醒 1:系统提醒
      }).then(res => {
        if (res) {
          this.reminderDetail = res.data
        }
      })
    },
    /* 附件下载 */
    handleFileDown(uuid) {
      downFileBase64({
        uuid: uuid
      }).then(res => {
        if (res) {
          const a = document.createElement('a')
          a.href = res.data
          a.download = '附件'
          a.click()
        }
      })
    },
    handleClose() {
      window.history.go(-1)
    },
    handleIndicateBody(indicatorInputBody) {
      if (indicatorInputBody.includes('&')) {
        return this.reminderDetail.inputBody ? indicatorInputBody.replace('&', this.reminderDetail.inputBody + this.reminderDetail.inputSegment) : indicatorInputBody
      } else {
        return indicatorInputBody
      }
    }
  }
}

</script>

<template>
  <view class="remind-page">
    <view class="remind-content">
      <view class="top">
        <view class="title">提醒编号：{{ reminderDetail.code }}</view>
        <view class="status">
          <span v-if="$route.query.type === '0'" style="color: #D9001B">红灯提醒</span>
          <span v-if="$route.query.type === '1'" style="color: #F59A23">黄灯提醒</span>
        </view>
      </view>

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

<style scoped lang="scss">
.remind-page {
  height: 100vh;
  background-color: #fff;
  padding: 20px;
  overflow: hidden;
  display: flex;
  box-sizing: border-box;
  flex-direction: column;
}

.remind {
  margin-top: 10px;
}

.remind-page .top {
  display: flex;
  font-weight: bold;
  justify-content: space-between;
  align-items: center;

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

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

.indicator-body {
  margin-top: 40px;
  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;
}

.remind-content {
  flex: 1;
  overflow-y: auto;
}

.page-bottom {
  height: 50px;
  display: flex;
  width: 100%;
}

/* 默认情况下，每个按钮平分空间 */
.page-bottom .van-button {
  flex: 1;
  margin-right: 10px;
}

/* 取消最后一个按钮的右侧间距 */
.page-bottom .van-button:last-child {
  margin-right: 0;
}

/* 当只有两个按钮时的样式 */
.page-bottom .van-button:first-child:nth-last-child(2) {
  flex: 1; /* 第一个按钮占 1/3 */
}

.page-bottom .van-button:nth-child(2):last-child {
  flex: 3; /* 第二个按钮占 2/3 */
}

</style>