index.vue 11.7 KB
Newer Older
冯超鹏's avatar
冯超鹏 committed
1 2 3 4
<template>
  <div class="app-container">
    <div class="filter-container">
      <el-form ref="query" :model="userdata" style="display: inline-block;">
5
        <el-input v-model="userdata.name" placeholder="用户名称" clearable style="width: 200px;" class="filter-item" name="userskk" @input="changeValue" />
冯超鹏's avatar
冯超鹏 committed
6 7 8 9 10 11 12 13 14 15
        <el-select v-model="userdata.state" placeholder="状态" clearable class="filter-item" style="width: 130px" @change="selectOne">
          <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>
      <el-button v-if="userList != '' " v-waves :loading="downloadLoading" class="filter-item" type="primary" icon="el-icon-download" @click="handleDownload">
        {{ $t('table.export') }}
      </el-button>
冯超鹏's avatar
冯超鹏 committed
16
      <el-badge v-if="paper > 0" :value="paper" class="item" style="margin-bottom: 8px;">
冯超鹏's avatar
冯超鹏 committed
17
        <el-button size="small" @click="userpaty">
冯超鹏's avatar
冯超鹏 committed
18 19 20
          <svg-icon class-name="custom-class" icon-class="feizhilou" />废纸篓
        </el-button>
      </el-badge>
冯超鹏's avatar
冯超鹏 committed
21 22 23 24 25 26 27 28 29 30 31 32 33 34
    </div>
    <el-table :key="tableKey" v-loading="loading" :data="userList" border fit highlight-current-rows>
      <el-table-column align="center" label="id" width="80">
        <template slot-scope="scope">
          <span>{{ scope.row.id }}</span>
        </template>
      </el-table-column>
      <el-table-column align="center" label="账号名称" width="150">
        <template slot-scope="scope">
          <span>{{ scope.row.username }}</span>
        </template>
      </el-table-column>
      <el-table-column align="center" label="用户名称" width="150">
        <template slot-scope="scope">
35
          <span>{{ scope.row.name }}</span>
冯超鹏's avatar
冯超鹏 committed
36 37
        </template>
      </el-table-column>
38
      <el-table-column align="center" label="用户邮箱" width="180">
冯超鹏's avatar
冯超鹏 committed
39 40 41 42 43 44 45 46 47
        <template slot-scope="scope">
          <span @click="handleCopy(scope.row.email,$event)">{{ scope.row.email }}</span>
        </template>
      </el-table-column>
      <el-table-column align="center" label="用户下设备数量" width="170">
        <template slot-scope="scope">
          <span v-for="item in userDaviceNum" :key="item.index">{{ scope.row.id==item.id ? item.count : '' }}</span>
        </template>
      </el-table-column>
48
      <el-table-column align="center" label="用户地址" width="340">
冯超鹏's avatar
冯超鹏 committed
49 50 51 52 53 54
        <template slot-scope="scope">
          <span>{{ scope.row.province }}-{{ scope.row.area }}-{{ scope.row.city }}</span>
        </template>
      </el-table-column>
      <el-table-column align="center" label="创建时间" width="170">
        <template slot-scope="scope">
55
          <span>{{ scope.row.created_at | parseTime('{y}-{m}-{d} {h}:{i}') }}</span>
冯超鹏's avatar
冯超鹏 committed
56 57
        </template>
      </el-table-column>
58
      <el-table-column align="center" label="状态" width="250">
冯超鹏's avatar
冯超鹏 committed
59
        <template slot-scope="scope">
60
          <span :style="{color:( scope.row.state==1 ? '#F56C6C' : ( scope.row.state==3 ? '#909399' : '#67C23A' ) )}">{{ scope.row.state==1 ? '禁用' : ( scope.row.state==3 ? '用户已被丢弃废纸篓' : '正常' ) }}</span>
冯超鹏's avatar
冯超鹏 committed
61 62 63 64 65 66 67 68
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" width="230" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button type="primary" size="mini" @click="userUpdate(scope.row.id)">编辑</el-button>
          <el-popover width="160" trigger="click" placement="top">
            <p>此删除,分丢弃废纸篓,和删除</p>
            <div style="text-align: right; margin: 0">
69
              <el-button v-if="scope.row.state<3" size="mini" type="text" @click="userDelete(scope.row.id, 1)">丢弃废纸篓</el-button>
冯超鹏's avatar
冯超鹏 committed
70 71 72 73
              <el-button type="text" size="mini" @click="userDelete(scope.row.id, 2)">删除</el-button>
            </div>
            <el-button slot="reference" size="mini" type="danger">删除</el-button>
          </el-popover>
