<template>
  <div class="app-container">
    <!-- 筛选条件 -->
    <div>
      <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="customerNumber">
              <el-select v-model="searchForm.customerNumber" class="selectStyle" placeholder="请选择" filterable>
                <el-option v-for="(v, i) in customerList" :key="i" :label="v.name" :value="v.number">
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :xs="24" :sm="12" :lg="6">
            <el-form-item label="钱包" prop="walletId">
              <el-select v-model="searchForm.walletId" class="selectStyle" placeholder="请选择" filterable>
                <el-option v-for="(v, i) in walletList" :key="i" :label="v.name" :value="v.id">
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :xs="24" :sm="12" :lg="6">
            <el-form-item label="区域" prop="area">
              <el-select v-model="searchForm.area" 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-col :xs="24" :sm="24" :lg="6">
            <el-form-item label="" class="fr">
              <el-button size="mini" @click="clearFn">清空</el-button>
              <el-button size="mini" type="primary" @click="searchFn">搜索</el-button>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
    </div>
    <!-- 按钮 -->
    <div class="btn-group clearfix">
      <div class="fr">
        <ExportButton :exUrl="'finance/totalCustomer/export'" :exParams="exParams" />
      </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 show-summary :summary-method="$getSummaries">
          <el-table-column align="left" label="经销商编码" prop="customerNumber" min-width="160" show-overflow-tooltip>
            <template slot-scope="scope">
              <CopyButton :copyText="scope.row.customerNumber" />
              <span>{{scope.row.customerNumber}}</span>
            </template>
          </el-table-column>
          <el-table-column align="left" label="经销商名称" prop="customerName" min-width="160" show-overflow-tooltip>
            <template slot-scope="scope">
              <CopyButton :copyText="scope.row.customerName" />
              <span>{{scope.row.customerName}}</span>
            </template>
          </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="total" min-width="160" show-overflow-tooltip>
            <template slot-scope="scope">
              {{ scope.row.total | numToFixed }}
            </template>
          </el-table-column>

          <el-table-column align="center" label="操作" min-width="160" show-overflow-tooltip fixed="right">
            <template v-slot="{ row }">
              <el-button type="text" class="textColor" @click="walletFn(row.customerId)">
                余额
              </el-button>
              <el-button type="text" class="textColor" @click="
                  seeFN(row.customerName, row.customerNumber, row.customerId)
                ">
                明细
              </el-button>
            </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 { getCustomerList } from "@/api/finance/account_list";
import {
  getFinanceTotalCustomer,
  getAdminWebsitByparent,
  getFinanceList,
} from "@/api/finance/blance_sum";
export default {
  data() {
    return {
      // currentPage: 1, // 当前页码
      // pageSize: 10, // 每页数量
      // listTotal: 0, // 列表总数
      areaList: [],
      dataList: [], // 列表数据
      walletList: [], //钱包数据
      searchForm: {
        // customerName: "",
        customerNumber: "",
        area: "",
        walletId: "",
      }, //搜索表单
      customerList: [],
      listLoading: false, // 列表加载loading
    };
  },
  computed: {
    exParams() {
      return {
        ...this.searchForm,
      };
    },
  },
  created() {
    this.getAreaList();
    this.getDataList();
    this.getWalletList();
    this.getCustomerDataList({
      pageSize: -1,
      pageNum: 1,
    });
  },
  methods: {
    //获取钱包数据
    async getWalletList() {
      let res = await getFinanceList();
      console.log(res, 122);
      this.walletList = res.data;
    },
    //获取区域数据
    async getAreaList() {
      let res = await getAdminWebsitByparent({ parentId: 1 });
      this.areaList = res.data;
    },
    //获取经销商数据
    async getCustomerDataList(data) {
      const res = await getCustomerList(data);
      this.customerList = res.data.records;
    },
    //清除
    clearFn() {
      this.$refs.searchForm.resetFields();
    },
    //搜索
    searchFn() {
      this.getDataList(this.searchForm);
    },
    //获取列表数据
    async getDataList(data) {
      const res = await getFinanceTotalCustomer(data);
      // console.log(res);
      res.data.forEach((item) => {
        item.sums1 = [];
        item.sums2 = ["total"];
      });
      this.dataList = res.data;
    },
    //余额
    walletFn(v) {
      this.$router.push({
        path: "/finance/details/wallet",
        query: {
          id: v,
        },
      });
    },
    //明细
    seeFN(customerName, customerNumber, customerId) {
      this.$router.push({
        path: "/finance/details/standbook_list",
        query: {
          customerName,
          customerNumber,
          customerId,
        },
      });
    },
  },
};
</script>

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