<template>
  <div style="width: 50%">
    <el-form :model="desc" label-width="100px">
      <el-form-item label="结构编码">
        <el-input v-model="desc.code"></el-input>
      </el-form-item>
      <el-form-item label="上级节点">
        <el-cascader
          v-model="desc.parentcode"
          :options="cascaderdata"
          :props="{ checkStrictly: true, emitPath: false }"
          :show-all-levels="false"
          clearable
        />
      </el-form-item>
      <el-form-item label="设备ID">
        <el-input v-model="desc.deviceid" disabled></el-input>
      </el-form-item>
      <el-form-item label="结构名称">
        <el-input v-model="desc.name"></el-input>
      </el-form-item>
      <el-form-item label="结构英文名称">
        <el-input v-model="desc.enname"></el-input>
      </el-form-item>
      <el-form-item label="英文缩写">
        <el-input v-model="desc.sortname"></el-input>
      </el-form-item>
      <el-form-item label="描述">
        <el-input
          v-model="desc.description"
          :rows="4"
          clearable
          type="textarea"
        ></el-input>
      </el-form-item>
      <el-form-item label="序号">
        <el-input v-model="desc.orderno"></el-input>
      </el-form-item>
      <el-form-item label="是否有效">
        <el-switch
          v-model="desc.enabled"
          active-color="#13ce66"
          inactive-color="#ff4949"
        />
      </el-form-item>
    </el-form>
    <el-button
      style="float: right"
      type="primary"
      @click="savedesc"
      :disabled="desc.code == ''"
      >保存</el-button
    >
  </div>
</template>
<script setup>
import { ref, onMounted, inject } from "vue";
import { ElMessageBox, ElMessage } from "element-plus";
import { treeAdd } from "/@/api/api.js";
let desc = inject("desc");
let cascaderdata = inject("cascaderdata");
const savedesc = async () => {
  const res = await treeAdd(desc.value);
  if (res.code === 200) {
    ElMessage.success(`操作成功!`);
  } else {
    ElMessage.success(res.msg);
  }
};
</script>