<template>
  <div v-loading="loading">
    <div class="white-box">
      <leo-filter
        :filter="handleFilter"
        :dateRangePickerDisplay="false"
        :dateMonthPickerDisplay="true"
        :dateMonthPickerDefault="dateMonthPickerDefault"
      ></leo-filter>
      <el-table class="table-box" ref="multipleTable" :data="tableData" stripe style="width: 100%;"
                @row-click="handleExpand">
        <el-table-column type="expand">
          <template slot-scope="scope">
            <el-form label-position="left" inline class="demo-table-expand">
              <el-form-item label="个人首购">
                <span>{{tool.formatPrice(scope.row.PV_PCS_ZC)}}PV</span>
              </el-form-item>
              <el-form-item label="个人增购">
                <span>{{tool.formatPrice(scope.row.PV_PCS_ZG)}}PV</span>
              </el-form-item>
              <el-form-item label="个人零售">
                <span>{{tool.formatPrice(scope.row.PV_PCS_LS)}}PV</span>
              </el-form-item>
              <el-form-item label="个人复销">
                <span>{{tool.formatPrice(scope.row.PV_PCS_FX)}}PV</span>
              </el-form-item>
              <el-form-item label="左区业绩">
                <span>{{tool.formatPrice(Number.parseFloat(scope.row.PV_1L_ZC) + Number.parseFloat(scope.row.PV_1L_ZG) + Number.parseFloat(scope.row.PV_1L_LS) + Number.parseFloat(scope.row.PV_1L_FX))}}PV</span>
              </el-form-item>
              <el-form-item label="中区业绩">
                <span>{{tool.formatPrice(Number.parseFloat(scope.row.PV_2L_ZC) + Number.parseFloat(scope.row.PV_2L_ZG) + Number.parseFloat(scope.row.PV_2L_LS) + Number.parseFloat(scope.row.PV_2L_FX))}}PV</span>
              </el-form-item>
              <el-form-item label="右区业绩">
                <span>{{tool.formatPrice(Number.parseFloat(scope.row.PV_3L_ZC) + Number.parseFloat(scope.row.PV_3L_ZG) + Number.parseFloat(scope.row.PV_3L_LS) + Number.parseFloat(scope.row.PV_3L_FX))}}PV</span>
              </el-form-item>
              <el-form-item label="零售区业绩">
                <span>{{tool.formatPrice(scope.row.PV_PERSON_LS)}}PV</span>
              </el-form-item>
              <el-form-item label="上期左区结余未碰业绩">
                <span>{{tool.formatPrice(scope.row.SURPLUS_1L)}}PV</span>
              </el-form-item>
              <el-form-item label="上期中区结余未碰业绩">
                <span>{{tool.formatPrice(scope.row.SURPLUS_2L)}}PV</span>
              </el-form-item>
              <el-form-item label="上期右区结余未碰业绩">
                <span>{{tool.formatPrice(scope.row.SURPLUS_3L)}}PV</span>
              </el-form-item>
              <el-form-item label="上期零售区结余未碰业绩">
                <span>{{tool.formatPrice(scope.row.SURPLUS_LS)}}PV</span>
              </el-form-item>
            </el-form>
          </template>
        </el-table-column>
        <el-table-column label="期数" prop="PERIOD_NUM"></el-table-column>
        <el-table-column label="结算月" prop="CALC_MONTH"></el-table-column>
        <el-table-column label="结算时间" width="200">
          <template slot-scope="scope">
            {{tool.formatDate(scope.row.CREATED_AT)}}
          </template>
        </el-table-column>
      </el-table>
      <div class="white-box-footer">
        <pagination :total="totalCount" :page_size="pageSize" @size-change="handleSizeChange" @current-change="handleCurrentChange"></pagination>
      </div>
    </div>
  </div>
</template>

<script>
import Vue from 'vue'
import network from '@/utils/network'
import tool from '@/utils/tool'
import LeoFilter from '@/components/Filter'
import Pagination from '@/components/Pagination'

export default {
  name: 'finance_perf',
  components: {LeoFilter,Pagination},
  mounted () {
    this.getData()
  },
  data () {
    return {
      tableData: null,
      loading: true,
      multipleSelection: [],
      currentPage: 1,
      totalPages: 1,
      totalCount: 1,
      pageSize: 20,
      tool: tool,
      filterData: null,
      dateMonthPickerDefault: '',
    }
  },
  methods: {
    handleExpand (row, event, column) {
      this.$refs.multipleTable.toggleRowExpansion(row)
    },
    handleCurrentChange (page) {
      this.getData(page, this.pageSize)
    },
    handleSizeChange (pageSize) {
      this.getData(this.currentPage, pageSize)
    },
    handleFilter (model) {
      this.filterData = model
      this.getData(1, this.pageSize)
    },
    getData (page, pageSize) {
      let vueObj = this
      network.getPageData(this, 'finance/perf', page, pageSize, this.filterData, function (response) {
        vueObj.tableData = response.list
        if (response.request) {
          vueObj.dateMonthPickerDefault = response.request.yearMonth
        }
      })
    },
  }
}

</script>

<style scoped>
  .table-box .el-form-item__label {
    width: 100px;
    color: #99a9bf;
  }

  .table-box .el-form-item {
    width: 30%;
    margin-right: 0;
    margin-bottom: 0;
  }
</style>