<template>
  <basic-container class="park">
    <div class="park-title">数据总览</div>
    <div class="card">
      <div class="card-item">
        <p class="text">积分余额</p>
        <p class="num">{{ info.score }}</p>
        <p class="bot">本月消耗积分：{{ info.usedScore }}</p>
      </div>
      <div class="card-item">
        <p class="text">可开票积分</p>
        <p class="num">{{ info.toInvoiceScore }}</p>
        <p class="bot">本月已开票积分：{{ info.invoicedScore }}</p>
      </div>
    </div>
    <div class="tips" v-if="info.score < 1000">
      您的积分余额已不足1,000，请及时充值！
    </div>
    <div class="data-detail">数据明细</div>
    <div class="tabs">
      <span :class="{ act: active == 0 }" @click="changeTab(0)">积分记录</span>
      <!-- <i class="line">|</i><span :class="{ act: active == 1 }" @click="changeTab(1)">开票记录</span> -->
    </div>
    <div v-show="active == 0">
      <avue-crud
        :data="recordData"
        :option="recordOption"
        :page.sync="page"
        :table-loading="tableLoading"
        @on-load="getrecordList"
        @size-change="sizeChange"
        @current-change="currentChange"
        @search-change="searchVal"
      >
      </avue-crud>
    </div>
    <div v-show="active == 1">
      <avue-crud
        :data="tableData"
        :option="tabOption"
        :page.sync="tabPage"
        :table-loading="tableLoading"
        @on-load="getList"
        @size-change="tabSizeChange"
        @current-change="tabCurrentChange"
        @search-change="tabSearchVal"
      >
        <template slot-scope="scope" slot="menu">
          <!-- <el-button v-if='scope.row.approvalStatus =="PENDING"' type="text" @click="auditClick(scope.row)">审核</el-button> -->
          <el-button type="text" @click="auditClick(scope.row)">详情</el-button>
        </template>
      </avue-crud>
    </div>
  </basic-container>
</template>

<script>
import {
  deptOverview,
  getRecordPage,
  getInvoiceRecord
} from "@/api/account/enterprise/index.js";
import { recordOption } from "@/const/crud/account/enterprise/index.js";
import { tabOption } from "@/const/crud/account/invioce/index.js";

export default {
  data() {
    return {
      info: {},
      active: false,
      recordOption,
      page: {
        total: 0, // 总页数
        pageSize: 10,
        pagerCount: 0
      },
      tabPage: {
        total: 0, // 总页数
        pageSize: 10,
        pagerCount: 0
      },
      tableData: [],
      tabOption,
      tableLoading: false,
      recordData: [],
      searchForm: {},
      tabSearchForm: {}
    };
  },
  created() {
    this.getInfo();
  },
  beforeMount() {
    this.tabOption.column[0].search = false;
  },
  methods: {
    async getInfo() {
      const res = await deptOverview();
      if (res.data.code === 0) {
        this.info = res.data.data;
        this.info.score = this.info.score.toLocaleString();
        this.info.usedScore = this.info.usedScore.toLocaleString();
        this.info.toInvoiceScore = this.info.toInvoiceScore.toLocaleString();
        this.info.invoicedScore = this.info.invoicedScore.toLocaleString();
      }
    },
    async getList(page, params) {
      this.tableLoading = true;
      let data = Object.assign(
        {
          current: page.currentPage,
          size: page.pageSize
        },
        params,
        this.tabSearchForm
      );
      let res = await getInvoiceRecord(data);
      if (res.data.code === 0) {
        this.tableData = res.data.data.records;
        this.tabPage.total = res.data.data.total;
      }
      this.tableLoading = false;
    },
    tabSizeChange(pageSize) {
      this.tabPage.pageSize = pageSize;
    },
    tabCurrentChange(current) {
      this.tabPage.currentPage = current;
    },
    tabSearchVal(form, done) {
      this.tabSearchForm = form;
      this.tabPage.currentPage = 1;
      this.getList(this.tabPage, form);
      done();
    },

    changeTab(type) {
      this.active = type;
    },
    auditClick(row) {
      this.$router.push({
        path: "/admin/account/recharge/audit?id=" + row.id + "&type=disabled"
      });
    },
    async getrecordList(page, params) {
      this.tableLoading = true;
      let data = Object.assign(
        {
          current: page.currentPage,
          size: page.pageSize
        },
        params,
        this.searchForm
      );
      let res = await getRecordPage(data);
      if (res.data.code === 0) {
        this.recordData = res.data.data.records;
        this.page.total = res.data.data.total;
      }
      this.tableLoading = false;
    },
    sizeChange(pageSize) {
      this.page.pageSize = pageSize;
    },
    currentChange(current) {
      this.page.currentPage = current;
    },
    searchVal(form, done) {
      this.searchForm = form;
      this.page.currentPage = 1;
      this.getrecordList(this.page, form);
      done();
    }
  }
};
</script>

<style lang="scss" scoped>
.park-title {
  font-size: 16px;
  color: #333;
  font-weight: 600;
}
.card {
  margin-top: 20px;
  display: flex;
  .card-item {
    margin-right: 30px;
    min-width: 320px;
    height: 120px;
    background-color: #f7f7f7;
    border-radius: 8px;
    box-sizing: border-box;
    padding: 20px;
    .text {
      color: #333;
      font-size: 14px;
      margin-bottom: 5px;
    }
    .num {
      font-size: 26px;
      font-weight: 600;
      margin-bottom: 5px;
    }
    .bot {
      font-size: 12px;
      color: #666;
    }
  }
}
.tips {
  margin: 10px 0;
  font-size: 12px;
  color: #ff0202;
}
.data-detail {
  font-size: 16px;
  color: #333;
  margin-bottom: 10px;
  margin-top: 20px;
}
.tabs {
  margin-bottom: 20px;
  .line {
    margin: 0 10px;
  }
  span {
    font-size: 14px;
    color: #333;
    cursor: pointer;
    &.act {
      color: #ff8002;
    }
  }
}
</style>
