<template>
  <!-- 转移分组模板 -->
  <el-dialog
    :title="title"
    append-to-body
    :visible.sync="box"
    :close-on-click-modal="false"
    :close-on-press-escape="false"
    @closed="closed"
    width="555px"
  >
    <avue-form ref="groups" :option="option" v-model="form" @submit="handleSubmit">
      <template slot="menuForm" slot-scope="{disabled}">
        <!-- <el-button type="primary" icon="el-icon-check" @click="copy" :disabled="formLoading">提交</el-button> -->
        <el-button icon="el-icon-circle-close" @click="box = false" :loading="disabled">取消</el-button>
      </template>
    </avue-form>
  </el-dialog>
</template>

<script>
import { transferDept } from "@/api/tenant/talents";
export default {
  props: {
    ids: String,
  },
  data() {
    return {
      title: "",
      groupId: "",
      box: false,
      form: {},
      option: {
        menuPosition: "right",
        menuBtn: true,
        submitBtn: true,
        emptyBtn: false,
        column: [
          {
            label: "所属分组",
            prop: "groupId",
            type: "tree",
            span: 24,
            display: true,
            dicUrl: `/api/jobslink-api/tenant/talents/group/listAll`,
            dicMethod: "get",
            dicFormatter: (res) => {
              return res.data.list; //返回字典的层级结构
            },
            props: {
              label: "groupName",
              value: "id",
            },
            rules: [
              {
                required: true,
                whitespace: true,
                message: "请选择分组",
                trigger: "change",
              },
            ],
            placeholder: "请选择分组",
          },
        ],
      },
    };
  },
  computed: {},
  methods: {
    closed() {
      this.form = {};
      if (this.$refs.groups) {
        this.$refs.groups.init();
        this.$refs.groups.clearValidate();
        this.$refs.groups.resetForm();
      }
    },
    openDialog() {
      this.title = "转移分组";
      this.box = true;
      if (this.$refs.groups) {
        this.$refs.groups.init();
        this.$refs.groups.clearValidate();
        this.$refs.groups.resetForm();
      }
    },
    handleSubmit(form, done) {
      //提交转移分组接口
      transferDept(this.form.groupId, this.ids).then(
        () => {
          this.box = false;
          this.$message({
            type: "success",
            message: "操作成功!",
          });
          this.$emit("refresh");
          done();
        },
        (error) => {
          window.console.log(error);
          done();
        }
      );
    },
  },
};
</script>

<style>
</style>
