<template>
  <div class="dialog" v-if="dialogForm">
    <div class="head_box">
      <span class="title">场所案事件信息{{ title }}</span>
      <div>
        <el-button type="primary" v-if="title != '详情'" size="small" :loading="loading" @click="submit">保存</el-button>
        <el-button size="small" @click="close">关闭</el-button>
      </div>
    </div>
    <div class="cntinfo">
      <el-form :model="listQuery" :label-width="230" label-position="left">
        <div class="form-row">
          <el-form-item label="场所代码">
            <el-input v-model="listQuery.csdm" placeholder="01"/>
          </el-form-item>
          <el-form-item label="场所名称">
            <el-input v-model="listQuery.csmc" placeholder="天上人间ktv"/>
          </el-form-item>
        </div>

        <div class="form-row">
          <el-form-item label="案事件编号">
            <el-input v-model="listQuery.asjbh" placeholder="123456"/>
          </el-form-item>
          <el-form-item label="按时间发生时间">
            <el-input v-model="listQuery.sbmc" placeholder="2025-03-10 10:10:10"/>
          </el-form-item>
        </div>

        <el-form-item label="简要案情">
          <el-input v-model="listQuery.sbxh" type="textarea" placeholder="1234566"/>
        </el-form-item>

        <div class="labelTileile">
          <span>案事件人员</span>
          <el-button size="small" @click="modelValue = true,titleValue = '新增'">新增人员</el-button>
        </div>

        <div class="form-row" v-for="(it,idx) in listQuery.list" :key="idx">
          <el-form-item label="姓名">
            <el-input v-model="it.xm" placeholder="xxxxxxx"/>
          </el-form-item>
          <el-form-item label="证件号码">
            <el-input v-model="it.zjhm" placeholder="100"/>
          </el-form-item>
        </div>
      </el-form>
    </div>
  </div>

  <!-- 新增人员 -->
  <el-dialog :title="titleValue" width="700px" :model-value="modelValue" @close="closed">
      <el-form :model="addForm" :rules="rules" ref="addFormVal" :inline="true">
        <el-form-item label="姓名" prop="xm">
          <el-input v-model="addForm.xm" placeholder="请输入姓名" clearable />
        </el-form-item>
        <el-form-item label="身份证" prop="zjhm">
          <el-input v-model="addForm.zjhm" placeholder="请输入身份证" clearable />
        </el-form-item>
      </el-form>
      
      <template #footer>
        <div class="tc">
          <el-button @click="closed">取消</el-button>
          <el-button type="primary" @click="onComfirm">确认</el-button>
        </div>
      </template>
    </el-dialog>
</template>

<script setup>
import { ref, reactive } from 'vue';
import { Plus } from '@element-plus/icons-vue';

const dialogForm = ref(false);
const activeName = ref('basic');
const title = ref('详情');
const listQuery = ref({
  list: [
    {xm:'张三',zjhm:'510183199626565555'},
    {xm:'张三',zjhm:'510183199626565555'},
    {xm:'张三',zjhm:'510183199626565555'},
    {xm:'张三',zjhm:'510183199626565555'},
    {xm:'张三',zjhm:'510183199626565555'},
  ]
});
const addFormVal = ref()
const modelValue = ref(false)
const titleValue = ref('')
const addForm = reactive({});
const rules = reactive({
  xm: [{ required: true, message: '请输入姓名', trigger: 'blur' }],
  zjhm: [{ required: true, message: '请输入身份证', trigger: 'blur' }],
});
const closed = () => {
  modelValue.value = false;
  addForm.xm = ''
  addForm.zjhm = ''
};
const onComfirm = () => {
  addFormVal.value.validate((valid) => {
    if (!valid) return false;
    modelValue.value = false;
    listQuery.value.list.push(addForm);
  })
};

// 提交
const submit = ()=>{
  elform.value.validate((valid) => {
    if (!valid) return false;
    // loading.value = true;
    let params = { ...listQuery.value}
    let url = title.value == '新增' ? '/mosty-lzcj/tbDwYy/insert' :'/mosty-lzcj/tbDwYy/update'
    // qcckPost(params, url).then((res) => {
    //   proxy.$message({ type: "success", message: title.value+'成功'});
    //   close()
    //   emit("updateDate",modelLx.value);
    // }).catch(()=>{
    //   loading.value = false;
    // });
  });
}

// 初始化数据
const init = (type, row,) => {
  dialogForm.value = true;
  title.value = type == 'add' ? '新增' : type == 'eidt' ? '编辑' : '详情'
  // 根据type和row初始化表单数据
};

const close = () => {
  dialogForm.value = false;
};

defineExpose({init})
</script>

<style lang="scss" scoped>
.dialog {
  padding: 20px;

  :deep(.el-form-item__label) {
    background-color: #F7FAFB;
    padding: 0px 8px;
    color: #000;
    font-weight: 500;
    border: 1px solid #E3E7ED;
  }

  .head_box {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
  }
  .cntinfo{
    height: calc(100% - 70px);
    overflow: hidden;
    overflow-y: auto;
  }

  .labelTileile{
    display: flex;
    justify-content: space-between;
    align-items: center;
    height: 30px;
    background-color: #F7FAFB;
    border: 1px solid #E3E7ED;
    padding: 0 8px;
    cursor: pointer;
    margin-top: 10px;
  }

  .form-row {
    display: flex;
    
    .el-form-item {
      flex: 1;
    }
  }

  .upload-group {
    display: flex;
    // gap: 20px;
    
    .el-form-item {
      flex: 1;
    }
  }

  .unit {
    margin-left: 5px;
  }
   ::v-deep .el-input__inner{
    height: 36px !important;
    line-height: 36px !important;
    border-radius: 0;
    color: #777575;
  }
}
.el-form-item--default{
  margin-bottom: 0px;
}
</style>