<template>
  <div id="fhSign">
    <el-row>
      <el-col :span="24" class="main">
        <el-col :span="24" class="crumbs">
          <el-breadcrumb separator="/">
            <el-breadcrumb-item> <i class="el-icon-lx-cascades"></i> 分行客户报名统计 </el-breadcrumb-item>
          </el-breadcrumb>
        </el-col>
        <el-col :span="24" class="container down">
          <el-col :span="24" class="downTop">
            <el-col :span="4">
              <el-select v-model="searchForm.fhid" clearable placeholder="请选择分行" :popper-append-to-body="false">
                <el-option v-for="item in fnList" :key="item.id" :label="item.name" :value="item.tableid"> </el-option>
              </el-select>
            </el-col>
            <el-col :span="6">
              <el-date-picker
                v-model="searchForm.date"
                value-format="yyyy-MM-dd"
                format="yyyy-MM-dd"
                type="daterange"
                range-separator="-"
                start-placeholder="开始日期"
                end-placeholder="结束日期"
                clearable
              >
              </el-date-picker>
            </el-col>
            <el-col :span="14">
              <el-button type="primary" icon="el-icon-search" @click="search">搜索</el-button>
            </el-col>
          </el-col>
          <el-col :span="24" class="downList">
            <el-col :span="24" class="downListOne">
              <el-col :span="12"> 分行客户总数{{ khtotal }}人 </el-col>
              <el-col :span="12" style="text-align:right;">
                <el-button type="primary" size="mini" @click="selectBtn()">导出数据</el-button>
              </el-col>
            </el-col>
            <el-col :span="24" class="downListTwo">
              <data-table :fields="fields" :opera="opera" :data="list" :total="total" @query="search"> </data-table>
            </el-col>
          </el-col>
        </el-col>
      </el-col>
    </el-row>
  </div>
</template>

<script>
import _ from 'lodash';
import dataTable from '@/components/frame/filter-page-table.vue';
import { mapState, createNamespacedHelpers } from 'vuex';
const { mapActions: sj } = createNamespacedHelpers('sj');
const { mapActions: xs } = createNamespacedHelpers('xs');
const { mapActions: kh } = createNamespacedHelpers('kh');
const { mapActions: count } = createNamespacedHelpers('count');
export default {
  metaInfo: { title: '分行客户报名统计' },
  name: 'fhSign',
  props: {},
  components: {
    dataTable, //列表组件
  },
  data: function() {
    return {
      // 查询
      searchForm: {},
      fnList: [],
      // 销售员列表
      opera: [],
      fields: [
        { label: '销售员', prop: 'name' },
        { label: '客户总数', prop: 'khtotal' },
      ],
      list: [],
      total: 0,
      khtotal: 0,
    };
  },
  created() {
    this.searchSj();
  },
  methods: {
    ...sj(['query']),
    ...xs({ xsQuery: 'query' }),
    ...kh({ khQuery: 'query' }),
    ...count({ countQuery: 'query', otherselectQuery: 'otherselectQuery' }),
    // 查询分行列表
    async searchSj() {
      let res = await this.query({ js: '1' });
      if (this.$checkRes(res)) {
        let data = res.data;
        data.push({ name: '全部' });
        this.$set(this, `fnList`, data);
      }
    },
    async search({ skip = 0, limit = 10, ...info } = {}) {
      info = {
        ssid: this.searchForm.fhid,
        start: _.get(this.searchForm, 'date[0]'),
        end: _.get(this.searchForm, 'date[1]'),
        table: 'xs',
      };
      let res = await this.countQuery({ skip, limit, ...info });
      if (this.$checkRes(res)) {
        this.$set(this, `list`, res.data);
        this.$set(this, `total`, res.total);
        let khtotal = res.data.reduce((p, n) => p + (n['khtotal'] * 1 || 0), 0);
        if (khtotal) this.$set(this, `khtotal`, khtotal);
      }
    },
    async selectBtn() {
      let info = {
        ssid: this.searchForm.fhid,
        start: _.get(this.searchForm, 'date[0]'),
        end: _.get(this.searchForm, 'date[1]'),
        table: 'xs',
      };
      let res = await this.otherselectQuery({ ...info });
      if (this.$checkRes(res)) {
        window.open(res.data);
      }
    },
  },
  computed: {
    ...mapState(['user']),
  },
};
</script>

<style lang="less" scoped>
.down {
  .downList {
    .downListOne {
      padding: 15px 0;
    }
  }
}
/deep/.el-select-dropdown__wrap {
  max-height: 340px;
}
</style>
