<template>
  <div class="app-container">
    <div class="filter-container">
      <div class="filter-left">
        <div class="filter-item">
          团队名称:
          <el-input
            v-model="input"
            placeholder=""
            style="width: 150px"
          ></el-input>
        </div>
        <div class="filter-item">
          责任人:
          <el-select v-model="value" placeholder="" style="width: 150px">
            <el-option
              v-for="item in options"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            >
            </el-option>
          </el-select>
        </div>

        <el-button type="primary" icon="el-icon-search" class="search-button"
          >搜索</el-button
        >
      </div>

      <div class="handle-button-right">
        <el-button
          icon="el-icon-plus"
          type="success"
          @click="dialogFormVisible = true"
          >新增</el-button
        >
        <el-button icon="el-icon-delete" type="danger" @click="batchDelete"
          >删除</el-button
        >
        <el-button type="warning">
          <svg-icon icon-class="export" />
          导出
        </el-button>
      </div>
    </div>

    <el-divider></el-divider>
    <el-table
      :data="tableData"
      stripe
      border
      :header-cell-style="{ background: '#EBF1FF', color: '#606266' }"
      style="width: 100%"
      id="out-table"
      @selection-change="handleSelectionChange"
    >
      <el-table-column type="selection" width="40"> </el-table-column>

      <el-table-column prop="teamName" label="团队名称"> </el-table-column>
      <el-table-column prop="ownerCompany" label="所属单位" width="200">
      </el-table-column>
      <el-table-column prop="persolal" label="责任人"> </el-table-column>

      <el-table-column prop="contact" label="联系方式"> </el-table-column>
      <el-table-column prop="createMan" label="创建人"> </el-table-column>
      <el-table-column
        prop="createTime"
        label="创建时间"
        width="200"
      ></el-table-column>

      <el-table-column label="操作" width="150" fixed="right">
        <template slot-scope="scope">
          <el-button
            icon="el-icon-edit"
            style="color: #406ce5"
            @click="handleEdit(scope.$index, scope.row)"
            >编辑</el-button
          >
          <el-button
            icon="el-icon-delete"
            style="color: #f27979"
            @click="handleDelete(scope.$index, scope.row)"
            >删除</el-button
          >
        </template>
      </el-table-column>
    </el-table>

    <el-pagination background layout="prev, pager, next" :total="1000">
    </el-pagination>

    <el-dialog title="新增" :visible.sync="dialogFormVisible">
      <el-form :model="form">
        <el-form-item label="团队名称:" :label-width="formLabelWidth">
          <el-input v-model="form.name" autocomplete="off"></el-input>
        </el-form-item>

        <el-form-item label="责任人:" :label-width="formLabelWidth">
          <el-select v-model="form.region" placeholder="" style="width: 100%">
            <el-option label="责任人一" value="1"></el-option>
            <el-option label="责任人二" value="2"></el-option>
          </el-select>
        </el-form-item>

        <el-form-item label="所属单位:" :label-width="formLabelWidth">
          <el-select v-model="form.region2" placeholder="" style="width: 100%">
            <el-option label="所属单位一" value="3"></el-option>
            <el-option label="所属单位二" value="4"></el-option>
          </el-select>
        </el-form-item>
        <div class="table-tit">组织人员</div>
        <el-table
          :data="tableData2"
          stripe
          border
          :header-cell-style="{ background: '#EBF1FF', color: '#606266' }"
          style="width: 100%"
          id="out-table"
          @selection-change="handleSelectionChange"
        >
          <el-table-column type="selection" width="40"> </el-table-column>

          <el-table-column prop="name" label="姓名"> </el-table-column>
          <el-table-column prop="contact" label="联系方式" >
          </el-table-column>

          
        </el-table>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button
          @click="dialogFormVisible = false"
          style="background: #f6f6f6"
          >关 闭</el-button
        >
        <el-button type="primary" @click="dialogFormVisible = false"
          >保 存</el-button
        >
      </div>
    </el-dialog>
  </div>
</template>


<script>
// 引入导出Excel表格依赖
import FileSaver from "file-saver";
import XLSX from "xlsx";

