<template>
  <div class="bigBox">
    <MOSTY.FromPage :title="props.formData.title" @closeDialog="closeDialog">
      <template #content>
        <!-- 风险基础信息 -->
        <MOSTY.Assort :title="'风险基础信息'" />
        <el-form ref="ruleFormRef" label-width="160px" :model="fromData" class="demo-ruleForm" style="display: block;"
          inline="true" :rules="rules" :disabled="true">
          <el-form-item label="风险单元(点)编号/信息:" prop="category">
            <el-input v-model="fromData.category" placeholder="" style="width: 260px" clearable></el-input>
          </el-form-item>
          <el-form-item label="风险描述:" prop="unitPartPerson">
            <el-input v-model="fromData.unitPartPerson" placeholder="" style="width: 260px" clearable></el-input>
          </el-form-item>
          <el-form-item label="原始风险等级:" prop="facilityType">
            <el-select v-model="formData.riskLevel" placeholder="" style="width: 260px;">
              <el-option v-for="item in D_BZ_FXDJS_XY" :key="item" :label="item.label" :value="item.value"></el-option>
            </el-select>
          </el-form-item>
        </el-form>
        <!-- 销号申请依据 -->
        <MOSTY.Assort :title="'销号申请依据'" />
        <el-form :disabled="true" ref="ruleFormRef" style="display: block;" inline="true" label-width="160px"
          :model="fromData">
          <el-form-item label="销号原因:" prop="inherentSeverity">
            <el-input v-model="fromData.inherentSeverity" placeholder="" style="width: 260px" clearable></el-input>
          </el-form-item>
          <el-form-item label="证明材料:" prop="inherentRiskLevel">
            <el-input v-model="fromData.inherentRiskLevel" placeholder="" style="width: 260px" clearable>
            </el-input>
          </el-form-item>
          <el-form-item label="现状风险值:" prop="inherentRiskDesc">
            <el-input v-model="fromData.inherentRiskDesc" type="textarea" :rows="3" placeholder="" style="width: 710px"
              clearable></el-input>
          </el-form-item>
        </el-form>
        <!-- 销号审核 -->
        <MOSTY.Assort :title="'销号审核'" />
        <el-form :disabled="true" class="mosty-from-wrap" ref="ruleFormRef" label-width="160px" :model="fromData"
          :inline="true">
          <el-form-item label="申请人" prop="possibility">
            <el-input v-model="fromData.possibility" placeholder="" style="width: 260px" clearable>
            </el-input>
          </el-form-item>
          <el-form-item label="申请日期" prop="currentSeverity">
            <el-date-picker v-model="fromData.currentSeverity" placeholder="" style="width: 260px" clearable>
            </el-date-picker>
          </el-form-item>
          <el-form-item label="部门审核意见:" prop="riskValue">
            <el-input v-model="fromData.riskValue" placeholder="" style="width: 260px" clearable></el-input>
          </el-form-item>
          <el-form-item label="安监部门终审:" prop="currentRiskLevel">
            <el-select v-model="fromData.currentRiskLevel" placeholder="" style="width: 260px" clearable>
              <el-option label="重大风险" value="重大风险"></el-option>
              <el-option label="较大风险" value="较大风险"></el-option>
              <el-option label="一般风险" value="一般风险"></el-option>
              <el-option label="低风险" value="低风险"></el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="销号生效日期:" prop="currentControlMeasures">
            <el-date-picker v-model="fromData.currentControlMeasures" type="textarea" :rows="3" placeholder=""
              style="width: 260px" clearable></el-date-picker>
          </el-form-item>
        </el-form>
        <!-- 风险分级管控措施策划 -->
        <!-- <MOSTY.Assort :title="'风险分级管控措施策划'" />
        <el-form :disabled="true" class="mosty-from-wrap" ref="ruleFormRef" label-width="160px" :model="fromData"
          :inline="true">
          <el-form-item label="风险管控等级:" prop="controlLevel">
            <el-select v-model="fromData.controlLevel" placeholder="请选择风险管控等级" style="width: 260px" clearable>
              <el-option label="公司级" value="公司级"></el-option>
              <el-option label="部门级" value="部门级"></el-option>
              <el-option label="车间级" value="车间级"></el-option>
              <el-option label="班组级" value="班组级"></el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="计划完成时间:" prop="planCompleteTime">
            <el-date-picker v-model="fromData.planCompleteTime" type="date" placeholder="请选择计划完成时间" style="width: 260px"
              clearable />
          </el-form-item>
          <el-form-item label="新增措施类型:" prop="newMeasureType">
            <el-input v-model="fromData.newMeasureType" placeholder="请输入新增措施类型" style="width: 260px"
              clearable></el-input>
          </el-form-item>
          <el-form-item label="是否保持原措施:" prop="keepOriginalMeasures">
            <el-radio-group v-model="fromData.keepOriginalMeasures" style="width: 710px">
              <el-radio label="是">是</el-radio>
              <el-radio label="否">否</el-radio>
            </el-radio-group>
          </el-form-item>

          <el-form-item label="新增措施内容:" prop="newMeasureContent">
            <el-input v-model="fromData.newMeasureContent" type="textarea" :rows="3" placeholder="请输入新增措施内容"
              style="width: 710px" clearable></el-input>
          </el-form-item>
          <el-form-item label="风险动态监测情况:" prop="riskMonitoring">
            <el-input v-model="fromData.riskMonitoring" type="textarea" :rows="3" placeholder="请输入风险动态监测情况"
              style="width: 710px" clearable></el-input>
          </el-form-item>
        </el-form> -->
      </template>
      <template #footer>
        <el-button type="primary" @click="submit(ruleFormRef)" v-loading='saveloading'
          v-if="props.formData.saveBtnShow">
          <el-icon>
            <DocumentChecked />
          </el-icon>
          保存
        </el-button>
        <el-button @click="black">
          <el-icon>
            <DocumentDelete />
          </el-icon>
          关闭
        </el-button>
      </template>
    </MOSTY.FromPage>
  </div>
