<template>
  <div class="app-container">
    <!-- 查询和其他操作 -->
    <div class="filter-container">
      <el-input
        v-model="listQuery.phone" clearable size="mini" class="filter-item"
        style="width: 200px;" placeholder="请输入下单用户号码"
      />
      <el-input
        v-model="listQuery.superiorPhone" clearable size="mini" class="filter-item"
        style="width: 200px;margin-left: 10px;" placeholder="请输入绑定上级手机号码"
      />
      <el-input
        v-model="listQuery.orderFormid" clearable size="mini" class="filter-item"
        style="width: 200px;margin-left: 10px;" placeholder="请输入关联订单编号"
      />
      <el-button
        size="mini" class="filter-item" type="primary" icon="el-icon-search"
        style="margin-left:10px;"
        @click="handleSearch"
      >
        查找
      </el-button>
    </div>

    <!-- 查询结果 -->
    <div v-tableHeight>
      <el-table
        v-loading="listLoading" height="100%" element-loading-text="正在查询中。。。" :data="list"
        v-bind="{ stripe: true, size: 'small', border: true, fit: true, highlightCurrentRow: true }"
      >
        <el-table-column align="center" width="100" label="ID" prop="commissionLogId" fixed="left" />
        <el-table-column align="center" label="分佣类型" prop="commissionType">
          <template slot-scope="{ row }">
            <el-tag v-if="row.commissionType === 1" effect="plain">升级活动</el-tag>
            <el-tag v-else-if="row.commissionType === 2" effect="plain">分佣活动</el-tag>
            <el-tag v-else-if="row.commissionType === 3" effect="plain">社区活动</el-tag>
            <el-tag v-else-if="row.commissionType === 4" effect="plain">赠券活动</el-tag>
            <el-tag v-else-if="row.commissionType === 5" effect="plain">赠金活动</el-tag>
            <el-tag v-else-if="row.commissionType === 6" effect="plain">商圈订单</el-tag>
            <el-tag v-else-if="row.commissionType === 7" effect="plain">爆品家具</el-tag>
            <el-tag v-else-if="row.commissionType === 8" effect="plain">社区订单</el-tag>
            <el-tag v-else-if="row.commissionType === 9" effect="plain">用户代金券转增</el-tag>
            <el-tag v-else-if="row.commissionType === 10" effect="plain">商家代金券转赠</el-tag>
            <el-tag v-else-if="row.commissionType === 11" effect="plain">同城联盟卡</el-tag>
            <span v-else>--</span>
          </template>
        </el-table-column>
        <el-table-column align="center" width="150" label="交易时间" prop="tradeTime" show-overflow-tooltip />
        <el-table-column align="center" width="150" label="关联订单编号" prop="orderFormid" show-overflow-tooltip />
        <el-table-column align="center" width="100" label="购买用户ID" prop="buyerUserId" show-overflow-tooltip />
        <el-table-column align="center" width="150" label="下单用户号码" prop="phone" show-overflow-tooltip />
        <el-table-column align="center" width="100" label="支付金额" prop="orderPrice" show-overflow-tooltip />
        <el-table-column align="center" width="120" prop="orderProportion" label="佣金比例/金额">
          <template slot-scope="{ row }">
            <span v-if="row.orderProportion <= 1">{{ row.orderProportion * 100 }}%</span>
            <span v-else-if="row.orderProportion > 1">￥{{ row.orderProportion }}</span>
          </template>
        </el-table-column>
        <el-table-column align="center" width="120" label="上级身份" prop="tidentity" show-overflow-tooltip />
        <el-table-column align="center" width="100" label="上级ID" prop="tid" show-overflow-tooltip />
        <el-table-column align="center" width="120" label="上级手机号" prop="tphone" show-overflow-tooltip />
        <el-table-column align="center" width="100" label="用于分佣的佣金总额" prop="commissionPrice" show-overflow-tooltip />
        <el-table-column align="center" width="100" label="获得佣金" prop="userCommission" show-overflow-tooltip />
        <!-- <el-table-column align="center" width="100" label="佣金分配详情" prop="commissionDetail" show-overflow-tooltip /> -->
        <el-table-column align="center" label="操作" width="120" fixed="right" class-name="small-padding fixed-width">
          <template slot-scope="{ row }">
            <el-button type="warning" size="mini" @click="handleDetail(row)">
              详情
            </el-button>
          </template>
        </el-table-column>
      </el-table>
    </div>

    <div>
      <el-pagination
        :current-page="listQuery.page" :page-sizes="[10, 20, 50, 100]" :page-size="listQuery.pageSize"
        layout="total, sizes, prev, pager, next, jumper" :total="total"
        @size-change="(val) => ((listQuery.pageSize = val) && getList())"
        @current-change="(val) => ((listQuery.page = val) && getList())"
      />
    </div>

    <!-- 查看详情 -->
    <DetailModal ref="DetailModal" />
  </div>
</template>

<script>
import DetailModal from './components/DetailModal'
import { getAllCommissionLog } from '@/api/relationshipChainManagement/commissionLog'

export default {
  name: 'CommissionLog',
  components: {
    DetailModal
  },
  data() {
    return {
      list: [],
      total: 0,
      listLoading: true,
      listQuery: {
        page: 1,
        pageSize: 20,
        phone: '',
        superiorPhone: '',
        orderFormid:""
      }
    }
  },
  created() {
    this.getList()
  },
  methods: {
    async getList() {
      this.listLoading = true
      try {
        const res = await getAllCommissionLog(this.listQuery)
        this.list = res.data.list
        this.total = res.data.total
      } finally {
        this.listLoading = false
      }
    },
    handleSearch() {
      this.listQuery.page = 1
      this.getList()
    },
    handleDetail(row) {
      this.$refs.DetailModal && this.$refs.DetailModal.handleOpen(row)
    }
  }
}
</script>

<style lang="scss" scoped>
.app-container {
	padding: 20px;
	display: flex;
	flex-direction: column;

	.filter-container {
		.filter-item {
			display: inline-block;
			vertical-align: middle;
			margin-bottom: 10px;
		}
	}

	.small-padding {
		.cell {
			padding-left: 5px;
			padding-right: 5px;
		}
	}

	.fixed-width {
		.el-button--mini {
			padding: 7px 10px;
		}
	}
}
</style>
