11
jhzh
2024-08-01 4ebbadfe4c8c7aa6404dcd9b126cc8265bf03c0d
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
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
<template>
  <div id="wantBuy" class="flex flex-col w-full h-full">
    <div>
      <div
        class="w-full h-122 pl-40 pr-31 box-border flex text-white items-center"
      >
        <van-icon class="c2cColor" name="arrow-left" @click="$router.back()" />
        <div class="flex-1 text-right mr-100" @click="showPopup">
          <span class="font-35 font-700 mr-8 titleColor">{{
            $t("快捷区")
          }}</span>
          <van-icon name="arrow-down" class="c2cColor" />
        </div>
        <van-popup round position="top" v-model="show" :closeable="true">
          <span class="w-232 font-28 c2cColor font-500 ml-32 block mt-20">{{
            $t("选择交易区")
          }}</span>
          <div class="flex justify-around c2cColor mt-40 pb-48">
            <div class="flex flex-col items-center" @click="show = false">
              <img
                class="w-56 h-56"
                src="@/assets/image/otc/wantBuyHead/fast.png"
                alt=""
              />
              <span class="font-24 mt-10 h-32 font-500">{{
                $t("快捷区")
              }}</span>
            </div>
            <div
              class="flex flex-col items-center"
              @click="
                $router.push({
                  path: '/wantBuy',
                })
              "
            >
              <img
                class="w-56 h-56"
                src="@/assets/image/otc/wantBuyHead/optional.png"
                alt=""
              />
              <span class="font-24 mt-10 font-500">{{ $t("自选区") }}</span>
            </div>
          </div>
        </van-popup>
        <div
          class="w-232 h-64 px-23 box-border box-radius textColor flex justify-around items-center tabBackground"
        >
          <div
            class="flex items-center"
            @click="
              $router.push({
                path: '/selectLegalCurrency',
              })
            "
          >
            <span class="mr-15 font-31 font-400">{{ exchangeCurrency }}</span>
            <img
              class="w-24 h-20"
              :src="require('@/assets/image/otc/wantBuyHead/Group.png')"
              alt=""
            />
          </div>
          <span class="w-2 h-36">|</span>
          <van-popover
            get-container="#quick"
            v-model="showPopover"
            :actions="actions"
            @select="onSelect"
            placement="bottom-end"
            theme="dark"
            :offset="[20, 20]"
          >
            <template #reference>
              <span @click="showPopover = !showPopover">
                <img
                  class="relative bottom-4 w-24 h-6 list-img"
                  :src="require('@/assets/image/otc/wantBuyHead/Group2.png')"
                  alt=""
                />
              </span>
            </template>
          </van-popover>
        </div>
      </div>
      <div class="px-32 pb-42 type">
        <div class="flex items-center font-36">
          <div :class="{ active: isBuy }" @click="isBuy = true">
            {{ $t("我要买") }}
          </div>
          <div
            class="w-34 h-1 mx-20"
            style="transform: rotate(90deg); background: #eaebee"
          ></div>
          <div :class="{ active: !isBuy }" @click="isBuy = false">
            {{ $t("我要卖") }}
          </div>
        </div>
        <div class="flex mt-40 currency text-center">
          <div
            v-for="(item, index) in currency"
            :key="index"
            :class="{ active: activeCurrency === item.title }"
            @click="changeTab(item)"
          >
            <p>{{ item.title }}</p>
            <p>{{ item.label }}</p>
          </div>
        </div>
      </div>
    </div>
    <div class="w-full flex-1 px-32 pt-36 box-border mainBackground">
      <div class="px-32 py-40 c2cTabBackground item" v-show="isBuy">
        <div v-show="order_type === 'Amount'">
          <div class="mb-18 textColor1">{{ $t("购买金额") }}</div>
          <div
            class="w-full relative box-border rounded-xl inputBackground1 input"
          >
            <span class="font-32 absolute left-22 text font-700 c2cColor">{{
              currencySymbol
            }}</span>
            <input
              class="w-full font-36 h-110 rounded-xl border-none box-border pl-94 inputBackground1 c2cColor"
              type="number"
              :placeholder="$t('最小金额') + 100"
              v-model="buyAmount"
            />
          </div>
          <div class="flex justify-between mt-28 font-24">
            <div class="text-grey">
              {{ $t("参考单价") }}&nbsp;{{ currencySymbol }}{{ referPrice }}
            </div>
            <div
              class="flex items-center text-blue"
              @click="changeOrderType('Num')"
            >
              <span class="mr-11">{{ $t("按数量购买") }}</span>
              <img
                class="w-24 h-24"
                :src="require('@/assets/image/c2c/Group241.png')"
                alt=""
              />
            </div>
          </div>
        </div>
        <div v-show="order_type === 'Num'">
          <div class="flex justify-between mb-18">
            <span class="textColor1">{{ $t("购买数量") }}</span>
          </div>
          <div
            class="w-full relative box-border rounded-xl inputBackground1 input"
          >
            <input
              class="w-full font-36 h-110 rounded-xl border-none box-border pl-38 inputBackground1 c2cColor"
              type="number"
              :placeholder="$t('请输入数量')"
              v-model="buyNum"
            />
            <span class="font-28 absolute right-19 text" style="color: #1a6ebd">
              <span class="mr-22 c2cColor">{{ activeCurrency }}</span>
            </span>
          </div>
          <div class="flex justify-between mt-28 font-24">
            <div class="text-grey">
              {{ $t("参考单价") }}&nbsp;{{ currencySymbol }}{{ referPrice }}
            </div>
            <div
              class="flex items-center text-blue"
              @click="changeOrderType('Amount')"
            >
              <span class="mr-11">{{ $t("按金额购买") }}</span>
              <img
                class="w-24 h-24"
                :src="require('@/assets/image/c2c/Group241.png')"
                alt=""
              />
            </div>
          </div>
        </div>
        <div class="mt-76">
          <van-button
            class="w-full h-80 font-32 rounded-xl"
            type="primary"
            color="#2EBD85"
            @click="handleClick"
            >{{ $t("0手续费购买") }}
          </van-button>
        </div>
      </div>
      <div class="px-32 py-40 c2cTabBackground item" v-show="!isBuy">
        <div v-show="order_type === 'Num'">
          <div class="flex justify-between mb-18">
            <span class="textColor1">{{ $t("出售数量") }}</span>
            <span
              class="font-24 text-blue"
              style="text-decoration: underline"
              @click="isBuy = !isBuy"
              >{{ $t("划转") }}</span
            >
          </div>
          <div
            class="w-full relative box-border rounded-xl inputBackground1 input"
          >
            <input
              class="w-full font-36 h-110 rounded-xl border-none box-border pl-38 inputBackground1 c2cColor"
              type="number"
              :placeholder="$t('请输入数量')"
              v-model="sellNum"
            />
            <span class="font-28 absolute right-19 text" style="color: #1a6ebd">
              <span class="mr-22 c2cColor">{{ activeCurrency }}</span>
            </span>
          </div>
          <div class="flex justify-between mt-28 font-24">
            <div class="text-grey">
              {{ $t("参考单价") }}&nbsp;{{ currencySymbol }}{{ referPrice }}
            </div>
            <div
              class="flex items-center text-blue"
              @click="order_type = 'Amount'"
            >
              <span class="mr-11">{{ $t("按金额出售") }}</span>
              <img
                class="w-24 h-24"
                :src="require('@/assets/image/c2c/Group241.png')"
                alt=""
              />
            </div>
          </div>
        </div>
        <div v-show="order_type === 'Amount'">
          <div class="flex justify-between mb-18" style="color: #595c61">
            <span class="textColor1">{{ $t("出售金额") }}</span>
            <span
              class="font-24 text-blue"
              style="text-decoration: underline"
              @click="$router.push('/exchange/exchangePage')"
              >{{ $t("划转") }}</span
            >
          </div>
          <div
            class="w-full relative box-border rounded-xl inputBackground1 input"
          >
            <div
              class="w-full relative box-border rounded-xl inputBackground1 input"
            >
              <span class="font-32 absolute left-22 text font-700 c2cColor">{{
                currencySymbol
              }}</span>
              <input
                class="w-full font-36 h-110 rounded-xl border-none box-border pl-94 inputBackground1 c2cColor"
                type="number"
                :placeholder="$t('最小金额') + 100"
                v-model="sellAmount"
              />
            </div>
          </div>
          <div class="flex justify-between mt-28 font-24">
            <div class="text-grey">
              {{ $t("参考单价") }}&nbsp;{{ currencySymbol }}{{ referPrice }}
            </div>
            <div
              class="flex items-center text-blue"
              @click="order_type = 'Num'"
            >
              <span class="mr-11">{{ $t("按数量出售") }}</span>
              <img
                class="w-24 h-24"
                :src="require('@/assets/image/c2c/Group241.png')"
                alt=""
              />
            </div>
          </div>
        </div>
        <div class="mt-76">
          <van-button
            class="w-full h-80 font-32 rounded-xl"
            type="primary"
            color="#E35461"
            @click="handleClick"
            >{{ $t("0手续费出售") }}
          </van-button>
        </div>
      </div>
    </div>
 
    <van-popup v-model="enterTrade" position="bottom">
      <enter-trade
        v-if="paymentMethod.length"
        :type="fullType"
        :payment-method="paymentMethod"
        :info="info"
        :session-token="session_token"
        :symbol="activeCurrency"
        :exchangeCurrency="exchangeCurrency"
        @updataToken="updataToken"
        @close="enterTrade = false"
      />
    </van-popup>
  </div>
