list.vue 5.87 KB
Newer Older
Davve's avatar
Davve committed
1 2 3 4 5 6 7
<template>
  <div class="app-container">
    <div class="filter-container">
      <el-input :placeholder="'搜素'" v-model="listQuery.filter.value" style="width: 160px;" class="filter-item" @keyup.enter.native="handleFilter"/>
      <el-select v-model="listQuery.filter.key" :placeholder="'搜索字段'" clearable class="filter-item" style="width: 110px">
        <el-option v-for="item in SearchTypeOptions" :key="item.key" :label="item.display_name" :value="item.key"/>
      </el-select>
Davve's avatar
Davve committed
8
      <el-select v-model="listQuery.filter.gender" :placeholder="'性别'" clearable class="filter-item" style="width: 110px">
Davve's avatar
Davve committed
9 10 11 12 13 14 15 16 17 18 19
        <el-option v-for="item in GenderTypeOptions" :key="item.key" :label="item.display_name" :value="item.key"/>
      </el-select>
      <el-select v-model="listQuery.filter.is_online" :placeholder="'上线'" clearable class="filter-item" style="width: 100px">
        <el-option v-for="item in BooleanTypeOptions" :key="item.key" :label="item.display_name" :value="item.key"/>
      </el-select>
      <el-button v-waves class="filter-item" type="primary" icon="el-icon-search" @click="handleFilter">搜索</el-button>
      <el-button class="filter-item" style="margin-left: 10px;" type="primary" icon="el-icon-edit" @click="handleCreate">创建</el-button>
      <el-button class="filter-item" style="margin-left: 10px;" type="primary" icon="el-icon-edit" @click="handleOfflineOrOnline('offline')">下线</el-button>
      <el-button class="filter-item" style="margin-left: 10px;" type="primary" icon="el-icon-edit" @click="handleOfflineOrOnline('online')">上线</el-button>
    </div>
    <el-table v-loading="listLoading" :data="list" border fit highlight-current-row style="width: 100%" ref="multipleTable" @selection-change="handleSelectionChange">
Davve's avatar
Davve committed
20
      <el-table-column type="selection"  align="center"></el-table-column>
Davve's avatar
Davve committed
21 22
      <el-table-column align="center" label="明星ID" width="80">
        <template slot-scope="scope">
Davve's avatar
Davve committed
23
          <router-link :to="'/star/edit/'+scope.row.id" class="link-type">
Davve's avatar
Davve committed
24 25 26 27 28
          <span>{{ scope.row.id }}</span>
            </router-link>
        </template>
      </el-table-column>

Davve's avatar
Davve committed
29
      <el-table-column  align="center" label="明星名称">
Davve's avatar
Davve committed
30 31 32 33 34
        <template slot-scope="scope">
          <span>{{ scope.row.name }}</span>
        </template>
      </el-table-column>

Davve's avatar
Davve committed
35
      <el-table-column  align="center" label="性别">
Davve's avatar
Davve committed
36
        <template slot-scope="scope">
Davve's avatar
Davve committed
37
          <el-tag>{{ scope.row.gender==0 ? '男' : '女' }}</el-tag>
Davve's avatar
Davve committed
38 39 40
        </template>
      </el-table-column>

Davve's avatar
Davve committed
41
      <el-table-column  align="center" label="城市">
Davve's avatar
Davve committed
42
        <template slot-scope="scope">
Davve's avatar
Davve committed
43
          <span>{{ scope.row.city.name }}</span>
Davve's avatar
Davve committed
44 45 46
        </template>
      </el-table-column>

Davve's avatar
Davve committed
47
      <el-table-column  align="center" label="小组数量">
Davve's avatar
Davve committed
48
        <template slot-scope="scope">
Davve's avatar
Davve committed
49
          <router-link :to="{path: '/group/list/', query: {star_id: scope.row.id}}" class="link-type">
Davve's avatar
Davve committed
50
            <span>{{ scope.row.group_nums }}</span>
