<template>

    <van-loading size="16px" v-if="isLoading">加载中...</van-loading>
    <div class="main" v-if="!isLoading">
      <div class="banner">
        <h2>扎实提升“三力”</h2>
        <h2>深入推进“三化”</h2>
        <h2>坚持“三个思维”</h2>
      </div>
      <div class="info">
        <p>场所名称：{{ info.siteName.name }}</p>
        <p>地&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;点：{{ info.place }}</p>
        <p>详细地址：{{ info.placeDel }}</p>
        <p>督查时间：{{ info.supervisionTime }}</p>
        <p>
          附&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;件：
          <span v-if="fileList.length != 0" style="color: #6892ff">{{
            fileList[0].name
          }}</span>
          <span v-else style="color: red">无</span>
        </p>
        <p>督查内容：{{ info.supervisionContent }}</p>
      </div>
      <van-button v-if="canAudit" type="primary" class="btn-sub" @click="update">审核</van-button>
    </div>
  </template>
    
    <script>
  import { ref } from "vue";
  import siteInspectionService from "@/api/siteInspection/siteInspectionService";
  import UserManage from "@/api/user/UserManage";
  import { useRoute } from "vue-router";
  export default {
    setup() {
      //window.xm.setNavigationBarTitle({ title: '场所检查详情'})
      let isLoading = ref(true);
      let canAudit = ref(false);
      // 活动信息
      const info = ref({        
      });
      let fileList = ref([]);
      let route = useRoute();
      new siteInspectionService().queryById(route.query.id).then((data) => {
        info.value = data;
        if(data.assessment=="0"){
          canAudit.value = true;
        }else{
          canAudit.value = false;
        }
        
        info.value.enclosure.split("|").forEach((item) => {
          if (item.trim().length > 0) {
            fileList.value.push({
              name: decodeURIComponent(item.substring(item.lastIndexOf("/") + 1)),
              url: item,
            });
          }
        });
        isLoading.value = false;
      });
      // 审核通过
      const update = () => {
        isLoading.value = true;
        info.value.assessment = 1;
        new siteInspectionService().save(info.value).then((res) => {
          console.log(res);
          isLoading.value = false;
          window.xm.showToast({
             message:"审核成功!"
          })
          history.back();
        });
      };
      return {
        info,
        isLoading,
        update,
        fileList,
        canAudit,
      };
    },
  };
  </script>
    
  <style lang="less">
  .main {
    background: #fff;
    position: relative;
    top: 40px;
  }
  .banner {
    background-color: #36a7f3;
    padding: 20px 50px 40px 50px;
    color: #fff;
    h2 {
      &:nth-child(1) {
        margin-top: 0px;
        text-align: left;
      }
      &:nth-child(2) {
        text-align: center;
      }
      &:nth-child(3) {
        text-align: right;
      }
    }
  }
  .info {
    position: relative;
    width: 86vw;
    margin: 10px auto;
    padding: 10px;
    background: #fff;
    border-radius: 20px;
    top: -50px;
    font-size: 14px;
  }
  .btn-sub {
    width: 90%;
    border-radius: 20px;
    margin-left: 5%;
  }
  .van-loading {
    text-align: center;
    margin-top: 80px;
  }
  </style>