<template>
  <div class="divBox">
    <!--主要内容-->
    <el-card class="box-card">
      <!--顶部搜索栏-->
      <div slot="header" class="clearfix">
        <div class="container">
          <el-form inline size="small" label-width="80px">
            <el-form-item label="">
              <el-input v-model="tableFrom.search_text" placeholder="请输入用户id|电话号码|昵称" clearable class="selWidth">
                <el-button slot="append" icon="el-icon-search" class="el-button-solt" @click="getList(1)"/>
              </el-input>
            </el-form-item>
          </el-form>
          <!--<el-button size="small" type="success" @click="editInfo">添加等级</el-button>-->
        </div>
      </div>
      <!--表格信息-->
      <el-table v-loading="listLoading" :data="tableData.data" style="width: 100%" size="mini">
        <el-table-column label="ID" prop="id" min-width="80" align="center"/>
        <el-table-column label="用户信息" min-width="230" align="center">
          <template slot-scope="scope">
            <div class="user-content">
              <div class="user-avatar">
                <img :src="scope.row.user.avatar || moren" />
              </div>
              <div class="user-info">
                <div class="nickname">{{ scope.row.user.nickname }}</div>
                <div class="agent-type-text">
                  <el-tag type="info" effect="dark" size="small">{{ scope.row.user.uid }}</el-tag>
                </div>
              </div>
            </div>
          </template>
        </el-table-column>
        <el-table-column label="归属商户" min-width="230" align="center">
          <template slot-scope="scope">
            <div class="user-content">
              <div class="user-avatar">
                <img :src="scope.row.merchant.mer_avatar || moren" />
              </div>
              <div class="user-info">
                <div class="nickname">{{ scope.row.merchant.mer_name }}</div>
                <div class="agent-type-text">
                  <el-tag type="info" effect="dark" size="small">{{ scope.row.merchant.mer_id }}</el-tag>
                </div>
              </div>
            </div>
          </template>
        </el-table-column>
        <el-table-column label="股东等级" prop="level_name" min-width="150" align="center"/>
        <el-table-column label="支付金额" min-width="80" align="center">
          <template slot-scope="scope">
            <div v-if="scope.row.status == 0"></div>
            <div v-else>{{ scope.row.price > 0 ? scope.row.price : '免费' }}</div>
          </template>
        </el-table-column>
        <el-table-column label="状态" min-width="80" align="center">
          <template slot-scope="scope">
            <el-tag v-if="scope.row.status == 0">待支付</el-tag>
            <el-tag v-else-if="scope.row.status == 1" type="success">已支付</el-tag>
          </template>
        </el-table-column>
        <el-table-column label="操作" min-width="100" fixed="right" align="center">
          <template slot-scope="scope">
            <!--<el-button type="text" size="small" @click="editInfo({id: scope.row.id})">编辑</el-button>-->
            <el-button type="text" size="small" @click="delInfo(scope.row.id)">删除</el-button>
          </template>
        </el-table-column>
      </el-table>
      <!--分页-->
      <div class="block">
        <el-pagination :page-size="tableFrom.limit" :current-page="tableFrom.page" :total="tableData.total" @current-change="pageChange" />
      </div>
    </el-card>

  </div>
</template>

<script>
import {merchantTypeText} from "@/filters";
import {merShareholderDel, merShareholderList, merShareholderUserList} from "@/api/merchant";

export default {
  name: "MerchantShareholderList",
  components: {},
  data() {
    return {
      moren: require("@/assets/images/f.png"),
      merchantTitle: '商户',
      // 列表
      listLoading: false,
      tableFrom: {
        page: 1,
        limit: 20,
        search_text: '',
        merchant_type: '',
      },
      tableData: {
        data: [],
        total: 0,
      },


    };
  },
  watch: {
    // 路由变更
    '$route' () {
      this.tableFrom.merchant_type = this.$route.meta.merchant_type || 0;
    },
    // 商户类型变更
    'tableFrom.merchant_type' () {
      this.merchantTitle = merchantTypeText(this.tableFrom.merchant_type);
      this.getList();
    },
  },
  mounted() {
    this.tableFrom.merchant_type = this.$route.meta.merchant_type || 0;
  },
  methods: {
    // 列表
    getList(num = ''){
      let _this = this;
      _this.listLoading = true;
      _this.tableFrom.page = num ? num : _this.tableFrom.page;
      merShareholderUserList(_this.tableFrom).then((res) => {
        _this.tableData.data = res.data.list;
        _this.tableData.total = res.data.count;
        _this.listLoading = false;
      }).catch((res) => {
        _this.listLoading = false;
        _this.$message.error(res.message);
      });
    },
    pageChange(page) {
      this.tableFrom.page = page;
      this.getList('');
    },
    // 删除
    delInfo(id){
      let _this = this;
      this.$confirm('删除后不可恢复，您确认删除吗?', '提示', {
        confirmButtonText: '删除',
        cancelButtonText: '不删除',
        type: 'warning'
      }).then(() => {
        merShareholderDel(id).then((res) => {
          _this.getList('')
          this.$message({
            type: 'success',
            message: '删除成功'
          })
        }).catch((res) => {
          console.log('错误',res)
        });
      }).catch(action => {})
    },


  }
};
</script>

<style scoped lang="scss">
.user-content{
  --user-content-height-: 80px;

  height: var(--user-content-height-);
  width: 100%;
  display: inline-flex;
  flex-direction: row;
  flex-wrap: nowrap;
  justify-content: flex-start;
  align-items: center;
  .user-avatar{
    height: var(--user-content-height-);
    width: var(--user-content-height-);
    display: inline-flex;
    flex-direction: row;
    flex-wrap: nowrap;
    justify-content: center;
    align-items: center;
    img{
      height: 80%!important;
      width: 80%!important;
      border-radius: 50% !important;
    }
  }
  .user-info{
    max-width: calc(100% - var(--user-content-height-));
    height: var(--user-content-height-);
    display: inline-flex;
    flex-direction: column;
    flex-wrap: nowrap;
    justify-content: center;
    align-items: flex-start;
    .nickname{
      width: 100%;
      height: 25px;
      line-height: 25px;
      text-align: left;
      font-size: 15px;
      font-weight: bold;
      white-space: nowrap;
      overflow: hidden;
      text-overflow: ellipsis;
      display: inline-flex;
      flex-direction: row;
      flex-wrap: nowrap;
      justify-content: flex-start;
      align-items: center;
      .user-id{
        color: #fff;
        background-color: #409eff;
        border-color: #409eff;
        height: 18px;
        line-height: 20px;
        font-size: 13px;
        padding: 0 5px;
        border-radius: 5px;
        margin-left: 10px;
        width: max-content!important;
      }
    }
    .user-id{
      width: 100%;
      text-align: left;
      font-size: 13px;
      line-height: calc(var(--user-content-height- * 35%));
    }
  }
}
</style>
