<script setup>
import { closeToast, showLoadingToast, showToast } from 'vant'

const { currentRoute } = useRouter()
const route = currentRoute.value
const xm_id = route.query.xm_id
const detailData = ref({})
const shjl = ref([])
const fileFinalArr = ref([])
function getData() {
  showLoadingToast({
    message: '加载中...',
    forbidClick: true,
  })
  request({
    url: '/jdbg/xmlxsb_xmsq/detail',
    data: {
      xm_id,
    },
  }).then((res) => {
    closeToast()
    detailData.value = res.data.one_info
    shjl.value = res.data.one_info.shjl

    // 判断是几个附件
    const ifOneB = res.data.one_info.xm_file.indexOf(',')
    if (ifOneB != '-1') { // 能找到，不止一个附件
      const muilArr = res.data.one_info.xm_file.split(',')
      const flileArr = []
      muilArr.forEach((item) => {
        const secSpil = item.split('|')
        flileArr.push({
          fileUrl: secSpil[0],
          fileName: secSpil[1],
        })
      })
      fileFinalArr.value = flileArr
    }
    else {
      const singleArr = res.data.one_info.xm_file.split('|')
      fileFinalArr.value = [{
        fileUrl: singleArr[0],
        fileName: singleArr[1],
      }]
    }
  })
}
getData()

const auditchecked = ref('')
const auditDialogShow = ref(false)
const sh_reason = ref('')
function clickAudit() {
  auditchecked.value = ''
  sh_reason.value = ''
  auditDialogShow.value = true
}
function beforeCloseDialog(action) {
  if (action == 'confirm') {
    if (auditchecked.value == '') {
      showToast('请选择审核结果')
      return false
    }
    else if ((auditchecked.value === '2') && sh_reason.value == '') {
      showToast('请填写意见')
      return false
    }
    else {
      dialogSubmit()
      return true
    }
  }
  else {
    return true
  }
}
function dialogSubmit() {
  const transObj = {
    xm_id,
    sh_status: auditchecked.value, // 待审核 1通过 2驳回
    sh_reason: sh_reason.value, // 处理意见
  }
  showLoadingToast({
    message: '提交中...',
    forbidClick: true,
  })
  request({
    url: '/jdbg/gwgl_gw/check',
    data: transObj,
  }).then((res) => {
    closeToast()
    if (res.code == 1) {
      showToast(res.msg)
      getData()
    }
  })
}
</script>

<template>
  <div>
    <div class="tableContainer">
      <div class="topPart">
        <table class="Tb" width="100%" cellspacing="0" cellpadding="0">
          <tr>
            <td class="titleOpt">
              项目名称：
            </td>
            <td>{{ detailData.xm_name }}</td>
          </tr>
          <tr>
            <td class="titleOpt">
              项目类别：
            </td>
            <td>{{ detailData.lb_name }}</td>
          </tr>
          <tr>
            <td class="titleOpt">
              项目理由：
            </td>
            <td>{{ detailData.xm_reason }}</td>
          </tr>
          <tr>
            <td class="titleOpt">
              申请科室：
            </td>
            <td>{{ detailData.department_name }}</td>
          </tr>
          <tr>
            <td class="titleOpt">
              项目预算：
            </td>
            <td>{{ detailData.xm_price }}</td>
          </tr>
          <tr>
            <td class="titleOpt">
              申报时间：
            </td>
            <td>{{ detailData.xm_sbsj }}</td>
          </tr>
          <tr>
            <td class="titleOpt">
              项目内容：
            </td>
            <td>
              <div class="specialTd" v-html="detailData.xm_content" />
            </td>
          </tr>
          <tr>
            <td class="titleOpt">
              项目方式：
            </td>
            <td>{{ detailData.xm_type }}</td>
          </tr>

          <tr>
            <td class="titleOpt">
              项目附件：
            </td>
            <td style="color:#1989fa">
              <div v-for="(item, index) in fileFinalArr" :key="index" class="singleD">
                <a :href="item.fileUrl" target="_blank">{{ item.fileName }}</a>
              </div>
            </td>
          </tr>
          <tr>
            <td class="titleOpt">
              状态：
            </td>
            <td>{{ detailData.xm_status_option_n }}</td>
          </tr>

          <tbody v-for="(item, index) in shjl" :key="index" class="bg-hex-fffff9 border_bottom">
            <tr>
              <td class="titleOpt">
                序号：
              </td>
              <td>
                <div class="specialTd">
                  {{ index + 1 }}
                </div>
              </td>
            </tr>
            <tr>
              <td class="titleOpt">
                审核部门：
              </td>
              <td>
                <div class="specialTd">
                  {{ item.sh_user_name }}
                </div>
              </td>
            </tr>
            <tr>
              <td class="titleOpt">
                审核人：
              </td>
              <td>
                <div class="specialTd">
                  {{ item.sh_user_name }}
                </div>
              </td>
            </tr>
            <tr>
              <td class="titleOpt">
                审核时间：
              </td>
              <td>
                <div class="specialTd">
                  {{ item.sh_user_name }}
                </div>
              </td>
            </tr>

            <tr>
              <td class="titleOpt">
                状态：
              </td>
              <td>
                <div :style="{ color: item.sh_status == 3 ? 'red' : '' }">
                  {{ item.sh_status == 1 ? "未处理" : (item.sh_status == 2 ? '通过' : '不通过') }}
                </div>
              </td>
            </tr>
            <tr>
              <td class="titleOpt">
                处理意见：
              </td>
              <td>
                <div class="specialTd">
                  {{ item.sh_reason }}
                </div>
              </td>
            </tr>
          </tbody>
        </table>
      </div>
    </div>
  </div>
</template>

<style lang="scss" scoped>
.rightButton {
  height: 30px;
  width: 75px;
}

.titleOpt {
  min-width: 90px;
}

:deep(.specialTd table tbody tr td) {
  border: 1px #CCCCCC solid !important;
}
</style>
