zj
2024-06-03 a1e25849cf08c5580fe139b39d5b58c9d958b455
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
<template>
  <div class="indexdialog dialog-wrapper">
    <el-dialog
      title="期货购买"
      :center='true'
      :visible.sync="DialogVisible"
      width="500px">
      <div class="buy-table">
        <el-tabs v-model="activeName" class="black-style">
          <el-tab-pane label="交易" name="first">
            <!-- 买 -->
            <div class="buy-box">
              <el-form ref="ruleForm" :hide-required-asterisk='true' size="mini" :model="form" :rules="rule"
                       label-width="60px">
                <div class="buy-item">
                  <span class="buy-name">{{futuresInfo.futuresName}}</span><span class="buy-code">{{futuresInfo.futuresCode}}</span>
                </div>
                <el-row class="buy-item">
                  <el-col :span="12">
                    最新:<span
                    :class="((detail.buyPrice - detail.lastClose)/detail.lastClose).toFixed(2) < 0 ?'green price':((detail.buyPrice - detail.lastClose)/detail.lastClose).toFixed(2) > 0 ?'red price':'price'">{{detail.buyPrice}} {{futuresInfo.coinCode}}</span>
                  </el-col>
                  <el-col :span="12">
                    <!-- 涨跌幅: -->
                    <span style="margin-right:20px;"
                          :class="((detail.buyPrice - detail.lastClose)/detail.lastClose).toFixed(2) < 0 ?'green price':((detail.buyPrice - detail.lastClose)/detail.lastClose).toFixed(2) > 0 ?'red price':'price'">{{Number(detail.buyPrice - detail.lastClose).toFixed(2)}} {{futuresInfo.coinCode}}</span>
                    <span
                      :class="((detail.buyPrice - detail.lastClose)/detail.lastClose).toFixed(2) < 0 ?'green price':((detail.buyPrice - detail.lastClose)/detail.lastClose).toFixed(2) > 0 ?'red price':'price'">{{((detail.buyPrice - detail.lastClose)/detail.lastClose).toFixed(2)}}%</span>
                  </el-col>
                </el-row>
                <!-- <el-form-item label="买入价">
                    <el-input v-model="form.stock" placeholder="买入价格">
                        <el-button slot="append" icon="el-icon-search"></el-button>
                    </el-input>
                </el-form-item> -->
                <el-form-item label="手数" prop="buyNum">
                  <el-input placeholder="手数" v-model="form.buyNum" class="input-with-select">
                    <el-select v-model="form.buyNum" title="点击选择手数" slot="prepend" placeholder="请选择">
                      <!-- <el-option label="50手" value="50"></el-option>
                      <el-option label="100手" value="100"></el-option>
                      <el-option label="150手" value="150"></el-option>
                      <el-option label="200手" value="200"></el-option> -->
                      <el-option v-for="i in buyNumList" :key="i.value" :label="i.label" :value="i.value"></el-option>
                    </el-select>
                    <el-button slot="append">手</el-button>
                  </el-input>
                </el-form-item>
                <p class="prompt clearfix">
                  <span class="pull-left">最小购买{{Number(futuresInfo.minNum)}}手</span>
                  <span class="pull-right">最大可购买{{Number(futuresInfo.maxNum)}}手</span>
                </p>
                <el-form-item label="方向" prop="buyType">
                  <el-radio-group v-model="form.buyType">
                    <el-radio label="买涨" value="0"></el-radio>
                    <el-radio label="买跌" value="1"></el-radio>
                  </el-radio-group>
                </el-form-item>
 
                <p class="prompt clearfix">
                  <span class="">{{form.buyNum*futuresInfo.futuresStandard}} {{futuresInfo.futuresUnit}}</span>
                  <span class="pull-right">最大购买金额{{(settingInfo.buyMaxPercent * $store.state.userInfo.enableFuturesAmt).toFixed(2)}}元</span>
                </p>
                <el-row class="buy-item">
                  <el-col :span="24">
                    需要支付:<span class="price">{{total?total:0}} {{futuresInfo.coinCode}}</span>
                    ≈ <span class="price">{{cnyTotal?cnyTotal:0}} CNY</span>
                  </el-col>
                </el-row>
                <p class="prompt clearfix">
                  <span class="pull-right">可用资金:{{$store.state.userInfo.enableFuturesAmt}}元</span>
                </p>
                <el-row class="buy-item text-center" style="font-size:12px;">
                  <!-- <el-checkbox class="check-box" v-model="agree" name="type"></el-checkbox>我同意<a href="javascript:;" @click="tradeDialogVisible = true">《{{siteInfo.tradeAgreeTitle}}》</a> -->
                </el-row>
              </el-form>
              <el-button :loading="loadingBtn" class="buy-button" type="primary" @click="onSubmit('ruleForm')">
                下单
              </el-button>
            </div>
          </el-tab-pane>
        </el-tabs>
        <el-dialog
          :title="siteInfo.tradeAgreeTitle"
          class="agree-dialog"
          :center='true'
          :visible.sync="tradeDialogVisible"
          append-to-body
          width="80%">
          <div class="dialog-iframe">
            <div class="content" style="margin:20px;background:#fff;border-radius:5px;margin-top:60px;line-height:200%;">
                <p v-for="item in tradeAgreeText.split('。')" :key="item">{{item}}。</p>
            </div>
            <!-- <iframe class="iframe-box" :src="$store.state.siteInfo.tradeAgree" frameborder="0"></iframe> -->
            <div slot="footer" class="text-center dialog-footer clearfix">
              <el-button type="primary" @click="agreeTrade">我已阅读并同意{{siteInfo.tradeAgreeTitle}}</el-button>
            </div>
          </div>
        </el-dialog>
      </div>
    </el-dialog>
  </div>
