<template>
  <div class="item-shield">
    <bread-crumb :curmbFirst="curmbFirst" :curmbSecond="curmbSecond"></bread-crumb>
    <div class="component-content screenSet" id="screenSet">
      <el-radio-group v-model="shieldType" @change="changeType">
        <el-radio-button label="1">屏蔽机构</el-radio-button>
        <el-radio-button label="2">屏蔽人员</el-radio-button>
      </el-radio-group>
      <el-button class="complete" type="primary" size="small" @click="complete">完成</el-button>
      <el-row :gutter="30" class="row" type="flex" style="margin-top: 10px;">
        <el-form :model="formInline" ref="formInline" label-width="75px" class="form-inline">
          <el-col :span="6">
            <el-form-item label="所属机构：">
              <el-input size="small" v-model="formInline.organizationName" placeholder="请输入机构名称"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="姓名：">
              <el-input size="small" v-model="formInline.userName" placeholder="请输入人员名称"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="状态：">
              <el-select size="small" v-model="formInline.status" placeholder="请选择状态">
                <el-option
                  v-for="(item, index) in statusList"
                  :key="index"
                  :label="item.label"
                  :value="item.value"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="6" style="padding:0;text-align:right;padding-right:10px;">
            <el-button type="primary" size="small" @click="searchList()">搜索</el-button>
          </el-col>
        </el-form>
      </el-row>
      <el-table :data="tableData" style="width: 100%">
        <el-table-column prop="userName" label="人员名称" min-width="100" align="center"></el-table-column>
        <el-table-column prop="hospitalName" label="所属医院" align="center"></el-table-column>
        <el-table-column prop="departmentName" label="所属科室" align="center" min-width="100"></el-table-column>
        <el-table-column prop="province" label="所属省份" align="center"></el-table-column>
        <el-table-column prop="city" label="所属城市" align="center"></el-table-column>
        <el-table-column prop="county" label="所属区县" align="center"></el-table-column>
        <el-table-column fixed="right" label="状态" width="200" align="center">
          <template slot-scope="scope">{{ scope.row.status | shieldStatus }}</template>
        </el-table-column>
        <el-table-column fixed="right" label="操作" width="200" align="center">
          <template slot-scope="scope">
            <el-button
              type="text"
              size="small"
              @click="changeStatus(scope.row)"
            >{{ scope.row.status | shieldButton }}</el-button>
          </template>
        </el-table-column>
      </el-table>
      <div class="pagination">
        <el-pagination
          background
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
          :current-page="formInline.pageNo"
          :page-sizes="[10, 20, 30, 100]"
          :page-size="formInline.pageSize"
          layout="total, sizes, prev, pager, next, jumper"
          :total="totalRows"
        ></el-pagination>
      </div>
    </div>
  </div>
</template>
<script>
import BreadCrumb from "../../components/breadcrumb.vue";
import { mapGetters } from "vuex";
import { openLoading, closeLoading } from "../../utils/utils";
import * as commonUtil from "../../utils/utils";
let vm = null;
export default {
  components: {
    BreadCrumb
  },
  data() {
    return {
      curmbFirst: "教培项目",
      curmbSecond: "屏蔽",
      shieldType: 1,
      formInline: {
        organizationName: "",
        userName: "",
        status: "",
        pageNo: 1,
        pageSize: 10
      },
      statusList: [
        {
          label: "屏蔽",
          value: 0
        },
        {
          label: "取消屏蔽",
          value: 1
        }
      ],
      tableData: [],
      totalRows: 0
    };
  },
  computed: {
    ...mapGetters(["_token"])
  },
  created() {
    vm = this;
    this.search();
    // window.onbeforeunload = function(e) {
    //   let pathname = location.href.split("/");
    //   pathname = pathname[pathname.length - 1];
    //   // console.log(pathname);
    //   if (pathname == "item-shield") {
    //     e = e || window.event;
    //     if (e) {
    //       e.returnValue = "关闭提示";
    //     }
    //     return "关闭提示";
    //   }
    // };
  },
  // 挂载到Dom完成时
  mounted: function() {
    window.onbeforeunload = function(e) {
      let pathname = location.href.split("/");
      pathname = pathname[pathname.length - 1];
      console.log(pathname);
      if (pathname == "item-shield") {
        e = e || window.event;
        if (e) {
          e.returnValue = "数据不会保存";
        }
        return "数据不会保存";
      }
    };
    commonUtil.resizeHeight();
  },
  beforeRouteLeave(to, from, next) {
    const answer = window.confirm(
      "Do you really want to leave? you have unsaved changes!"
    );
    if (answer) {
      next();
    } else {
      next(false);
    }
  },
  destroyed() {},
  methods: {
    searchList() {
      this.formInline.pageNo = 1;
      this.search();
    },
    search() {
      vm.tableData = [
        {
          userName: "云小鹊",
          hospitalName: "测试医院",
          departmentName: "呼吸科",
          province: "上海市",
          city: "上海市",
          county: "浦东新区",
          status: 0
        }
      ];
    },
    // 屏蔽/取消屏蔽
    changeStatus() {
      vm.tableData[0].status = 1;
    },
    //改变
    changeType(value) {
      console.log(value);
      vm.searchList();
    },
    complete() {
      console.log("完成");
    },
    handleSizeChange(val) {
      console.log(`每页 ${val} 条`);
      this.formInline.pageSize = val;
    },
    handleCurrentChange(val) {
      console.log(`当前页: ${val}`);
      this.formInline.pageNo = val;
      this.search();
    }
  }
};
</script>
<style lang="scss">
.item-shield {
  .component-content {
    padding: 10px;
    background: #fff;
    .complete {
      float: right;
    }
  }
}
</style>