<!--
 * @Descripttion:
 * @version:
 * @Author: kBank
 * @Date: 2022-10-24 15:45:01
-->
<template>
  <div class="page">
    <topBar
      v-if="topList.length > 0"
      :top-list="topList"
      :moren="moren"
    />
    <div class="main">
      <el-form
        ref="select"
        :model="select"
        style="padding:10px 10px 0 0"
        label-width="80px"
      >
        <el-row>
          <!-- 一层 -->
          <el-col :span="4">
            <el-form-item :label="'结算期数'">
              <el-input v-model="select.numberPeriods" clearable />
            </el-form-item>
          </el-col>
          <el-col :span="4">
            <el-form-item :label="'币种展示'">
              <el-select
                v-model="select.websiteType"
                clearable
                :placeholder="'请选择'"
              >
                <el-option
                  v-for="item in acList"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"
                />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item :label="'创建日期'">
              <el-date-picker
                v-model="creationTime"
                value-format="yyyy-MM-dd hh:mm:ss"
                type="datetimerange"
                :range-separator="'至'"
                :start-placeholder="'开始日期'"
                :end-placeholder="'结束日期'"
                @change="changeTime"
              />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col>
            <el-form-item :label="'隶属体系'">
              <el-checkbox-group v-model="select.pkVertex">
                <el-checkbox
                  v-for="item in verList"
                  :key="item.value"
                  :value="item.pkId"
                  :label="item.vertexName"
                />
              </el-checkbox-group>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col>
            <el-form-item :label="'隶属团队'">
              <el-checkbox-group v-model="select.pkMemberTeam">
                <el-checkbox
                  v-for="item in memberList"
                  :key="item.value"
                  :value="item.pkId"
                  :label="item.vertexName"
                />
              </el-checkbox-group>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row style="margin-left:20px">
          <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"
            class="thebtn2"
            @click="openDig"
          > {{ '导出' }}</el-button>
        </div>
        <div>
          <el-dropdown :hide-on-click="false">
            <span class="el-dropdown-link kuang">
              {{ '下拉菜单' }}<i class="el-icon-arrow-down el-icon--right" />
            </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
            :data="tableData.censusSummaryList"
            style="width: 100%"
            :header-cell-style="{ background: '#EEEEEE' }"
            :row-class-name="tableRowClassName"
            :summary-method="getSummaries"
            show-summary
            @selection-change="handleSelectionChange"
          >
            <el-table-column
              type="selection"
              width="100"
            />
            <el-table-column
              align="center"
              prop="numberPeriods"
              width="130"
              :label="'结算期数'"
            />
            <el-table-column
              align="center"
              prop="settleDate"
              width="130"
              :label="'结算日期'"
            />
            <el-table-column
              align="center"
              prop="firstBuyAmount"
              width="130"
              :label="'首购金额'+'(¥)'"
            />
            <el-table-column
              align="center"
              prop="upgradeAmount"
              width="130"
              :label="'升级金额'+'(¥)'"
            />
            <el-table-column
              align="center"
              prop="repurchaseAmount"
              width="130"
              :label="'复购金额'+'(¥)'"
            />
            <el-table-column
              align="center"
              prop="firstBuyAmount"
              width="130"
              :label="'海粉金额'+'(¥)'"
            />

            <el-table-column
              v-for="item in menuList"
              v-if="item.checked&&item.id != 0&&item.id < 13"
              :key="item.id"
              align="center"
              width="130"
              :prop="item.prop"
              :label="item.text"
            />
            <el-table-column
              align="center"
              prop="time"
              :label="'操作'"
              fixed="right"
            >
              <template slot-scope="scope">
                <el-button
                  type="text"
                  size="small"
                  @click="toFixed(scope.row.pkId)"
                >
                  {{ '修改' }}
                </el-button>
                <el-button
                  type="text"
                  size="small"
                  @click="toFixed(scope.row.pkId)"
                >
                  {{ '查看' }}
                </el-button>
                <el-button
                  type="text"
                  size="small"
                  style="color: #c73030"
                  @click="handleDelete(scope.row.pkId)"
                >
                  {{'删除'}}
                </el-button>
              </template>
            </el-table-column>
          </el-table>
        </div>
        <div class="heji">
          <div
            v-for="item in menuList"
            v-if="item.checked&&item.id != 0&&item.id > 13"
            :key="item.id"
            class="dis"
          >
            <div>{{ item.text }}</div>
            <div>{{ tableData[item.prop] }}</div>
          </div>
        </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'
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: true,
          prop: 'firstBuyAmountDollar'
        },
        {
          id: 2,
          text: '升级金额' + '($)',
          checked: true,
          prop: 'upgradeAmountDollar'
        },
        {
          id: 3,
          text: '复购金额' + '($)',
          checked: true,
          prop: 'repurchaseAmountDollar'
        },
        {
          id: 4,
          text: '海粉金额' + '($)',
          checked: true,
          prop: 'fansAmountDollar'
        },
        {
          id: 5,
          text: '首购业绩' + '(¥)',
          checked: false,
          prop: 'firstBuyAmountPv'
        },
        {
          id: 6,
          text: '升级业绩' + '(¥)',
          checked: false,
          prop: 'upgradePv'
        },
        {
          id: 7,
          text: '复购业绩' + '(¥)',
          checked: false,
          prop: 'repurchasePv'
        },
        {
          id: 8,
          text: '嗨粉业绩' + '(¥)',
          checked: false,
          prop: 'hiFunAmountPv'
        },
        {
          id: 9,
          text: '首购业绩' + '($)',
          checked: false,
          prop: 'firstBuyAmountPvDollar'
        },
        {
          id: 10,
          text: '升级业绩' + '($)',
          checked: false,
          prop: 'upgradePvDollar'
        },
        {
          id: 11,
          text: '复购业绩' + '($)',
          checked: false,
          prop: 'repurchasePvDollar'
        },
        {
          id: 12,
          text: '嗨粉业绩' + '($)',
          checked: false,
          prop: 'hiFunAmountPvDollar'
        },
        {
          id: 13,
          text: '首购金额总计'+'($)',
          checked: false,
          prop: 'firstBuyAmountDollarTotal'
        },
        {
          id: 14,
          text: '复购金额总计'+'($)',
          checked: false,
          prop: 'repurchaseAmountDollarTotal'
        },
        {
          id: 15,
          text: '首购业绩总计' + '(¥)',
          checked: false,
          prop: 'firstBuyAmountPvTotal'
        },
        {
          id: 16,
          text: '复购业绩总计' + '(¥)',
          checked: false,
          prop: 'repurchasePvTotal'
        },
        {
          id: 17,
          text: '首购业绩总计' + '($)',
          checked: false,
          prop: 'firstBuyAmountPvDollarTotal'
        },
        {
          id: 18,
          text: '复购业绩总计'+'($)',
          checked: false,
          prop: 'repurchasePvDollarTotal'
        },
        {
          id: 19,
          text: '业绩总计' + '(¥)',
          checked: false,
          prop: 'pvTotal'
        },
        {
          id: 20,
          text: '金额总计' + '($)',
          checked: false,
          prop: 'amountTotalDollar'
        },
        {
          id: 21,
          text: '业绩总计' + '($)',
          checked: false,
          prop: 'pvTotalDollar'
        },
        {
          id: 22,
          text: '首购金额总计' + '(¥)',
          checked: true,
          prop: 'firstBuyAmountTotal'
        },
        {
          id: 23,
          text: '复购金额总计' + '(¥)',
          checked: true,
          prop: 'repurchaseAmountTotal'
        },
        {
          id: 24,
          text: '金额总计' + '(¥)',
          checked: true,
          prop: 'amountTotal'
        }
      ],
      creationTime: [],
      creationTime1: [],
      select: {
        pkVertex: [],
        pkMemberTeam: []
      },
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 50
      },
      addOrEdit: '',
      total: 0,
      dialogVisible: false,
      tableData: {
        censusSummaryList: []
      },
      moren: '/settlementCenter/performanceTotal',
      topList: [
        {
          name: '业绩汇总',
          path: '/settlementCenter/performanceTotal'
        }
      ],
      form: {
        name: ''
      },
      rules: {
        name: [{ required: true, message: '请输入规格类型', trigger: 'blur' }]
      },
      acList: [],
      verList: [],
      memberList: []
    }
  },
  mounted() {
    // 获取下拉
    this.getData()
    // 获取列表
    this.getDataList()
  },
  methods: {
    reset() {
      this.select = {
        pkVertex: [],
        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() {
      api
        .memberStructure(Object.assign({}, this.queryParams, this.select))
        .then((res) => {
          this.tableData = res.data
          // 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-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);
    .maintop {
      display: flex;
      padding: 10px 20px;
      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;
      }
    }
  }
  .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>
