<template>
  <div class="page-container researchGroupManage-listPage">
    <div class="researchGroupManage-listPage-min" v-if="pageType == 1">
      <div class="page-top-title-box">
        <p class="page-top-title-name-p">{{propsData.topicName}}</p>
        <p class="page-top-title-out-p" @click="backPage">返回</p>
      </div>
      <div class="page-form-title-box">
        <el-form :model="queryParams" class="form-box" ref="queryForm"
                 :inline="true" style="width:100%;">
          <el-form-item label="" prop="userType">
            <div class="user-table-box">
              <p :class="queryParams.userType == '' ? 'check-table' : ''" @click="tableTitleButton('')">
                全部
              </p>
              <p :class="queryParams.userType == 1 ? 'check-table' : ''" @click="tableTitleButton(1)">
                教职工
              </p>
              <p :class="queryParams.userType == 2 ? 'check-table' : ''" @click="tableTitleButton(2)">
                学生
              </p>
            </div>
          </el-form-item>
          <el-form-item label="" prop="isStart">
            <el-select v-model="queryParams.isStart" placeholder="请选择状态" style="width: 200px">
              <el-option
                v-for="dict in optionList"
                :key="dict.value"
                :label="dict.label"
                :value="dict.value"
              />
            </el-select>
          </el-form-item>
          <el-form-item label="" prop="deptId">
            <el-select v-model="queryParams.deptId" placeholder="请选择部门" style="width: 200px">
              <el-option
                v-for="dict in sectionOptionList"
                :key="dict.deptId"
                :label="dict.deptName"
                :value="dict.deptId"
              />
            </el-select>
          </el-form-item>
          <el-form-item label="" prop="searchValue">
            <el-input
              maxLength="30"
              v-model="queryParams.searchValue"
              placeholder="姓名/工号/学号"
              style="width: 200px"
            />
          </el-form-item>
          <p class="page-inquire-common-style-button" @click="handleQuery">查询</p>
          <p class="page-reset-common-style-button" @click="resetQuery">重置</p>
          <p style="float: right;line-height:40px;font-size:16px;color:#0045AF;margin-right:10px;">成员数：{{total}}</p>
        </el-form>
      </div>
      <div class="page-content-box">
        <el-table class="table-box" v-loading="loading" border :data="dataList">
          <el-table-column label="姓名" prop="userName"  show-overflow-tooltip/>
          <el-table-column label="身份" prop="userType" width="250" show-overflow-tooltip>
            <template slot-scope="scope">{{scope.row.userType == 1?'老师':'学生'}}</template>
          </el-table-column>
          <el-table-column label="手机号码" prop="userPhone" width="300" show-overflow-tooltip/>
          <el-table-column label="所属部门" prop="deptName" width="250" show-overflow-tooltip/>
          <el-table-column label="状态" prop="isStart" width="200" show-overflow-tooltip
                           v-hasPermiRouter="['system:topic:edit']">
            <template slot-scope="scope">
              <el-switch
                @click.native="tableButton(2,scope.row)"
                class="switch captcha-img"
                :active-value="true"
                :inactive-value="false"
                active-color="#0183FA"
                inactive-color="#999"
                v-model="scope.row.isStart"
                active-text="启用"
                inactive-text="停用"
                disabled
              ></el-switch>
            </template>
          </el-table-column>
          <el-table-column label="操作" width="200" show-overflow-tooltip v-if="tableButtonType">
            <template slot-scope="scope">
              <div class="table-button-box">
                <p class="table-button-null"></p>
                <p class="table-button-p"
                   @click="tableButton(1,scope.row)"
                   v-hasPermiRouter="['system:user:detail']"
                >详情</p>
                <p class="table-button-null"></p>
              </div>
            </template>
          </el-table-column>
        </el-table>
        <pagination :page-sizes="[20, 30, 40, 50]"
                    v-show="total>0"
                    :total="total"
                    :page.sync="queryParams.page"
                    :limit.sync="queryParams.pageSize"
                    @pagination="getList"
        />
      </div>
    </div>
    <list-info-page v-if="pageType == 2" :infoPropsData="infoPropsData" :propsData="propsData"></list-info-page>
  </div>
</template>

