交易所前端蓝色ui 4.5 jiem
jhzh
2025-05-19 c5487881d04780e03f4dd86ed1606c587f2c7952
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
<template>
  <div>
    <date-search />
    <el-table
      class="history-apply-position"
      :data="showData"
      :cell-style="cellStyle"
      :empty-text="$t('message.home.noData')"
    >
      <el-table-column
        v-for="(item, index) in tables"
        :key="index"
        :prop="item.prop"
        :label="$t(item.label)"
        :formatter="item.formatter"
      />
      <el-table-column align="right">
        <!-- class="m-2" -->
        <template #header>
          <el-select
            v-model="selectVal"
            popper-class="position-select"
            placeholder="Select"
            size="small"
            @change="selectChange"
          >
            <el-option
              v-for="item in options"
              :key="item.value"
              :label="$t(item.label)"
              :value="item.value"
            />
          </el-select>
        </template>
        <template #default="scope">
          <div>{{ stateFormatter(scope.row.state) }}</div>
        </template>
      </el-table-column>
    </el-table>
    <div class="paginatio">
      <el-icon
        ><ArrowLeft
          class="page-btn"
          :disabled="noPre || pageNum == 1"
          @click="changePageNum('pre')"
      /></el-icon>
      <div class="pageNum">
        {{ pageNum }}
      </div>
 
      <el-icon
        ><ArrowRight
          class="page-btn"
          :disabled="noNext"
          @click="changePageNum('next')"
      /></el-icon>
    </div>
  </div>
</template>
 
<script>
import Axios from "@/api/perpetualContract.js";
import { ArrowLeft, ArrowRight } from "@element-plus/icons-vue";
import dateSearch from "./dateSearch.vue";
export default {
  name: "historyApplyPosition",
  props: {
    symbol: {
      type: String,
    },
    paramsType: {
      type: String,
      default: "indices",
    },
  },
  data() {
    return {
      pageNum: 1,
      noNext: false, //noNext
      noPre: false,
      timer: null,
      startTime: "",
      endTime: "",
      tables: [
        {
          prop: "create_time",
          label: "message.home.shijian",
        },
        {
          prop: "name",
          label: "message.jiaoyi.heyue",
        },
        // 历史只有平多和平空
        {
          prop: "direction",
          label: "message.home.fangxiang",
          formatter: this.directionFormatter,
        },
        {
          prop: "trade_avg_price",
          label: "message.home.chengjiaojunjia",
        },
        {
          prop: "volume_open",
          label: "message.home.weituoshuliang",
        },
        {
          prop: "volume",
          label: "message.user.chengjiaoshuliang",
          formatter: this.volumnFormatter,
        },
      ],
 
      tableData: [],
      showData: [],
      // 下拉框
      options: [
        {
          value: "all",
          label: "message.home.quanbu",
        },
        {
          value: "submitted",
          label: "message.home.yitijiao",
        },
        {
          value: "created",
          label: "message.home.weituowancheng",
        },
        {
          value: "canceled",
          label: "message.home.yichexiao",
        },
      ],
      selectVal: "all",
    };
  },
  components: {
    dateSearch,
    ArrowLeft,
    ArrowRight,
  },
  mounted() {
    this.getList();
    this.timer = setInterval(() => {
      this.getList();
    }, 2000);
  },
 
  unmounted() {
    clearInterval(this.timer);
  },
  methods: {
    //分页
    changePageNum(type) {
      if (type == "next") {
        if (!this.noNext) {
          this.pageNum = this.pageNum + 1;
        }
      } else {
        if (!this.noPre && this.pageNum > 1) {
          this.pageNum = this.pageNum - 1;
        }
      }
      this.getList();
    },
    //设置单个单元格样式   行下标:rowIndex    列下标:columnIndex
    cellStyle({ row, column, rowIndex, columnIndex }) {
      // 未实现盈亏
      if (columnIndex == 2) {
        if (row.direction == "sell") {
          return { color: "#E05561" };
        } else {
          return { color: "#62C885" };
        }
      }
    },
    //获取列表数据
    getList(startTime = "", endTime = "", isReset) {
      // 轮训的时候,把时间筛选的参数带上
      if (startTime || endTime || isReset) {
        this.startTime = startTime;
        this.endTime = endTime;
      }
      const data = {
        page_no: this.pageNum,
        type: "hisorders",
        symbol: this.symbol,
        endTime: this.endTime,
        startTime: this.startTime,
        symbolType: this.paramsType,
      };
      //历史委托和历史成交是一样的
      Axios.contractOrderList(data).then((res) => {
        this.tableData = res.data;
        const noNext = res.data.length == 0 || res.data.length < 10; //刚好等于10下一页就没数据
        this.noNext = noNext;
        this.filterData(); //轮训后,需要保留之前的筛选状态
      });
    },
    stateFormatter(state) {
      const stateMap = {
        submitted: "message.home.yitijiao",
        canceled: "message.home.yichexiao",
        created: "message.home.weituowancheng",
      };
      return this.$t(`${stateMap[state]}`);
    },
 
    directionFormatter(row) {
      const { direction } = row;
      return direction == "buy"
        ? this.$t("message.home.pingduo")
        : this.$t("message.home.pingkong");
    },
    // directionFormatter(row) {
    //   const map = {
    //     "close buy": "pingduo",
    //     "open buy": "kaiduo",
    //     "close sell": "pingkong",
    //     "open sell": "kaikong",
    //   };
    //   const { direction, offset } = row;
    //   const value = `${offset} ${direction}`;
    //   const text = map[value];
    //   return this.$t(`message.home.${text}`);
    // },
    volumnFormatter(row) {
      //委托数量(剩余)(张),委托数量(张)
      const { volume, volume_open } = row;
      return volume_open - volume;
    },
    filterData() {
      if (this.selectVal == "all" || !this.selectVal) {
        this.showData = this.tableData;
        return;
      }
      this.showData = this.tableData.filter((it) => it.state == this.selectVal);
    },
    //数据筛选
    selectChange() {
      // this.pageNum = ""; //需要访问所有的数据,然后自己过滤.因为有分页所以需要后端配合
      // this.getList();
      this.filterData();
    },
  },
};
</script>