export default {
  name: "javascriptthree",
  data() {
    return {
      tableData: [
        {
          teamName: "测试团队1",
          ownerCompany: "徐乐路208号虹泾总部园",
          persolal: "admin",
          contact: "13256789034",
          createMan: "admin",
          createTime: "2020-09-15 12:20:12",
        },
        {
          teamName: "测试团队2",
          ownerCompany: "徐乐路208号虹泾总部园",
          persolal: "admin",
          contact: "13256789034",
          createMan: "admin",
          createTime: "2020-09-15 12:20:12",
        },
        {
          teamName: "测试团队3",
          ownerCompany: "徐乐路208号虹泾总部园",
          persolal: "admin",
          contact: "13256789034",
          createMan: "admin",
          createTime: "2020-09-15 12:20:12",
        },
      ],

      tableData2: [
        {
          name: "admin",
          contact: "13245678902",
        },
         {
          name: "张三三",
          contact: "13245678902",
        },
         {
          name: "李思思",
          contact: "13245678902",
        },
         {
          name: "王呜呜",
          contact: "13245678902",
        },
         {
          name: "admin",
          contact: "13245678902",
        },
         
      ],
      multipleSelection: [],

      options: [
        {
          value: "1",
          label: "责任人1",
        },
        {
          value: "2",
          label: "责任人2",
        },
        {
          value: "3",
          label: "责任人3",
        },
      ],
      value: "",

      options2: [
        {
          value: "1",
          label: "角色1",
        },
        {
          value: "2",
          label: "角色2",
        },
        {
          value: "3",
          label: "角色3",
        },
      ],
      value2: "",

      options3: [
        {
          value: "1",
          label: "单位名称1",
        },
        {
          value: "2",
          label: "单位名称2",
        },
        {
          value: "3",
          label: "单位名称3",
        },
      ],
      value3: "",

      input: "",

      dialogFormVisible: false,
      form: {
        name: "",
        region: "",
        region2: "",
        date1: "",
        date2: "",
        delivery: false,
        type: [],
        resource: "",
        desc: "",
      },
      formLabelWidth: "100px",
    };
  },
  methods: {
    //定义导出Excel表格事件
    exportExcel() {
      /* 从表生成工作簿对象 */
      var wb = XLSX.utils.table_to_book(document.querySelector("#out-table"));
      /* 获取二进制字符串作为输出 */
      var wbout = XLSX.write(wb, {
        bookType: "xlsx",
        bookSST: true,
        type: "array",
      });
      try {
        FileSaver.saveAs(
          //Blob 对象表示一个不可变、原始数据的类文件对象。
          //Blob 表示的不一定是JavaScript原生格式的数据。
          //File 接口基于Blob，继承了 blob 的功能并将其扩展使其支持用户系统上的文件。
          //返回一个新创建的 Blob 对象，其内容由参数中给定的数组串联组成。
          new Blob([wbout], { type: "application/octet-stream" }),
          //设置导出文件名称
          "sheetjs.xlsx"
        );
      } catch (e) {
        if (typeof console !== "undefined") console.log(e, wbout);
      }
      return wbout;
    },
    handleEdit(index, row) {
      alert(index, row);
    },
    handleDelete(index, row) {
      this.$confirm("确定删除该数据吗?", "删除", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          this.$message({
            type: "success",
            message: "删除成功!",
          });
          this.tableData.splice(index, 1);
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消删除",
          });
        });
    },

    batchDelete() {
      let multData = this.multipleSelection;
      let tableData = this.tableData;
      let multDataLen = multData.length;
      let tableDataLen = tableData.length;

      for (let i = 0; i < multDataLen; i++) {
        for (let y = 0; y < tableDataLen; y++) {
          if (JSON.stringify(tableData[y]) == JSON.stringify(multData[i])) {
            //判断是否相等，相等就删除
            this.tableData.splice(y, 1);
            console.log("aa");
          }
        }
      }
    },
    handleSelectionChange(val) {
      this.multipleSelection = val;
    },
  },
};
</script>
<style scoped>
.table-tit{
  background: rgb(235, 241, 255);
    border: 1px solid #d9d9d9;
  border-bottom:0;
    font-weight: bold;
    padding: 8px 10px;
}
</style>