<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" label-width="90px">
      <el-form-item label="企微公司" prop="corpId">
        <el-select v-model="queryParams.corpId" placeholder="企微公司" size="small" @change="updateCorpId()">
          <el-option
            v-for="dict in myQwCompanyList"
            :key="dict.dictValue"
            :label="dict.dictLabel"
            :value="dict.dictValue"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="群名" prop="name">
        <el-input
          v-model="queryParams.name"
          placeholder="请输入群名"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-table v-loading="loading" :data="transferLogList" border>
      <el-table-column label="群名" align="center" prop="name" >
        <template slot-scope="scope">
          <i class="el-icon-s-comment"></i>
          {{scope.row.name}}
        </template>
      </el-table-column>
      <el-table-column label="原群主(后台)" align="center" prop="oldCompanyUserName" />
      <el-table-column label="原群主(企微)" align="center" prop="oldQwUserName" />
      <el-table-column label="新群主(后台)" align="center" prop="newCompanyUserName" />
      <el-table-column label="新群主(企微)" align="center" prop="newQwUserName" />
      <el-table-column label="继承类型" align="center" prop="transferType" >
        <template slot-scope="scope">
          {{scope.row.transferType === 0 ?  '在职继承' : '离职继承'}}
        </template>
      </el-table-column>
      <el-table-column label="操作人" align="center" prop="companyUserName" />
      <el-table-column label="操作时间" align="center" prop="createTime" />
      <el-table-column label="企微主体ID" align="center" prop="corpId" />
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

  </div>
</template>

<script>
import { getMyQwCompanyList } from '@/api/qw/user'
import { list } from '@/api/qw/groupChatTransferLog'

export default {
  name: 'groupChatTransferLog',
  data() {
    return {
      loading: false,
      total: 0,
      queryParams: {
        corpId: null,
        name: null,
        pageNum: 1,
        pageSize: 10
      },
      myQwCompanyList: [],
      transferLogList: [],
    }
  },
  created() {
    this.getMyQwCompanyList();
  },
  methods: {
    getMyQwCompanyList() {
      getMyQwCompanyList().then(response => {
        this.myQwCompanyList = response.data;
        if(this.myQwCompanyList!=null){
          this.queryParams.corpId=this.myQwCompanyList[0].dictValue
          this.getList();
        }
      });
    },
    updateCorpId() {
      this.handleQuery()
    },
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    getList() {
      this.loading = true;
      list(this.queryParams).then(response => {
        this.transferLogList = response.rows;
        this.total = response.total;
        this.loading = false;
      })
    },
    resetQuery() {
      this.resetForm("queryForm");
      this.queryParams.corpId= this.myQwCompanyList[0].dictValue
      this.handleQuery();
    }
  }
}
</script>

<style scoped>

</style>
