<template>
  <div>
    <!-- @tab-click="handleClick" -->
    <el-tabs v-model="activeName">
      <el-tab-pane label="老师调整" name="first">
        <resetTeacher
          v-if="activeName == 'first'"
          @cancaleMerge="cancaleMerge"
          :idList="idList"
          :dataList="dataList"
          @submit="submit"
        />
      </el-tab-pane>
      <el-tab-pane label="课程顺延" name="second">
        <couresPostpone   v-if="activeName == 'second'"  @cancaleMerge="cancaleMerge"
          :idList="idList"
          :dataList="dataList"
          @submit="submit"/>
      </el-tab-pane>
      <el-tab-pane label="课程调整" name="third">
        <courseResets  v-if="activeName == 'third'" @cancaleMerge="cancaleMerge"
          :idList="idList"
          :dataList="dataList"
          @submit="submit"/>
      </el-tab-pane>
    </el-tabs>

    <el-dialog
      title="班级预览"
      :visible.sync="previewVisible"
      append-to-body
      width="900px"
    >
      <preview :details="previewList" />
      <div slot="footer" class="dialog-footer">
        <el-button @click="previewVisible = false">上一步</el-button>
        <el-button type="primary" @click="resetsubmit">确认调整</el-button>
      </div>
    </el-dialog>
  </div>
</template>
<script>
import resetTeacher from "./modals/resetTeacher";
import couresPostpone from './modals/coursePostpone'
import courseResets from './modals/resetCourses'
import { batchCourseAdjust } from "@/api/buildTeam";
import preview from "./modals/resetCoursePreview";
export default {
  components: { resetTeacher, preview,couresPostpone,courseResets },
  props: ["dataList", "idList"],
  data() {
    return {
      activeName: "first",
      previewVisible: false,
      previewList: [],
      obj: {},
    };
  },
  methods: {
    handleClick(val) {

    },
    cancaleMerge() {
      this.$emit("cancaleMerge");
    },
    async submit(form) {
      try {
        const res = await batchCourseAdjust(form);
        if (res.code == 206) {
          this.previewList = res.data;
          this.previewVisible = true;
          this.obj = form;
        }
        if(res.code == 200){
            this.$message.success('调整成功')
             this.$emit("closeReset");
        }
      } catch (e) {
        console.log(e);
      }
    },
    async resetsubmit() {
      try {
        this.obj.confirmGenerate = true;
        const res = await batchCourseAdjust(this.obj);
        if (res.code == 200) {
           this.$message.success('调整成功')
          this.$emit("closeReset");
        }
        if(res.code == 207){
           await this.$confirm(
          res.msg || `当前课程课酬预计为0,是否继续`,
          "提示",
          {
            type: "warning",
          }
        );
        this.obj.allowZeroSalary = true;
        await batchCourseAdjust(this.obj);
        this.$message.success('调整成功')
          this.$emit("closeReset");
        }
      } catch (e) {
        console.log(e);
      }
    },
  },
};
</script>

<style lang="scss" scoped>
</style>
