detail.vue 3.68 KB
<template>
  <layout-body>
    <layout-filter>
      <filter-item :label="filters.balanceId.label">
        <i-input v-model.trim="filters.balanceId.model" :placeholder="filters.balanceId.holder"></i-input>
      </filter-item>
      <filter-item :label="filters.sku.label">
        <i-input v-model.trim="filters.sku.model" :placeholder="filters.sku.holder"></i-input>
      </filter-item>
      <filter-item :label="filters.brandId.label">
        <select-brand v-model="filters.brandId.model"></select-brand>
      </filter-item>
      <filter-item>
        <Button @click="returnPage">返回结算单列表</Button>
        <Button type="primary" :loading="loading" @click="search">筛选</Button>
        <Button @click="reset">清空条件</Button>
        <Button type="warning" class="table-btn" @click="exportData">导出</Button>
      </filter-item>
    </layout-filter>
    <layout-list>
      <Table border :columns="tableCols" :data="tableData"></Table>
      <Page
        :total="pageData.total"
        :current="pageData.pageNo"
        :page-size="20"
        show-total
        @on-change="pageChange"
      ></Page>
    </layout-list>
  </layout-body>
</template>

<script>
import detail from './store/detail';
import FranchiseService from 'services/finance/franchise-service';
import _ from 'lodash';
import qs from 'querystringify';

export default {
  data() {
    return detail.call(this);
  },
  created() {
    this.franchiseService = new FranchiseService();
    this.search();
  },
  methods: {
    filterValues() {
      const params = {
        balanceId: +this.filters.balanceId.model,
        brandId: +this.filters.brandId.model,
        productSku: +this.filters.sku.model,
        pageSize: this.pageData.pageSize,
        pageNo: this.pageData.pageNo,
        manageMode: 2,
      };

      return _.pickBy(params, val => val);
    },
    search() {
      // const sumParams = _.pickBy(
      //   {
      //     balanceId: +this.filters.balanceId.model,
      //     brandId: +this.filters.brandId.model,
      //     productSku: +this.filters.sku.model,
      //     manageMode: 2,
      //   },
      //   val => val
      // );

      if (this.loading) {
        return;
      }

      this.loading = true;
      // using pagination
      const params = this.filterValues();

      return Promise.all([
        this.franchiseService.settlementDetail(params),
        this.franchiseService.settlementSumNums(params),
        this.franchiseService.settlementSumAmount(params),
      ])
        .then(([list, sumNums, sumAmount]) => {
          this.tableData = _.get(list, 'data.records', []);
          this.pageData.total = _.get(list, 'data.totalCount', 0);
          this.pageData.pageNo = _.get(list, 'data.pageNo', 1);
          this.tableData.push({
            agencyTypeDesc: '总计',
            salesNums: +sumNums.data,
            salesAmount: +sumAmount.data,
          });
          this.loading = false;
        })
        .catch(() => {
          this.loading = false;
        });
    },
    reset() {
      this.filters.balanceId.model = null;
      this.filters.brandId.model = null;
      this.filters.sku.model = null;
      this.pageData.pageNo = 1;
      this.pageData.total = 0;
      this.search();
    },
    pageChange(val) {
      this.pageData.pageNo = val;
      this.search();
    },
    exportData() {
      const querystring = qs.stringify(this.filterValues(), true);
      const href = `${FranchiseService.exportSettlementDetail}${querystring}`;

      window.open(href, '_blank');
    },
    returnPage() {
      this.$router.push({
        name: 'finance.franchise-payment.payment',
      });
    },
  },
};
</script>

<style scoped lang="scss">
.table-btn {
  margin-left: 15px;
}
</style>