</template>
 
<script>
import otcApi from "@/API/otc";
 
import { Icon, Popup, Popover, Button, Toast } from "vant";
 
import EnterTrade from "@/page/quick/EnterTrade";
import { mapGetters } from "vuex";
export default {
  name: "index",
  data() {
    return {
      referPrice: "--",
      paymentMethod: [],
      order_type: "Amount",
      enterTrade: false,
      isBuy: true, // 模式
      activeCurrency: "USDT",
      show: false,
      showPopover: false,
      currency: [
        {
          title: "USDT",
          label: this.$t("计价币种"),
        },
        {
          title: "BTC",
          label: this.$t("最知名币种"),
        },
        {
          title: "ETH",
          label: this.$t("以太坊"),
        },
      ],
      actions: [
        {
          text: this.$t("收款方式"),
          icon: require("@/assets/image/otc/buy/collection_icon.png"),
          path: "/paymentMethod",
        },
        // {
        //   text: this.$t('c2c帮助中心'),
        //   icon: require('@/assets/image/otc/buy/help_icon.png'),
        //   path: '/c2cHelpCenter',
        // },
        // {
        //   text: 'c2c用户中心',
        //   icon: require('@/assets/image/otc/buy/user_icon.png'),
        //   path: '/c2c/c2cUser',
        // },
        // {
        //   text: this.$t('接单模式'),
        //   icon: require('@/assets/image/otc/buy/order_icon.png'),
        // },
      ],
      session_token: "",
 
      buyAmount: "",
      buyNum: "",
      sellAmount: "",
      sellNum: "",
      info: {},
      all_price: {},
      isPay: false,
    };
  },
  created() {
    otcApi
      .getSessionToken({
        currency: this.exchangeCurrency,
      })
      .then((res) => {
        this.session_token = res.data.session_token;
        console.log(this.activeCurrency.toLowerCase());
        this.all_price = res.data.all_price;
        this.referPrice = this.all_price[this.activeCurrency.toLowerCase()];
      });
 
    otcApi.ctcPaymentMethodList({ language: this.$i18n.locale }).then((res) => {
      if (res.data.length) {
        this.isPay = true;
      } else {
        this.isPay = false;
      }
    });
  },
  methods: {
    changeOrderType(order_type) {
      this.buyAmount = "";
      this.buyNum = "";
      this.sellAmount = "";
      this.sellNum = "";
      this.order_type = order_type;
    },
    getPriceList(type) {
      //获取承兑商支付方式列表
      otcApi
        .c2cgetBestPrice({
          order_type: this.order_type == "Amount" ? "by_amount" : "by_num",
          amount: this.isBuy ? this.buyAmount : this.sellAmount,
          coin_amount: this.isBuy ? this.buyNum : this.sellNum,
          direction: this.isBuy ? "buy" : "sell",
          currency: this.exchangeCurrency,
          symbol: this.activeCurrency.toLowerCase(),
          language: this.$i18n.locale,
        })
        .then((data) => {
          this.paymentMethod = data;
          if (this.paymentMethod.length == 0) {
            this.$toast(this.$t("无匹配的承兑商"));
            return;
          } else {
            this.enterTrade = true;
            this.info = {
              type: this.order_type,
              num: this[type + this.order_type],
            };
          }
        });
    },
    changeTab(item) {
      this.buyAmount = "";
      this.buyNum = "";
      this.sellAmount = "";
      this.sellNum = "";
      this.activeCurrency = item.title;
      this.referPrice = this.all_price[this.activeCurrency.toLowerCase()];
    },
    updataToken() {
      otcApi
        .getSessionToken({
          currency: this.exchangeCurrency,
        })
        .then((res) => {
          this.session_token = res.data.session_token;
        });
    },
    showPopup() {
      this.show = true;
    },
    onSelect(action) {
      if (action.text == this.$t("接单模式")) {
        this.showJie = true;
        return;
      }
 
      this.$router.push({
        path: action.path,
      });
    },
    handleClick() {
      const type = this.isBuy ? "buy" : "sell";
      if (!this[type + this.order_type]) {
        const text =
          this.order_type === "Amount" ? this.$t("金额") : this.$t("数量");
        Toast(this.$t("请输入") + text);
      } else {
        if (this.isPay) {
          this.getPriceList(type);
        } else {
          this.$toast(this.$t("请添加收款方式"));
          setTimeout(() => {
            this.$router.push("/paymentMethod");
          }, 500);
        }
      }
    },
  },
  computed: {
    ...mapGetters("c2c", ["exchangeCurrency", "currencySymbol"]),
    fullType() {
      return this.isBuy ? "buy" : "sell";
    },
  },
  components: {
    [Icon.name]: Icon,
    [Popup.name]: Popup,
    [Popover.name]: Popover,
    [Button.name]: Button,
    EnterTrade,
  },
};
</script>
 
<style lang="scss" scoped>
.box-radius {
  border-radius: 40px;
}
 
.type {
  color: #b8bcc5;
 
  .active {
    @include themify() {
      color: themed("c2c_color");
    }
  }
}
 
.currency {
  .active {
    p {
      color: #1a6ebd !important;
    }
  }
 
  & > div {
    padding: 10px 50px;
    margin-right: 30px;
    border-radius: 12px;
 
    @include themify() {
      background: themed("tab_background");
    }
 
    &:last-child {
      margin: 0;
    }
  }
 
  p:first-child {
    margin-bottom: 8px;
    font-weight: 500;
    color: #595c61;
  }
 
  p:last-child {
    color: #868c9a;
  }
}
 
.item {
  box-shadow: 0px 0px 12px rgba(0, 0, 0, 0.1);
  border-radius: 10px;
}
 
.input {
  span {
    top: 50%;
    transform: translateY(-50%);
  }
}
</style>