<template>
  <div class="userCenterGrowthRecord">
    <div class="search">
      <span>{{ $i18n.locale === "zh" ? "成长值记录" : "Growth Record" }}</span>
    </div>
    <div class="list">
      <el-table
        :data="userTaskComplete"
        v-loading="loading"
        style="width: 100%"
        :header-cell-style="{ backgroundColor: '#f8f8f8' }"
      >
        <el-table-column
          align="center"
          :label="$i18n.locale === 'zh' ? '来源名称' : 'Source Title'"
          min-width="230"
        >
          <template slot-scope="scope">
            <span>{{ $i18n.locale == "zh" ? "获取" : "Gain" }}</span>
          </template>
        </el-table-column>
        <el-table-column
          align="center"
          :label="
            $i18n.locale === 'zh' ? '成长值（分）' : 'Growth Value (Points)'
          "
          width="200"
        >
          <template slot-scope="scope">
            <span style="color: #d61016">+</span>
            <span style="color: #d61016">{{ scope.row.growth }}</span>
          </template>
        </el-table-column>
        <el-table-column
          align="center"
          :label="$i18n.locale === 'zh' ? '日期' : 'Date'"
          min-width="130"
        >
          <template slot-scope="scope">
            <span>{{
              scope.row.createDate | time("YYYY-MM-DD ")
            }}</span>
          </template>
        </el-table-column>
		<el-table-column
          align="center"
          :label="$i18n.locale === 'zh' ? '时间' : 'Time'"
          min-width="130"
        >
          <template slot-scope="scope">
            <span>{{
              scope.row.createDate | time(" HH:mm:ss")
            }}</span>
          </template>
        </el-table-column>
        <el-table-column
          :prop="$i18n.locale==='zh'?'title':'titleEn'"
          align="center"
          :label="$i18n.locale === 'zh' ? '备注' : 'Remark'"
          min-width="230"
        >
        </el-table-column>
      </el-table>
      <el-pagination
        background
        @size-change="
          (val) => {
            page.pageSize = val;
          }
        "
        @current-change="
          (val) => {
            page.pageNo = val;
          }
        "
        layout="prev, pager, next, sizes, jumper"
        :total="page.total"
        :current-page="page.pageNo"
        :page-sizes="[10, 20, 50, 100]"
        :page-size="page.pageSize"
        style="text-align: center; margin-top: 20px"
      >
      </el-pagination>
    </div>
  </div>
</template>

<script>
import moment from "moment";
import { getUserGrowthDetails, getUserPointDetailsPage } from "@/api/user";

export default {
  name: "userCenterGrowthRecord",
  data() {
    return {
      loading: false,
      params: {
        search1: "全部",
      },
      page: {
        pageNo: 1,
        pageSize: 10,
        total: 3,
      },
      userTaskComplete: [],
    };
  },
  filters: {
    time(date, type) {
      return moment(date).format(type);
    },
  },
  watch: {
    page: {
      handler: function () {
        this.loading = true;
        this.getUserGrowthDetailPage();
      },
      deep: true,
    },
    params: {
      handler: function () {
        this.loading = true;
        this.getUserGrowthDetailPage();
      },
      deep: true,
    },
  },
  mounted() {
    this.init();
  },
  methods: {
    init() {
      this.getUserGrowthDetailPage();
    },
    getUserGrowthDetailPage() {
      let param = {
        pageSize: this.page.pageSize,
        pageNo: this.page.pageNo,
        userId: JSON.parse(window.localStorage.getItem("user")).userId,
      };
      getUserGrowthDetails(param)
        .then((res) => {
          if (res) {
            this.userTaskComplete = res.data.umsUserGrowthDetailss;
            this.page.total = Number(res.data.page.totalCount);
          }
        })
        .then(() => {
          this.loading = false;
        })
        .catch(() => {
          this.loading = false;
        });
    },
  },
};
</script>

<style scoped lang="less">
.userCenterGrowthRecord {
  background-color: #fff;
  min-height: 700px;
  .search {
    font-size: 14px;
    font-weight: 600;
    height: 70px;
    line-height: 70px;

    span {
      cursor: pointer;
      margin: 0 30px;

      &.active {
        color: #60aae3;
      }
    }
  }

  .list {
    width: 100%;
    padding: 0 18px 18px 18px;
    box-sizing: border-box;
  }
}
</style>