dcc
2024-07-19 06c4bb090a7b24442bf106f6614f70310dfab040
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
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
<template>
  <div>
    <el-table
      :data="tableData"
      class="position"
      :cell-style="cellStyle"
      :empty-text="$t('message.home.noData')"
    >
      <!-- 合约会显示buy和杠杆 -->
      <el-table-column :label="$t('message.jiaoyi.heyue')" width="280">
        <template #default="scope">
          <div class="first-column">
            <span
              class="direction"
              :class="`direction-${scope.row.direction}`"
            ></span>
            <span class="name"
              >{{ scope.row.name }} {{ $t("message.home.yongxu") }}</span
            >
            <span class="lever_rate">{{
              scope.row.lever_rate ? `${scope.row.lever_rate}x` : "1x"
            }}</span>
          </div>
        </template>
      </el-table-column>
      <el-table-column
        v-for="(item, index) in tables"
        :key="index"
        :prop="item.prop"
        :label="$t(item.label)"
        :formatter="item.formatter"
      />
      <el-table-column :label="$t('message.home.caozuo')" min-width="100">
        <template #default="scope">
          <!-- <el-button
            class="btn"
            size="small"
            @click="handleClose(scope.$index)"
            >{{ $t("message.home.pingcang") }}</el-button
          > -->
 
          <el-button class="btn" size="small" @click="handleAllClose(scope)">{{
            $t("message.home.pingcang")
          }}</el-button
          >&nbsp;&nbsp;
          <el-button class="btn" size="small" @click="zhiyingzhisunClose(scope)">{{
            $t("message.jiaoyi.zhiyingzhisun")
          }}</el-button>
        </template>
      </el-table-column>
    </el-table>
    <close-all-dialog ref="closeAllDialog"></close-all-dialog>
    <close-dialog ref="closeDialog"></close-dialog>
    <el-dialog v-model="dialogFormVisible" width="400">
      <el-form :model="form">
        <el-form-item :label="$t('message.jiaoyi.zhiying')" :label-width="formLabelWidth">
          <el-input v-model="form.zhiying" :placeholder="$t(`message.jiaoyi['请输入止盈金额']`)" autocomplete="off" />
        </el-form-item>
      </el-form>
      <el-form :model="form">
        <el-form-item :label="$t('message.jiaoyi.zhisun')" :label-width="formLabelWidth">
          <el-input v-model="form.zhisun" :placeholder="$t(`message.jiaoyi['请输入止损金额']`)" autocomplete="off" />
        </el-form-item>
      </el-form>
      <template #footer>
        <div class="dialog-footer">
          <el-button @click="dialogFormVisible = false">{{ $t('message.jiaoyi.quxiao') }}</el-button>
          <el-button type="primary" @click="quedingSetting">
            {{ $t('message.user.queding') }}
          </el-button>
        </div>
      </template>
    </el-dialog>
  </div>
</template>
 
<script>
import CloseAllDialog from "./dialog/closeAllDialog.vue";
import CloseDialog from "./dialog/closeDialog.vue";
import Axios from "@/api/perpetualContract.js";
import bus from "vue3-eventbus";
 
