<template>
  <div class="divBox">
<div>adfasdfasdf</div>
    <el-button type="primary" @click="test">test</el-button>
    <el-card class="box-card">
      <div slot="header" class="clearfix">
        <div class="container">



          <el-form size="small" label-width="100px">
            <div class="form-item-container">

              <el-form-item label="订单号：">
                <el-input v-model.trim="searchInfo.orderNo" placeholder="请输入订单号"
                  class="selWidth1" size="small" clearable>
                  <el-button slot="append" icon="el-icon-search"
                    size="small" @click="searchList" />
                </el-input>
              </el-form-item>


              <el-form-item label="时间选择：">
                <el-radio-group v-model="searchInfo.dateLimit" type="button"
                  class="mr20" size="small" @change="searchList">
                  <el-radio-button v-for="(item, i) in fromList.fromTxt"
                    :key="i" :label="item.val">
                    {{ item.text }}
                  </el-radio-button>
                </el-radio-group>
                <el-date-picker v-model="timeVal" value-format="yyyy-MM-dd"
                  format="yyyy-MM-dd" size="small" type="daterange"
                  placement="bottom-end" placeholder="自定义时间"
                  style="width: 250px" @change="onchangeTime" />
              </el-form-item>
            </div>
            <div class="form-item-container">
              <el-form-item label="分销商名称：">
                <el-input v-model.trim="searchInfo.name" placeholder="请输入分销商名称"
                  class="selWidth" size="small" clearable>
                  <el-button slot="append" icon="el-icon-search"
                    size="small" @click="searchList" />
                </el-input>
              </el-form-item>
              <el-form-item label="结算状态：">
                <el-select v-model="searchInfo.settleStatus" @change="searchList">
                  <el-option label="全部" :value="-1"></el-option>
                  <el-option label="待生效" :value="1"></el-option>
                  <el-option label="冻结中" :value="2"></el-option>
                  <el-option label="待结算" :value="3"></el-option>
                  <el-option label="结算中" :value="4"></el-option>
                  <el-option label="已结算" :value="5"></el-option>
                  <el-option label="无效" :value="6"></el-option>
                </el-select>
              </el-form-item>

            </div>
            <div class="total-amount">总笔数：{{totalCount}}笔 | 总成交金额：{{totalPayPrice}}元 | 总佣金：{{totalBrokeragePrice}}元</div>
          </el-form>
        </div>
      </div>





      <el-table v-loading="listLoading" :data="reportList"
        style="width: 100%" size="mini" class="table"
        highlight-current-row @selection-change="selectOptions">
        <el-table-column type="selection" width="55" align="center"></el-table-column>
        <el-table-column prop="orderNo" label="订单ID" width="150" align="center" />


        <el-table-column prop="orderTime" label="结算单号" min-width="140" align="center" />
        <el-table-column prop="orderTime" label="渠道商" min-width="140" align="center" />
        <el-table-column prop="orderTime" label="账期" min-width="140" align="center" />
        <el-table-column prop="orderTime" label="结算数量(条)" min-width="140" align="center" />
        <el-table-column prop="orderTime" label="实付总金额(元)" min-width="140" align="center" />
        <el-table-column prop="orderTime" label="结算佣金(元)" min-width="140" align="center" />





        <el-table-column label="结算状态" min-width="100" align="center">
          <template slot-scope="scope">
            <span>{{
              scope.row.settleStatus === 1 ? '待生效' :
              scope.row.settleStatus === 2 ? '冻结中' :
              scope.row.settleStatus === 3 ? '待结算' :
              scope.row.settleStatus === 4 ? '结算中' :
              scope.row.settleStatus === 5 ? '已结算' : '无效'
            }}</span>
          </template>
        </el-table-column>


        <el-table-column prop="orderTime" label="结算单生成时间" min-width="140" align="center" />