<script>
  import { systemTopicMemberList,systemTopicEditMemberStart } from "@/api/integratedManagement/index";
  import { getDeptDropList } from "@/api/commonality/permission";
  //import { getDicts } from "@/api/commonality/noPermission";
  //import { systemUserSelect } from "@/api/commonality/permission";
  //import { getInfo } from "@/api/basicsModules/index";
  import listInfoPage from "./listInfoPage.vue";
  export default {
    name: 'listPage',
    components: {
      listInfoPage,
    },
    props:{
      propsData:{},
    },
    data(){
      return{
        //页面遮罩
        loading:false,
        tableButtonType:this.hasPermiDom(['system:user:detail',]),
        pageType:1,
        //状态
        optionList:[{value:true,label:'启用'},{value:false,label:'停用'}],
        //部门列表
        sectionOptionList:[],
        //查询条件
        queryParams:{
          page:1,
          pageSize:20,
          userType:'',
          isStart :null,
          deptId :null,
          searchValue:"",
        },
        //列表数据
        dataList:[],
        //数据数量
        total:0,
        //详情数据
        infoPropsData:{},
      }
    },
    created(){

    },
    mounted(){
      this.getDeptDropList();
      this.getList();
    },
    methods:{
      //切换状态
      tableTitleButton(type){
        if (this.queryParams.userType != type){
          this.$set(this.queryParams,'userType',type);
          this.getList();
        }
      },
      tableButton(type,row){
        let self = this;
        if(type == 1){
          //详情
          this.$set(this,'infoPropsData',row);
          this.$set(this,'pageType',2);
        }else if(type == 2){
          //启用&停用
          let text = row.isStart  ? "停用" : "启用";
          this.$confirm('是否确认' + text + '?', "警告", {
            confirmButtonText: "确定",
            cancelButtonText: "取消",
            type: "warning"
          }).then(function() {
          }).then(() => {
            systemTopicEditMemberStart({id:row.id,isStart:!row.isStart,}).then(response => {
              self.msgSuccess(response.message)
              self.getList();
            });
          }).catch(() => {});
        }else if(type == 3){
          this.$set(this,'pageType',1);
        }
      },
      // 返回按钮
      backPage(){
        this.$parent.tableButton(6);
      },
      //查询按钮
      handleQuery(){
        this.$set(this.queryParams,'page',1);
        this.getList();
      },
      //重置按钮
      resetQuery(){
        this.$set(this,'queryParams',{
          page:1,
          pageSize:20,
          userType:'',
          isStart :null,
          deptId :null,
          searchValue:"",
        });
        this.getList();
      },
      //获取数据列表
      getList(){
        this.$set(this,'loading',true);
        let obj = JSON.parse(JSON.stringify(this.queryParams))
        obj.topicId = this.propsData.id
        systemTopicMemberList(obj).then(response => {
          this.$set(this,'loading',false);
          this.$set(this,'dataList',response.data.records);
          this.$set(this,'total',response.data.total);
        });
      },
      //获取二级单位列表
      getDeptDropList(){
        getDeptDropList({level:2 }).then(response => {
          this.$set(this,'sectionOptionList',response.data);
        });
      },
    },
  }
</script>

<style scoped lang="scss">
  .researchGroupManage-listPage{
    .researchGroupManage-listPage-min{
      flex:1;
      display: flex;
      flex-direction: column;
      overflow: hidden;
      .page-form-title-box{
        border:none!important;
        .user-table-box{
          display: flex;
          p{
            cursor: pointer;
            width:80px;
            line-height:38px;
            height:40px;
            text-align: center;
            font-size:14px;
            color:#333;
            border:1px solid #dedede;
          }
          p:nth-child(1){
            border-top-left-radius:4px;
            border-bottom-left-radius:4px;
            border-right:none;
          }
          p:nth-child(2){

          }
          p:nth-child(3){
            border-left:none;
            border-top-right-radius:4px;
            border-bottom-right-radius:4px;
          }
          .check-table{
            color:#fff!important;
            background-color: #0045AF!important;
            border:1px solid #0045AF!important;
          }
        }
      }
      .page-content-box{
        padding-top:0;
        flex:1;
        display: flex;
        flex-direction: column;
        overflow: hidden;
      }
    }
  }
</style>
