<template>
  <div>
    <el-dialog :title="props.title" width="1000px" v-model="props.addDiaShow" :before-close="handleClose">
      <!-- 培训计划新增或修改 -->
      <div class="config">
        <el-form ref='formEl' :model="ruleForm" :rules="rules" label-width="150px" class="demo-ruleForm.value"
          style="width: 100% !important;">
          <el-form-item label="车牌号：" prop="carNumber">
            <el-input v-model="ruleForm.carNumber" clearable style="width: 100%"></el-input>
          </el-form-item>
          <el-form-item label="累计行驶里程：" prop="mileage">
            <el-input v-model="ruleForm.mileage" type='number' clearable style="width: 100%">
              <template #append> 公里</template>
            </el-input>
          </el-form-item>
          <el-form-item label="累计使用年限：" prop="usedLife">
            <el-input v-model="ruleForm.usedLife" type='number' clearable style="width: 100%">
              <template #append> 年</template>
            </el-input>
            <!-- <el-date-picker v-model="ruleForm.usedLife" style="width: 100%" type="date" format="YYYY-MM-DD" value-format="YYYY-MM-DD" /> -->
          </el-form-item>
          <el-form-item label="鉴定人：">
            <el-input v-model="ruleForm.expert" clearable style="width: 100%"></el-input>
          </el-form-item>
          <el-form-item label="鉴定时间：">
            <el-date-picker v-model="ruleForm.identifyDate" style="width: 100%" type="date" format="YYYY-MM-DD"
              value-format="YYYY-MM-DD" />
          </el-form-item>
          <el-form-item label="发动机技术鉴定：" style="width: 850px;">
            <el-input v-model="ruleForm.motorIdentify" type="textarea" show-word-limit maxlength="200"
              style="width:700px" />
          </el-form-item>
          <el-form-item label="变速箱技术鉴定：" style="width: 850px;">
            <el-input v-model="ruleForm.gearboxIdentify" type="textarea" autosize show-word-limit maxlength="200"
              style="width:700px" />
          </el-form-item>
          <el-form-item label="前后桥技术鉴定：" style="width: 850px;">
            <el-input v-model="ruleForm.axleIdentify" type="textarea" autosize show-word-limit maxlength="200"
              style="width:700px" />
          </el-form-item>
          <el-form-item label="车架技术鉴定：" style="width: 850px;">
            <el-input v-model="ruleForm.frameIdentify" type="textarea" autosize show-word-limit maxlength="200"
              style="width:700px" />
          </el-form-item>
          <el-form-item label="车身技术鉴定：" style="width: 850px;">
            <el-input v-model="ruleForm.bodyworkIdentify" type="textarea" autosize show-word-limit maxlength="200"
              style="width:700px" />
          </el-form-item>
          <el-form-item label="鉴定小组意见：" style="width: 850px;">
            <el-input v-model="ruleForm.idea" type="textarea" autosize show-word-limit maxlength="200"
              style="width:700px" />
          </el-form-item>
          <el-form-item label="报废原因：" style="width: 850px;">
            <el-input v-model="ruleForm.scrapCause" type="textarea" autosize show-word-limit maxlength="200"
              style="width:700px" />
          </el-form-item>
          <el-form-item label="审批意见：" style="width: 850px;">
            <el-input v-model="ruleForm.approvalIdea" type="textarea" autosize show-word-limit maxlength="200"
              style="width:700px" />
          </el-form-item>
        </el-form>
      </div>

      <template #footer>
        <span class="dialog-footer">

          <el-button type="primary" :loading="loading" @click="handleSave(formEl)" v-if="saveBtnShow">
            <el-icon>
              <DocumentChecked />
            </el-icon>
            <span>保存</span>
          </el-button>
          <el-button @click="handleClose" type="primary">
            <el-icon>
              <DocumentDelete />
            </el-icon>
            <span>关闭</span>
          </el-button>
        </span>
      </template>
    </el-dialog>
  </div>
</template>

