<!--
 * @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">
    </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/topBarRole'
import * as api from '@/api/settle.js'
import { classifyUpdate, classifySave } from '@/api/product'
import {queryBonusDetail, queryBonusTotal} from '@/api/bonus'
import {getRouters} from "@/api/settle.js";
export default {
  name: 'Bzpz',
  components: {
    topBar
  },
  filters: {
 isAgree(val) {
      if (!val) {
        return '允许';
      } else {
        return '禁止';
      }
    }
  },
  data() {
    return {
      typeList: [
        {
          value: 0,
          label: '前台'
        },
        {
          value: 1,
          label: '后台'
        }
      ],
      digList: [
        {
          value: 0,
          label: '允许',
        },
        {
          value: 1,
          label: '禁止',
        },
      ],
      menuList: [
        {
          id: 0,
          text: '全选',
          checked: false
        },
        {
          id: 1,
          text: '直推收益' + '($)',
          checked: false,
          prop: 'firstBuyAmountDollar',
        },
        {
          id: 2,
          text: '拓展收益' + '($)',
          checked: false,
          prop: 'expandIncome',
        },
        {
          id: 3,
          text: '辅导收益' + '($)',
          checked: false,
          prop: 'coachIncome',
        },
        {
          id: 4,
          text: '分红收益' + '($)',
          checked: false,
          prop: 'shareIncome',
        },
        {
          id: 5,
          text: '报单收益' + '($)',
          checked: false,
          prop: '',
        },
        {
          id: 6,
          text: '云代直推收益' + '($)',
          checked: false,
          prop: 'cloudDirectIncome',
        },
        {
          id: 7,
          text: '云代首购收益' + '($)',
          checked: false,
          prop: 'cloudPurIncome',
        },
        {
          id: 8,
          text: '云代复购收益'+'($)',
          checked: false,
          prop: 'cloudRepurIncome',
        },
        {
          id: 9,
          text: '复购级差收益'+'($)',
          checked: false,
          prop: 'repurRangeIncome',
        },
        {
          id: 10,
          text: '复购拓展收益'+'($)',
          checked: false,
          prop: 'repurExpandIncome',
        },
        {
          id: 11,
          text: '复购券',
          checked: false,
          prop: 'repurCoupon',
        },
        {
          id: 12,
          text: '商城重消'+'($)',
          checked: false,
          prop: 'backPoints',
        },
        {
          id: 13,
          text: '平台服务费'+'($)',
          checked: false,
          prop: 'serviceSpend',
        },
        {
          id: 14,
          text: '首购实发小计' + '($)',
          checked: false,
          prop: 'purRealSubtotal',
        },
        {
          id: 15,
          text: '云代实发小计' + '($)',
          checked: false,
          prop: 'cloudRealSubtotal',
        },
        {
          id: 16,
          text: '复购实发小计'+'($)',
          checked: false,
          prop: 'repurRealSubtotal',
        },
        {
          id: 17,
          text: '实发收益总计'+'($)',
          checked: false,
          prop: 'realIncomeTotal',
        },
      ],
      creationTime: [],
      creationTime1: [],
      select: {
        // pkVertex: [],
        // pkMemberTeam: [],
      },
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 50
      },
      addOrEdit: '',
      total: 0,
      dialogVisible: false,
      tableData: {
        censusSummaryList: []
      },
      moren: '/settlementCenter/recommendDatas',
      topList: [
        {
          name: '推荐数据',
          path: '/settlementCenter/recommendData',
          url: 'placementData',
          changed: false
        },
        {
          name: '推荐图表',
          path: '/settlementCenter/recommendDatas',
          url: 'placementChat',
          changed: false
        }
      ],
      form: {
        name: ''
      },
      rules: {
        name: [{ required: true, message: '请输入规格类型', trigger: 'blur' }]
      },
      acList: [],
      verList: [],
      memberList: [],
      pkMemberTeam: [],
      pkVertex: [],
      pkTeamId: '', // 隶属团队id
      pkVertId: '' // 隶属体系id
    }
  },
  mounted() {
    // 获取下拉
    this.getData()
    // 获取列表
    this.getDataList()
    this.getUserRoute()
  },
  methods: {
    getUserRoute() {
      getRouters().then((res)=>{
        res.data.forEach((item)=>{
          this.topList.forEach((items)=>{
            if (item.routeName == items.url){
              items.changed = true
            }
          })
        })
      })
    },
    vertCheck(index, item) {
      if (this.pkVertex.length > 1) {
        this.pkVertex.splice(0, 1)
      }
      this.pkVertId = item.pkId
    },
    teamCheck(index, item) {
      if (this.pkMemberTeam.length > 1) {
        this.pkMemberTeam.splice(0, 1)
      }
      this.pkTeamId = item.pkId
    },
    reset() {
      this.select = {
        // pkVertex: [],
        // pkMemberTeam: [],
      }
      this.pkVertex = []
      this.pkMemberTeam = []
    },
    getMenu(e, id) {
      if (e && id == 0) {
        this.menuList.forEach((item) => {
          this.$set(item, 'checked', true)
        })
      } else if (!e && id == 0) {
        this.menuList.forEach((item) => {
          this.$set(item, 'checked', false)
        })
      }
    },
    getData() {
      api.accountList().then((res) => {
        this.acList = res.data
      })
      api.vertexList().then((res) => {
        this.verList = res.data
      })
      api.memberTeam().then((res) => {
        this.memberList = res.rows
      })
    },
    changeTime(val) {
      this.select.startDate = val[0]
      this.select.endDate = val[1]
    },
    changeTime1(val) {
      this.select.startEffectDate = val[0]
      this.select.endEffectDate = val[1]
    },
    // 点击修改
    toFixed(id) {
      this.addOrEdit = false
      this.dialogVisible = true
      this.$router.push({
        path: 'noticeList/details',
        query: {
          pkId: id
        }
      })
    },
    getSummaries(param) {
      const { columns, data } = param
      const sums = []
      columns.forEach((column, index) => {
        if (index === 0) {
          sums[index] = '小计' +'(￥)'
          return
        }
        if (index === 1) {
          sums[index] = ''
          return
        }
        const values = data.map((item) => Number(item[column.property]))
        if (!values.every((value) => isNaN(value))) {
          sums[index] = values.reduce((prev, curr) => {
            const value = Number(curr)
            if (!isNaN(value)) {
              return prev + curr
            } else {
              return prev
            }
          }, 0)
          // sums[index] += ' 元'
        } else {
          sums[index] = ''
        }
      })

      return sums
    },
    // 删除
    handleDelete(id) {
      this.$confirm('确认删除?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        api.classifyDel(id).then((res) => {
          this.getDataList()
        })
      })
    },
    onSubmit(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          let url = ''
          if (this.addOrEdit == true) {
            url = classifySave
          } else {
            url = classifyUpdate
          }
          url(this.form).then((res) => {
            if (res.code == 200) {
              this.$message({
                message: res.msg,
                type: 'success'
              })
              this.dialogVisible = false
              // 充值数据
              this.$refs[formName].resetFields()
              // 获取列表
              this.getDataList()
            }
          })
        } else {
          return false
        }
      })
    },
    handleClose() {
      this.dialogVisible = false
      this.$refs['form'].clearValidate()
      this.$refs['form'].resetFields()
    },
    openDig() {
      this.$router.push({
        path: 'noticeList/details'
      })
    },
    getDataList() {
      queryBonusDetail(Object.assign({}, this.queryParams, this.select,
        this.pkMemberTeam.length > 0 ? { 'pkTeamCode': this.pkTeamId } : '',
        this.pkVertex.length > 0 ? { 'pkVertex': this.pkVertId } : ''
      ))
        .then((res) => {
          console.error(res.rows)
          this.tableData.censusSummaryList = res.rows
          this.total = res.total
        })
    },
    handleSelectionChange(val) {},
    /** 导出按钮操作 */
    handleExport() {
      const queryParams = this.queryParams
      this.$confirm( '是否确认导出所有数据项?', '警告', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      })
        .then(function() {
          return api.exportClassIfy(queryParams)
        })
        .then((response) => {
          this.download(response)
        })
    },
    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-range-editor.el-input__inner{
  width: 100%;
}
::v-deep .el-button{
  padding: 8px 20px;
}
::v-deep .el-date-editor .el-range__close-icon{
  margin-top: -10px;
}
::v-deep .el-date-editor .el-range-separator{
  margin-top: -10px;
}
::v-deep .el-date-editor .el-range__icon{
  margin-top: -10px;
}
::v-deep .el-input__inner{
  //height:28px;
  //line-height: 28px;
}
::v-deep .el-form-item{
  margin-bottom: 0;
}
::v-deep .el-form-item__label{
  color: #333;
  font-weight: inherit;
}
::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: #f9f9f9;
    .maintop {
      display: flex;
      padding: 10px 0px;
      justify-content: space-between;
      align-items: center;
      .mainbtn {
        .thebtn1 {
          background: #3181e5;
          color: #ffffff;
        }
        .thebtn2 {
          background: #ffad41;
          color: #ffffff;
          height: 32px;
        }
      }
      .maintitle {
        font-size: 10px;
        font-family: MicrosoftYaHei;
        color: #999999;
      }
    }
  }
  .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;
    }
  }
}
</style>
<style>
.itemTrading .el-table {
  overflow: auto;
}
.itemTrading .el-table__body-wrapper,
.itemTrading .el-table__header-wrapper,
.itemTrading .el-table__footer-wrapper {
  overflow: visible;
}
.itemTrading .el-table::after {
  position: relative !important;
}

.body-theme-grenn .el-table--scrollable-x .el-table__body-wrapper {
  overflow: visible;
}
</style>
