<!-- 电产院科研管理系统-项目成员管理 -->
<template>
  <el-card shadow="never" class="aui-card--fill">
    <div class="mod-teammateManagement__teammatemanagement}">
      <el-form :inline="true" :model="dataForm" @keyup.enter.native="getDataList()">
        <el-form-item label="所属项目：">
          <el-select v-model="dataForm.projectId" placeholder="选择项目">
            <el-option v-for="(project, index) in projectList" :label="project.projectName" :value="project.id"
                       :key="index"></el-option>
          </el-select>
        </el-form-item>

        <!--        <el-form-item>-->
        <!--          <el-input v-model="dataForm.id" placeholder="id" clearable></el-input>-->
        <!--        </el-form-item>-->
        <el-form-item>
          <el-button @click="getDataList()">{{ $t('query') }}</el-button>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="addOrUpdateHandleWapper()">{{ $t('add') }}</el-button>
        </el-form-item>
        <el-form-item>
          <el-button type="danger" @click="deleteHandleWapper()">{{ $t('deleteBatch') }}</el-button>
        </el-form-item>
      </el-form>
      <el-table v-loading="dataListLoading" :data="dataList" border @selection-change="dataListSelectionChangeHandle"
                style="width: 100%;">
        <el-table-column type="selection" header-align="center" align="center" width="50"></el-table-column>
        <!--         <el-table-column prop="id" label="管理记录ID" header-align="center" align="center"></el-table-column>-->
        <!--         <el-table-column prop="projectId" label="项目ID" header-align="center" align="center"></el-table-column>-->
        <el-table-column prop="name" label="姓名" header-align="center" align="center"></el-table-column>
        <!--        <el-table-column prop="advantages" label="技能特长" header-align="center" align="center"></el-table-column>-->
        <!--        <el-table-column prop="expectDevelop" label="开发模块" header-align="center" align="center"></el-table-column>-->
        <!--        <el-table-column prop="projectApplicaitonId" label="立项申请ID" header-align="center" align="center"></el-table-column>-->
        <el-table-column prop="groupName" label="小组名称" header-align="center" align="center"></el-table-column>
        <el-table-column prop="isTeamleader" label="是否小组长" header-align="center" align="center"></el-table-column>
        <!--        <el-table-column prop="status" label="审核状态" header-align="center" align="center"></el-table-column>-->
        <!--        <el-table-column prop="creator" label="创建人" header-align="center" align="center"></el-table-column>-->
        <!--        <el-table-column prop="createDate" label="创建时间" header-align="center" align="center"></el-table-column>-->
        <el-table-column :label="$t('handle')" fixed="right" header-align="center" align="center" width="230">
          <template slot-scope="scope">
            <el-button size="small" @click="lookUpInfo(scope.row.id)">{{ "详情" }}</el-button>
            <el-button size="small" @click="addOrUpdateHandleWapper(scope.row.id)">{{ $t('update') }}</el-button>
            <el-button type="danger" size="small" @click="deleteHandleWapper(scope.row.id)">{{
                $t('delete')
              }}
            </el-button>
          </template>
        </el-table-column>
      </el-table>
      <el-pagination
          :current-page="page"
          :page-sizes="[10, 20, 50, 100]"
          :page-size="limit"
          :total="total"
          layout="total, sizes, prev, pager, next, jumper"
          @size-change="pageSizeChangeHandle"
          @current-change="pageCurrentChangeHandle">
      </el-pagination>
      <!-- 弹窗, 新增 / 详情/ 修改 -->
      <add-or-update :isedit="popIsEdit" v-if="addOrUpdateVisible" ref="addOrUpdate"
                     :currentProjectInfo="this.projectInfo"
                     @refreshDataList="getDataList"></add-or-update>
    </div>
  </el-card>
</template>

<script>
import mixinViewModule from '@/mixins/view-module'
import AddOrUpdate from './teammatemanagement-add-or-update'

export default {
  mixins: [mixinViewModule],
  data() {
    return {
      mixinViewModuleOptions: {
        getDataListURL: '/system/teammateManagement/teammatemanagement/page',
        getDataListIsPage: true,
        deleteURL: '/system/teammateManagement/teammatemanagement',
        deleteIsBatch: true
      },
      dataForm: {
        id: '',
        projectId: "选择项目",
      },
      projectList: [],
      popIsEdit: false,
      projectInfo:{projectAppId:"", projectAppName:""},
    }
  },
  created() {
    this.getProjectList();
  },
  components: {
    AddOrUpdate
  },
  methods: {
    lookUpInfo(scopeRowId) {

      this.popIsEdit = false;
      this.addOrUpdateHandle(scopeRowId)

    },
    addOrUpdateHandleWapper(scopeRowId) {
      if (this.dataForm.projectId==="选择项目") {
        return this.$message({
          message: "请先选择所属项目",
          type: 'warning',
          duration: 3000
        })
      }

      this.projectList.forEach((item)=>{
        if(item.id === this.dataForm.projectId){
          this.projectInfo.projectAppId = item.id;
          this.projectInfo.projectAppName = item.projectName;
        }
      })

      // console.log(this.projectList);
      //
      // console.log(this.dataForm.projectId)
      // console.log(this.projectInfo)
      // console.log("before")
      this.popIsEdit = true;
      this.addOrUpdateHandle(scopeRowId)
    },
    deleteHandleWapper(scopeRowId) {
      if (this.dataForm.projectId==="选择项目") {
        return this.$message({
          message: "请先选择所属项目",
          type: 'warning',
          duration: 3000
        })
      }
      this.deleteHandle(scopeRowId)
    },
    getProjectList() {
      // 获取项目列表
      this.$http.get(
          '/system/projectApplication/projectapplication/page', {
            params: {
              order: this.order,
              orderField: this.orderField,
              page: this.mixinViewModuleOptions.getDataListIsPage ? this.page : null,
              // limit: this.mixinViewModuleOptions.getDataListIsPage ? this.limit : null,
              limit: 1000,
              studentNumber: this.$store.state.user.username,
            }
          }
      ).then(({
                data: res
              }) => {
        // console.log(res);
        this.projectList = res.data.list
        // console.log(this.projectList)
        if (res.code !== 0) {
          this.projectList = []
          this.total = 0
          return this.$message.error(res.msg)
        }
      }).catch(() => {
      })
    },
  }

}
</script>
