lxf
2025-04-28 df817cb82947971993b65b48fa987e42c7b12837
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
<template>
  <div class="wrapper">
    <!-- <div class="header">
      <mt-header :title="$t('账户资金互转')">
        <router-link to="/user" slot="left">
          <mt-button icon="back"></mt-button>
        </router-link>
      </mt-header>
    </div> -->
    <!-- <van-nav-bar
      :placeholder="true"
      :safe-area-inset-top="true"
      :title="$t('账户资金互转')"
      left-arrow
      @click-left="onClickLeft"
    >
    </van-nav-bar>
    <mt-navbar v-model="selected">
      <mt-tab-item id="1">{{ $t("沙特账户转黄金原油账户") }}</mt-tab-item>
      <mt-tab-item id="2">{{ $t("黄金原油账户转沙特账户") }}</mt-tab-item> -->
    <!-- <mt-tab-item v-if="this.$store.state.settingForm.futuresDisplay" id="3">融资转期货</mt-tab-item> -->
    <!-- <mt-tab-item v-if="this.$store.state.settingForm.futuresDisplay" id="4">期货转融资</mt-tab-item> -->
    <!-- </mt-navbar>
    <mt-tab-container class="order-list" v-model="selected">
      <mt-tab-container-item id="1">
        <div class="form-block">
          <mt-field
            :label="$t('可转金额')"
            :placeholder="$t('可转金额')"
            type="text"
            disabled
            v-model="myMoney[0].availableBalance"
          >
          </mt-field>
        </div>
        <div class="form-block">
          <mt-field
            :label="$t('转账金额')"
            name="amt"
            v-model="form.account1"
            :placeholder="$t('请输入转账金额')"
            type="text"
          >
            <span @click="selectAll1">{{ $t("hj60") }}</span>
          </mt-field>
        </div>
        <!-- <div class="form-block">
            <mt-field label="资金密码" placeholder="资金密码" type="password" v-model="form.password"></mt-field>
        </div>
        <p class="prompt">资金密码默认为登录密码</p> -->
    <!-- <div class="btnbox">
          <span class="text-center btnok loginout" @click="tosubmit">{{
            $t("确认转入黄金原油账户")
          }}</span>
        </div> -->
    <!-- <van-button
          class="but"
          type="primary"
          style="margin-top: 1.04rem; margin-bottom: 1.04rem"
          @click="tosubmit"
          >{{ $t("确认") }}</van-button
        >
      </mt-tab-container-item>
      <mt-tab-container-item id="2">
        <div class="form-block">
          <mt-field
            :label="$t('可转金额')"
            :placeholder="$t('可转金额')"
            type="text"
            disabled
            v-model="myMoney[1].availableBalance"
          ></mt-field>
        </div> -->
    <!-- <div class="form-block">
          <mt-field
            :label="$t('转账金额')"
            v-model="form.account2"
            :placeholder="$t('请输入转账金额')"
            type="text"
          >
            <span @click="selectAll2">{{ $t("hj60") }}</span>
          </mt-field>
        </div> -->
    <!-- <div class="btnbox">
          <span class="text-center btnok loginout" @click="tosubmit">{{
            $t("确认转入沙特账户")
          }}</span>
        </div> -->
    <!-- <van-button
          class="but"
          type="primary"
          style="margin-top: 1.04rem; margin-bottom: 1.04rem"
          @click="tosubmit"
          >{{ $t("确认") }}</van-button
        >
      </mt-tab-container-item> -->
    <!-- <mt-tab-container-item id="3">
        <div class="form-block">
          <mt-field label="可转金额" placeholder="可转金额" type="text" disabled v-model="this.$store.state.userInfo.enableAmt">
          </mt-field>
        </div>
        <div class="form-block">
          <mt-field label="转账金额" v-model="form.account3" placeholder="请输入转账金额" type="text">
            <span @click="selectAll3">全部</span>
          </mt-field>
        </div>
        <div class="btnbox">
          <span class="text-center btnok loginout" @click="tosubmit">确认转入黄金原油账户</span>
        </div>
      </mt-tab-container-item>
     -->
    <!-- <mt-tab-container-item id="4">
        <div class="form-block">
          <mt-field label="可转金额" placeholder="可转金额" type="text" disabled
            v-model="this.$store.state.userInfo.enableFuturesAmt"></mt-field>
        </div>
        <div class="form-block">
          <mt-field label="转账金额" v-model="form.account4" placeholder="请输入转账金额" type="text">
            <span @click="selectAll4">全部</span>
          </mt-field>
        </div>
        <div class="btnbox">
          <span class="text-center btnok loginout" @click="tosubmit">确认转入沙特账户</span>
        </div>
      </mt-tab-container-item>
       -->
    <!-- </mt-tab-container> -->
 
    <div class="exchange-wrapper">
      <van-nav-bar
        :title="$t('账户资金互转')"
        left-arrow
        @click-left="$router.go(-1)"
      />
 
      <van-form @submit="onSubmit">
        <!-- 从货币 -->
        <van-cell-group>
          <van-field
            v-model="fromAmount"
            type="number"
            :label="$t('转出金额')"
            :placeholder="$t('请输入转出金额')"
            :rules="[{ required: true, message: $t('请输入转出金额') }]"
          >
            <template #button>
              <van-dropdown-menu active-color="#1989fa">
                <van-dropdown-item
                  v-model="fromCurrency"
                  :options="currencyOptions"
                  disabled
                />
              </van-dropdown-menu>
            </template>
          </van-field>
          <van-field
            v-model="myMoney[my_availableBalance].availableBalance"
            :label="$t('可用余额')"
            disabled
          />
        </van-cell-group>
 
        <!-- 兑换箭头 -->
        <div class="exchange-icon">
          <van-icon name="exchange" size="24" @click="switchCurrency" />
        </div>
 
        <!-- 到货币 -->
        <van-cell-group>
          <van-field
            v-model="toAmount"
            type="number"
            :label="$t('转入金额')"
            :placeholder="$t('转入金额')"
            disabled
          >
            <template #button>
              <van-dropdown-menu active-color="#1989fa">
                <van-dropdown-item
                  v-model="toCurrency"
                  :options="currencyOptions"
                  disabled
                />
              </van-dropdown-menu>
            </template>
          </van-field>
        </van-cell-group>
 
        <!-- 汇率显示 -->
        <!-- <van-cell title="汇率" :value="exchangeRate" /> -->
 
        <!-- 提交按钮 -->
        <div style="margin: 16px;">
          <van-button
            class="but"
            type="primary"
            style="margin-top: 1.04rem; margin-bottom: 1.04rem"
            native-type="submit"
          >
            {{ $t("确认兑换") }}
          </van-button>
        </div>
      </van-form>
    </div>
  </div>
