1
lxf
2025-06-23 1e47b1681854ea564215482fb3b2d73934fa3edc
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
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
<template>
  <div class="order">
    <van-loading color="#1194F7" v-if="isLoading" />
    <van-sticky>
      <div class="flex justify-between py-4 px-4" style="background: #fff;">
        <van-icon name="arrow-left" @click="$router.go(-1)"></van-icon><span>{{ chartData.symbol }}</span>
        <div class="flex items-center"><img class="img" src="@/assets/image/chart/Group3758.png" />
          <van-icon @click="close" name="cross"></van-icon>
        </div>
      </div>
    </van-sticky>
    <div class="flex justify-center">
      <p class="inline-block text-white px-4 rounded mx-auto flex">
        <van-dropdown-menu>
          <van-dropdown-item v-model="value" :options="options"></van-dropdown-item>
        </van-dropdown-menu>
      </p>
    </div>
    <div class="h-4 border mx-4 border-t-0 border-bd-gray"></div>
    <div class="px-4 mt-4 flex justify-between px-8">
      <div class="flex-1 flex justify-between"><span class="text-gray" @click="onCalc(-10)">-10</span><span
          class="text-gray" @click="onCalc(-1)">-1</span></div>
      <div class="flex justify-between flex-1">
        <!-- {{ amount.toFixed(2) }} -->
        <input class="text-center chatBg" type="number" v-model="deviation"/>
      </div>
      <div class="flex-1 flex justify-between"><span class="text-gray" @click="onCalc(1)">+1</span><span
          class="text-gray" @click="onCalc(10)">+10</span></div>
    </div>
    <div class="h-4 border mx-4 border-t-0 border-bd-gray"></div>
    <div class="flex-1 px-4" v-if="value != 0">
      <div class="text-center pt-2  pb-2"><span class="text-base">{{ $t('price') }}</span>
        <!--span.text-lg 85-->
        <!--span.text-xs 4-->
      </div>
      <div class="flex justify-between px-4 flex-1">
        <input class="w-full text-center chatBg" readonly type="number" v-model="chartData.close" />
      </div>
      <div class="h-4 border border-t-0 border-bd-gray"> </div>
    </div>
    <div class="px-4 mt-4 flex justify-between gap-6">
      <div class="flex-1">
        <div class="text-right text-down flex  justify-end">
          <span class="font-semibold text-lg">
            {{ chartData.ask ? chartData.ask.toString().substr(0, chartData.ask.toString().length - 3) : '' }}
          </span>
          <span class="font-semibold text-lg font-24">
            {{
              chartData.ask ? chartData.ask.toString().substr(chartData.ask.toString().length - 3, 2) : '--'
            }}
          </span>
          <span class="text-xs">
            {{ chartData.ask ? chartData.ask.toString().substr(chartData.ask.toString().length - 1) : '' }}
          </span>
        </div>
        <div class="flex justify-between px-4 flex-1 mt-3">
          <span @click="sellReducePrice" :class="value == 0 ? 'text-gray' : ''">-</span>
          <div class="text-gray" v-if="value == 0">{{ chartData.ask ?? '--' }}</div>
          <input v-else class="text-black w-full text-center chatBg" placeholder="SL" type="number"
            v-model="sellPrice" />
          <span @click="sellAddPrice" :class="value == 0 ? 'text-gray' : ''">+</span>
        </div>
        <div class="h-4 border border-t-0 border-down"> </div>
      </div>
      <div class="flex-1">
        <div class="text-up flex justify-start">
          <span class="font-semibold text-lg">
            {{ chartData.bid ? chartData.bid.toString().substr(0, chartData.bid.toString().length - 3) : '' }}
          </span>
          <span class="font-semibold text-lg font-24">
            {{
              chartData.bid ? chartData.bid.toString().substr(chartData.bid.toString().length - 3, 2) : '--'
            }}
          </span>
          <span class="text-xs">
            {{ chartData.bid ? chartData.bid.toString().substr(chartData.bid.toString().length - 1) : '' }}
          </span>
        </div>
        <div class="flex justify-between px-4 flex-1 mt-3">
          <span @click="buyReducePrice" :class="value == 0 ? 'text-gray' : ''">-</span>
          <div class="text-gray" v-if="value == 0">{{ chartData.bid ?? '--' }}</div>
          <input v-else class="text-black w-full text-center chatBg" placeholder="TP" type="number"
            v-model="buyPrice" />
          <span @click="buyAddPrice" :class="value == 0 ? 'text-gray' : ''">+</span>
        </div>
        <div class="h-4 border border-t-0 border-up"> </div>
      </div>
    </div>
    <div class="px-4 mt-4  flex ">
      <div class="dad flex-1">
        <div> <span @click="reduceNum">-</span></div>
        <div class="input-center"> <span class="text-gray "> <span>{{ $t('Numberofsheets') }}&nbsp;</span>
            <input type="number" class="text-leftr chatBg" v-model="deviation" /></span>
        </div>
        <div class="input-right"> <span @click="addNum">+</span></div>
        <div class="h-4 lever-border border  border-t-0 border-bd-gray flex-1"></div>
      </div>
 
 
      <div class="lever-box flex align-center" @click.stop="openSelect">
        {{ listData[activeIndex].lever_rate }}x<img class="down-img" src="@/assets/image/down.png" />
        <div class="select-div" v-if="showSelect">
          <ul>
            <li v-for="(item, index) in listData" :key="index" @click.stop="onSelectSheet(item, index)"
              :class="[index == activeIndex ? 'active' : '']">{{ item.lever_rate }}x
            </li>
          </ul>
        </div>
      </div>
      <!-- <span @click="reduceNum">-</span>
      <span class="text-gray ">张数
        <input type="number" class="text-gray  text-leftr chatBg" v-model="deviation" /></span>
 
      <span @click="addNum">+</span> -->
    </div>
    <!-- <div class="h-4 lever-border border mx-4 border-t-0 border-bd-gray flex-1"></div> -->
    <!-- <div class="flex justify-between px-4 mt-4 px-8 ">
      <span @click="reduceNum">-</span>
      <span class="text-gray ">张数
        <input type="number" class="text-gray  text-leftr chatBg" v-model="deviation" /></span>
 
      <span @click="addNum">+</span>
    </div> -->
    <fx-kline :showBottom="false" :height="320" chartType="candle_stroke" :symbol="symbol" @data="onData"
      @loading="onLoading">
    </fx-kline>
    <div class="px-4 mt-4 flex justify-between gap-4">
      <van-button class="flex-1" type="danger" @click="onSubmit('sell')">{{ $t('sell') }} </van-button>
      <van-button class="flex-1" type="primary" @click="onSubmit('buy')">{{ $t('buy') }}</van-button>
      <!--van-button.flex-1(type="primary") 下单-->
    </div>
  </div>