</template>
<script setup>
import {
  ref,
  getCurrentInstance,
  onMounted
} from "vue"
import * as MOSTY from "@/components/MyComponents/index"
import { ElMessage } from "element-plus"
import { getApi, deleteApi, putApi, postApi } from "@/api/tobAcco_api.js"
const { proxy } = getCurrentInstance()
const {
  D_TB_AQBS_LX,
  D_BZ_SYZT,
  D_BZ_FXDJS_XY
} = proxy.$dict("D_TB_AQBS_LX", "D_BZ_SYZT", "D_BZ_FXDJS_XY")
const rules = {
  sitename: [{
    required: true,
    message: "请选择场所名称",
    trigger: "blur"
  }],
}
const saveloading = ref(false)
const props = defineProps({
  formData: {
    type: Object,
    default: {}
  },
  type: {
    default: "",
    type: String
  }
})
const emit = defineEmits("changePage", 'createPage')
const ruleFormRef = ref()
const fromData = ref({
  state: "01"
})

onMounted(() => {
  if (props.formData.id) {
    getmain(props.formData.id)
  }
})
// 保存
const submit = async (ruleFormRef) => {
  saveloading.value = true
  if (!ruleFormRef) return
  await ruleFormRef.validate((valid) => {
    if (valid) {
      ruleFormRef.value.validate((valid) => {
        if (valid) {
          fromData.value.file = fromData.value.file ? fromData.value.file.toString() : null
          if (fromData.value) {
            if (!fromData.value.id) {
              postApi(fromData.value, "/mosty-jcgl/sitelogo/addTbSitelogoOne")
                .then((res) => {
                  ElMessage.success("新增成功")
                  emit("createPage", res)
                }).finally(() => {
                  saveloading.value = false
                })
            } else {
              postApi(fromData.value, "/mosty-jcgl/sitelogo/updateTbSitelogoOne")
                .then((res) => {
                  ElMessage.success("修改成功")
                  emit("changePage")
                }).finally(() => {
                  saveloading.value = false
                })
            }

          }
        } else {

          ElMessage.error("请输入必填项!")
          saveloading.value = false
        }
      })
    } else {

      ElMessage.error("请输入必填项!")
      saveloading.value = false
    }
  })
}

//获取详情
function getmain (id) {
  if (id) {
    getApi({ id: id }, "/mosty-jcgl/sitelogo/queryTbSitelogoById").then((res) => {
      if (res) {
        res.responsibleusername = res.responsibleusername ? res.responsibleusername.replace(/（null）/g, "") : ""
        fromData.value = res
        fromData.value.saveBtnShow = props.formData.saveBtnShow
        getlcxq(fromData.value.buildingid)
        initCsJzwLcBW(res)
        // if (props.formData.type == "cs") {
        //   getjzwlist(res.siteid)
        // } else if (props.formData.type == "lc") {
        //   getbwdata(res.floorid)
        // } else if (["aqbs"].includes(addtype.value)) {
        //   getcsData()

        // }

        if (res.partid) {
          getApi({ id: res.partid }, "/mosty-jcgl/part/queryScenePartById").then(res => {
            if (res) {
              fromData.value.partname = res.partname ? res.partname : res.qtmc
            }
          })
        }

      }
    })
  }
}


const black = () => {
  // if (props.formData.saveBtnShow) {
  //   proxy.$modal.confirm("离开会丢失页面中修改的内容，确认离开吗？")
  //     .then(() => {
  //       ruleFormRef.value.clearValidate()
  //       emit("changePage")
  //     })
  //     .catch(() => {
  //       // catch error
  //     })
  // } else {
  //   // 关闭上一次的表单校验
  //   ruleFormRef.value.clearValidate()

  // }
  emit("close")
}

function closeDialog () {
  // 关闭上一次的表单校验
  ruleFormRef.value.clearValidate()
  emit("changePage")
}


</script>

<style lang="scss" scoped>
.table-lable {
  margin: 10px;
  color: var(--el-color-primary);
}

::v-deep ::-webkit-scrollbar {
  display: none !important;
}

::v-deep .el-pagination {
  justify-content: center !important;
}

::v-deep .el-form {
  // margin: 5px 10px;
  // padding: 10px;
  // display: flex;
  // flex-wrap: wrap;
}

:deep(.el-form-item) {
  // margin-right: 1cap;
}

::v-deep .el-table .cell {
  padding: 0 0 !important;
}

::v-deep .el-table--border .el-table__cell .cell {
  padding-left: 0px !important;

  >input {
    width: 100%;
    height: 33px;
  }
}


::v-deep .el-upload-list {
  width: 50%;
}

::v-deep .el-form-item__content {
  margin-left: 0px !important;
}
</style>
