<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="rectImplRef" label-width="140px">
        <el-row>
          <el-col :span="12">
            <el-form-item label="整改责任单位" prop="goverRespWiunGuid">
              <el-input v-model="form.goverRespWiunGuid" placeholder="请输入整改责任单位" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="整改责任人" prop="rectLegPers">
              <el-input v-model="form.rectLegPers" placeholder="请输入整改责任人" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="联系电话" prop="rectPersOffiTel">
              <el-input v-model="form.rectPersOffiTel" placeholder="请输入联系电话" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="要求完成日期" prop="requCompDate">
              <el-date-picker v-model="form.requCompDate" 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="acimpGoverFund">
              <el-input-number v-model="form.acimpGoverFund" :min="0" :precision="2" style="width: 100%" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="24">
            <el-form-item label="整改措施" prop="corrMeas">
              <el-input v-model="form.corrMeas" 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="HiddRectImplAdd">
import { addBisHiddRectImpl } from "@/api/slaj/hidd"

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

const form = ref({
  hiddGuid: route.query.hiddGuid,
  goverRespWiunGuid: undefined,
  rectLegPers: undefined,
  rectPersOffiTel: undefined,
  requCompDate: undefined,
  acimpGoverFund: undefined,
  corrMeas: undefined,
  note: undefined
})

const rules = {
  rectLegPers: [{ required: true, message: "整改责任人不能为空", trigger: "blur" }],
  requCompDate: [{ required: true, message: "要求完成日期不能为空", trigger: "change" }]
}

function submitForm() {
  proxy.$refs["rectImplRef"].validate(valid => {
    if (valid) {
      addBisHiddRectImpl(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>
