<template>
  <div class="app-container">
    <!-- 筛选条件 -->
    <div>
      <Collapse :screen-form="searchForm">
        <template #right_btn>
          <el-button size="mini" @click="clearFn">清空</el-button>
          <el-button size="mini" type="primary" @click="searchFn">搜索</el-button>
        </template>
        <template #search>
          <el-form ref="searchForm" :model="searchForm" label-width="100px" size="mini" label-position="left">
            <el-row :gutter="20">
              <el-col :xs="24" :sm="12" :lg="6">
                <el-form-item label="区域" prop="websitId">
                  <el-select v-model="searchForm.websitId" class="selectStyle" placeholder="请选择" filterable>
                    <el-option v-for="(v, i) in areaList" :key="i" :label="v.name" :value="v.adminWebsitId">
                    </el-option>
                  </el-select>
                </el-form-item>
              </el-col>
            </el-row>
          </el-form>
        </template>
      </Collapse>
    </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
          show-summary
          :summary-method="$getSummaries"
        >
          <!-- <el-table-column align="left" label="品类" prop="mainName" min-width="160" show-overflow-tooltip></el-table-column> -->
          <el-table-column
            align="left"
            label="钱包名称"
            prop="name"
            min-width="160"
            show-overflow-tooltip
          ></el-table-column>
          <el-table-column
            align="left"
            label="更新时间"
            prop="theTime"
            min-width="160"
            show-overflow-tooltip
          ></el-table-column>
          <el-table-column align="right" label="余额" prop="totalAmount" min-width="160" show-overflow-tooltip>
            <template slot-scope="scope">
              {{ scope.row.totalAmount | numToFixed }}
            </template>
          </el-table-column>
          <el-table-column
            align="right"
            label="可用信用额度"
            prop="freezeCreditAmount"
            min-width="160"
            show-overflow-tooltip
          >
            <template slot-scope="scope">
              {{ scope.row.freezeCreditAmount | numToFixed }}
            </template>
          </el-table-column>
          <el-table-column
            align="right"
            label="已用信用额度"
            prop="usedCreditAmount"
            min-width="160"
            show-overflow-tooltip
          >
            <template slot-scope="scope">
              {{ scope.row.usedCreditAmount | numToFixed }}
            </template>
          </el-table-column>
        </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"
        >
        </el-pagination>
      </div> -->
    </div>
  </div>
</template>

<script>
import { getFinanceTotal, getProductCategoryList } from '@/api/finance/finance_sum'
import { getAdminWebsitByparent } from '@/api/finance/blance_sum'
export default {
  data() {
    return {
      // currentPage: 1, // 当前页码
      // pageSize: 10, // 每页数量
      // listTotal: 0, // 列表总数
      dataList: [], // 列表数据
      areaList: [],
      isCollapse: true,
      searchForm: {
        // mainId: "",
        websitId: ''
      }, //搜索表单
      listLoading: false, // 列表加载loading
      categoryList: [] //品类数据
    }
  },
  created() {
    // this.getCategoryList();
    this.getAreaList()
    this.getDataList()
  },
  methods: {
    //获取区域数据
    async getAreaList() {
      let res = await getAdminWebsitByparent({ parentId: 1 })
      this.areaList = res.data
    },
    //清空
    async clearFn() {
      await this.$refs.searchForm.resetFields()
    },
    //搜索
    searchFn() {
      this.getDataList({ websitId: this.searchForm.websitId })
    },
    //获取品类数据
    async getCategoryList() {
      const res = await getProductCategoryList()
      this.categoryList = res.data
    },
    //获取列表数据
    async getDataList(data) {
      const res = await getFinanceTotal(data)
      res.data.forEach(item => {
        item.sums1 = []
        item.sums2 = ['freezeCreditAmount', 'usedCreditAmount', 'totalAmount']
      })
      this.dataList = res.data
    }
  }
}
</script>

<style lang="scss" scoped>
.selectStyle {
  width: 100%;
}
</style>