</template>
 
 
<script setup>
import fxKline from '@/components/fx-kline/index.vue'
import { onMounted, ref, watch } from 'vue'
import { useRoute, useRouter } from 'vue-router';
import { _initClose, _initOpen } from "@/service/trade.api.js";
import { showToast } from 'vant';
import { useI18n } from "vue-i18n";
import { useUserStore } from "@/store/user.js";
const { t } = useI18n()
const useStore = useUserStore();
 
const value = ref(0)
const isLoading = ref(false)
const showSelect = ref(false)
const router = useRouter()
const route = useRoute()
 
const chartData = ref({})
 
const symbol = ref('')
const deviation = ref(1)
const buyPrice = ref(null)
const sellPrice = ref(null)
const price = ref(0)
const initOpen = ref({})
const initClose = ref(null)
const maxAmount = ref(0)
const activeIndex = ref(0)
const listData = ref([{ lever_rate: 1 }])
onMounted(() => {
  symbol.value = route.params.symbol
  initOpenFun()
})
 
const options = [
  { text: t('marketPrice'), value: 0 },
  { text: t('priceLimit'), value: 1 }
]
 
 
const onData = (evt) => {
  console.log(evt)
  chartData.value = evt
}
 
const onLoading = (val) => {
  isLoading.value = val
}
const openSelect = () => {
  showSelect.value = !showSelect.value
}
const onSelectSheet = (item, index) => {
  activeIndex.value = index
  showSelect.value = false
 
}
 
