<!-- 课题组管理 -->
<template>
  <div class="app-container researchGroupManage">
    <div class="page-container researchGroupManagePage" v-if="pageType === 1">
      <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="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 class="page-submit-common-style-button"
             style="float: right;"
             @click="tableButton(1)"
             v-hasPermiRouter="['system:topic:add']"
          >新增</p>
          <el-form-item style="float: right;"
                        v-hasPermiRouter="['system:topic:import']">
            <import-component :importConfig="importConfig"></import-component>
          </el-form-item>
        </el-form>
      </div>
      <div class="page-content-box">
        <el-table class="table-box" v-loading="loading" border :data="dataList">
          <el-table-column label="课题组" prop="topicName"  show-overflow-tooltip/>
          <el-table-column label="负责人" prop="userName" width="180" show-overflow-tooltip/>
          <el-table-column label="联系电话" prop="userPhone" width="150" show-overflow-tooltip/>
          <el-table-column label="所属部门" prop="deptName" width="150" show-overflow-tooltip/>
          <el-table-column label="成员数" prop="num" width="100" show-overflow-tooltip/>
          <el-table-column label="状态" prop="isStart" width="135" show-overflow-tooltip
                           v-hasPermiRouter="['system:topic:edit']">
            <template slot-scope="scope">
              <el-switch
                @click.native="tableButton(5,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="创建时间" prop="createTime" width="180" show-overflow-tooltip>
            <template slot-scope="scope">
              <span>{{ parseTime(scope.row.createTime,"{y}-{m}-{d} {h}:{i}") }}</span>
            </template>
          </el-table-column>
          <el-table-column label="创建人" prop="createByName" width="150" show-overflow-tooltip/>
          <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(2,scope.row)"
                   v-hasPermiRouter="['system:topic:detail']"
                >成员</p>
                <p class="table-button-p"
                   @click="tableButton(3,scope.row)"
                   v-hasPermiRouter="['system:topic:detail','system:topic:edit']"
                >编辑</p>
                <p class="table-button-p"
                   @click="tableButton(4,scope.row)"
                   v-hasPermiRouter="['system:topic:del']"
                >删除</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>
    <add-page :propsData="propsData" v-if="pageType === 2"></add-page>
    <list-page :propsData="propsData" v-if="pageType === 3"></list-page>
  </div>
</template>
<script>
  import { systemTopicList,systemTopicAdd,systemTopicTopicDel,systemTopicEditTopicStart } from "@/api/integratedManagement/index";
  import { getDeptDropList } from "@/api/commonality/permission";
  import importComponent from "@/components/importComponent/importComponent.vue";
  import addPage from "./addPage.vue";
  import listPage from "./listPage.vue";
  export default {
    name: 'index',
    components: {
      importComponent,
      addPage,
      listPage,
    },
    data () {
      return {
        tableButtonType:this.hasPermiDom(['system:topic:detail','system:topic:edit','system:topic:del']),
        //页面状态
        pageType:1,
        //页面遮罩
        loading:false,
        //导入设置
        importConfig:{
          upLoadApi:'/system/topic/importData',                //上传接口地址
          downloadApi:'/system/topic/importTemplate',          //下载模板接口地址
          loseApi:'/system/topic/exportErrorData',             //失败报表接口地址
          fileName:'课题组导入模板',                                   //下载模板命名
        },
        //状态
        optionList:[{value:true,label:'启用'},{value:false,label:'停用'}],
        //部门列表
        sectionOptionList:[],
        //查询条件
        queryParams:{
          page:1,
          pageSize:20,
          searchValue:"",
          isStart :null,
          deptId :null,
        },
        //列表数据
        dataList:[],
        //数据数量
        total:0,
        //组件传参
        propsData:{},
      }
    },
    created () {

    },
    mounted () {
      this.getDeptDropList();
      this.getList();
    },
    methods: {
      //查询按钮
      handleQuery(){
        this.$set(this.queryParams,'page',1);
        this.getList();
      },
      //重置按钮
      resetQuery(){
        this.$set(this,'queryParams',{
          page:1,
          pageSize:20,
          searchValue:"",
          isStart :null,
          deptId :null,
        });
        this.getList();
      },
      //获取数据列表
      getList(){
        this.$set(this,'loading',true);
        systemTopicList(this.queryParams).then(response => {
          this.$set(this,'dataList',response.data.records);
          this.$set(this,'total',response.data.total);
          this.$set(this,'loading',false);
        });
      },
      //操作按钮
      tableButton(type,row){
        let self = this;
        if(type == 1){
          //新增
          this.$set(this,'pageType',2);
          this.$set(this,'propsData',{});
        }else if(type == 2){
          //成员列表
          let obj = JSON.parse(JSON.stringify(row))
          this.$set(this,'propsData',obj);
          this.$set(this,'pageType',3);
        }else if(type == 3){
          //编辑
          let obj = JSON.parse(JSON.stringify(row))
          this.$set(this,'propsData',obj);
          this.$set(this,'pageType',2);
        }else if(type == 4){
          //删除
          this.$confirm('是否确认删除?', "警告", {
            confirmButtonText: "确定",
            cancelButtonText: "取消",
            type: "warning"
          }).then(function() {
          }).then(() => {
            systemTopicTopicDel({id:row.id}).then(response => {
              self.msgSuccess(response.message)
              self.getList();
            });
          }).catch(() => {});
        }else if(type == 5){
          //启用&停用
          let text = row.isStart  ? "停用" : "启用";
          this.$confirm('是否确认' + text + '?', "警告", {
            confirmButtonText: "确定",
            cancelButtonText: "取消",
            type: "warning"
          }).then(function() {
          }).then(() => {
            systemTopicEditTopicStart({id:row.id,isStart:!row.isStart,}).then(response => {
              self.msgSuccess(response.message)
              self.getList();
            });
          }).catch(() => {});
        }else if(type == 6){
          //返回并刷新
          this.$set(this,'pageType',1);
          this.getList();
        }
      },
      //获取二级单位列表
      getDeptDropList(){
        getDeptDropList({level:2 }).then(response => {
          this.$set(this,'sectionOptionList',response.data);
        });
      },
    },
  }
</script>
<style scoped lang="scss">
  .researchGroupManage{
    .researchGroupManagePage{

    }
  }
</style>
