clearing.vue 4.38 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.brandId.label">
        <select-brand v-model="filters.brandId.model"></select-brand>
      </filter-item>
      <filter-item :label="filters.status.label">
        <Select v-model.trim="filters.status.model" clearable>
          <Option v-for="option in filters.status.options" :key="option.value" :value="option.value">{{
            option.label
          }}</Option>
        </Select>
      </filter-item>
      <filter-item :label="filters.createTime.label">
        <Date-picker
          v-model="filters.createTime.model"
          placement="bottom-end"
          type="daterange"
          format="yyyy-MM-dd"
          placeholder="选择日期"
        >
        </Date-picker>
      </filter-item>
      <filter-item>
        <Button type="primary" @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 list from './store/list';
import filter from './store/filter';
import FinanceService from 'services/finance/finance-service';
import _ from 'lodash';
import qs from 'querystringify';

export default {
  data() {
    return _.assign(list.call(this), filter);
  },
  computed: {
    startTime() {
      const createTime = this.filters.createTime.model;

      if (_.isEmpty(createTime)) {
        return 0;
      } else {
        return createTime[0] ? createTime[0].getTime() / 1000 : 0;
      }
    },
    endTime() {
      const createTime = this.filters.createTime.model;

      if (_.isEmpty(createTime)) {
        return 0;
      } else {
        return createTime[1] ? createTime[1].getTime() / 1000 : 0;
      }
    },
  },
  created() {
    this.financeService = new FinanceService();
    this.search();
  },
  methods: {
    filterValues() {
      const params = {
        type: 1,
        balanceId: +this.filters.balanceId.model,
        brandId: +this.filters.brandId.model,
        status: this.filters.status.model,
        beginTime: this.startTime,
        endTime: this.endTime,
        pageSize: this.pageData.pageSize,
        pageNo: this.pageData.pageNo,
        manageMode: 1,
      };

      return _.pickBy(params, val => val);
    },
    search() {
      this.financeService.balanceList(this.filterValues()).then(ret => {
        this.tableData = _.get(ret, 'data.records', []);
        this.pageData.total = _.get(ret, 'data.totalCount', 0);
        this.pageData.pageNo = _.get(ret, 'data.pageNo', 1);
      });
    },
    reset() {
      this.filters.balanceId.model = null;
      this.filters.brandId.model = null;
      this.filters.status.model = null;
      this.filters.createTime.model = null;
      this.pageData.pageNo = 1;
      this.pageData.total = 0;

      this.search();
    },
    pageChange(val) {
      this.pageData.pageNo = val;
      this.search();
    },
    onClickInfo(params) {
      this.$router.push({
        name: 'finance.clearing.detail',
        params: {},
        query: {
          balanceId: params.row.balanceId,
          brandId: params.row.brandId,
          status: {
            未结算: 1,
            已结算: 2,
          }[params.row.statusDesc],
        },
      });
    },
    onClickStock(params) {
      const opt = _.pickBy(
        {
          brandId: params.row.brandId,
          begin: params.row.startTime,
          end: params.row.endTime,
          supplierName: params.row.supplierName,
        },
        val => val
      );

      this.$router.push({
        name: 'finance.clearing.stock',
        params: {},
        query: opt,
      });
    },
    exportData() {
      const querystring = qs.stringify(this.filterValues(), true);
      const href = `${FinanceService.exportBalanceList}${querystring}`;

      window.open(href, '_blank');
    },
  },
};
</script>

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