<!--
 * @Descripttion:
 * @version:
 * @Author: kBank
 * @Date: 2022-10-24 15:45:01
-->
<template>
  <div class="page">
    <topBar
      v-if="topList.length > 0"
      :topList="topList"
      :moren="moren"
    ></topBar>
    <div class="main">
      <el-form
        ref="select"
        :model="select"
        style="padding: 0 10px 0 0"
        label-width="80px"
      >
        <el-row>
          <el-col :span="8">
            <el-form-item :label="'业绩时间'">
              <el-date-picker
                v-model="creationTime"
                @change="changeTime"
                value-format="yyyy-MM-dd"
                type="daterange"
                :range-separator="'至'"
                :start-placeholder="'开始日期'"
                :end-placeholder="'结束日期'"
              >
              </el-date-picker>
            </el-form-item>
          </el-col>

          <el-col :span="4" style="margin-left: 10px">
            <el-button type="primary" @click="getDataList">
              {{ '搜索' }}</el-button
            >
            <el-button type="primary" @click="reset">
              {{ '重置' }}</el-button
            >
            <el-button
              type="primary"
              v-hasButtons="['TopPerformanceTotal']"
              @click="getNewData"
            >
              统计</el-button
            >
          </el-col>
        </el-row>
        <el-row> </el-row>
        <!-- <el-row>
          <el-col>
            <el-form-item :label="'隶属体系'">
              <el-checkbox-group @change="getpkVertex"
                                 v-model="select.pkVertexList">
                <el-checkbox v-for="item in verList"
                             :key="item.value"
                             :value="item.pkId"
                             :label="item.pkId">{{ item.vertexName }}</el-checkbox>
              </el-checkbox-group>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col>
            <el-form-item :label="'隶属团队'">
              <el-checkbox-group @change="getTeam"
                                 v-model="select.pkMemberTeamList">
                <el-checkbox v-for="item in memberList"
                             :key="item.value"
                             :value="item.pkId"
                             :label="item.pkId">{{ item.vertexName }}</el-checkbox>
              </el-checkbox-group>
            </el-form-item>
          </el-col>
        </el-row> -->
        <!-- <el-row style="margin-left:10px">
          <el-col :span="4">
            <el-button type="primary"
                       @click="getDataList"> {{ '搜索' }}</el-button>
            <el-button type="primary"
                       @click="reset"> {{ '重置' }}</el-button>
          </el-col>
        </el-row> -->
      </el-form>
      <div class="maintop">
        <div class="mainbtn">
          <el-button
            size="small"
            @click="handleExport"
            v-hasButtons="['LenTopPerformanceExport']"
            class="thebtn2"
          >
            {{ '导出' }}</el-button
          >
        </div>
        <!-- <div>
          <el-dropdown :hide-on-click="false" placement="top">
            <span class="el-dropdown-link kuang">
              {{ '下拉菜单' }}<i class="el-icon-arrow-down el-icon--right"></i>
            </span>
            <el-dropdown-menu slot="dropdown">
              <el-dropdown-item v-for="item in menuList"
                                :key="item.id" >
                <el-checkbox v-model="item.checked"
                             @change="getMenu($event,item.id)">{{ item.text }}</el-checkbox></el-dropdown-item>
            </el-dropdown-menu>
          </el-dropdown>
        </div> -->
      </div>
      <div class="maintable">
        <!-- <div class="itemTrading"> -->
        <el-table
          v-loading="loading"
          :data="tableData"
          ref="mainTable"
          height="700px"
          :header-cell-style="{ background: '#EEEEEE' }"
          :summary-method="getSummaries"
          show-summary
          :row-class-name="tableRowClassName"
          @selection-change="handleSelectionChange"
        >
          <el-table-column type="selection" width="60"> </el-table-column>
          <el-table-column
            v-for="(item, index) in menuList"
            :key="index"
            align="center"
            :prop="item.prop"
            :label="item.text"
          >
            <template slot-scope="scope">
              <div v-if="index > 4">
                {{ scope.row[item.prop] | numberToCurrency }}
              </div>
              <div v-if="index <= 4">{{ scope.row[item.prop] }}</div>
            </template>
          </el-table-column>
        </el-table>
        <!-- </div> -->
      </div>
    </div>
    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getDataList"
    />
  </div>