冯超鹏's avatar
冯超鹏 committed
74
          <el-switch v-if="scope.row.state==2" :v-model="false" inactive-color="#ff4949" @change="UpuserForbidden(scope.row.id)"></el-switch>
冯超鹏's avatar
冯超鹏 committed
75 76 77 78
        </template>
      </el-table-column>
    </el-table>
    <pagination v-show="total>0" :total="total" :page.sync="userdata.page" :limit.sync="userdata.limit" @pagination="getUserList" />
冯超鹏's avatar
冯超鹏 committed
79
    <el-dialog :visible.sync="dialogPvVisible" title="编辑用户" width="85%" style="margin-top: auto;">
冯超鹏's avatar
冯超鹏 committed
80 81 82 83 84
      <el-form :model="upUserData" class="demo-ruleForm" status-icon>
        <el-form-item label="账号名称" prop="username">
          <el-input v-model.number="upUserData.username"></el-input>
        </el-form-item>
        <el-form-item label="用户名称" prop="nickname">
85
          <el-input v-model.number="upUserData.name"></el-input>
冯超鹏's avatar
冯超鹏 committed
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104
        </el-form-item>
        <el-form-item label="邮箱" prop="email">
          <el-input v-model.number="upUserData.email"></el-input>
        </el-form-item>
        <el-form-item label="自定义标题" prop="title">
          <el-input v-model.number="upUserData.title"></el-input>
        </el-form-item>
        <el-form-item label="自定义公司名称" prop="company">
          <el-input v-model.number="upUserData.company"></el-input>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="submitForm()">提交</el-button>
          <el-button @click="resetForm()">重置</el-button>
        </el-form-item>
      </el-form>
    </el-dialog>
  </div>
