<template>
  <div class="divBox">
    <el-card class="box-card">
      <el-table v-loading="listLoading" :data="tableData.data" style="width: 100%" size="mini">
        <el-table-column prop="id" label="ID" min-width="60" align="center"/>
        <el-table-column prop="total_commission" label="周期总佣金" min-width="100" align="center"/>
        <el-table-column prop="total_weight_value" label="周期总权重值" min-width="100" align="center"/>
        <el-table-column prop="total_people" label="分佣总人数" min-width="100" align="center"/>
        <el-table-column label="周期时间段" min-width="300" align="center">
          <template slot-scope="scope">
            {{ scope.row.start_time }} ~ {{ scope.row.end_time }}
          </template>
        </el-table-column>
        <el-table-column prop="create_time" label="处理时间" min-width="150" align="center"/>
        <el-table-column label="操作" min-width="150" align="center">
          <template slot-scope="scope">
            <el-button type="primary" @click="seeDetailRecord(scope.row.id)">分佣明细</el-button>
          </template>
        </el-table-column>
      </el-table>
      <div class="block">
        <el-pagination
          :page-sizes="[20, 40, 60, 80]"
          :page-size="tableFrom.limit"
          :current-page="tableFrom.page"
          layout="total, sizes, prev, pager, next, jumper"
          :total="tableData.total"
          @size-change="handleSizeChange"
          @current-change="pageChange"
        />
      </div>
    </el-card>
    <!--明细弹框-->
    <el-dialog title="周期明细" :visible.sync="dialogVisible" width="80%" :before-close="handleClose">
      <el-table v-loading="dialogLoading" :data="dialogTableData.data" style="width: 100%" size="mini">
        <el-table-column prop="id" label="ID" min-width="60" align="center"/>
        <el-table-column label="用户信息" prop="nickname" min-width="280" align="left">
          <template slot-scope="scope">
            <div class="user-content">
              <div class="user-avatar" v-if="scope.row.avatar && scope.row.avatar != 1">
                <img :src="scope.row.avatar" />
              </div>
              <div class="user-info">
                <div class="nickname">{{ scope.row.nickname }}</div>
                <div class="user-id">ID：{{ scope.row.uid }}</div>
              </div>
            </div>
          </template>
        </el-table-column>
        <el-table-column label="分红佣金" prop="money" min-width="150" align="center"/>
        <el-table-column label="截止时间持有权重值" prop="total_contribution" min-width="200" align="center"/>
        <el-table-column label="分红比例" prop="proportion" min-width="150" align="center"/>
        <el-table-column label="是否结算" min-width="150" align="center">
          <template slot-scope="scope">
            <el-tag v-if="scope.row.is_settlement == 1" type="success" effect="dark">已结算</el-tag>
            <el-tag v-else type="info" effect="dark">待结算</el-tag>
          </template>
        </el-table-column>
        <el-table-column prop="create_time" label="处理时间" min-width="150" align="center"/>
      </el-table>
      <div class="block">
        <el-pagination
          :page-sizes="[20, 40, 60, 80]"
          :page-size="dialogTableFrom.limit"
          :current-page="dialogTableFrom.page"
          layout="total, sizes, prev, pager, next, jumper"
          :total="dialogTableData.total"
          @size-change="seeDetailHandleSizeChange"
          @current-change="seeDetailPageChange"
        />
      </div>
    </el-dialog>

  </div>
</template>

<script>
import { platformCommissionPartnerCycleList, platformCommissionPartnerList } from '@/api/platformCommission'
export default {
  name: "platformCommissionPartner",
  components: { },
  data() {
    return {
      // 周期信息相关
      listLoading: true,
      tableData: {
        data: [],
        total: 0,
      },
      tableFrom: {
        page: 1,
        limit: 20,
      },
      // 周期明细相关
      dialogVisible: false,
      dialogLoading: true,
      dialogTableData: {
        data: [],
        total: 0,
      },
      dialogTableFrom: {
        page: 1,
        limit: 20,
        cycle_id: 0
      },

    };
  },
  watch: {},
  mounted() {
    this.getList('');
  },
  methods: {
    // 获取列表 列表分页
    getList(num) {
      this.listLoading = true;
      this.tableFrom.page = num ? num : this.tableFrom.page;
      platformCommissionPartnerCycleList(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('');
    },
    handleSizeChange(val) {
      this.tableFrom.limit = val;
      this.getList('');
    },
    // 查看周期明细
    seeDetailRecord(cycleId){
      this.dialogLoading = true;
      this.dialogTableFrom.cycle_id = cycleId;
      platformCommissionPartnerList(this.dialogTableFrom)
        .then((res) => {
          this.dialogTableData.data = res.data.list;
          this.dialogTableData.total = res.data.count;
          this.dialogLoading = false;
          this.dialogVisible = true;
        })
        .catch((res) => {
          this.dialogLoading = false;
          this.$message.error(res.message);
        });
    },
    seeDetailPageChange(page) {
      this.dialogTableFrom.page = page;
      this.getList('');
    },
    seeDetailHandleSizeChange(val) {
      this.dialogTableFrom.limit = val;
      this.getList('');
    },
    // 关闭弹框
    handleClose() {
      this.dialogVisible = false
    },

  },
};
</script>

<style scoped lang="scss">
.selWidth {
  width: 350px !important;
}
.seachTiele {
  line-height: 35px;
}
.title{
  margin-bottom: 16px;
  color: #17233d;
  font-size: 14px;
  font-weight: bold;
}
.scollhide::-webkit-scrollbar {
  display: none; /* Chrome Safari */
}
.user-content{
  --user-content-height-: 80px;

  height: var(--user-content-height-);
  width: 100%;
  display: inline-flex;
  flex-direction: row;
  flex-wrap: nowrap;
  justify-content: center;
  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{
    height: var(--user-content-height-);
    width: calc(100% - var(--user-content-height-)) !important;
    display: inline-flex;
    flex-direction: column;
    flex-wrap: nowrap;
    justify-content: center;
    align-items: flex-start;
    .nickname{
      font-size: 15px;
      font-weight: bold;
      line-height: calc(var(--user-content-height- * 65%)) !important;
      width: 100%;
      text-align: left;
      white-space: nowrap;
      overflow: hidden;
      text-overflow: ellipsis;
    }
    .user-id{
      font-size: 13px;
      line-height: calc(var(--user-content-height- * 35%));
    }
  }
}
.rate-num{
  margin-top: 10px!important;
}
/deep/ .cell{
  padding: 0!important;
}
</style>
