<template>
  <div class="">
    <el-row style="margin: 0 0 48px 0">
      <el-col :span="2">
        <div class="">
          <div class="totalCount-number">{{ this.totalCount }}</div>
          <div class="totalCount-text">地址数量</div>
        </div>
      </el-col>

      <el-col :span="3" :offset="15">
        <el-button type="primary" class="btn-add" @click="generateAddress">
          批量生成地址
        </el-button>
      </el-col>
      <el-col :span="3">
        <el-button type="primary" class="btn-add" @click="downloadAddress">
          批量下载地址
        </el-button>
      </el-col>
    </el-row>

    <div class="block-title">地址列表</div>
    <el-table :data="tableData" style="width: 100%">
      <el-table-column prop="address" label="地址账号" width="420">
        <template slot-scope="{ row }">
          {{row.groupName}} <span style="margin-left:10px"></span> {{row.address}}
        </template>
      </el-table-column>

      <!-- <el-table-column prop="groupName" label="地址组"> </el-table-column> -->
      <el-table-column prop="" label="gas消耗"> </el-table-column>
      <el-table-column prop="" label="地址余额"> </el-table-column>
      <el-table-column prop="addressType" label="地址类型">
        <template slot-scope="{ row }">
          <el-tag v-if="row.addressType === 1" type="info">批量号</el-tag>
          <el-tag v-else>精品号</el-tag>
        </template>
      </el-table-column>
      <el-table-column prop="createTime" label="创建时间"> </el-table-column>
    </el-table>
    <el-pagination
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      :current-page.sync="page"
      :page-sizes="[10, 15, 25, 35]"
      :page-size.sync="pageSize"
      layout="total, sizes, prev, pager, next, jumper"
      :total="totalCount"
    >
    </el-pagination>
    <SaveOrUpdate ref="SaveOrUpdate" />
    <download ref="download"></download>
  </div>
</template>
<script>
import { pageAddress, batchAddress } from "@/api/adress";
import SaveOrUpdate from "./SaveOrUpdate.vue";
import Download from "./download.vue";
export default {
  components: { SaveOrUpdate, Download },
  data() {
    return {
      url: process.env.VUE_APP_BASE_API,
      address: {
        password: undefined,
        groupName: undefined,
        numWallet: undefined,
      },
      tableData: [],
      page: 1,
      pageSize: 10,
      totalCount: 0,
    };
  },
  created() {
    this.getAddresses();
  },
  methods: {
    generateAddress() {
      this.$refs.SaveOrUpdate.addressModal = true;
      this.$refs.SaveOrUpdate.resetField();
      this.$refs.SaveOrUpdate.resetUserForm();
    },
    downloadAddress() {
      this.$refs.download.downloadModal = true;
      this.$refs.download.resetField();
      this.$refs.download.resetUserForm();
    },
    getAddresses() {
      pageAddress({
        page: this.page,
        pageSize: this.pageSize,
      }).then((res) => {
        this.tableData = res.records;
        this.totalCount = res.total;
      });
    },

    handleSizeChange(val) {
      this.pageSize = val;
      this.page = 1;
      this.getAddresses();
    },
    handleCurrentChange(val) {
      this.page = val;
      this.getAddresses();
    },
  },
  computed: {},
};
</script>