Davve's avatar
Davve committed
51 52 53 54
           </router-link>
        </template>
      </el-table-column>

Davve's avatar
Davve committed
55
      <el-table-column  align="center" label="是否在线">
Davve's avatar
Davve committed
56
        <template slot-scope="scope">
Davve's avatar
Davve committed
57
          <el-tag>{{ scope.row.is_online==1 ? '是' : '否' }}</el-tag>
Davve's avatar
Davve committed
58 59 60 61 62
        </template>
      </el-table-column>

    </el-table>

Davve's avatar
Davve committed
63
    <pagination v-show="total>0" :total="total" :page.sync="listQuery.page" :limit.sync="listQuery.limit" style="margin-left: 250px;" @pagination="getList" />
Davve's avatar
Davve committed
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84

  </div>
</template>

<script>
import { fetchList, OffLineOrOnLine } from '@/api/star'
import Pagination from '@/components/Pagination' // Secondary package based on el-pagination
import waves from '@/directive/waves'

export default {
  name: 'StartList',
  components: { Pagination },
  directives: { waves },
  data() {
    return {
      list: null,
      total: 0,
      listLoading: true,
      multipleSelection: [],
      del_list: [],
      listQuery: {
Davve's avatar
Davve committed
85
        page: 0,
Davve's avatar
Davve committed
86 87 88 89
        limit: 10,
        filter: {
          value: '',
          key: '',
Davve's avatar
Davve committed
90 91
          is_online: '',
          gender: '',
Davve's avatar
Davve committed
92 93 94 95 96 97 98 99 100 101 102 103 104 105 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 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145
        },
      },
      BooleanTypeOptions: [
        {'key': 1, 'display_name': '是'},
        {'key': 0, 'display_name': '否'}
      ],
      GenderTypeOptions: [
        {'key': 0, 'display_name': '男'},
        {'key': 1, 'display_name': '女'}
      ],
      SearchTypeOptions:[
        {'key': 'id', 'display_name': '明星ID'},
        {'key': 'name', 'display_name': '明星名称'},
      ]
    }
  },
  created() {
    this.getList()
  },
  methods: {
    getList() {
      this.listLoading = true
      fetchList(this.listQuery).then(response => {
        this.list = response.data.data.data
        this.total = response.data.data.total
        this.listLoading = false
      })
    },
    handleSelectionChange(val) {
        this.multipleSelection = val;
    },
    handleSizeChange(val) {
      this.listQuery.limit = val
      this.getList()
    },
    handleCurrentChange(val) {
      this.listQuery.page = val
      this.getList()
    },
    handleOfflineOrOnline(val){
      const length = this.multipleSelection.length;
      let str = '';
      this.del_list = this.del_list.concat(this.multipleSelection);
      for (let i = 0; i < length; i++) {
          if (val === 'offline'){
            this.multipleSelection[i].is_online = 0
          }else{
            this.multipleSelection[i].is_online = 1
          }
          str += this.multipleSelection[i].id + ' ';
      }
      OffLineOrOnLine({type:val, ids:str}).then(response => {
        this.multipleSelection = [];
        this.$message.success(response.data.data.message);
Davve's avatar
Davve committed
146 147 148
        setTimeout(() => {
              this.$router.go(0)
            }, 1300)
Davve's avatar
Davve committed
149 150 151
      })
    },
    handleFilter() {
Davve's avatar
Davve committed
152
      this.listQuery.page = 1
Davve's avatar
Davve committed
153 154 155
      this.getList()
    },
    handleCreate() {
Davve's avatar
Davve committed
156
      this.$router.push('/star/create')
Davve's avatar
Davve committed
157 158 159 160 161 162 163 164 165 166 167 168 169 170 171
    }
  }
}
</script>

<style scoped>
.edit-input {
  padding-right: 100px;
}
.cancel-btn {
  position: absolute;
  right: 15px;
  top: 10px;
}
</style>