<script setup>
// 引入
import {
  ref,
  onMounted,
  defineProps,
  defineEmits,
  reactive,
  watch,
  watchEffect,
  getCurrentInstance
} from "vue";
import { getItem } from "@/utils/storage";
import { useRouter } from "vue-router";
import { getApi, postApi, putApi } from "@/api/tobAcco_api.js";
import { ElMessage } from "element-plus";
import * as MOSTY from "@/components/MyComponents/index";
import * as rule from "@/utils/rules.js";
const { proxy } = getCurrentInstance();
const { D_TB_BGLB } = proxy.$dict("D_TB_BGLB");
//表单数据
const ruleForm = ref({
});
const loading = ref(false)
const formEl = ref()
//规则校验
const rules = reactive({
  carNumber: [{ required: true, message: "车牌号不能为空", trigger: "blur" }],
  ...rule.znumberRule({ validator: true, require: true }, "mileage"),
  ...rule.intfsRule({ validator: true, require: false }, "usedLife"),
});
const props = defineProps({
  addDiaShow: {
    type: Boolean,
    default: false
  },
  rowxq: {
    type: Object,
    default: () => { }
  },
  title: String,
  saveBtnShow: {
    default: true,
    type: Boolean
  }
});


const emits = defineEmits(["changeAddVi", "changeclose"]);

onMounted(() => {
  if (props.rowxq) {
    ruleForm.value = JSON.parse(JSON.stringify(props.rowxq));
  } else {
    ruleForm.value = {}
  }
});

// 关闭
const handleClose = () => {
  if(!formEl.value) return;
  if (props.saveBtnShow) {
    proxy.$modal.confirm('离开会丢失页面中修改的内容，确认离开吗？')
      .then(() => {
        emits("changeclose", false);
      })
      .catch(() => {
        // catch error
      })
  } else {
    emits("changeclose", false);
  }

};

// 关闭×
// 保存
const handleSave = async (formEl) => {
  if (!formEl) return;
  await formEl.validate((valid) => {
    if (valid) {
      loading.value = true
      if (ruleForm.value) {
        emits("changeAddVi", ruleForm.value);
        loading.value = false
      }
      emits("changeclose", false);
      loading.value = false
    } else {
      ElMessage.warning('请输入必填项！！！')
    }
  })
};
</script>

<style lang="scss" scoped>
.fj {
  .el-form {
    padding: 10px;
    margin-top: 10px;
    flex-wrap: wrap;
    // width: 1170px;
    justify-content: flex-end;
  }

  .from_fix {
    display: flex;
    flex-wrap: wrap;
    padding: 10px;
    margin-top: 10px;

    // .el-form-item--default .el-form-item__content {
    //   flex-wrap: nowrap !important;
    // }

    .el-input {
      width: 100%;
    }
  }
}

::v-deep .el-form-item__content {
  flex-wrap: nowrap !important;
}

.config {
  width: 955px;

  .el-form {
    padding: 10px 40px;
    margin-top: 10px;
    flex-wrap: wrap;
    justify-content: space-between;
  }

  .el-form-item {
    width: 46%;
    text-align: center;
  }
}

.pxdx_box {
  width: 500px;
}

.titleBox {
  align-items: center;
  margin: 0;
  padding: 0;
  height: 60px;
  border: 1px solid rgb(32, 75, 54);
  padding: 20px;
}

.form>div {
  position: relative;
  margin-top: 30px;
  display: flex;
  justify-content: space-between;

  div {
    display: flex;
    align-items: center;

    .el-select {
      width: 65%;
    }
  }
}

.el-input {
  width: 75%;
}

.two .el-input {
  width: 65%;
}

.three {
  justify-content: flex-start !important;

  .el-select {
    width: 15%;
  }
}

.four {
  display: flex;
  align-items: center;

  span {
    width: 5%;
  }

  .el-textarea__inner {
    width: 95%;
  }
}

.group {
  margin-top: 50px;
  // background-color: red;
  position: relative;
}

.fj {
  margin-top: 50px;
  width: 100%;

  .content {
    width: 100%;
    display: flex;
    padding: 20px;

    div {
      display: flex;
      width: 85%;
      align-items: center;
    }

    justify-content: space-between;
  }
}

.jc {
  margin-top: 50px;
}

.tabBox {
  height: 300px !important;
}

.el-table {
  height: 300px !important;
  border: 1px solid var(--el-color-primary);
}

.el-form-item__content {
  flex-wrap: nowrap;
}
</style>
