index.vue 7.13 KB
Newer Older
冯超鹏's avatar
冯超鹏 committed
1 2 3
<template>
  <div class="app-container">
    <div class="filter-container">
冯超鹏's avatar
冯超鹏 committed
4
      <el-form ref="query" :model="query" style="display: inline-block;">
Administrator's avatar
Administrator committed
5 6
        <el-input v-model="query.mobile" placeholder="手机号" style="width: 200px;" class="filter-item" name="userskk" />
        <el-input v-model="query.city" placeholder="地区" style="width: 200px;" class="filter-item" name="city" />
冯超鹏's avatar
冯超鹏 committed
7
        <el-select v-model="query.sex" placeholder="性别" clearable style="width: 90px" class="filter-item" @change="selectOneSex">
Administrator's avatar
Administrator committed
8
          <el-option v-for="item in importanceOptions" :key="item.key" :label="item.val" :value="item.key" />
冯超鹏's avatar
冯超鹏 committed
9
        </el-select>
冯超鹏's avatar
冯超鹏 committed
10
        <el-select v-model="query.state" placeholder="状态" clearable class="filter-item" style="width: 130px" @change="selectOneState">
Administrator's avatar
Administrator committed
11
          <el-option v-for="item in calendarTypeOptions" :key="item.key" :label="item.val" :value="item.key" />
冯超鹏's avatar
冯超鹏 committed
12 13 14 15 16
        </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
17 18 19
      <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
20
      <el-checkbox v-model="showReviewer" class="filter-item" style="margin-left:15px;" @change="tableKey=tableKey+1">OpenId</el-checkbox>
冯超鹏's avatar
冯超鹏 committed
21
    </div>
冯超鹏's avatar
冯超鹏 committed
22 23
    <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
24 25 26 27
        <template slot-scope="scope">
          <span>{{ scope.row.id }}</span>
        </template>
      </el-table-column>
冯超鹏's avatar
冯超鹏 committed
28

Administrator's avatar
Administrator committed
29
      <el-table-column align="left" label="用户名称">
冯超鹏's avatar
冯超鹏 committed
30
        <template slot-scope="scope">
Administrator's avatar
Administrator committed
31 32
          <el-image :src="scope.row.headimgurl" :preview-src-list="srcList" style="width:50px"></el-image>
          <a class="zl-nickname">{{ scope.row.nickname | handeNickname }}</a>
冯超鹏's avatar
冯超鹏 committed
33 34
        </template>
      </el-table-column>
Administrator's avatar
Administrator committed
35
      <el-table-column v-if="showReviewer" align="center" label="openid" width="320">
冯超鹏's avatar
冯超鹏 committed
36
        <template slot-scope="scope">
冯超鹏's avatar
冯超鹏 committed
37
          <span style="color: #909399;" @click="handleCopy(scope.row.openid,$event)">{{ scope.row.openid }}</span>
冯超鹏's avatar
冯超鹏 committed
38 39
        </template>
      </el-table-column>
冯超鹏's avatar
冯超鹏 committed
40 41

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

