<template>
  <div>
    <div class="sty">
      <el-page-header content="信用额度变更记录" @back="goBack" />
    </div>
    <el-divider />
    <!-- 表头 -->
    <div>
      <el-form ref="searchForm" :model="searchForm" label-width="100px" size="small" label-position="left">
        <el-row :gutter="20">
          <el-col :xs="24" :sm="12" :lg="6">
            <el-form-item label="开始时间" prop="startTime">
              <el-date-picker
                v-model="searchForm.startTime"
                class="selectStyle"
                type="datetime"
                placeholder="选择日期时间"
                default-time="00:00:00"
                value-format="yyyy-MM-dd HH:mm:ss"
              />
            </el-form-item>
          </el-col>
          <el-col :xs="24" :sm="12" :lg="6">
            <el-form-item label="结束时间" prop="endTime">
              <el-date-picker
                v-model="searchForm.endTime"
                class="selectStyle"
                type="datetime"
                placeholder="选择日期时间"
                default-time="00:00:00"
                value-format="yyyy-MM-dd HH:mm:ss"
              />
            </el-form-item>
          </el-col>

          <el-col :xs="24" :sm="24" :lg="12">
            <el-form-item label="" class="fr">
              <el-button size="small" @click="clearFn">清空</el-button>
              <el-button size="small" type="primary" @click="searchFn">搜索</el-button>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
    </div>
    <!-- 按钮 -->
    <div class="btn-group clearfix">
      <div class="fr">
        <el-button type="primary" size="small" @click="exportList">导出</el-button>
      </div>
    </div>
    <!-- 列表 -->
    <div class="mymain-container">
      <div class="table">
        <el-table
          v-loading="listLoading"
          :data="dataList"
          element-loading-text="Loading"
          border
          fit
          highlight-current-row
          stripe
        >
          <el-table-column label="序号" align="left" width="100" type="index" show-overflow-tooltip />
          <el-table-column align="left" label="经销商编码" prop="customerNumber" min-width="160" show-overflow-tooltip>
            <template slot-scope="scope">
              <CopyButton :copy-text="scope.row.customerNumber" />
              <span>{{ scope.row.customerNumber }}</span>
            </template>
          </el-table-column>
          <el-table-column align="left" label="经销商名称" prop="customerName" min-width="260" show-overflow-tooltip>
            <template slot-scope="scope">
              <CopyButton :copy-text="scope.row.customerName" />
              <span>{{ scope.row.customerName }}</span>
            </template>
          </el-table-column>
          <el-table-column
            align="left"
            label="关联钱包"
            prop="customerWalletName"
            min-width="160"
            show-overflow-tooltip
          />
          <el-table-column
            align="right"
            label="变更金额"
            prop="amount"
            min-width="160"
            show-overflow-tooltip
          />
          <el-table-column
            align="right"
            label="使用金额"
            prop="useAmount"
            min-width="160"
            show-overflow-tooltip
          />
          <el-table-column
            align="left"
            label="开始日期"
            prop="startTime"
            min-width="160"
            show-overflow-tooltip
          />
          <el-table-column
            align="left"
            label="结束日期"
            prop="endTime"
            min-width="160"
            show-overflow-tooltip
          />
          <el-table-column
            align="left"
            label="变更时间"
            prop="updateTime"
            min-width="160"
            show-overflow-tooltip
          />
          <el-table-column
            align="left"
            label="变更人"
            prop="updateBy"
            min-width="160"
            show-overflow-tooltip
          />
        </el-table>
      </div>
      <!-- 分页 -->
      <div class="fr">
        <el-pagination
          :current-page="currentPage"
          :page-sizes="[10, 20, 30, 50]"
          :page-size="10"
          layout="total, sizes, prev, pager, next, jumper"
          :total="listTotal"
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
        />
      </div>
    </div>
  </div>
</template>

<script>
import { getCreditRecordList } from '@/api/finance/credit_list'
import { downloadFiles } from '@/utils/util'
export default {
  props: {
    recordsListId: {
      type: String,
      required: true
    }
  },
  data() {
    return {
      currentPage: 1, // 当前页码
      pageSize: 10, // 每页数量
      listTotal: 0, // 列表总数
      dataList: [], // 列表数据
      searchForm: {
        startTime: '',
        endTime: ''
      }, // 搜索表单
      listLoading: false // 列表加载loading
    }
  },
  created() {
    this.getDataList({
      customerWalletId: this.recordsListId,
      pageSize: this.pageSize,
      pageNum: this.currentPage
    })
  },
  methods: {
    // 更改每页数量
    handleSizeChange(val) {
      this.pageSize = val
      this.currentPage = 1
      this.getDataList({ customerWalletId: this.recordsListId, pageNum: 1, pageSize: this.pageSize })
    },
    // 更改当前页
    handleCurrentChange(val) {
      this.currentPage = val
      this.getDataList({ customerWalletId: this.recordsListId, pageNum: val, pageSize: 10 })
    },
    // 导出
    exportList() {
      const screenData = {
        customerWalletCreditId: this.recordsListId,
        startTime: this.searchForm.startTime,
        endTime: this.searchForm.endTime
      }
      downloadFiles('credit/record/export', screenData)
    },
    // 清除
    clearFn() {
      this.$refs.searchForm.resetFields()
    },
    // 搜索
    searchFn() {
      console.log(this.searchForm)
      this.getDataList({
        customerWalletId: this.recordsListId,
        pageSize: this.pageSize,
        pageNum: this.currentPage,
        ...this.searchForm
      })
    },
    // 获取信用额度变更记录数据
    async getDataList(data) {
      const res = await getCreditRecordList(data)
      this.dataList = res.data.records
      this.listTotal = res.data.total
    },
    goBack() {
      this.$parent.showRecord = true
    }
  }
}
</script>

<style></style>