</template>
 
<script>
// import '@/assets/style/common.less'
import * as api from "@/axios/api";
import { Toast } from "mint-ui";
 
export default {
  components: {},
  data() {
    return {
      selected: "1", // 选中
 
      form: {
        account1: "",
        account2: "",
        account3: "",
        account4: "",
        password: ""
      },
      userInfo: {
        realName: ""
      },
      myMoney: "",
      my_availableBalance: 0,
      fromCurrency: "USDT",
      toCurrency: "ST",
      fromAmount: "",
      toAmount: "",
      fromBalance: "1000.00",
      exchangeRate: "1 USDT = 100 ST",
      currencyOptions: [
        { text: "USDT", value: "USDT" },
        { text: "ST", value: "ST" }
        // { text: "欧元(EUR)", value: "EUR" },
        // { text: "英镑(GBP)", value: "GBP" }
      ]
    };
  },
  watch: {
    fromAmount() {
      this.calculateAmount();
    },
    fromCurrency() {
      this.calculateAmount();
    },
    toCurrency() {
      this.calculateAmount();
    }
  },
  computed: {
    toCurrencyDisabled() {
      return this.currencyOptions.length <= 1;
    }
  },
  created() {
    this.getProductSetting();
    this.getMoney();
  },
  mounted() {
    if (this.$route.query.type) {
      this.selected = this.$route.query.type + "";
    }
    this.getUserInfo();
  },
  methods: {
    onSubmit() {
      // 处理兑换逻辑
      console.log(
        "提交兑换:",
        this.fromAmount,
        this.fromCurrency,
        "->",
        this.toAmount,
        this.toCurrency
      );
 
      this.tosubmit();
    },
    switchCurrency() {
      // 切换货币方向
      const temp = this.fromCurrency;
      this.fromCurrency = this.toCurrency;
      this.toCurrency = temp;
 
      if (this.fromCurrency === "ST") {
        this.my_availableBalance = 0;
      } else if (this.fromCurrency === "USDT" || this.fromCurrency === "USD") {
        this.my_availableBalance = 1;
      }
      console.log(this.myMoney[this.my_availableBalance].availableBalance);
      this.calculateAmount();
    },
    calculateAmount() {
      // 这里应该调用汇率API计算金额
      // 示例简单计算
      if (this.fromAmount && this.fromCurrency && this.toCurrency) {
        const rate =
          this.fromCurrency === "USDT" && this.toCurrency === "ST" ? 100 : 1;
        this.toAmount = (this.fromAmount * rate).toFixed(2);
      }
    },
    onClickLeft() {
      this.$router.push("/user");
    },
    async getProductSetting() {
      let data = await api.getProductSetting();
      if (data.status === 0) {
        this.$store.state.settingForm = data.data;
        if (!this.$store.state.settingForm.indexDisplay) {
          this.selected = "3";
        }
      } else {
        this.$message.error(data.msg);
      }
    },
    selectAll1() {
      // 选择全部
      this.form.account1 = this.myMoney[0].availableBalance;
    },
    selectAll2() {
      // 选择全部
      this.form.account2 = this.myMoney[1].availableBalance;
    },
    selectAll3() {
      // 选择全部
      this.form.account3 = this.$store.state.userInfo.enableAmt;
    },
    selectAll4() {
      // 选择全部
      this.form.account4 = this.$store.state.userInfo.enableFuturesAmt;
    },
    async tosubmit() {
      // 融资转指数
      let opt = {
        amt: this.fromAmount,
        // type: this.selected, // 1 融资转指数 2 指数转融资
        userId: this.$store.state.userInfo.id, // 用户id
        disbursementAccount: this.fromCurrency, //  划出账户
        depositAccount: this.toCurrency // 划入账户
      };
      let data = await api.transfer(opt);
      if (data.status === 0) {
        Toast(data.msg);
        this.$router.push("/user");
      } else {
        Toast(data.msg);
      }
    },
    async getUserInfo() {
      // 获取用户信息
      let data = await api.getUserInfo();
      if (data.status === 0) {
        this.$store.state.userInfo = data.data;
      } else {
        Toast(data.msg);
      }
    },
    async getMoney() {
      let data = await api.getMoney();
      if (data.status === 0) {
        this.myMoney = data.data;
        if (this.fromCurrency === "ST") {
          this.my_availableBalance = 0;
        } else if (
          this.fromCurrency === "USDT" ||
          this.fromCurrency === "USD"
        ) {
          this.my_availableBalance = 1;
        }
      } else {
        Toast(data.msg);
      }
    }
  }
};
</script>
<style lang="less" scoped>
.payclass {
  width: 150px;
  height: 40px;
  border-radius: 5px;
  border: 1px solid #e5e8ed;
  text-align: center;
  line-height: 40px;
}
.but {
  width: 95%;
  color: #ffffff;
  background-color: #1989fa;
  border-radius: 8px;
  height: 66px;
  font-size: 22px;
  margin-left: 2.5%;
}
.is-selected .mint-tab-item-label:hover {
  text-decoration: none;
}
 
.wrapper /deep/ .mint-tab-item-label {
  font-size: 0.264rem;
}
 
.mint-navbar .mint-tab-item.is-selected {
  // color: #d50000;
  // border-bottom: 2px solid #d50000;
  text-decoration: none;
  margin-bottom: 0;
}
 
.order-list {
  /deep/ .mint-cell {
    background: initial !important;
  }
  /deep/ .mint-cell .mint-cell-text {
    color: #000 !important;
  }
  /deep/ .mint-cell-wrapper {
    line-height: 1 !important;
  }
}
 
.prompt {
  padding: 0.3rem 0 0.2rem 0.7rem;
}
 
.exchange-wrapper {
  padding-bottom: 20px;
}
 
.exchange-icon {
  display: flex;
  justify-content: center;
  margin: 15px 0;
  color: #1989fa;
}
 
.van-dropdown-menu {
  width: 120px;
  height: 44px;
}
</style>