<template>
  <el-dialog :visible.sync="visible" :title="$t('look')" :close-on-click-modal="false" :close-on-press-escape="false">
    <el-form :label-width="$i18n.locale === 'en-US' ? '100px' : '80px'">
      <el-form-item label="群介绍:">
        <div>{{responseForm.groupIntroduction}}</div>
      </el-form-item>
      <el-form-item label="状态:">
        <div v-if="responseForm.state === 0">待审核</div>
        <div v-if="responseForm.state === 5">审核不通过</div>
        <div v-if="responseForm.state === 10">审核通过</div>
        <div v-if="responseForm.state === 15">禁言</div>
        <div v-if="responseForm.state === 20">已解散</div>
      </el-form-item>
      <el-form-item label="备注:" v-if="responseForm.state === 5 || responseForm.state === 20">
        <div>{{responseForm.processingOpinions}}</div>
      </el-form-item>
    </el-form>
    <el-form :inline="true" :model="dataForm" ref="dataForm">
      <el-form-item label="姓名">
        <el-input v-model="dataForm.nickname" placeholder="姓名" clearable @keyup.native="btKeyUpNickname"></el-input>
      </el-form-item>
      <el-form-item label="电话">
        <el-input v-model="dataForm.mobile" placeholder="电话" clearable @keyup.native="btKeyUpMobile"></el-input>
      </el-form-item>
      <el-form-item>
        <el-button @click="getDataListSearch()" type='success'>{{ $t('query') }}</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="index" width="50" label="序号"></el-table-column>
      <el-table-column prop="nickname" label="成员名称" header-align="center" align="center"></el-table-column>
      <el-table-column prop="lordFlag" label="群主标识" header-align="center" align="center" :formatter="formatterLoadFlag"></el-table-column>
      <el-table-column prop="mobile" label="联系电话" header-align="center" align="center"></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>
    <template slot="footer">
      <el-button @click="visible = false">{{ $t('cancel') }}</el-button>
    </template>
  </el-dialog>
</template>

<script>
import mixinViewModule from '@/mixins/view-module'
export default {
  mixins: [mixinViewModule],
  data () {
    return {
      mixinViewModuleOptions: {
        getDataListURL: '/group/usergroup/page',
        getDataListIsPage: true
      },
      visible: false,
      dataForm: {
        groupId: '',
        nickname: '',
        mobile: ''
      },
      responseForm: {
        id: '',
        groupIntroduction: '',
        state: '',
        processingOpinions: ''
      }
    }
  },
  methods: {
    init () {
      this.visible = true
      this.$nextTick(() => {
        this.$refs['dataForm'].resetFields()
        if (this.dataForm.groupId) {
          this.getInfo()
          this.getDataList()
        }
      })
    },
    // 获取信息
    getInfo () {
      this.$http.get(`/group/group/${this.dataForm.groupId}`).then(({ data: res }) => {
        if (res.code !== 0) {
          return this.$message.error(res.msg)
        }
        this.responseForm = {
          ...this.responseForm,
          ...res.data
        }
      }).catch(() => {})
    },
    // 群主标识 0：否，1：是
    formatterLoadFlag: function (row, column) {
      let lordFlag = row.lordFlag
      if (lordFlag === '0') {
        return '否'
      } else if (lordFlag === '1') {
        return '是'
      }
    },
    btKeyUpNickname(e){
       e.target.value = e.target.value.replace(/[`~!#$%^&*()_\+=<>?:"{}|~！#￥%……&*（）={}|《》？：“”【】\\[\]、；‘’，。、\s+]/g, '')
       this.dataForm.nickname= e.target.value
    },
    btKeyUpMobile(e){
       e.target.value = e.target.value.replace(/[`~!#$%^&*()_\+=<>?:"{}|~！#￥%……&*（）={}|《》？：“”【】\\[\]、；‘’，。、\s+]/g, '')
       this.dataForm.mobile = e.target.value
    }
  }
}
</script>