</template>

<script>
import topBar from "@/components/topBar";
import * as api from "@/api/settle.js";
import { classifyUpdate, classifySave } from "@/api/product";
import { getRouters } from "@/api/settle.js";
import { isOther, numberToCurrencyNo } from "@/utils/numberToCurrency";
export default {
  name: "Bzpz",
  components: {
    topBar,
  },
  filters: {
    isAgree(val) {
      if (!val) {
        return '允许';
      } else {
        return '禁止';
      }
    },
  },
  data() {
    return {
      loading: false,
      typeList: [
        {
          value: 0,
          label: '前台',
        },
        {
          value: 1,
          label: '后台',
        },
      ],
      digList: [
        {
          value: 0,
          label: '允许',
        },
        {
          value: 1,
          label: '禁止',
        },
      ],
      menuList: [
        {
          text: "顶点编号",
          prop: "memberCode",
        },
        {
          text: "顶点名称",
          prop: "memberName",
        },
        {
          text: "业绩时间",
          prop: "creationTime",
        },
        {
          text: `乐享海购金额（￥）`,
          prop: "lenjoyAmount",
        },
        {
          text: `乐享极差（￥）`,
          prop: "cloudRealSubtotal",
        },
        {
          text: `极差拨比`,
          prop: "lenjoyRate",
        },
      ],
      creationTime: [],
      creationTime1: [],
      select: {
        pkVertexList: [],
        pkMemberTeamList: [],
      },
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 50,
      },
      addOrEdit: "",
      total: 0,
      dialogVisible: false,
      tableData: [],
      moren: "lenTopPerformance",
      topList: [
        {
          name: "乐享顶点奖金拨比列表",
          path: "lenTopPerformance",
        },
      ],
      form: {},
      verList: [],
      memberList: [],
      acList: [],
      tableList: {},
      props: {
        multiple: true,
        expandTrigger: "hover",
        value: "pkId",
        label: "vertexName",
        children: "childList",
      },
      subtotal: {},
    };
  },
  mounted() {
    // 获取列表
    // this.getDataList();
  },
  methods: {
    getTotal() {
      api
        .topSubtotal(Object.assign({}, this.queryParams, this.select))
        .then((res) => {
          if (res.code == 200) {
            this.tableList = res.data;
          }
        });
    },
    // getSummaries({ columns, data }) {
    //   this.$nextTick(() => {
    //     this.$refs.mainTable.doLayout();
    //   });
    //   let sums = [];
    //   sums.push("合计");
    //   columns.forEach((column, index) => {
    //     if (
    //       column.property == "lenjoyAmount" ||
    //       column.property == "cloudRealSubtotal"
    //     ) {
    //       const values = data.map((item) => Number(item[column.property]));
    //       const sum = values.reduce((prev, curr) => prev + curr, 0);
    //       sums[index] = sum;
    //     } else {
    //       sums.push("");
    //     }
    //   });
    //   console.log(sums, "123");
    //   return sums;
    // },
    getSummaries({ columns, data }) {
      this.$nextTick(() => {
        this.$refs.mainTable.doLayout();
      });
      const lastRecord = this.subtotal;
      return columns.map((column, index) => {
        const { property } = column;
        if (index === 0) {
          return "合计";
        } else if (index === 4 || index === 5 || index === 6) {
          return lastRecord[property];
        } else {
          return "";
        }
      });
    },
    reset() {
      this.select = {
        pkVertexList: [],
        pkMemberTeamList: [],
        pkTeamCodeStr: "",
        pkBdVertexStr: "",
      };
      this.creationTime = [];
    },
    getData() {
      api
        .bonusLenSubtotal(Object.assign({}, this.queryParams, this.select))
        .then((res) => {
          this.$set(this, "subtotal", res.data);
          this.subtotal = res.data;
        });
    },
    changeTime(val) {
      this.select.startDate = val ? val[0] : "";
      this.select.endDate = val ? val[1] : "";
    },
    getNewData() {
      this.loading = true;
      api
        .topBonusLenListHistory(
          Object.assign({}, this.queryParams, this.select)
        )
        .then((res) => {
          this.getDataList();
        });
    },
    getDataList() {
      api
        .bonusLenStatis(Object.assign({}, this.queryParams, this.select))
        .then((res) => {
          this.loading = false;
          if (res.code == 200) {
            this.tableData = res.rows;
            this.total = res.total;
            this.$nextTick(() => {
              this.getData();
            });
          }
        });
    },
    handleSelectionChange(val) {},
    /** 导出按钮操作 */
    handleExport() {
      this.$confirm('是否确认导出所有数据项?', '警告', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: "warning",
      }).then((_) => {
        this.download(
          "/member/manage/bonus-len-statis/export",
          Object.assign({}, this.queryParams, this.select),
          `乐享顶点奖金拨比列表-${new Date().getTime()}.xlsx`
        );
      });
    },
    tableRowClassName({ row, rowIndex }) {
      if (rowIndex % 2 == 1) {
        return "warning-row";
      } else if (rowIndex % 2 == 0) {
        return "success-row";
      }
      return "";
    },
  },
};
</script>
<style scoped lang="scss">
::v-deep .el-table .warning-row {
  background: #f9f9f9;
}

