<template>
  <!-- <Views url="getDesignPage.action?funcId=1917040528219537410" /> -->
  <div class="RCSbox common-page">
    <el-tabs
      v-model="activeTab"
      @tab-click="e=>handleClick(e,scriptId, 'FxSwapPositionDetail', posType)"
    >
      <el-tab-pane label="实时头寸">
        <FormSearch
          :form-arr="formArr"
          :form-data="searchParams"
          @outOperation="outOperation"
          @searchSubmit="searchSubmit"
          @reset="resetForm"
        />
        <PublicTable
          ref="table"
          class="table"
          row-key="id"
          :loading="loading"
          :has-index="false"
          :need-select="false"
          :table-data="tableData"
          :table-info="tableInfo"
          :table-column="columns"
          :events="events"
          operation-width="150px"
          :has-operation="false"
          :btn-button="operations"
          :table-top-button="tableTopButton"
          :operation-fixed="true"
          :is-need-pagination="false"
          :is-need-customcolumn="true"
          :drop-custom-buttons="dropCustomButtons"
          :current-page="searchParams.pageStart"
          :page-size="searchParams.pageLimit"
          :total="total"
          @sizeChange="handleSizeChange"
          @currentChange="handleCurrentChange"
          @handleSelectionChange="handleSelectionChange"
        >
          <template #realTime>
            <el-switch
              v-model="isRealTime"
              active-color="#3389ff"
              inactive-color="#C0CCDA"
              @change="e=>startTimer(e,scriptId)"
            />
            <span style="margin:0 8px 0 5px;font-size:14px">实时数据模式</span>
          </template>
          <template #dropExportPage>
            <span @click="exportPage(scriptId,posType,searchParams.folder,0)">导出当前页</span>
          </template>
          <template #dropExportAll>
            <span @click="exportPage(scriptId,posType,searchParams.folder,1)">导出全部</span>
          </template>
        </PublicTable>
      </el-tab-pane>
      <el-tab-pane label="历史头寸">
        <HistoryPos
          v-if="activeTab=='1'"
          :query="queryParam"
        /></el-tab-pane>
    </el-tabs>
  </div>
</template>

<script>
import FormSearch from '@/components/formSearch/index.vue';
import PublicTable from '@/components/table/index.vue';
import posMixin from '../../../mixins/posMixin';
import HistoryPos from '../forexSpotSingleCurrencyPosition/historyPos.vue';
export default {
  components: {
    FormSearch,
    PublicTable,
    HistoryPos,
  },
  mixins: [posMixin],
  data() {
    return {
      formArr: [
        {
          type: 'selectTreeTable',
          prop: 'folder',
          span: 4,
          attrs: {
            label: '账户',
            placeholder: '请选择',
            info: { title: '账户检索' },
            clearable: false,
          },
          options: [],
        },
        {
          type: 'select',
          prop: 'dfType',
          span: 4,
          attrs: {
            label: '贴现类型',
          },
          options: [],
        },
      ],
      loading: false,
      // table数据源
      tableData: [],
      tableInfo: {
        tableHeight: 350,
        tableTitle: this.$t('menu.forexSwapPosition'),
      },
      // 表格项绑定的属性
      columns: [],
      // 操作栏自定义按钮
      operations: [],
      tableTopButton: [
        {
          slot: 'realTime',
        },
      ],
      // 搜索查询的参数
      searchParams: {
        pageStart: 1,
        pageLimit: 20,
        folder: '',
        dfType: 'NO',
      },
      total: 0,
      scriptId: 'FxSwapPairPosition',
      posType: 'FxSwapPairPosition',
    };
  },
  async mounted() {
    await this.getOptions('folderTreeAuthWithGrp,DfType');
    await this.setUserFolder(this.scriptId);
    await this.getTableConfig(this.scriptId, 'FxSwapPositionDetail', this.posType);
    this.getTableList(this.scriptId);
  },
  methods: {
    searchSubmit(val) {
      console.log('search结果', val);
      this.searchParams = { ...this.searchParams, ...val };
      this.getTableList(this.scriptId);
    },
    resetForm() {
      // this.searchParams = {
      //   pageStart: 1,
      //   pageLimit: 20,
      //   folder: '',
      //   dfType: 'NO',
      // };
      this.searchParams.dfType = 'NO';
    },
    outOperation(val, index, prop, num) {
      console.log(val, index, prop, num, '查询');
      this.searchParams[prop] = val;
    },
    // 页面展示条数改变事件-pageLimit
    handleSizeChange(pageLimit) {
      this.searchParams.pageLimit = pageLimit;
      this.getTableList(this.scriptId);
    },
    // 页面切换事件-pageStart
    handleCurrentChange(pageStart) {
      this.searchParams.pageStart = pageStart;
      this.getTableList(this.scriptId);
    },
    // 多选事件
    handleSelectionChange(val) {
      console.log('多选事件 ', val);
      this.selection = val;
    },

  },
};
</script>

<style lang="scss" scoped>
:deep(.define-btn){
  margin-right:10px;
  cursor:pointer
}
</style>
