<template>
  <div class="divBox">
    <el-card class="box-card">
      <!--顶部统计栏-->
      <div slot="header" class="clearfix">
        <div class="container">
          <cards-data :card-lists="cardLists" />
        </div>
      </div>
      <!--列表信息-->
      <el-tabs v-model="activeName" @tab-click="changeTabs">
        <el-tab-pane label="周期信息" name="cycle_list">
          <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_platform_commission_money" label="基金数量" min-width="100" align="center"/>
            <el-table-column prop="legumes_price" label="豆豆价格" min-width="100" align="center"/>
            <el-table-column prop="legumes_num" label="豆豆数量" min-width="100" align="center"/>
            <el-table-column prop="legumes_num" 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="100" align="center">
              <template slot-scope="scope">
                <el-tag v-if="scope.row.status == 1" type="success" effect="dark">已分配</el-tag>
                <el-tag v-else type="info" effect="dark">待分配</el-tag>
              </template>
            </el-table-column>
            <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>
        </el-tab-pane>
        <el-tab-pane label="分配明细" name="list">
          <!--顶部搜索栏-->
          <div class="clearfix">
            <div class="container">
              <el-form inline size="small" label-width="80px">
                <el-form-item label="搜索：">
                  <el-select v-model="tableFrom.status" placeholder="请选择" class="filter-item selWidth" clearable>
                    <el-option label="冻结中" :value="0" />
                    <el-option label="可使用" :value="1" />
                    <el-option label="已失效" :value="2" />
                  </el-select>
                  <el-input v-model="tableFrom.uid" placeholder="请输入用户ID" class="selWidth" clearable>
                    <el-button slot="append" icon="el-icon-search" class="el-button-solt" @click="clickSearch" />
                  </el-input>
                </el-form-item>
                <el-form-item class="width100">
                  <!--<el-button size="small" type="primary" @click="exports">导出</el-button>-->
                </el-form-item>
              </el-form>
            </div>
          </div>
          <!--表单列表-->
          <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 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 prop="order_money" label="订单金额" min-width="100" align="center"/>
            <el-table-column prop="order_money_rate" label="占比例(%)" min-width="100" align="center"/>
            <el-table-column prop="get_legumes" label="获得豆豆" min-width="100" align="center"/>
            <el-table-column prop="get_integral" label="获取积分" min-width="100" align="center"/>
            <el-table-column prop="use_integral" label="已使用积分" min-width="100" align="center"/>
            <el-table-column prop="create_time" label="处理时间" min-width="150" align="center"/>
            <el-table-column label="状态" min-width="100" align="center">
              <template slot-scope="scope">
                <el-tag v-if="scope.row.status == 0" type="info" effect="dark">冻结中</el-tag>
                <el-tag v-else-if="scope.row.status == 1" type="success" effect="dark">可使用</el-tag>
                <el-tag v-else type="danger" effect="dark">已失效</el-tag>
              </template>
            </el-table-column>
          </el-table>
        </el-tab-pane>
        <el-tab-pane label="持有明细" name="hold_list">
          <el-alert
            title="由于获取积分不能超过订单实际支付金额 + 抵扣积分；因此当前豆豆价格 * 持有的豆豆 ≠ 已获取积分！"
            type="warning"
            :closable="false"
            style="margin-bottom: 10px!important;"
            show-icon
            center
          ></el-alert>
          <!--顶部搜索栏-->
          <div class="clearfix">
            <div class="container">
              <el-form inline size="small" label-width="80px">
                <el-form-item label="搜索：">
                  <el-input v-model="tableFrom.uid" placeholder="请输入用户ID" class="selWidth" clearable>
                    <el-button slot="append" icon="el-icon-search" class="el-button-solt" @click="clickSearch" />
                  </el-input>
                </el-form-item>
                <el-form-item class="width100">
                  <!--<el-button size="small" type="primary" @click="exports">导出</el-button>-->
                </el-form-item>
              </el-form>
            </div>
          </div>
          <!--表单列表-->
          <el-table v-loading="listLoading" :data="tableData.data" style="width: 100%" size="mini">
            <el-table-column label="用户信息" prop="nickname" min-width="280" align="center">
              <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 prop="total_get_legumes" label="持有豆豆" min-width="150" align="center"/>
            <el-table-column label="已获取积分 / 积分上限" min-width="200" align="center">
              <template slot-scope="scope">
                <el-tag type="success" effect="dark">{{ scope.row.total_get_integral }} / {{ scope.row.total_order_money }}</el-tag>
              </template>
            </el-table-column>
            <el-table-column prop="total_freeze_integral" label="冻结中积分" min-width="150" align="center"/>
            <el-table-column prop="total_use_integral" label="已使用积分" min-width="150" align="center"/>
            <el-table-column prop="surplus_use_integral" label="剩余可用积分" min-width="150" align="center"/>
          </el-table>
        </el-tab-pane>
      </el-tabs>
      <div class="block">
        <el-pagination
          :page-sizes="[10, 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>
  </div>
</template>

<script>
import cardsData from '@/components/cards/index'
import { platformCommissionLegumes, platformCommissionLegumesTitle } from '@/api/platformCommission'
export default {
  name: "platformCommissionLegumes",
  components: { cardsData },
  data() {
    return {
      // 选项卡相关内容
      activeName: 'cycle_list',
      // 周期信息相关
      listLoading: true,
      tableData: {
        data: [],
        total: 0,
      },
      tableFrom: {
        page: 1,
        limit: 10,
        uid: '',
        legumes_id: '',
        status: '',
      },
      cardLists: [],
    };
  },
  watch: {},
  mounted() {
    this.getIntegralTitle();
    this.getList('');
  },
  methods: {
    // 获取统计数据
    getIntegralTitle() {
      platformCommissionLegumesTitle(this.tableFrom).then((res) => {
        this.cardLists = res.data
      }).catch((res) => {
        this.$message.error(res.message)
      })
    },
    // 获取列表 列表分页
    getList(num) {
      this.listLoading = true;
      this.tableFrom.page = num ? num : this.tableFrom.page;
      platformCommissionLegumes(this.tableFrom,this.activeName)
        .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('');
    },
    // 点击搜索
    clickSearch(){
      this.getList(1);
    },
    // 点击变更选项卡
    changeTabs(tab, event){
      this.tableFrom.legumes_id = '';
      this.tableFrom.uid = '';
      this.getList(1);
    },
    // 查看周期明细
    seeDetailRecord(legumes_id){
      this.tableFrom.legumes_id = legumes_id;
      this.activeName = 'list';
      this.getList(1);
    }



  },
};
</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>
