index.vue 6.45 KB
Newer Older
冯超鹏's avatar
冯超鹏 committed
1 2 3
<template>
  <div class="app-container">
    <div class="filter-container">
冯超鹏's avatar
冯超鹏 committed
4 5
      <el-form ref="query" :model="query" style="display: inline-block;">
        <el-input v-model="query.nickname" placeholder="用户名称" style="width: 200px;" class="filter-item" name="userskk" />
冯超鹏's avatar
冯超鹏 committed
6
        <el-select v-model="query.sex" placeholder="性别" clearable style="width: 90px" class="filter-item" @change="selectOneSex">
冯超鹏's avatar
冯超鹏 committed
7 8
          <el-option v-for="item in importanceOptions" :key="item" :label="item" :value="item" />
        </el-select>
冯超鹏's avatar
冯超鹏 committed
9
        <el-select v-model="query.state" placeholder="状态" clearable class="filter-item" style="width: 130px" @change="selectOneState">
冯超鹏's avatar
冯超鹏 committed
10 11 12 13 14 15
          <el-option v-for="item in calendarTypeOptions" :key="item" :label="item" :value="item" />
        </el-select>
        <el-button v-waves class="filter-item" type="primary" icon="el-icon-search" @click="handleSubmit">
          {{ $t('table.search') }}
        </el-button>
      </el-form>
冯超鹏's avatar
冯超鹏 committed
16 17 18
      <el-button v-waves :loading="downloadLoading" class="filter-item" type="primary" icon="el-icon-download" @click="handleDownload">
        {{ $t('table.export') }}
      </el-button>
冯超鹏's avatar
冯超鹏 committed
19
      <el-checkbox v-model="showReviewer" class="filter-item" style="margin-left:15px;" @change="tableKey=tableKey+1">OpenId</el-checkbox>
冯超鹏's avatar
冯超鹏 committed
20
    </div>
冯超鹏's avatar
冯超鹏 committed
21 22
    <el-table :key="tableKey" v-loading="loading" :data="list" border fit highlight-current-row>
      <el-table-column align="center" label="id" width="80">
冯超鹏's avatar
冯超鹏 committed
23 24 25 26
        <template slot-scope="scope">
          <span>{{ scope.row.id }}</span>
        </template>
      </el-table-column>
冯超鹏's avatar
冯超鹏 committed
27 28

      <el-table-column align="center" label="用户名称" width="150">
冯超鹏's avatar
冯超鹏 committed
29 30
        <template slot-scope="scope">
          <span>{{ scope.row.nickname }}</span>
冯超鹏's avatar
冯超鹏 committed
31 32
        </template>
      </el-table-column>
冯超鹏's avatar
冯超鹏 committed
33 34

      <el-table-column align="center" label="用户头像" width="150">
冯超鹏's avatar
冯超鹏 committed
35
        <template slot-scope="scope">
冯超鹏's avatar
冯超鹏 committed
36
          <el-image :src="scope.row.headimgurl" :preview-src-list="srcList"></el-image>
冯超鹏's avatar
冯超鹏 committed
37 38
        </template>
      </el-table-column>
冯超鹏's avatar
冯超鹏 committed
39 40

      <el-table-column v-if="showReviewer" align="center" label="openid" width="150">
冯超鹏's avatar
冯超鹏 committed
41
        <template slot-scope="scope">
冯超鹏's avatar
冯超鹏 committed
42
          <span style="color: #909399;" @click="handleCopy(scope.row.openid,$event)">{{ scope.row.openid }}</span>
冯超鹏's avatar
冯超鹏 committed
43 44
        </template>
      </el-table-column>
冯超鹏's avatar
冯超鹏 committed
45 46

      <el-table-column align="center" label="性别" width="150">
冯超鹏's avatar
冯超鹏 committed
47
        <template slot-scope="scope">
冯超鹏's avatar
冯超鹏 committed
48
          <span>{{ scope.row.sex==1 ? '男' : '女' }}</span>
冯超鹏's avatar
冯超鹏 committed
49 50
        </template>
      </el-table-column>
冯超鹏's avatar
冯超鹏 committed
51
      <el-table-column align="center" label="手机号" width="170">
冯超鹏's avatar
冯超鹏 committed
52
        <template slot-scope="scope">
冯超鹏's avatar
冯超鹏 committed
53
          <span>{{ scope.row.mobile }}</span>
冯超鹏's avatar
冯超鹏 committed
54 55
        </template>
      </el-table-column>
冯超鹏's avatar
冯超鹏 committed
56
      <el-table-column align="center" label="地区" width="170">
冯超鹏's avatar
冯超鹏 committed
57
        <template slot-scope="scope">
冯超鹏's avatar
冯超鹏 committed
58
          <span>{{ scope.row.country }}{{ scope.row.province }}{{ scope.row.city }}</span>
冯超鹏's avatar
冯超鹏 committed
59 60
        </template>
      </el-table-column>
冯超鹏's avatar
冯超鹏 committed
61
      <el-table-column align="center" label="创建时间" width="170">
冯超鹏's avatar
冯超鹏 committed
62 63
        <template slot-scope="scope">
          <span>{{ scope.row.created_at | parseTime('{y}-{m}-{d} {h}:{i}') }}</span>
冯超鹏's avatar
冯超鹏 committed
64 65
        </template>
      </el-table-column>
冯超鹏's avatar
冯超鹏 committed
66 67
      <el-table-column align="center" label="状态" width="170">
        <template slot-scope="scope">
冯超鹏's avatar
冯超鹏 committed
68
          <span :style="{color:( scope.row.state==1 ? '#F56C6C' : '#67C23A' )}">{{ scope.row.state==1 ? '禁用' : '正常' }}</span>