<!--


        <el-table-column prop="productName" label="商品名称" min-width="130" align="center" />
        <el-table-column prop="payPrice" label="成交金额" min-width="130" align="center" />
        <el-table-column prop="brokeragePrice" label="佣金" min-width="130" align="center" />



        <el-table-column label="分销员类型" min-width="80" align="center">
          <template slot-scope="scope">
            <span>{{ scope.row.brokerageUserType === 1 ? '企业' : '个人' }}</span>
          </template>
        </el-table-column>
        <el-table-column prop="brokerageUserRealName" label="分销员姓名" min-width="100" align="center" />
        <el-table-column prop="brokerageUserNikeName" label="分销员昵称" min-width="130" align="center" />
        <el-table-column prop="brokerageUserPhone" label="分销员手机号" min-width="130" align="center" />
        <el-table-column prop="brokerageUserOrg" label="分销员所属企业" min-width="130" align="center" />
        <el-table-column label="佣金类型" min-width="100" align="center">
          <template slot-scope="scope">
            <span>{{ scope.row.brokerageConfigType === 1 ? '默认比例' : '自定义比例' }}</span>
          </template>
        </el-table-column>
        <el-table-column prop="brokerageRatio" label="分佣规则" min-width="130" align="center" />
        <el-table-column prop="orderUserRealName" label="客户(购买人)" min-width="130" align="center" /> -->




        <el-table-column label="操作" min-width="100" align="center">
          <template slot-scope="scope">

            <el-button type="primary">test</el-button>
            <el-button type="primary">test</el-button>
            <el-button type="primary">test</el-button>
            <el-button type="primary">test</el-button>


          </template>
        </el-table-column>



      </el-table>
      <div class="block">
        <el-pagination :page-sizes="[20, 40, 60, 80]" :page-size="limit"
          :current-page="page" layout="total, sizes, prev, pager, next, jumper"
          :total="total" @size-change="handleSizeChange" @current-change="pageChange" />
      </div>
    </el-card>
  </div>
</template>

<script>
  import { earningListApi, reportStatisticsApi,test1,test2 } from '@/api/distribution';
  import cardsData from '@/components/cards/index';
  import { checkPermi } from '@/utils/permission'; // 权限判断函数

  export default {
    name: 'distributionCompany',
    components: { cardsData },
    data() {
      return {
        listLoading: false,
        fromList: this.$constants.fromList,
        reportList: [],
        checkList: [],
        selectionList: [],
        timeVal: [],
        searchInfo: {
          name: '',
          dateLimit: '',
          orderNo: '',
          settleStatus: null
        },
        page: 1,
        limit: 20,
        total: 0,
        bcxId: null,
        totalBrokeragePrice: '',
        totalCount: '',
        totalPayPrice: ''
      };
    },
    mounted() {
      this.bcxId = this.$route.query.bcxId;
      this.getList();
    },
    methods: {
      checkPermi,

      test(){


        test1({}).then((res)=>{
          console.log(' ========== 145  --  index1  ==========');
          console.log(res);
        })
        test2({}).then((res)=>{
          console.log(' ========== 145  --  index1  ==========');
          console.log(res);
        })


      },
      getList() {
        this.listLoading = true;
        let params = {
          limit: this.limit,
          page: this.page,
          bcxId: this.bcxId ? this.bcxId : null,
          dateLimit: this.searchInfo.dateLimit,
          name: this.searchInfo.name,
          orderNo: this.searchInfo.orderNo,
          settleStatus: this.searchInfo.settleStatus
        };


        test1(params).then((res) => {
          // this.getStatistics()

          console.log(' ========== 174  --  index1  ==========');
          console.log(res);

          this.limit = res.limit;
          this.reportList = res.list;
          this.page = res.page;
          this.total = res.total;
          this.listLoading = false;
        }).catch(() => {
          this.listLoading = false;
        });
      },




      getStatistics() {
        let params = {
          searchType: 4,
          bcxId: this.bcxId,
          dateLimit: this.searchInfo.dateLimit,
          name: this.searchInfo.name,
          orderNo: this.searchInfo.orderNo,
          settleStatus: this.searchInfo.settleStatus
        };
        reportStatisticsApi(params).then((res) => {
          this.totalBrokeragePrice = res.totalBrokeragePrice
          this.totalCount = res.totalCount
          this.totalPayPrice = res.totalPayPrice
        })
      },
      searchList() {
        this.page = 1;
        this.getList();
      },
      // 具体日期
      onchangeTime(e) {
        this.timeVal = e;
        this.searchInfo.dateLimit = e ? this.timeVal.join(',') : '';
        this.getList();
      },
      selectOptions(selection) {
        this.checkList = selection;
      },
      handleSizeChange(val) {
        this.limit = val;
        this.getList();
      },
      pageChange(page) {
        this.page = page;
        this.getList();
      },
    },
  };
</script>

<style scoped>
  .selWidth {
    width: 200px;
  }

  .selWidth1 {
    width: 350px;
  }

  .el-dropdown-link {
    cursor: pointer;
    color: #409eff;
    font-size: 12px;
  }

  .el-icon-arrow-down {
    font-size: 12px;
  }

  .form-item-container {
    display: flex;
    flex-direction: row;
    align-items: center;
  }

  .total-amount {
    margin-left: 20px;
    font-size: 16px;
  }
</style>
