<template>
  <div class="app-container">
    <el-card shadow="never">
      <template #header>
        <div class="card-header">
          <span>新增隐患排查</span>
          <el-button plain icon="ArrowLeft" @click="goBack">返回</el-button>
        </div>
      </template>
      <el-form :model="form" :rules="rules" ref="inveRef" label-width="120px">
        <el-row>
          <el-col :span="12">
            <el-form-item label="排查单位" prop="inspOrgGuid">
              <el-input v-model="form.inspOrgGuid" placeholder="请输入排查单位" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="排查日期" prop="inspDate">
              <el-date-picker v-model="form.inspDate" type="date" placeholder="请选择排查日期" value-format="YYYY-MM-DD" style="width: 100%" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="排查负责人" prop="inspLeader">
              <el-input v-model="form.inspLeader" placeholder="请输入排查负责人" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="负责人职务" prop="inspLeaderPost">
              <el-input v-model="form.inspLeaderPost" placeholder="请输入负责人职务" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="24">
            <el-form-item label="排查成员" prop="inspMem">
              <el-input v-model="form.inspMem" placeholder="请输入排查成员" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="24">
            <el-form-item label="隐患内容" prop="hiddContent">
              <el-input v-model="form.hiddContent" type="textarea" :rows="4" placeholder="请输入隐患内容" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="24">
            <el-form-item label="备注" prop="note">
              <el-input v-model="form.note" type="textarea" :rows="2" placeholder="请输入备注" />
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <div class="form-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="goBack">取 消</el-button>
      </div>
    </el-card>
  </div>
</template>

<script setup name="HiddInveAdd">
import { addBisHiddInve } from "@/api/slaj/hidd"

const { proxy } = getCurrentInstance()
const route = useRoute()
const router = useRouter()

const form = ref({
  hiddGuid: route.query.hiddGuid,
  inspOrgGuid: undefined,
  inspDate: undefined,
  inspLeader: undefined,
  inspLeaderPost: undefined,
  inspMem: undefined,
  hiddContent: undefined,
  note: undefined
})

const rules = {
  inspDate: [{ required: true, message: "排查日期不能为空", trigger: "change" }]
}

function submitForm() {
  proxy.$refs["inveRef"].validate(valid => {
    if (valid) {
      addBisHiddInve(form.value).then(() => {
        proxy.$modal.msgSuccess("新增成功")
        goBack()
      })
    }
  })
}

function goBack() {
  router.push({ path: '/slaj/hidd/detail', query: { guid: form.value.hiddGuid } })
}
</script>

<style scoped>
.card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.form-footer {
  text-align: center;
  padding-top: 20px;
}
</style>