</template>
<script>
冯超鹏's avatar
冯超鹏 committed
105
import { userList, userSeek, userDelete, userDataInfo, postUpUser, paperBasket, UpuserForbidden } from '@/api/users';
冯超鹏's avatar
冯超鹏 committed
106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130
import Pagination from '@/components/Pagination'; // 分页
import waves from '@/directive/waves'; // 水波纹效果
import clip from '@/utils/clipboard';
import { parseTime } from '@/utils';
export default {
  name: 'UserData',
  components: { Pagination },
  directives: { waves },
  data() {
    return {
      tableKey: 0,
      downloadLoading: false,
      dialogPvVisible: false,
      userList: [],
      userDaviceNum: [],
      calendarTypeOptions: ['正常', '禁用', '已删除'],
      total: 0,
      userdata: {
        limit: 10,
        page: 1,
        nickname: undefined,
        state: undefined,
      },
      upUserData: {
        username: undefined,
131
        name: undefined,
冯超鹏's avatar
冯超鹏 committed
132 133 134
        title: undefined,
        email: undefined,
        company: undefined,
冯超鹏's avatar
冯超鹏 committed
135
        userid: undefined,
冯超鹏's avatar
冯超鹏 committed
136
      },
冯超鹏's avatar
冯超鹏 committed
137
      paper: undefined,
冯超鹏's avatar
冯超鹏 committed
138 139 140 141
    };
  },
  created() {
    this.getUserList(); // 用户列表
冯超鹏's avatar
冯超鹏 committed
142
    this.paperBasket();
冯超鹏's avatar
冯超鹏 committed
143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205
  },
  methods: {
    getUserList() {
      this.loading = true;
      userList(this.userdata.limit, this.userdata.page)
        .then(response => {
          var userlistdata = response.data.users;
          this.userList = userlistdata;
          this.userList.forEach((element, index) => {
            element['index'] = (this.userdata.page - 1) * this.userdata.limit + index + 1;
          });
          this.total = response.data.count;
          this.userDaviceNum = response.data.davicenum;
          this.loading = false;
        })
        .catch(err => {
          console.log(err);
        });
    },
    // 搜索
    handleSubmit() {
      userSeek(this.userdata)
        .then(response => {
          var userlistdata = response.data.users;
          this.userList = userlistdata;
          this.userList.forEach((element, index) => {
            element['index'] = (this.userdata.page - 1) * this.userdata.limit + index + 1;
          });
          this.total = response.data.count;
          this.userDaviceNum = response.data.davicenum;
        })
        .catch(err => {
          console.log(err);
        });
    },
    handleDownload() {
      this.downloadLoading = true;
      import('@/vendor/Export2Excel').then(excel => {
        const tHeader = ['id', '账号名称', '用户名称', '用户邮箱', '用户地址(省)', '用户地址(市)', '用户地址(区)', '创建时间', '状态'];
        const filterVal = ['id', 'username', 'nickname', 'email', 'province', 'area', 'city', 'add_time', 'state'];
        const data = this.formatJson(filterVal, this.userList);
        excel.export_json_to_excel({
          header: tHeader,
          data,
          filename: '用户列表',
        });
        this.downloadLoading = false;
      });
    },
    formatJson(filterVal, jsonData) {
      return jsonData.map(v => filterVal.map(j => {
        if (j === 'add_time') {
          return parseTime(v[j]);
        } else if (j === 'state') {
          return v[j] === 1 ? '用户已被删除' : (v[j] === 3 ? '禁用' : '正常');
        } else {
          return v[j];
        }
      }));
    },
    handleCopy(text, event) {
      clip(text, event);
    },
冯超鹏's avatar
冯超鹏 committed
206 207 208 209
    // 用户废纸篓
    userpaty() {
      this.$router.push({ path: '/users/userStatus' });
    },
冯超鹏's avatar
冯超鹏 committed
210 211 212
    // 编辑
    userUpdate(id) {
      this.dialogPvVisible = true;
冯超鹏's avatar
冯超鹏 committed
213 214
      this.getuserDataInfo(id);
      this.upUserData.userid = id;
冯超鹏's avatar
冯超鹏 committed
215 216 217 218 219 220 221 222 223 224 225 226 227 228 229
    },
    userDelete(id, type) {
      var data = {
        'duserid': id,
        'type': type,
      };
      userDelete(data)
        .then(response => {
          if (response.code === 105) {
            this.$message({
              message: response.msg,
              type: 'warning',
            });
          } else {
            this.getUserList();
冯超鹏's avatar
冯超鹏 committed
230
            this.paperBasket();
冯超鹏's avatar
冯超鹏 committed
231 232 233 234 235 236 237 238 239 240 241 242
          }
        })
        .catch(err => {
          console.log(err);
        });
    },
    // 删除
    selectOne(event, item) {
      if (event === '') {
        this.userdata.state = undefined;
      }
    },
冯超鹏's avatar
冯超鹏 committed
243 244 245 246 247
    changeValue(event, item) {
      if (event === '') {
        this.userdata.nickname = undefined;
      }
    },
冯超鹏's avatar
冯超鹏 committed
248 249 250 251 252 253 254
    // 重置
    resetForm() {
      for (const key in this.upUserData) {
        this.upUserData[key] = undefined;
      }
    },
    submitForm() {
冯超鹏's avatar
冯超鹏 committed
255 256 257 258 259 260 261 262 263 264 265
      postUpUser(this.upUserData)
        .then(response => {
          if (response.code === 105) {
            this.$notify.error({
              message: response.msg,
              type: 'warning',
            });
          } else {
            if (response.code === 200) {
              this.dialogPvVisible = false;
              this.getUserList();
冯超鹏's avatar
冯超鹏 committed
266
              this.paperBasket();
冯超鹏's avatar
冯超鹏 committed
267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296
            }
          }
        })
        .catch(err => {
          console.log(err);
        });
    },
    getuserDataInfo(id) {
      userDataInfo(id)
        .then(response => {
          if (response.code === 105) {
            this.$message({
              message: response.msg,
              type: 'warning',
            });
          } else {
            for (const key in this.upUserData) {
              for (const k in response.data) {
                if (key === k) {
                  if (response.data[k] !== null) {
                    this.upUserData[key] = response.data[k];
                  }
                }
              }
            }
          }
        })
        .catch(err => {
          console.log(err);
        });
冯超鹏's avatar
冯超鹏 committed
297
    },
冯超鹏's avatar
冯超鹏 committed
298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330
    // 获取废纸篓数量
    paperBasket() {
      paperBasket()
        .then(response => {
          if (response.code === 200) {
            this.paper = response.data;
          }
        })
        .catch(err => {
          console.log(err);
        });
    },
    UpuserForbidden(id) {
      this.$confirm('是否将用户禁用', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning',
      }).then(() => {
        UpuserForbidden(id)
          .then(response => {
            this.getUserList();
            this.paperBasket();
          })
          .catch(err => {
            console.log(err);
          });
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消',
        });
      });
    },
冯超鹏's avatar
冯超鹏 committed
331 332 333 334 335 336
  },
};
</script>

<style>
</style>