<!-- 数据接收人员 -->
<template>
  <div>
    <el-form
      style="margin-top: 20px; margin-left: 20px"
      :inline="true"
      :model="queryForm"
      class="demo-form-inline"
    >
      <el-form-item label="级部:">
        <el-input
          v-model="queryForm.gradeName"
          placeholder="请输入级部"
        ></el-input>
      </el-form-item>
      <el-form-item label="姓名:">
        <el-input
          v-model="queryForm.teacherName"
          placeholder="请输入姓名"
        ></el-input>
      </el-form-item>
      <el-form-item label="进度:">
        <el-select v-model="queryForm.state" placeholder="请选择进度">
          <!-- 状态 (1未发布 2已发布 3已填写 4已提交 5已确认 9驳回) -->
          <el-option label="未发布" value="1"></el-option>
          <el-option label="已发布" value="2"></el-option>
          <el-option label="已填写" value="3"></el-option>
          <el-option label="已提交" value="4"></el-option>
          <el-option label="已确认" value="5"></el-option>
          <el-option label="驳回" value="9"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button
          size="mini"
          icon="el-icon-search"
          type="primary"
          @click="handleQuery"
          >搜索</el-button
        >
        <el-button size="mini" icon="el-icon-refresh" @click="resetQuery"
          >重置</el-button
        >
        <el-button
          size="mini"
          icon="el-icon-plus"
          :disabled="status == '已结束' ? true : false"
          type="success"
          @click="handleAdd"
          >新增</el-button
        >
      </el-form-item>
    </el-form>
    <el-table style="margin-top: 20px" border :data="tableData">
      <el-table-column type="index" label="序号" width="55" align="center" />
      <el-table-column
        label="学年学期"
        align="center"
        prop="filesSemester"
        min-width="200"
      />
      <el-table-column
        label="级部"
        align="center"
        prop="gradeName"
        min-width="150"
      />
      <el-table-column
        label="姓名"
        align="center"
        min-width="150"
        prop="teacherName"
      />
      <el-table-column
        label="身份证号"
        align="center"
        min-width="200"
        prop="idCard
"
      />
      <el-table-column label="进度" align="center" min-width="150" prop="state">
        <template slot-scope="{ row }">
          <!-- 状态 (1未发布 2已发布 3已填写 4已提交 5已确认 9驳回) -->
          {{
            row.state == 1
              ? "未发布"
              : row.state == 2
              ? "已发布"
              : row.state == 3
              ? "已填写"
              : row.state == 4
              ? "已提交"
              : row.state == 5
              ? "已确认"
              : row.state == 9
              ? "驳回"
              : ""
          }}
        </template>
      </el-table-column>
      <el-table-column fixed="right" label="操作" align="center">
        <template slot-scope="scope">
          <el-button
            :disabled="status == '已结束' ? true : false"
            size="mini"
            type="text"
            @click="handleDelete(scope.row)"
            >删除
          </el-button>
        </template>
      </el-table-column>
    </el-table>
    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryForm.pageNum"
      :limit.sync="queryForm.pageSize"
      @pagination="getList"
    />
    <!--弹窗-->
    <el-dialog title="新增接收人" :visible.sync="dialogVisible" width="60%">
      <el-table
        ref="multipleTable"
        :data="dialogTableData"
        tooltip-effect="dark"
        @selection-change="handleSelectionChange"
      >
        <el-table-column align="center" type="selection"> </el-table-column>
        <el-table-column align="center" label="级部" prop="gruoName">
        </el-table-column>
        <el-table-column align="center" prop="userName" label="姓名">
        </el-table-column>
        <el-table-column align="center" prop="tel" label="身份证号">
        </el-table-column>
      </el-table>
      <span
        style="display: flex; justify-content: center"
        slot="footer"
        class="dialog-footer"
      >
        <el-button @click="dialogVisible = false">取 消</el-button>
        <el-button type="primary" @click="confirmDialog">确 定</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
import {
  addTeacherNotice, //添加任务
  listTeacherNotice, // 任务列表
  infoTeaNotice, //任务详情
  updateTask, //添加修改
  infoTeacherNotice, //发布任务
  taskRetracted, //任务撤回
  taskCompleted, //任务完成
  delTaskInfo, //任务删除
  getteacherNotice, // 通知下档案查看|数据维护
  getNoticeInfo, //老师查看档案详情
  getDepInfo, //级部查看档案详情
  getFileTnfo, //查看档案详情
  syncNotice, //同步档案
  updateInfo, //教师档案修改
  delInfo, //教师档案删除
  fileSubReview, //教师档案提交审核
  fileSubApproved, //教师档案提交通过
  fileSubRejected, //教师档案提交驳回
  getTeaList, //查看可添加老师列表
  addTeachaer, //添加老师
} from "@/api/smartSchool/teacherFiles/teacherElectronicFile";
export default {
  name: "dataReceiver",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 总条数
      total: 0,
      queryForm: {
        pageNum: 1,
        pageSize: 10,
        gradeName: "",
        teacherName: "",
        state: "",
      },
      tableData: [],
      dialogVisible: false,
      form: {},
      status: this.$route.query.status,
      dialogTableData: [],
      selectedRows: [], //选中数组
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
    };
  },
  mounted() {
    this.getList();
  },
  methods: {
    // 查看可添加老师列表
    handleSecher() {
      const tid = this.$route.query.noticeId;
      getTeaList(tid).then((res) => {
        console.log(res, 333333333333);
        this.dialogTableData = res.data;
      });
    },

    //弹窗确定按钮
    confirmDialog() {
      //   const ids = this.selectedRows.map((row) => parseInt(row.id));
      const ids = this.selectedRows.map((row) => parseInt(row.id));
      // dialogVisible = false
      addTeachaer(ids).then((res) => {
        this.$message.success("修改成功");
        this.dialogVisible = false;
        this.getList();
      });
    },

    /** 查询信息列表 */
    getList() {
      const params = {
        pageNum: this.queryForm.pageNum,
        pageSize: this.queryForm.pageSize,
        noticeId: this.$route.query.noticeId,
        gradeName: this.queryForm.gradeName,
        teacherName: this.queryForm.teacherName,
        state: this.queryForm.state,
      };
      getteacherNotice(params).then((res) => {
        this.tableData = res.rows;
        this.total = res.total;
      });
    },
    //  搜索按钮
    handleQuery() {
      this.getList();
    },
    //  重置按钮
    resetQuery() {
      this.queryForm = {
        pageNum: 1,
        pageSize: 10,
        gradeName: "",
        teacherName: "",
        state: "",
      };
      this.handleQuery();
    },
    //  新增按钮
    handleAdd() {
      this.dialogVisible = true;
      this.handleSecher();
    },
    handleSelectionChange(selection) {
      if (selection.length > 0) {
        this.selectedRows = selection.map((item) => item.id);
        this.selectedRows = selection;
        this.single = selection.length !== 1;
        this.multiple = false;
      } else {
        this.selectedRows = [];
        this.multiple = true;
      }
    },

    // 删除按钮
    handleDelete(row) {
      const selectedRows = row.id || this.selectedRows;
      this.$modal
        .confirm("是否确认删除？")
        .then(function () {
          return delInfo(selectedRows);
        })
        .then(() => {
          this.getList();
          this.$modal.msgSuccess("删除成功");
        })
        .catch(() => {});
    },
  },
};
</script>

<style scoped></style>
