<template>
  <div class="ele-body">
    <el-card shadow="never">
      <!-- 搜索表单 -->
      <user-search @search="reload" />
      <!-- 数据表格 -->
      <ele-pro-table
        ref="table"
        :columns="columns"
        :datasource="datasource"
        :selection.sync="selection"
        cache-key="systemUserTable"
      >
        <!-- 用户名列 -->
        <template v-slot:username="{ row }">
          <el-row>
            <el-col :span="12" class="ele-text-center">
              {{ row.username }}
            </el-col>
            <el-col :span="12" class="ele-text-center">
              {{ row.mobile }}
            </el-col>
          </el-row>
        </template>
        <!-- 角色列 -->
        <template v-slot:roles="{ row }">
          <el-tag
            v-for="item in row.roles"
            :key="item.roleId"
            size="mini"
            type="primary"
            :disable-transitions="true"
          >
            {{ item.roleName }}
          </el-tag>
        </template>
        <!-- 状态列 -->
        <template v-slot:status="{ row }">
          <span v-if="row.status" class="ele-text-success">正常</span>
          <span v-else class="ele-text-danger">禁用</span>
        </template>
        <!-- 操作列 -->
        <template v-slot:action="{ row }">
          <!--
          <el-link type="primary" :underline="false" @click="openEdit(row)">
            查看
          </el-link>
          -->
          <el-link type="primary" :underline="false" @click="goCmmssn(row)">
            佣金明细
          </el-link>
        </template>
      </ele-pro-table>
    </el-card>
    <!-- 编辑弹窗 -->
    <user-edit :visible.sync="showEdit" :data="current" @done="reload" />
    <!-- 佣金 -->
    <commssn :visible.sync="showCommssn" :data="current" />
  </div>
</template>

<script>
  import UserSearch from './components/user-search.vue';
  import UserEdit from './components/user-edit.vue';
  import commssn from './components/commssn.vue';
  import { pageTeam } from '@/api/user/team';

  export default {
    name: 'userTeam',
    components: {
      UserSearch,
      UserEdit,
      commssn
    },
    data() {
      return {
        // 表格列配置
        columns: [
          {
            prop: 'id',
            label: '编号',
            minWidth: 50,
            align: 'center',
            showOverflowTooltip: true,
            fixed: 'left'
          },
          {
            prop: 'username',
            label: '团员',
            showOverflowTooltip: true,
            slot: 'username',
            align: 'center',
            minWidth: 100
          },
          {
            prop: 'cityName',
            label: '所属区域',
            showOverflowTooltip: true,
            minWidth: 110,
            align: 'center'
          },
          {
            prop: 'sexName',
            label: '归属板块',
            showOverflowTooltip: true,
            minWidth: 80,
            align: 'center'
          },
          {
            prop: 'status',
            label: '状态',
            align: 'center',
            width: 100,
            resizable: false,
            slot: 'status',
            showOverflowTooltip: true
          },
          {
            columnKey: 'action',
            label: '操作',
            width: 220,
            align: 'center',
            resizable: false,
            slot: 'action',
            showOverflowTooltip: true
          }
        ],
        // 表格选中数据
        selection: [],
        // 当前编辑数据
        current: null,
        // 是否显示编辑弹窗
        showEdit: false,
        // 是否显示佣金
        showCommssn: false
      };
    },
    methods: {
      /* 表格数据源 */
      datasource({ page, limit, where, order }) {
        return pageTeam({ ...where, ...order, page, limit });
      },
      /* 刷新表格 */
      reload(where) {
        this.$refs.table.reload({ page: 1, where: where });
      },
      /* 打开编辑弹窗 */
      openEdit(row) {
        this.current = row;
        this.showEdit = true;
      },
      goCmmssn(row) {
        this.current = row;
        this.showCommssn = true;
      }
    }
  };
</script>