const onCalc = (value) => {
  if (deviation.value + value >= 0) {
    deviation.value += value
  }
}
const initCloseFun = async () => {
  initClose.value = await _initClose({ symbol: symbol.value })
  maxAmount.value = initClose.value.amount
}
const initOpenFun = async () => {
  initOpen.value = await _initOpen({ symbol: symbol.value })
  if (initOpen.value.lever.length !== 0) {
    listData.value = initOpen.value.lever
  }
}
const onSubmit = (direction) => {
  if (!useStore.userInfo.token) {
    router.push('/login')
    return false
  }
  if (value.value == 0) {
    price.value = direction === 'sell' ? chartData.value.ask : chartData.value.bid
    if(price.value === undefined || price.value === null || price.value===''){
      return false
    }
  } else {
    if (direction == 'sell') {
      if (!sellPrice.value) {
        showToast(t('enterPrice'))
        return
      } else {
        price.value = sellPrice.value
      }
    } else {
      if (!buyPrice.value) {
        showToast(t('enterPrice'))
        return
      } else {
        price.value = buyPrice.value
      }
    }
  }
  router.push({ path: '/chart/result', query: { chartData: JSON.stringify(chartData.value), direction: direction, symbol: symbol.value, deviation: deviation.value, price_type: value.value, price: price.value, lever_rate: listData.value[activeIndex.value].lever_rate } })
}
const sellReducePrice = () => {
  if (value.value != 0) {
    sellPrice.value = sellPrice.value ? (sellPrice.value * 1 - 0.00001).toFixed(5) : chartData.value.ask
  }
}
const sellAddPrice = () => {
  if (value.value != 0) {
    sellPrice.value = sellPrice.value ? (sellPrice.value * 1 + 0.00001).toFixed(5) : chartData.value.ask
  }
}
const buyReducePrice = () => {
  if (value.value != 0) {
    buyPrice.value = buyPrice.value ? (buyPrice.value * 1 - 0.00001).toFixed(5) : chartData.value.bid
  }
  //price.value = (price.value * 1 + amount.value).toFixed(2)
}
const buyAddPrice = () => {
  if (value.value != 0) {
    buyPrice.value = buyPrice.value ? (buyPrice.value * 1 + 0.00001).toFixed(5) : chartData.value.bid
  }
  //price.value = (price.value * 1 + amount.value).toFixed(2)
}
const addNum = () => {
  deviation.value = deviation.value + 1
}
const reduceNum = () => {
  if (deviation.value - 1 < 1) {
    deviation.value = 1
  } else {
    deviation.value = deviation.value - 1
  }
 
}
watch(value, (val, oldVal) => {
  if (value.value === 1) {
    sellPrice.value = ''
    buyPrice.value = ''
  }
})
// 返回
const close = () => {
  router.back();
}
</script>
 
<style lang="scss" scoped>
.order {
  padding-bottom: 20px;
}
 
.img {
  width: 15px;
  height: 15px;
  margin-right: 15px;
}
 
:deep(.van-dropdown-menu__bar){
  height: 32px;
}
 
.items-center {
  align-items: center;
}
 
.van-loading {
 
  position: fixed;
 
  z-index: 9999;
 
  width: 100%;
 
  height: 100%;
 
  background: rgba(255, 255, 255, 0.5);
 
  display: flex;
 
  justify-content: center;
 
  align-items: center;
 
}
 
.dad {}
 
.dad>div {
  display: inline-block;
  width: 33.3%;
 
}
 
.input-center {
  display: table;
  text-align: center;
 
  span {
    width: 10px;
  }
 
  input {
    width: 50%;
  }
 
}
 
.input-right {
  text-align: right
}
 
.text-up {
  color:  $active_line;
}
 
.lever-box {
  width: 90px;
  height: 42px;
  margin-left: 15px;
  background: #F1F3F9;
  justify-content: center;
  align-items: center;
  position: relative;
 
  .down-img {
    width: 15px;
    height: 15px;
    margin-left: 10px;
  }
}
 
.select-div {
  width: 90px;
  position: absolute;
  top: 42px;
  left: 0;
  z-index: 100;
 
  ul {
    box-shadow: 0px 3px 11px 0px rgb(0 0 0 / 10%);
 
    li {
      background:  $mainbgWhiteColor;
      text-align: center;
      padding: 5px 0;
      font-size: 16px;
      font-weight: bold;
 
      // border-bottom: 1px solid #f6f4f4;
      // box-shadow: 0px 3px 11px 0px rgb(0 0 0 / 10%);
    }
 
    li:not(:last-child) {
      border-bottom: 1px solid $border-grey;
    }
  }
}
 
.active {
  background: $btn_main !important;
  color: $text_color;
}
 
.lever-border {
  width: 100% !important
}
</style>