<template>
  <div class="category-add">
    <!-- <h2 class="dialog_add-title">请选择模板分类</h2> -->
    <SelectVue v-model="value" placeholder="请选择">
      <OptionVue
        v-for="item in MyCategories"
        :key="item.value"
        :label="item.name"
        :value="item.id"
      ></OptionVue>
    </SelectVue>
    <!-- <button class="dialog_add-btn_confirm" @click="checkForm">确定</button>
    <button class="dialog_add-btn_cancel" @click="closeDialog">取消</button> -->
  </div>
</template>

<script lang="ts">
import { defineComponent } from "vue";
import {
  GO_URLS,
  sySelect as SelectVue,
  syOption as OptionVue,
} from "cqk-sy-ui";
import { ElMessage } from "element-plus";
import { $ajax } from "@/service";
export default defineComponent({
  components: {
    SelectVue,
    OptionVue,
  },
  data() {
    return {
      name: "",
      // isErrorShowing: false, // 错误提示
      isInActive: false,
      MyCategories: [] as any,
      value: "",
    };
  },
  // components: { DialogInput },
  created() {
    this.getFolderList();
  },
  methods: {
    async checkForm() {
      if (this.isInActive) return;
      this.isInActive = true;
      // this.isErrorShowing = true;
      // 追加非空验证
      if (this.value === "") {
        ElMessage("请选择分类");
        this.isInActive = false;
        return null;
      }
      if (this.value) {
        this.$emit("successCallback", this.value);
      }
      this.isInActive = false;
    },
    closeDialog() {
      this.$emit("close");
    },
    // 获取我的模板列表
    async getFolderList() {
      const res = await $ajax({
        type: "post",
        url: GO_URLS.folderList,
        params: {
          page: 1,
          page_size: 100,
          template_type: 1,
        },
      });
      if (res) {
        this.MyCategories = res.data.results;
      }
    },
  },
});
</script>

<style lang="scss" scoped>
.category-add {
  background: rgba(255, 255, 255, 1);
}

.dialog_add-title {
  margin: 0;
  color: #000;
  font-size: 22px;
  line-height: 30px;
  padding-left: 44px;
  padding-top: 45px;
  padding-bottom: 45px;
}

.dialog_add-input_name {
  margin-left: 50px;
  margin-top: 39px;
  margin-bottom: 18px;
}

.dialog_add-btn_confirm {
  float: right;
  width: 120px;
  height: 40px;
  color: #fff;
  font-size: 14px;
  outline: none;
  background: var(--sy-blue);
  border-radius: 4px;
  border: none;
  cursor: pointer;
  margin-right: 39px;
}

.dialog_add-btn_cancel {
  float: right;
  margin-right: 18px; /* 28 - 10 */
  border: none;
  width: 48px; /* 28 + 增大20 */
  height: 40px;
  outline: none;
  background: #fff;
  color: #5c6476;
  font-size: 14px;
  cursor: pointer;
}
.el-select {
  width: 100%;
}
:deep(.el-input__inner) {
  height: 44px;
  padding: 0 26px;
}
</style>
