<template>
  <div class="dialog" v-if="dialogVisible">
    <div class="head_box">
      <span class="title">{{ title }}</span>
      <div>
        <!-- <el-button size="small" @click="save" type="primary" :loading="loading">保存</el-button> -->
        <el-button size="small" @click="close">关闭</el-button>
      </div>
    </div>
    <div class="cntinfo">
      <el-descriptions column="2" border label-width="120px">
        <el-descriptions-item label="姓名">{{ formData.xm }}</el-descriptions-item>
        <el-descriptions-item label="身份证号">{{ formData.sfzh }}</el-descriptions-item>
        <el-descriptions-item label="联系电话">{{ formData.lxdh }}</el-descriptions-item>
        <el-descriptions-item label="所属保安公司">
          <DictTag :value="formData.ssbags" :options="D_BAXX_DWLX" />
        </el-descriptions-item>
        <el-descriptions-item label="线上培训时长">{{ formData.pxsc }}</el-descriptions-item>
        <el-descriptions-item label="提交日期">{{ formData.tjrq }}</el-descriptions-item>
      </el-descriptions>
    </div>
  </div>
</template>

<script setup>
import { ref, computed, getCurrentInstance } from 'vue'
import { qcckPost } from "@/api/qcckApi.js";

const { proxy } = getCurrentInstance()
const { D_BAXX_DWLX } = proxy.$dict("D_BAXX_DWLX")

const title = ref('保安考试申请')
const loading = ref(false)
const disabled = ref(false)
const FormRef = ref(null)

const props = defineProps({
  modelValue: {
    type: Boolean,
    default: false
  },
})

const emits = defineEmits(['update:modelValue'])

const dialogVisible = computed({
  get() {
    return props.modelValue
  },
  set(val) {
    emits('update:modelValue', val)
  }
})

const formData = ref({})

const close = () => {
  dialogVisible.value = false
}

const open = (row = {}, type = 'add') => {
  disabled.value = false
  dialogVisible.value = true
  formData.value = { ...row }
}

const save = () => {
  FormRef.value.submit(() => {
    loading.value = true;
    const url = !formData.value?.id ? `/mosty-base/baxx/cyry/add` : `/mosty-base/baxx/cyry/edit`;
    qcckPost(formData.value, url).then(() => {
      loading.value = false;
      proxy.$message.success("保存成功");
      emits("refresh");
      close();
    }).catch(() => {
      loading.value = false;
    })
  });
}

defineExpose({ open })
</script>

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

.cntinfo {
  padding: 2rem 12rem 0rem 12rem;
  height: calc(100% - 70px);
  overflow: hidden;
  overflow-y: auto;
}

.mapBox {
  width: 100%;
  height: 400px;
  overflow: hidden;
}
</style>