export default {
  emits: [
    "getPositionNum",
    "CurrencySort",
    "getSelectList",
    "checkCurrency",
    "filterFun",
    "deleteCollectFun",
  ],
  name: "position",
  props: {
    symbol: {
      type: String,
    },
    paramsType: {
      type: String,
      default: "indices",
    },
  },
  data() {
    return {
      formLabelWidth: '40px',
      form: {
        zhiying: "",
        zhisun: ""
      },
      order_no: '',
      dialogFormVisible: false,
      pageNum: 1,
      timer: null,
      tables: [
        {
          prop: "shuliang", //volume_open持仓总张数,volume表示剩余
          label: "message.home.shuliang",
        },
        {
          prop: "trade_avg_price",
          label: "message.user.kaicangjiage",
        },
        // {
        //   prop: "mark_price",
        //   label: "message.home.biaojijiage",
        // },
        {
          prop: "direction",
          label: "message.home.fangxiang",
          formatter: this.directionFormatter,
        },
 
        // {
        //   prop: "change_ratio",
        //   label: "message.home.baozhengjinbilv",
        //   formatter: this.ratioFormatter,
        // },
        {
          prop: "deposit",
          label: "message.home.baozhengjin",
        },
        {
          prop: "profit",
          label: "message.user.weishixianyingkui",
          formatter: this.formatterData,
        },
        {
          prop: "profit",
          label: "message.user.shouyilv",
          formatter: this.formatterData1,
        },
      ],
      tableData: [],
    };
  },
  mounted() {
    this.getList();
    this.timer = setInterval(() => {
      this.getList();
    }, 2000);
  },
  components: {
    CloseAllDialog,
    CloseDialog,
  },
 
  unmounted() {
    clearInterval(this.timer);
  },
  methods: {
    quedingSetting(){
      const data = {
        order_no: this.order_no,
        stop_price_profit: this.form.zhiying,
        stop_price_loss: this.form.zhisun,
      }
      Axios.quedingSetting(data).then(res => {
        if(res.code == 0) {
          this.$message({
            message: this.$t("message.user.chenggong"),
            type: "success",
          });
          this.dialogFormVisible = false
        }
      })
    },
    ratioFormatter(row) {
      const { change_ratio } = row;
      const ratio = `${bigDecimal.divide(change_ratio, 100, 4)}%`;
      return ratio;
    },
    directionFormatter(row, column, val) {
      return val === "buy"
        ? 'Long'
        : 'Shot';
    },
    formatterData(row) {
      const ratio = this.ratioFormatter(row);
      const profit = Number(row.profit).toFixed(4);
      return profit > 0 ?`+${profit}`: `${profit}`;
    },
    formatterData1(row) {
      const ratio = this.ratioFormatter(row);
      const profit = Number(row.profit).toFixed(4);
      return ratio > 0 ? `+${ratio}` : `${ratio}`;
    },
 
    //设置单个单元格样式   行下标:rowIndex    列下标:columnIndex
    cellStyle({ row, column, rowIndex, columnIndex }) {
      if (columnIndex == 6 || columnIndex == 5) {
        if (Number(row.profit) > 0) {
          return { color: "#62C885" };
        } else {
          return { color: "#E05561" };
        }
      }
      if (columnIndex == 3) {
        return row.direction === "buy"
          ? { color: "#62C885" }
          : { color: "#E05561" };
      }
    },
    getList() {
      const data = {
        page_no: this.pageNum,
        type: "orders",
        symbol: this.symbol,
        symbolType: this.paramsType,
      };
      Axios.contractOrderList(data).then((res) => {
        this.tableData = res.data;
        this.tableData.forEach(item => {
          let shuliang = item.deposit*item.lever_rate/item.trade_avg_price
          item.shuliang = shuliang.toFixed(4)
        })
        console.log(this.tableData,'this.tableData');
        this.$emit("getPositionNum", res.data.length);
        // 未实现盈亏
        const profitLoss = res.data.reduce(
          (accumulator, cur) => Number(accumulator) + Number(cur.profit),
          0
        );
        const dataloss = bigDecimal.round(profitLoss, 2);
        // 保证金率
        const marginRate = res.data.reduce(
          (accumulator, cur) =>
            Number(accumulator) +
            Number(bigDecimal.divide(cur.change_ratio, 100)),
          0
        );
        const datarate = `${bigDecimal.round(marginRate, 4)}%`;
        bus.emit("ProfitLossRefresh", dataloss);
        bus.emit("MarginRefresh", datarate);
      });
    },
    handleClose(index) {
      const data = this.tableData[index];
      this.$refs.closeDialog.open(data);
    },
    handleAllClose(data) {
      this.$refs.closeAllDialog.open(data.row);
    },
    zhiyingzhisunClose(data){
      this.order_no = data.row.order_no
      this.dialogFormVisible = true
    }
  },
};
</script>
<style scoped>
@import url("@/assets/css/commonTrade/constract/position/table.css");
.first-column {
  display: flex;
  align-items: center;
}
.name {
  margin: 0 2px;
}
.direction {
  display: inline-block;
  height: 20px;
  width: 2px;
}
.direction-buy {
  background: #62c885;
}
.direction-sell {
  background: #e05561;
}
.lever_rate {
  color: #1d91ff;
  background: #243046;
  border-radius: 2px;
  padding: 2px 6px;
}
.btn {
  background: #409eff;
  color: #fff;
}
/deep/ .el-dialog__header {
    border-bottom: none;
}
</style>