</template>
 
<script>
  import * as api from '../../../axios/api'
  import { Toast } from 'mint-ui'
 
  export default {
    components: {},
    props: {
      futuresInfo: {
        type: Object,
        default () {
          return {
            futuresName: '',
            futuresCode: '',
            currentPoint: '',
            floatPoint: '',
            floatRate: '',
            siteInfo:{}
          }
        }
      },
      handleOptions3: {
        type: Function,
        default: function () {}
      }
    },
    data () {
      return {
        loadingBtn: false, // 下单
        DialogVisible: false,
        tradeDialogVisible: false, //
        loading: false,
        tradeAgreeText: '',
        detail: '', // 当前股票的详情
        activeName: 'first',
        buyNumList: [
          { label: '1手', value: 1 }
        ],
        form: {
          buyNum: '',
          buyType: '',
          lever: ''
        },
        rule: {
          buyNum: [
            { required: true, message: '请输入或选择买入手数', trigger: 'blur' }
          ],
          buyType: [
            { required: true, message: '请选择买卖方向', trigger: 'blur' }
          ]
        },
        settingInfo: {}, // 设置信息
        agree: true, // 协议
        buyNumber: 0, // 下单次数
        exchangeNumber: '' // 获取汇率
      }
    },
    watch: {
      futuresInfo (newVal) {
        if (newVal) {
          this.buyNumList = []
          for (let i = 0; i < 10; i++) {
            if (i === 0 || i % 2 === 1) {
              let val = newVal.minNum * i + newVal.minNum
              let item = { label: val + '手', value: val }
              this.buyNumList.push(item)
            }
          }
          this.getDetail()
          this.queryExchange() // 获取当前基币汇率
        }
      }
    },
    computed: {
      total () {
        if (this.form.buyNum) {
          return (this.futuresInfo.depositAmt * this.form.buyNum).toFixed(2)
        } else {
          return 0
        }
        //   每手保证金 * 手数  = 价钱
      },
      cnyTotal () {
        // 价钱 * 汇率 转为 人民币
        return (this.total * this.exchangeNumber).toFixed(2)
      },
      price () {
        if (this.form.buyNum) {
          return (this.futuresInfo.depositAmt * this.form.buyNum).toFixed(2)
        } else {
          return 0
        }
        // 市值价 = 现价 * 股(1手 = 100股)
      }
    },
    created () {
      // this.timer = setInterval(this.getDetail, 5000)
    },
    beforeDestroy () {
      // clearInterval(this.timer)
    },
    mounted () {
      if (this.$store.state.haslogin) {
        this.getUserInfo()
      }
      this.getSettingInfo()
      this.getInfoSite()
    },
    methods: {
      async queryExchange () {
        // 基币汇率
        let data = await api.queryExchange({ coinCode: this.futuresInfo.coinCode })
        if (data.status === 0) {
          // 成功
          this.exchangeNumber = data.data
        } else {
          Toast(data.msg)
        }
      },
      async getInfoSite () {
        // 获取网站信息
        let result = await api.getInfoSite()
        if (result.status === 0) {
          this.siteInfo = result.data
          this.tradeAgreeText = this.siteInfo.tradeAgreeText
        } else {
          this.$message.error(result.msg)
        }
      },
      async getDetail () {
        let opts = {
          futuresGid: this.futuresInfo.futuresGid
        }
        this.loading = true
        let data = await api.querySingleMarket(opts)
        this.loading = false
        if (data.status === 0) {
          this.detail = data.data
        } else {
          this.$message.error(data.msg)
        }
      },
      async getSettingInfo () {
        // 网站设置信息 期货
        let data = await api.getFuturesSetting()
        if (data.status === 0) {
          // 成功
          this.settingInfo = data.data
        } else {
          this.$message.error(data.msg)
        }
      },
      async getUserInfo () {
        // 获取用户信息
        let data = await api.getUserInfo()
        if (data.status === 0) {
          this.$store.state.userInfo = data.data
        } else {
          this.$message.error(data.msg)
        }
      },
      onSubmit (formName) {
        // 先判断是否登录
        if (!this.$store.state.haslogin) {
          this.$store.state.loginIsShow = true
          this.$message.error('请先登录')
        } else {
          this.$refs[formName].validate(async (valid) => {
            if (valid) {
              if (!this.agree) {
                this.$message.error('阅读并同意注册协议才能下单')
                return
              }
              // 买入
              let opts = {
                FuturesId: this.futuresInfo.id,
                buyNum: this.form.buyNum ? this.form.buyNum : 0,
                buyType: this.form.buyType === '买涨' ? 0 : 1
              }
              this.loadingBtn = true
              let data = await api.buyFutures(opts)
              if (data.status === 0) {
                this.buyNumber++
                this.handleOptions3(this.buyNumber)
                this.$message.success(data.data)
                this.DialogVisible = false
                this.getUserInfo() // 刷新
              } else {
                this.$message.error(data.msg)
              }
              this.loadingBtn = false
            }
          })
        }
      },
      agreeTrade () {
        // 同意注册协议协议
        this.agree = true
        this.tradeDialogVisible = false
      }
    }
  }