冯超鹏's avatar
冯超鹏 committed
69 70 71
        </template>
      </el-table-column>
    </el-table>
冯超鹏's avatar
冯超鹏 committed
72
    <pagination v-show="total>0" :total="total" :page.sync="query.page" :limit.sync="query.limit" @pagination="getList" />
冯超鹏's avatar
冯超鹏 committed
73 74 75 76
  </div>
</template>

<script>
冯超鹏's avatar
冯超鹏 committed
77 78 79
import UserResource from '@/api/wxuser';
import clip from '@/utils/clipboard';
import Pagination from '@/components/Pagination'; // 分页
冯超鹏's avatar
冯超鹏 committed
80
import { parseTime } from '@/utils';
冯超鹏's avatar
冯超鹏 committed
81 82
import waves from '@/directive/waves'; // 水波纹效果
const userResource = new UserResource();
冯超鹏's avatar
冯超鹏 committed
83
export default {
冯超鹏's avatar
冯超鹏 committed
84
  name: 'Wxuser',
冯超鹏's avatar
冯超鹏 committed
85 86 87 88
  components: { Pagination },
  directives: { waves },
  data() {
    return {
冯超鹏's avatar
冯超鹏 committed
89
      total: 0,
冯超鹏's avatar
冯超鹏 committed
90
      tableKey: 0,
冯超鹏's avatar
冯超鹏 committed
91
      list: [],
冯超鹏's avatar
冯超鹏 committed
92
      loading: true,
冯超鹏's avatar
冯超鹏 committed
93
      showReviewer: false,
冯超鹏's avatar
冯超鹏 committed
94 95 96 97 98 99
      query: {
        page: 1,
        limit: 10,
        nickname: undefined,
        sex: undefined,
        state: undefined,
冯超鹏's avatar
冯超鹏 committed
100
      },
冯超鹏's avatar
冯超鹏 committed
101 102 103
      importanceOptions: ['男', '女'],
      calendarTypeOptions: ['正常', '禁用'],
      srcList: [],
冯超鹏's avatar
冯超鹏 committed
104 105 106 107 108 109 110 111
      downloadLoading: false,
    };
  },
  created() {
    this.getList();
  },
  methods: {
    async getList() {
冯超鹏's avatar
冯超鹏 committed
112 113 114 115 116 117 118
      const { limit, page } = this.query;
      this.loading = true;
      const { data } = await userResource.list(this.query);
      var Wxuser = data.Wxuser;
      this.list = Wxuser;
      this.list.forEach((element, index) => {
        element['index'] = (page - 1) * limit + index + 1;
冯超鹏's avatar
冯超鹏 committed
119
      });
冯超鹏's avatar
冯超鹏 committed
120 121
      for (var item of Wxuser) {
        this.srcList.push(item['headimgurl']);
冯超鹏's avatar
冯超鹏 committed
122
      }
冯超鹏's avatar
冯超鹏 committed
123 124
      this.total = data.cont;
      this.loading = false;
冯超鹏's avatar
冯超鹏 committed
125
    },
冯超鹏's avatar
冯超鹏 committed
126 127
    handleCopy(text, event) {
      clip(text, event);
冯超鹏's avatar
冯超鹏 committed
128 129 130 131
    },
    handleDownload() {
      this.downloadLoading = true;
      import('@/vendor/Export2Excel').then(excel => {
冯超鹏's avatar
冯超鹏 committed
132 133
        const tHeader = ['id', 'openid', 'nickname', 'sex', 'mobile', 'created_at'];
        const filterVal = ['id', 'openid', 'nickname', 'sex', 'mobile', 'created_at'];
冯超鹏's avatar
冯超鹏 committed
134 135 136 137
        const data = this.formatJson(filterVal, this.list);
        excel.export_json_to_excel({
          header: tHeader,
          data,
冯超鹏's avatar
冯超鹏 committed
138
          filename: '微信用户',
冯超鹏's avatar
冯超鹏 committed
139 140 141 142 143 144
        });
        this.downloadLoading = false;
      });
    },
    formatJson(filterVal, jsonData) {
      return jsonData.map(v => filterVal.map(j => {
冯超鹏's avatar
冯超鹏 committed
145
        if (j === 'created_at') {
冯超鹏's avatar
冯超鹏 committed
146
          return parseTime(v[j]);
冯超鹏's avatar
冯超鹏 committed
147 148
        } else if (j === 'sex') {
          return v[j] === 1 ? '男' : '女';
冯超鹏's avatar
冯超鹏 committed
149 150 151 152 153
        } else {
          return v[j];
        }
      }));
    },
冯超鹏's avatar
冯超鹏 committed
154 155 156 157 158 159 160 161 162 163 164 165 166 167 168
    async handleSubmit() {
      const { limit, page } = this.query;
      this.loading = true;
      const { data } = await userResource.fetchArticle(this.query);
      var Wxuser = data.Wxuser;
      this.list = Wxuser;
      this.list.forEach((element, index) => {
        element['index'] = (page - 1) * limit + index + 1;
      });
      for (var item of Wxuser) {
        this.srcList.push(item['headimgurl']);
      }
      this.total = data.cont;
      this.loading = false;
    },
冯超鹏's avatar
冯超鹏 committed
169 170 171 172 173 174 175 176 177 178
    selectOneSex(event, item) {
      if (event === '') {
        this.query.sex = undefined;
      }
    },
    selectOneState(event, item) {
      if (event === '') {
        this.query.state = undefined;
      }
    },
冯超鹏's avatar
冯超鹏 committed
179 180 181
  },
};
</script>