<template>
  <div class="dialog" v-if="dialogForm">
    <div class="head_box">
      <span class="title">爆破事故登记{{ title }} </span>
      <div>
        <el-button type="primary" size="small" :loading="loading" @click="submit" >保存</el-button>
        <el-button size="small" @click="close">关闭</el-button>
      </div>
    </div>
    <div class="form_cnt">
      <FormMessage :formList="formData" labelWidth="220px" ref="elform" :rules="rules"></FormMessage>
    </div>
  </div>
</template>

<script setup>
import FormMessage from '@/components/aboutTable/FormMessage.vue'
import { qcckGet, qcckPost, qcckPut } from "@/api/qcckApi.js";
import * as rule from "@/utils/rules.js";
import { ref, defineExpose, reactive, onMounted, defineEmits, getCurrentInstance, nextTick } from "vue";
const emit = defineEmits(["updateDate"]);
const props = defineProps({
  dic: Object
});
const { proxy } = getCurrentInstance();
const dialogForm = ref(false); //弹窗
const formData = ref([
  { label: "爆破事故登记业务流水号", prop: "ywlsh",  type: "input",width: "48%" },
  { label: "发生时间", prop: "ssxq", type: "datetime", width: "48%"},
  { label: "民用爆炸物品发生环节", prop: "mybzwpfshj",  type: "input",width: "48%" },
  { label: "事故发生地", prop: "sgfsd",  type: "input",width: "48%" },
  { label: "死亡人数", prop: "swrs",  type: "number" ,width: "48%"},
  { label: "受伤人数", prop: "ssrs",  type: "number" ,width: "48%"},
  { label: "损失价值（人民币万元）", prop: "ssjz",  type: "number",width: "48%" },
  { label: "民用爆炸物品爆炸事故原因", prop: "mybzwpbzsgyy",  type: "textarea" ,width: "100%"},
  { label: "民用爆炸物品爆炸事故发生区域", prop: "mybzwpbzsgfsqy",  type: "input",width: "48%" },
  { label: "民用爆炸物品爆炸事故性质", prop: "mybzwpbzsgxz",  type: "input",width: "48%" },
  { label: "登记人姓名", prop: "djrxm",  type: "input",width: "48%" },
  { label: "登记单位名称", prop: "djdwmc",  type: "input",width: "48%" },
  { label: "发生场所部位详细情况", prop: "djdwmc",  type: "textarea" ,width: "100%"  },
]);
const listQuery = ref({
  sfbqdj: []
}); //表单
const loading = ref(false);
const elform = ref();
const title = ref("");
const rules = reactive({
  rwbt: [{ required: true, message: "请输入任务标题", trigger: "blur" }]
});
const editpeo = ref();
onMounted(() => {});
// 初始化数据
const init = (type, row,) => {
  dialogForm.value = true;
  title.value = type == 'add' ? "新增" : "编辑";
  if (row) getDataById(row.id);
};
// 根据id查询详情
const getDataById = (id) => {
  // qcckGet({}, '/mosty-gsxt/tbGsxtBqgl/'+id).then((res) => {
  //   listQuery.value = res;
  // });
};

// 提交
const submit = () => {
  elform.value.submit((data)=>{
    // let url =  title.value == "新增" ? '/mosty-gsxt/tbGsxtBqgl/save':'/mosty-gsxt/tbGsxtBqgl/update';
    // let params = { ...data }
    // qcckPost(params, url).then((res) => {
    //   proxy.$message({ type: "success", message: title.value + "成功" });
    //   emit("updateDate");
    //   close();
    // }).catch(() => {});
  });
};

// 关闭
const close = () => {
  listQuery.value = {};
  dialogForm.value = false;
  loading.value = false;
};
defineExpose({ init });
</script>

<style lang="scss" scoped>
@import "~@/assets/css/layout.scss";
@import "~@/assets/css/element-plus.scss";
</style>