</script>
<style lang="less" scoped>
  .nowprice-box {
    height: 40px;
    line-height: 38px;
    color: #8b97b0;
 
    .price {
      font-size: 16px;
    }
  }
 
  .transaction-table .buy-table {
    /deep/ th.is-leaf {
      display: none;
    }
  }
 
  .buy-box {
    .buy-item {
      margin-bottom: 16px;
 
      .price {
        font-size: 16px;
      }
    }
 
    .prompt {
      font-size: 12px;
      color: #606266;
      margin-bottom: 10px;
    }
 
    .buy-name {
      font-size: 16px;
      color: #efbb53;
    }
 
    .buy-code {
      color: #4c5770;
      font-size: 12px;
      margin-left: 10px;
    }
 
    .buy-button {
      width: 100%;
    }
 
    .check-box {
      margin-right: 10px;
    }
 
    /deep/ .el-form-item__label {
      color: #8b97b0;
      text-align: left;
    }
 
    // /deep/ .el-input__inner{
    //     background: #202838;
    //     border-color: #202838;
    // }
    // /deep/ .el-checkbox__inner{
    //     color: #efbb53;
    //     background: #202838;
    // }
    // /deep/ .el-radio__inner{
    //    background: #202838;
    // }
    // 涨
    /deep/ .el-radio__input.is-checked + .el-radio__label {
      color: #c11815;
    }
 
    /deep/ .el-radio__input.is-checked .el-radio__inner {
      border-color: #c11815;
      background: #c11815;
    }
 
    // /deep/ .el-input-group__append{
    //     background: #202838;
    //     border-color: #202838;
    // }
    // /deep/ .el-input-group__prepend{
    //     background: #202838;
    //     border-color: #202838;
    // }
    /deep/ .el-radio {
      color: #8b97b0;
    }
  }
 
  .dialog-iframe {
    .iframe-box {
      width: 100%;
      height: 460px;
    }
 
    .dialog-footer {
      //  height: 300px;
      margin-top: 20px;
    }
  }
 
  // .dialog-wrapper /deep/ .el-dialog{
  //     background: #171e2a;
  //     .el-dialog__body{
  //         padding-top: 0px;
  //     }
  //     .el-dialog__title{
  //         color: #c3d4f7;
  //     }
  // }
</style>