<script>
冯超鹏's avatar
冯超鹏 committed
72 73 74
import UserResource from '@/api/wxuser';
import clip from '@/utils/clipboard';
import Pagination from '@/components/Pagination'; // 分页
冯超鹏's avatar
冯超鹏 committed
75
import { parseTime } from '@/utils';
冯超鹏's avatar
冯超鹏 committed
76
import waves from '@/directive/waves'; // 水波纹效果
Administrator's avatar
Administrator committed
77
const Base64 = require('js-base64').Base64;
冯超鹏's avatar
冯超鹏 committed
78
const userResource = new UserResource();
冯超鹏's avatar
冯超鹏 committed
79
export default {
冯超鹏's avatar
冯超鹏 committed
80
  name: 'Wxuser',
冯超鹏's avatar
冯超鹏 committed
81 82
  components: { Pagination },
  directives: { waves },
Administrator's avatar
Administrator committed
83 84 85 86
  filters: {
    handeNickname: function(value) {
      return Base64.decode(value);
    },
Administrator's avatar
Administrator committed
87 88 89 90 91 92
    handeSex: function(value) {
      const sexes = [
        '未知', '男', '女',
      ];
      return sexes[value];
    },
Administrator's avatar
Administrator committed
93
  },
冯超鹏's avatar
冯超鹏 committed
94 95
  data() {
    return {
冯超鹏's avatar
冯超鹏 committed
96
      total: 0,
冯超鹏's avatar
冯超鹏 committed
97
      tableKey: 0,
冯超鹏's avatar
冯超鹏 committed
98
      list: [],
冯超鹏's avatar
冯超鹏 committed
99
      loading: true,
冯超鹏's avatar
冯超鹏 committed
100
      showReviewer: false,
冯超鹏's avatar
冯超鹏 committed
101 102 103
      query: {
        page: 1,
        limit: 10,
Administrator's avatar
Administrator committed
104
        mobile: undefined,
冯超鹏's avatar
冯超鹏 committed
105 106
        sex: undefined,
        state: undefined,
Administrator's avatar
Administrator committed
107
        city: undefined,
冯超鹏's avatar
冯超鹏 committed
108
      },
Administrator's avatar
Administrator committed
109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125
      importanceOptions: [{
        'key': 0,
        'val': '未知',
      }, {
        'key': 1,
        'val': '男',
      }, {
        'key': 2,
        'val': '女',
      }],
      calendarTypeOptions: [{
        'key': 1,
        'val': '禁用',
      }, {
        'key': 2,
        'val': '启用',
      }],
冯超鹏's avatar
冯超鹏 committed
126
      srcList: [],
冯超鹏's avatar
冯超鹏 committed
127 128 129 130 131 132 133 134
      downloadLoading: false,
    };
  },
  created() {
    this.getList();
  },
  methods: {
    async getList() {
冯超鹏's avatar
冯超鹏 committed
135 136 137 138 139 140 141
      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
142
      });
冯超鹏's avatar
冯超鹏 committed
143 144
      for (var item of Wxuser) {
        this.srcList.push(item['headimgurl']);
冯超鹏's avatar
冯超鹏 committed
145
      }
冯超鹏's avatar
冯超鹏 committed
146 147
      this.total = data.cont;
      this.loading = false;
冯超鹏's avatar
冯超鹏 committed
148
    },
冯超鹏's avatar
冯超鹏 committed
149 150
    handleCopy(text, event) {
      clip(text, event);
冯超鹏's avatar
冯超鹏 committed
151 152 153 154
    },
    handleDownload() {
      this.downloadLoading = true;
      import('@/vendor/Export2Excel').then(excel => {
冯超鹏's avatar
冯超鹏 committed
155 156
        const tHeader = ['id', 'openid', 'nickname', 'sex', 'mobile', 'created_at'];
        const filterVal = ['id', 'openid', 'nickname', 'sex', 'mobile', 'created_at'];
冯超鹏's avatar
冯超鹏 committed
157 158 159 160
        const data = this.formatJson(filterVal, this.list);
        excel.export_json_to_excel({
          header: tHeader,
          data,
冯超鹏's avatar
冯超鹏 committed
161
          filename: '微信用户',
冯超鹏's avatar
冯超鹏 committed
162 163 164 165 166 167
        });
        this.downloadLoading = false;
      });
    },
    formatJson(filterVal, jsonData) {
      return jsonData.map(v => filterVal.map(j => {
冯超鹏's avatar
冯超鹏 committed
168
        if (j === 'created_at') {
冯超鹏's avatar
冯超鹏 committed
169
          return parseTime(v[j]);
冯超鹏's avatar
冯超鹏 committed
170
        } else if (j === 'sex') {
Administrator's avatar
Administrator committed
171 172 173 174
          const sexes = [
            '未知', '男', '女',
          ];
          return sexes[v[j]];
冯超鹏's avatar
冯超鹏 committed
175 176 177 178 179
        } else {
          return v[j];
        }
      }));
    },
冯超鹏's avatar
冯超鹏 committed
180 181 182 183 184 185 186 187 188 189 190 191 192 193 194
    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
195 196 197 198 199 200 201 202 203 204
    selectOneSex(event, item) {
      if (event === '') {
        this.query.sex = undefined;
      }
    },
    selectOneState(event, item) {
      if (event === '') {
        this.query.state = undefined;
      }
    },
冯超鹏's avatar
冯超鹏 committed
205 206 207
  },
};
</script>
Administrator's avatar
Administrator committed
208 209 210 211 212 213 214
<style>
  .zl-nickname{
    position: absolute;
    line-height: 50px;
    margin-left: 10px;
  }
</style>