<template>
  <div class="vip-personnel">
    <el-form :inline="true" :model="dataForm">
      <el-form-item>
        <el-input v-model="dataForm.userName" placeholder="用户名称" clearable></el-input>
      </el-form-item>
      <el-form-item>
        <el-input v-model="dataForm.tel" placeholder="手机号码" clearable></el-input>
      </el-form-item>
      <el-form-item>
        <el-input v-model="dataForm.email" placeholder="邮箱" clearable></el-input>
      </el-form-item>
      <el-form-item>
        <el-select v-model="dataForm.type" placeholder="请选择类型">
          <el-option label="超v" value=1></el-option>
          <el-option label="吴门医述v（原简易超v）" value=2></el-option>
          <el-option label="众秒之门vip" value=3></el-option>
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-select v-model="dataForm.state" placeholder="请选择状态">
          <el-option label="有效" value=0></el-option>
          <el-option label="失效" value=1></el-option>
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button @click="pageIndex = 1;getDataList()">查询</el-button>
      </el-form-item>
    </el-form>
    <el-table
      :data="dataList"
      border
      v-loading="dataListLoading"
      style="width: 100%;">
      <el-table-column
        type="selection"
        header-align="center"
        align="center"
        width="50">
      </el-table-column>
      <el-table-column
        prop="id"
        header-align="center"
        align="center"
        width="70"
        label="ID">
        <template slot-scope="scope">{{scope.row.user.id}}</template>
      </el-table-column>
      <el-table-column
        prop="name"
        header-align="center"
        align="center"
        width="120"
        label="用户名称">
        <template slot-scope="scope">{{scope.row.user.name}}</template>
      </el-table-column>
      <el-table-column
        prop="tel"
        header-align="center"
        align="center"
        width="120"
        label="手机号码">
        <template slot-scope="scope">{{scope.row.user.tel}}</template>
      </el-table-column>
      <el-table-column
        prop="email"
        header-align="center"
        align="center"
        width="120"
        label="邮箱">
        <template slot-scope="scope">{{scope.row.user.email}}</template>
      </el-table-column>
      <el-table-column
        prop="type"
        header-align="center"
        align="center"
        width="120"
        label="类型">
        <template slot-scope="scope">
          <span v-if="scope.row.type==1">超v</span>
          <span v-if="scope.row.type==2">吴门医述v（原简易超v）</span>
          <span v-if="scope.row.type==3">众秒之门vip</span>
        </template>
      </el-table-column>
      <el-table-column
        prop="state"
        header-align="center"
        align="center"
        label="状态">
        <template slot-scope="scope">
          <span v-if="scope.row.state==0">有效</span>
          <span v-if="scope.row.state==1" style=" color: red;">失效</span>
        </template>
      </el-table-column>
      <el-table-column
        prop="createTime"
        header-align="center"
        align="center"
        width="160"
        label="开始时间">
        <template slot-scope="scope">{{scope.row.startTime}}</template>
      </el-table-column>
      <el-table-column
        prop="endTime"
        header-align="center"
        align="center"
        width="160"
        label="结束时间">
        <template slot-scope="scope">{{scope.row.endTime}}</template>
      </el-table-column>
      <el-table-column
        fixed="right"
        header-align="center"
        align="center"
        width="130"
        label="操作">
        <template slot-scope="scope">
          <el-popover
            placement="right"
            width="300"
            trigger="click"
            @show="getVipMoney(scope.row)"
          >
            <el-table :data="vipList" class="vip-list-table">
              <el-table-column
                width="150"
                property="title"
                label="VIP名称"
              ></el-table-column>
              <el-table-column
                width="100"
                property="lastFee"
                label="开通金额"
              ></el-table-column>
            </el-table>
            <el-button slot="reference" size="small">办理金额</el-button>
          </el-popover>
        </template>
      </el-table-column>
    </el-table>
    <el-pagination
      @size-change="sizeChangeHandle"
      @current-change="currentChangeHandle"
      :current-page="pageIndex"
      :page-sizes="[10, 20, 50, 100]"
      :page-size="pageSize"
      :total="totalPage"
      layout="total, sizes, prev, pager, next, jumper">
    </el-pagination>
  </div>
</template>

<script>
export default {
  data () {
    return {
      dataForm: {
        userName: '',
        tel: '',
        email: '',
        type: '',
        state: ''
      },
      dataList: [],
      pageIndex: 1,
      pageSize: 10,
      totalPage: 0,
      dataListLoading: false,
      vipList: []
    }
  },
  methods: {
    // 获取列表数据
    getDataList () {
      this.dataListLoading = true
      this.$http({
        url: this.$http.adornUrl('/master/userVip/listByPage'),
        method: 'POST',
        data: {
          current: this.pageIndex,
          limit: this.pageSize,
          userName: this.dataForm.userName,
          tel: this.dataForm.tel,
          email: this.dataForm.email,
          type: this.dataForm.type,
          state: this.dataForm.state
        }
      }).then(({data}) => {
        if (data && data.code === 0) {
          this.dataList = data.result.records
          this.totalPage = data.result.total
        } else {
          this.dataList = []
          this.totalPage = 0
        }
        this.dataListLoading = false
      })
    },
    // 每页数
    sizeChangeHandle (val) {
      this.pageSize = val
      this.pageIndex = 1
      this.getDataList()
    },
    // 当前页
    currentChangeHandle (val) {
      this.pageIndex = val
      this.getDataList()
    },
    // VIP办理
    getVipMoney (data) {
      this.$http({
        url: this.$http.adornUrl('/master/userVip/getVipProductForUser'),
        method: 'POST',
        data: this.$http.adornData({
          uid: data.userId
        })
      }).then(({data}) => {
        let list = []
        if (data && data.code === 0) {
          for (let i in data.list) {
            if (data.list[i].length > 0) {
              list.push([...data.list[i]])
            }
          }
          this.vipList = list.flat(Infinity)
        } else {
          this.$message.error(data.msg)
          this.vipList = []
        }
      })
    }
  },
  activated () {
    this.getDataList()
  }
}
</script>

<style scoped>
.vip-personnel .el-form-item:last-child{
  margin-right:0;
}
</style>
