<template>
  <div class="app-container">
    <div v-show="viewState ==1">
      <el-tabs class="my-tabs" v-model="activeName" type="card" @tab-click="handleClick">
        <el-tab-pane label="自主学习计划" name="roleList">
          <div class="container">
            <el-table :data="tableData" border style="width: 100%">
              <el-table-column label="序号" width="70px" type="index" align="center">
              </el-table-column>
              <el-table-column label="操作" width="150px" align="center">
                <template slot-scope="scope">
                  <el-button type="primary" size="mini" @click="editRow(scope.row)">
                    编辑
                  </el-button>
                  <el-button type="danger" size="mini" @click.native.prevent="deleteRow(scope.row)">
                    删除
                  </el-button>
                  <!-- <el-button type="primary" size="mini" @click="detail(scope.row)">
                    查看
                  </el-button> -->
                </template>
              </el-table-column>
              <el-table-column prop="teacherNo" label="教师工号" align="center" />
              <el-table-column prop="studentNo" label="学生学号" align="center" />
              <el-table-column prop="planContent" label="学习计划" align="center" />
              <el-table-column prop="stateChinese" label="数据状态" align="center" />
              <el-table-column prop="planOpinionYj" label="反馈意见" align="center" />
            </el-table>
          </div>
        </el-tab-pane>

        <el-tab-pane label="新增计划" name="addrole">
          <table class="e-table" cellspacing="0">
            <tr>
              <td>教师工号</td>
              <td>
                <!-- <el-select v-model="form.type" class="addinputw" placeholder="请选择论坛类别" style="width:300px"
                  @change="getType">
                  <el-option v-for="item in typeList" :key="item.dictKey" :label="item.dictValue"
                    :value="item.dictKey" />
                </el-select> -->
                <el-input v-model="form.teacherNo" style="width: 300px"></el-input>
              </td>
            </tr>
            <tr>
              <td>学生学号</td>
              <td>
                <el-input v-model="form.studentNo" style="width: 300px"></el-input>
              </td>
            </tr>
            <tr>
              <td>学习计划内容</td>
              <td>
                <el-input v-model="form.planContent" style="width: 300px"></el-input>
              </td>
            </tr>
          </table>
          <div style="margin-top: 20px; text-align: center">
            <el-button type="primary" @click="save()">保存</el-button>
          </div>
        </el-tab-pane>
        <el-dialog :title="dialogTitle + '学习计划'" :visible.sync="editDialog" width="40%">
          <table class="e-table" cellspacing="0">
            <tr>
              <td>教师工号</td>
              <td>
                <!-- <el-select v-model="form.type" class="addinputw" placeholder="请选择论坛类别" style="width:300px"
             @change="getType">
             <el-option v-for="item in typeList" :key="item.dictKey" :label="item.dictValue"
               :value="item.dictKey" />
           </el-select> -->
                <!-- <span>{{form.teacherNo}}</span> -->
                <el-input v-model="form.teacherNo" style="width: 300px"></el-input>
              </td>
            </tr>
            <tr>
              <td>学生学号</td>
              <td>
                <!-- <span>{{form.studentNo}}</span> -->
                <el-input v-model="form.studentNo" style="width: 300px"></el-input>
              </td>
            </tr>
            <tr>
              <td>学习计划内容</td>
              <td>
                <!-- <span>{{form.planContent}}</span> -->
                <el-input v-model="form.planContent" style="width: 300px"></el-input>
              </td>
            </tr>
          </table>
          <div style="margin-top: 20px; text-align: center">
            <el-button type="primary" @click="save()">保存</el-button>
          </div>
        </el-dialog>
      </el-tabs>
    </div>
    <!-- <organizationManageInfo v-show="viewState ==4" ref="divInfo" @doback="resetState" /> -->
  </div>
</template>

<script>
  import {selectSysPlanXs,alterSysPlant,saveSysPlan,deleteSysPlan} from "@/api/system/region/region.js";
  // import organizationManageInfo from './organizationManageInfo.vue'
  export default {
    components: {
      // organizationManageInfo,
    },
    data() {
      return {
        viewState: 1,
        activeName: "roleList",
        dialogTitle: "",
        editDialog: false,
        form: {},
        formBackup: Object.assign({}, this.form),
        tableData: [],
        userName: window.sessionStorage.getItem("userName"),
      }
    },
    mounted() {
      this.getPageList();
    },
    methods: {
      getPageList() {
        // 获取列表
        selectSysPlanXs({userName:this.userName}).then((res) => {
          this.tableData = res.data;
        });
        console.log(this.userName);
      },
      handleClick(tab, event) {
        if (tab.name == "addrole") {
          this.dialogTitle = "新增";
          this.roleForm = Object.assign({}, this.formBackup);
        } else {
          this.getPageList();
        }
      },
      save() {
        console.log("form", this.form)

        if (this.form.sid) {
          alterSysPlant(this.form).then((res) => {
            this.editDialog = false;
            this.getPageList();
            this.$message({
              message: res.msg,
              type: "success",
            });
          });
        } else {
          saveSysPlan(this.form).then((res) => {
            this.getPageList();
            this.activeName = "roleList";
            this.$message({
              message: res.msg,
              type: "success",
            });
          });
        }
          this.reset();
      },
      reset() {
        this.form = {};
      },
      resetState() {
        this.viewState = 1
      },
      editRow(row) {
        this.dialogTitle = "编辑";
        this.editDialog = true;
        this.form = Object.assign({}, row);
      },
      detail(row) {
        this.viewState = 4
        this.$refs['divInfo'].showAdd(row)

      },
      deleteRow(row) {
        this.$confirm("确定要删除该资源吗, 是否继续?", "提示", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning",
        }).then(() => {
          deleteSysPlan(row.sid).then((res) => {
            this.getPageList();

            this.$message({
              type: "success",
              message: "删除成功!",
            });

          });

        });

      },
    }
  };
</script>

<style scoped="scoped" lang="scss">
  .my-tabs {
    margin-top: 10px;
  }
</style>