::v-deep .el-table .success-row {
  background: #ffffff;
}
::v-deep .el-table thead {
  color: #000000;
}
::v-deep .el-select {
  width: 100%;
}
.uploadIcon ::v-deep .el-upload--picture-card {
  display: none !important; /* 上传按钮隐藏 */
}
.page {
  padding: 20px;
  background: #f9f9f9;
  font-size: 14px;
  .main {
    background: #ffffff;
    border-radius: 8px;
    box-shadow: 0px 2px 20px 0px rgba(238, 238, 238, 0.5);
    display: flex;
    flex-direction: column;
    .maintop {
      display: flex;
      // padding: 0 10px;
      justify-content: space-between;
      align-items: center;
      .mainbtn {
        .thebtn1 {
          background: #3181e5;
          color: #ffffff;
        }
        .thebtn2 {
          background: #ffad41;
          color: #ffffff;
        }
      }
      .maintitle {
        font-size: 10px;
        font-family: MicrosoftYaHei;
        color: #999999;
      }
    }
    .maintable {
      flex: 1;
    }
  }
  .tem {
    display: flex;
    align-items: center;
    justify-content: center;
    img {
      width: 28px;
      height: 20px;
      margin-right: 3px;
    }
  }
  .isRed {
    color: #ed1d25;
  }
  .isGreen {
    color: #1ab62b;
  }
  .bgImg {
    width: 48px;
    height: 48px;
  }
}
.openClose {
  text-align: right;
  margin-right: 10px;
  color: #3181e5;
}
.kuang {
  padding: 5px 20px;
  background: rgba(255, 255, 255, 0);
  border-radius: 4px;
  border: 1px solid #cccccc;
}
.heji {
  margin-top: 10px;
  .dis {
    display: flex;
    justify-content: right;
    padding: 5px 10px;
    font-size: 14px;
    color: #333333;
    :nth-child(1) {
      font-size: 14px;
      font-weight: bold;
      color: #333333;
      margin-right: 20px;
    }
  }
}
::v-deep .el-date-editor--daterange,
.el-cascader {
  width: 100%;
}
::v-deep .el-input__suffix {
  top: -3px;
}
</style>
