<template>
  <el-dialog :title="titleValue" width="800px" :model-value="modelValue" append-to-body @close="closed">
    <el-form ref="historyForm" style="max-width: 600px" :model="ruleForm" :rules="rules" label-width="auto">
      <el-form-item label="车牌号" prop="cph">
        <el-input v-model="ruleForm.cph" placeholder="请输入车牌号" />
      </el-form-item>
      <el-form-item label="车辆识别码" prop="clsbm">
        <el-input v-model="ruleForm.clsbm" placeholder="请输入车辆识别码" />
      </el-form-item>
      <el-form-item label="车辆型号" prop="cllx">
      <el-select v-model="ruleForm.cllx" placeholder="请选择车辆型号">
        <el-option  :label="item.zdmc"  :value="item.dm" v-for="(item,index) in dict.D_BZ_CLLX" :key="index"></el-option>
      </el-select>
    </el-form-item>
    <el-form-item label="车辆颜色" prop="clys">
      <el-select v-model="ruleForm.clys" placeholder="请选择车辆颜色">
        <el-option  :label="item.zdmc"  :value="item.dm" v-for="(item,index) in dict.D_BZ_CLYS" :key="index"></el-option>
      </el-select>
    </el-form-item>
    <el-form-item label="车辆品牌" prop="clpp">
      <el-select v-model="ruleForm.clpp" placeholder="请选择车辆品牌">
        <el-option  :label="item.zdmc"  :value="item.dm" v-for="(item,index) in dict.D_BZ_CLPP" :key="index"></el-option>
      </el-select>
    </el-form-item>
    </el-form>
    <template #footer>
      <div class="dialog-footer">
        <el-button @click="closed">取消</el-button>
        <el-button type="primary" @click="onComfirm">确认</el-button>
      </div>
    </template>
  </el-dialog>
</template>

<script setup>
import { ref, onMounted, reactive, watch, getCurrentInstance } from "vue";
import { generateRandom10Digits } from '@/utils/tools'

const { proxy } = getCurrentInstance()

const props = defineProps({
  modelValue: {
    type: Boolean,
    default: false
  },
  titleValue: {
    type: String,
    default: "关联车辆"
  },
  data: {
    type: Object,
    default: () => { }
  }, dict: {
    type: Object,
    default: () => { }
  }
});
const emits = defineEmits(["update:modelValue", "comfirm"]);
const historyForm = ref(null)
const ruleForm = ref({})
const rules = reactive({
  cph: [
    { required: true, message: '请输入车牌号', trigger: 'blur' },
  ],

});

const onComfirm = () => {
  const promes = {...ruleForm.value,
    id: ruleForm.value.id ? ruleForm.value.id : generateRandom10Digits(),
  }
  console.log(promes);

  emits("comfirm", { ...promes });
  closed()

}
watch(() => props.modelValue, (val) => {
  ruleForm.value = props.data
},{deep: true})


const closed = () => {
  ruleForm.value = {}
  emits("update:modelValue", false);
};
</script>

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

.tabBoxRadio .el-checkbox__inner {
  border-radius: 50% !important;
}

.tabBoxRadio .el-table__header-wrapper .el-checkbox {
  display: none;
}

.file-attachment-section {
  margin-top: 15px;
}

.section-title {
  font-size: 14px;
  font-weight: 500;
  color: #303133;
  margin-bottom: 10px;
  padding-bottom: 5px;
  border-bottom: 1px solid #ebeef5;
}

.file-list-container {
  max-height: 100px;
  overflow-y: auto;
  border: 1px solid #ebeef5;
  border-radius: 4px;
  background-color: #ffffff;
  margin-bottom: 10px;
}

/* 自定义滚动条样式 */
.file-list-container::-webkit-scrollbar {
  width: 6px;
}

.file-list-container::-webkit-scrollbar-track {
  background: #f1f1f1;
  border-radius: 3px;
}

.file-list-container::-webkit-scrollbar-thumb {
  background: #c0c4cc;
  border-radius: 3px;
}

.file-list-container::-webkit-scrollbar-thumb:hover {
  background: #909399;
}

.empty-file-list {
  padding: 20px;
  text-align: center;
  color: #909399;
  font-size: 12px;
}

.file-list {
  padding: 5px;
}

.file-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 10px;
  margin-bottom: 2px;
  background-color: #f8f9fa;
  border-radius: 4px;
  transition: all 0.3s ease;
  cursor: pointer;
}

.file-item:hover {
  background-color: #e6f7ff;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
}

.file-info {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 15px;
  min-width: 0;
}

.file-name {
  flex: 1;
  font-size: 12px;
  color: #303133;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.file-size {
  font-size: 11px;
  color: #909399;
  min-width: 60px;
}

.file-time {
  font-size: 11px;
  color: #909399;
}

.file-actions {
  display: flex;
  align-items: center;
  gap: 5px;
  margin-left: 10px;
}

.file-actions .el-button {
  padding: 0 5px;
  margin: 0;
  color: #606266;
  transition: color 0.3s ease;
}

.file-actions .el-button:hover {
  color: #409eff;
}

.delete-btn:hover {
  color: #f56c6c !important;
}

.upload-btn-container {
  display: flex;
  justify-content: center;
  margin-top: 10px;
}

.butHandle {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

::v-deep .el-range-input {
  color: #000 !important;
}
</style>
