<template>
  <div class="dialog" v-if="dialogForm">
    <div class="head_box">
      <span class="title">{{ title }}重点车辆管理</span>
      <div>
        <el-button type="primary" size="small" v-if="!disabled" :loading="loading" @click="submit">保存</el-button>
        <el-button size="small" @click="close">关闭</el-button>
      </div>
    </div>
    <div class="form_cnt">
      <FormMessage :disabled="disabled" v-model="listQuery" :formList="formData" labelWidth="100px" ref="elform"
        :rules="rules">

      </FormMessage>
    </div>
  </div>
   <ChooseMarks v-model="chooseMarksVisible" @choosed="choosed" :roleIds="roleIds" />
</template>

<script setup>
import * as rule from "@/utils/rules.js";
import * as MOSTY from "@/components/MyComponents/index";
import { getItem } from "@/utils/storage";
import MyTable from "@/components/aboutTable/MyTable.vue";
import ChooseMarks from "@/components/ChooseList/ChooseMarks/index.vue";
import FormMessage from "@/components/aboutTable/FormMessage.vue";
import { qcckGet, qcckPost, qcckPut } from "@/api/qcckApi.js";
import {
  ref,
  defineExpose,
  reactive,
  onMounted,
  defineEmits,
  getCurrentInstance,
  watch
} from "vue";
const emit = defineEmits(["updateDate"]);
const props = defineProps({
  dic: Object
});
const { proxy } = getCurrentInstance();
const roleIds = ref([]);
const chooseMarksVisible = ref(false);
const dialogForm = ref(false); //弹窗
const pcsList = ref([]);
const rules = reactive({
  ryXm: [{ required: true, message: "请输入姓名", trigger: "blur" }],
  ...rule.identityCardRule({ validator: true },'rySfzh'), //身份证校验
  ...rule.phoneRule({ validator: true }, "ryLxdh"), // 是否必填 是否进行校验,
  ryXb: [{ required: true, message: "请选择性别", trigger: "change" }],
  ryMz: [{ required: true, message: "请选择民族", trigger: "change" }],
  ryCsrq: [{ required: true, message: "请选择出生日期", trigger: "change" }],
  ryJg: [{ required: true, message: "请选择籍贯", trigger: "change" }],
  zdrRyjb: [{ required: true, message: "请选择人员级别", trigger: "change" }],
  zdrYjdj: [{ required: true, message: "请选择预警等级", trigger: "change" }]
});
const listQuery = ref({}); //表单
const formData = ref([]);
watch(() => props.dic,(val) => {
    formData.value = [
      { label: "车牌号", prop: "hphm", type: "input" },
      { label: "车架号", prop: "clCjh", type: "input" },
      { label: "车辆颜色", prop: "clYs",type: "input", },
      { label: "车辆所有人", prop: "clSyr", type: "input" },
      { label: "人员身份证", prop: "clSyrsfzh", type: "input" },
      { label: "责任单位", prop: "zrSsbmdm",depMc:'zrSsbmmc', type: "department" },
      { label: "管辖单位", prop: "gxSsbmdm",depMc:'gxSsbmmc', type: "department" },
      { label: "管控民警姓名", prop: "gkMjXm", type: "input" },
      { label: "管控民警警号", prop: "gkMjJh", type: "input" },
      { label: "预警等级", prop: "yjdj", type: "select",options:props.dic.D_GS_ZDR_YJDJ },
      { label: "预警标签", prop: "yjbq", type: "select",options:props.dic.BD_BK_CLYJBQ },
      { label: "管控原因", prop: "clLkyy", type: "textarea", width: "100%" },
      { label: "车辆照片", prop: "fjdz", type: "upload", width: "100%" },
    ];
  },
  { immediate: true, deep: true }
);

const tableDate = reactive({
  tableConfiger: {
    rowHieght: 61,
    showSelectType: "null",
    loading: false
  },
  controlsWidth: 90, //操作栏宽度
  keyCount: 0,
  tableColumn: [
    { label: "标签名称", prop: "bqMc" },
    { label: "标签代码", prop: "bqDm" },
    { label: "标签种类", prop: "bqZl", showSolt: true },
    { label: "标签类型", prop: "bqLx", showSolt: true },
    { label: "标签类别", prop: "bqLb", showSolt: true }
  ]
});
const loading = ref(false);
const elform = ref();
const title = ref("");
const showInfo = ref(false);
const disabled = ref(false);

onMounted(() => {
});


// 初始化数据
const init = (type, row) => {
  dialogForm.value = true;
  title.value = type == "add" ? "新增" : type == "detail" ? "详情" : "编辑";
  disabled.value = type == "detail" ? true : false;
  tableDate.tableConfiger.haveControls = type == "detail" ? false : true;
  setTimeout(() => {
    showInfo.value = true;
  }, 5);
  if (row) getDataById(row.id);
};
// 根据id查询详情
const getDataById = (id) => {
  qcckGet({id}, "/mosty-gsxt/tbGsxtZdcl/selectByid").then((res) => {
    listQuery.value = res;
    listQuery.value.fjdz = listQuery.value.fjdz?.split(",");
  });
};

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


// 关闭
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";

::v-deep .el-tabs--card>.el-tabs__header .el-tabs__item.is-active {
  color: #0072ff;
  background: rgba(0, 114, 255, 0.3);
}

.boxlist {
  width: calc(99% - 50px);
  margin-top: 10px;
  overflow: hidden;
}

.depBox {
  border: 1px solid #e9e9e9;
  width: 305px;
  padding: 0 0 0 4px;
  border-radius: 4px;

  ::v-deep .el-input__inner {
    border: none;
  }

  ::v-deep .el-cascader .el-input.is-focus .el-input__inner {
    border-color: transparent !important;
  }

  ::v-deep .el-input__inner:focus {
    box-shadow: none;
  }

  ::v-deep .el-input.is-disabled .el-input__inner {
    border-color: transparent !important;
  }
}
.marks{
    width: 100%;
    width: 100%;
    min-height: 32px;
    border: 1px solid #e9e9e9;
    border-radius: 4px;
}
</style>
