投屏pc端
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

409 lines
14 KiB

6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
  1. <template>
  2. <div class="exchange-warp">
  3. <div class="titlebox">
  4. <div class="el-tabs-title">
  5. <span :class="{'active': dealType == 'E_I_P_T_ASTRICT'}" @click="chooseDealType('E_I_P_T_ASTRICT')">{{$t('限价交易')}}</span>
  6. <span :class="{'active': dealType == 'E_I_P_T_MARKET'}" @click="chooseDealType('E_I_P_T_MARKET')">{{$t('市价交易')}}</span>
  7. <span :class="{'active': dealType == 'E_I_P_T_DYNAMIC'}" @click="chooseDealType('E_I_P_T_DYNAMIC')">{{$t('止盈止损')}}</span>
  8. </div>
  9. <router-link to="/" class="feilv-aa">{{$t('费率')}}</router-link>
  10. </div>
  11. <div class="el-tab-pane">
  12. <div class="exchange-div1">
  13. <div class="list1-div1">
  14. <div class="available">{{$t('可用')}}: {{mainCoinBalance}} {{currentPair.convertType}}</div>
  15. <div class="btn" @click="$router.push('/assets/charge/' + currentPair.convertType)">{{$t('充币')}}</div>
  16. </div>
  17. <!-- 买入表单 -->
  18. <div class="exchange-box1 hc-bgColor2">
  19. <div class="inputbox" style="margin-bottom: 10px" v-if="dealType == 'E_I_P_T_DYNAMIC'">
  20. <span class="buy-span">{{$t('触发价')}}</span>
  21. <el-input :placeholder="$t('请输入触发价')" v-model="buyTriggerPrice" type="text" clearable autocomplete="off" @keyup.enter.native="submitBuy"></el-input>
  22. <span class="bz-span">{{currentPair.convertType}}</span>
  23. </div>
  24. <div class="inputbox">
  25. <span class="buy-span">{{$t('买入价')}}</span>
  26. <el-input :placeholder="$t('请输入买入价格')" v-model="buyPrice" type="text" clearable autocomplete="off" @input="enterBuyPrice" :disabled="dealType == 'E_I_P_T_MARKET'" @keyup.enter.native="submitBuy"></el-input>
  27. <span class="bz-span">{{currentPair.convertType}}</span>
  28. </div>
  29. <div class="text-Price">
  30. <span> 65826.98 CNY</span>
  31. </div>
  32. <div class="inputbox">
  33. <span class="buy-span">{{$t('买入量')}}</span>
  34. <el-input :placeholder="$t('请输入买入数量')" v-model="buyVolumn" type="text" clearable autocomplete="off" @input="enterBuyVolumn" @keyup.enter.native="submitBuy"></el-input>
  35. <span class="bz-span">{{currentPair.dealCoin}}</span>
  36. </div>
  37. <div class="sliderbox">
  38. <el-slider v-model="buyPercent" :step="25" :marks="buyMarks" show-stops @change="buySlider"></el-slider>
  39. </div>
  40. <div class="textbox">
  41. {{$t('交易额')}} <span>{{buySummary}} {{currentPair.convertType}}</span>
  42. </div>
  43. <div class="buy-btnbox" @click="submitBuy">
  44. <el-button class="buy-btn" type="primary" :loading="true" v-if="loading1">{{$t('提交中...')}}</el-button>
  45. <el-button class="buy-btn" type="primary" v-else>{{$t('买入')}} {{currentPair.dealCoin}}</el-button>
  46. </div>
  47. </div>
  48. </div>
  49. <!-- 卖出表单 -->
  50. <div class="exchange-div1">
  51. <div class="list1-div1">
  52. <div class="available">{{$t('可用')}}: {{tradeCoinBalance}} {{currentPair.dealCoin}}</div>
  53. <div class="btn" @click="$router.push('/assets/charge/' + currentPair.dealCoin)">{{$t('充币')}}</div>
  54. </div>
  55. <div class="exchange-box1 hc-bgColor2">
  56. <div class="inputbox" style="margin-bottom: 10px" v-if="dealType == 'E_I_P_T_DYNAMIC'">
  57. <span class="buy-span">{{$t('触发价')}}</span>
  58. <el-input :placeholder="$t('请输入触发价')" v-model="sellTriggerPrice" type="text" clearable autocomplete="off" @keyup.enter.native="submitSell"></el-input>
  59. <span class="bz-span">{{currentPair.convertType}}</span>
  60. </div>
  61. <div class="inputbox">
  62. <span class="buy-span">{{$t('卖出价')}}</span>
  63. <el-input :placeholder="$t('请输入卖出价格')" v-model="sellPrice" type="text" clearable autocomplete="off" :disabled="dealType == 'E_I_P_T_MARKET'" @keyup.enter.native="submitSell"></el-input>
  64. <span class="bz-span">{{currentPair.convertType}}</span>
  65. </div>
  66. <div class="text-Price">
  67. <span> 8512.98 CNY</span>
  68. </div>
  69. <div class="inputbox">
  70. <span class="buy-span">{{$t('卖出量')}}</span>
  71. <el-input :placeholder="$t('请输入卖出数量')" v-model="sellVolumn" type="text" clearable autocomplete="off" @input="enterSellVolumn" @keyup.enter.native="submitSell"></el-input>
  72. <span class="bz-span">{{currentPair.dealCoin}}</span>
  73. </div>
  74. <div class="sliderbox">
  75. <el-slider v-model="sellPercent" :step="25" :marks="sellMarks" show-stops @change="sellSlider"></el-slider>
  76. </div>
  77. <div class="textbox">
  78. {{$t('交易额')}} <span>{{sellSummary}} {{currentPair.convertType}}</span>
  79. </div>
  80. <div class="buy-btnbox" @click="submitSell">
  81. <el-button class="sell-button" type="primary" :loading="true" v-if="loading2">{{$t('提交中...')}}</el-button>
  82. <el-button class="sell-button" type="primary" v-else>{{$t('卖出')}} {{currentPair.dealCoin}}</el-button>
  83. </div>
  84. </div>
  85. </div>
  86. </div>
  87. <!-- 验证支付密码的弹窗 -->
  88. <el-dialog class="user-dialog" :title="$t('验证支付密码')" :visible.sync="showPassword" :before-close="closePassword">
  89. <div class="title-tips">{{$t('支付密码')}}</div>
  90. <div class="address-form-input">
  91. <el-input :placeholder="$t('请输入支付密码')" v-model="payPassword" type="password" clearable autocomplete="off" @keyup.enter.native="submitTrade">
  92. </el-input>
  93. </div>
  94. <div class="title-tips">{{$t('动态验证')}}</div>
  95. <div class="address-form-input">
  96. <el-input class="verify-input" :placeholder="$t('请输入验证码')" v-model="verifyCode" type="text" clearable autocomplete="off" @keyup.enter.native="submitTrade">
  97. </el-input>
  98. <span class="get-code" v-if="isCodeSend">{{iTime + $t('s后重新获取')}}</span>
  99. <span class="get-code" @click="getCode" v-else>{{$t('获取验证码')}}</span>
  100. </div>
  101. <span slot="footer" class="dialog-footer">
  102. <el-button type="primary" :loading="true" v-if="loading3">{{$t('提交中...')}}</el-button>
  103. <el-button type="primary" @click="submitTrade" v-else>{{$t('确定')}}</el-button>
  104. </span>
  105. </el-dialog>
  106. </div>
  107. </template>
  108. <script>
  109. import { mapState } from 'vuex'
  110. let Countdown; //定时器
  111. export default {
  112. name: 'tradeForm',
  113. props: {
  114. mainCoinBalance: String, //主币余额
  115. tradeCoinBalance: String, //交易币余额
  116. },
  117. data() {
  118. return {
  119. dealType: 'E_I_P_T_ASTRICT', //交易类型
  120. dealDirection: 'E_I_D_T_BUY', //交易方向 E_I_D_T_BUY, E_I_D_T_SELL
  121. //买入
  122. buyPrice: '', //价格
  123. buyVolumn: '', //数量
  124. buyTriggerPrice: '', //止盈止损
  125. buyMarks: {0: '0%', 25: '25%', 50: '50%', 75: '75%', 100: '100%'},
  126. buyPercent: 0,
  127. //卖出
  128. sellPrice: '', //价格
  129. sellVolumn: '', //数量
  130. sellTriggerPrice: '', //止盈止损
  131. sellMarks: {0: '0%', 25: '25%', 50: '50%', 75: '75%', 100: '100%'},
  132. sellPercent: 0,
  133. loading1: false, //买入提交
  134. loading2: false, //卖出提交
  135. loading3: false, //支付密码提交
  136. showPassword: false, //密码弹框
  137. payPassword: '', //支付密码
  138. iTime: 60, //验证码倒计时
  139. isCodeSend: false,
  140. verifyCode: '', //验证码
  141. }
  142. },
  143. computed: {
  144. ...mapState('user', ['userInfoData']),
  145. ...mapState('trend', ['allPairList', 'allTrendList', 'myCollectList', 'currentPair']),
  146. maxBuyVolumn() { //最大买入数量
  147. let val = 0;
  148. if (this.buyPrice > 0 && this.buyPrice != '') {
  149. val = this.common.accDiv(this.mainCoinBalance, this.buyPrice); //最大买入量=主币余额÷单价
  150. }
  151. return val;
  152. },
  153. buySummary() { //买入交易额
  154. let val = 0;
  155. if (this.buyPrice && this.buyVolumn) {
  156. val = this.common.accMul(this.buyPrice, this.buyVolumn); //交易额=单价×数量
  157. }
  158. return val;
  159. },
  160. maxSellVolumn() { //最大卖出数量
  161. let val = 0;
  162. if (this.tradeCoinBalance) {
  163. val = this.tradeCoinBalance; //最大卖出量=交易币余额
  164. }
  165. return val;
  166. },
  167. sellSummary() { //卖出交易额
  168. let val = 0;
  169. if (this.sellPrice && this.sellVolumn) {
  170. val = this.common.accMul(this.sellPrice, this.sellVolumn); //交易额=单价×数量
  171. }
  172. return val;
  173. },
  174. },
  175. watch: {
  176. currentPair(newVal) {
  177. if (newVal) {
  178. this.buyPrice = this.currentPair.price;
  179. this.sellPrice = this.currentPair.price;
  180. }
  181. }
  182. },
  183. methods: {
  184. chooseDealType(val) { //切换交易方式
  185. this.dealType = val;
  186. if(val == 'E_I_P_T_MARKET') {
  187. this.buyPrice = this.currentPair.price;
  188. this.sellPrice = this.currentPair.price;
  189. }
  190. this.clearData();
  191. },
  192. enterBuyPrice() { //监听输入买入价格
  193. if (this.buyPrice && this.buyPercent) {
  194. let percent = this.common.accDiv(this.buyPercent, 100);
  195. this.buyVolumn = this.common.accMul(this.maxBuyVolumn, percent);
  196. }
  197. },
  198. enterBuyVolumn() { //监听输入买入数量
  199. if (!this.buyPrice) {
  200. this.$message.warning(this.$t('请先输入价格!'));
  201. this.buyVolumn = '';
  202. this.buyPercent = 0;
  203. return;
  204. } else if (parseFloat(this.buyVolumn) > this.maxBuyVolumn) {
  205. this.$message.warning(this.$t('数量不能超过最大可买入量') + this.maxBuyVolumn);
  206. this.buyVolumn = this.maxBuyVolumn;
  207. this.buyPercent = 100;
  208. } else {
  209. let buy = parseFloat(this.buyVolumn);
  210. this.buyPercent = parseFloat(this.common.accDiv(buy, this.maxBuyVolumn) * 100);
  211. }
  212. },
  213. buySlider(val) { //买入滑块
  214. if (!this.buyPrice) {
  215. this.$message.warning(this.$t('请先输入价格!'));
  216. this.buyVolumn = '';
  217. this.buyPercent = 0;
  218. return;
  219. }
  220. let percent = this.common.accDiv(val, 100);
  221. this.buyVolumn = this.common.accMul(this.maxBuyVolumn, percent);
  222. },
  223. enterSellVolumn() { //监听输入卖出数量
  224. if (parseFloat(this.sellVolumn) > this.maxSellVolumn) {
  225. this.$message.warning(this.$t('数量不能超过最大可卖出量') + this.maxSellVolumn);
  226. this.sellVolumn = this.maxSellVolumn;
  227. this.sellPercent = 100;
  228. } else if(this.sellVolumn) {
  229. let sell = parseFloat(this.sellVolumn);
  230. this.sellPercent = parseFloat(this.common.accDiv(sell, this.maxSellVolumn) * 100);
  231. }
  232. },
  233. sellSlider(val) { //卖出滑块
  234. let percent = this.common.accDiv(val, 100);
  235. this.sellVolumn = this.common.accMul(this.maxSellVolumn, percent);
  236. },
  237. submitBuy() { //买入提交
  238. if (this.loading1) {
  239. return;
  240. }
  241. if(!this.userInfoData.initPayPwd) {
  242. this.$message.error(this.$t('您还未设置支付密码!'));
  243. return;
  244. }
  245. if (!this.buyPrice) {
  246. this.$message.error(this.$t('请输入买入价格!'));
  247. return;
  248. }
  249. if (!this.buyVolumn) {
  250. this.$message.error(this.$t('请输入买入数量!'));
  251. return;
  252. }
  253. if(this.dealType == 'E_I_P_T_DYNAMIC' && !this.buyTriggerPrice) {
  254. this.$message.error(this.$t('请输入触发价!'));
  255. return;
  256. }
  257. this.loading1 = true;
  258. this.dealDirection = 'E_I_D_T_BUY';
  259. this.showPassword = true;
  260. },
  261. submitSell() { //卖出提交
  262. if (this.loading2) {
  263. return;
  264. }
  265. if(!this.userInfoData.initPayPwd) {
  266. this.$message.error(this.$t('您还未设置支付密码!'));
  267. return;
  268. }
  269. if (!this.sellPrice) {
  270. this.$message.error(this.$t('请输入买入价格!'));
  271. return;
  272. }
  273. if (!this.sellVolumn) {
  274. this.$message.error(this.$t('请输入买入数量!'));
  275. return;
  276. }
  277. if(this.dealType == 'E_I_P_T_DYNAMIC' && !this.sellTriggerPrice) {
  278. this.$message.error(this.$t('请输入触发价!'));
  279. return;
  280. }
  281. this.loading2 = true;
  282. this.dealDirection = 'E_I_D_T_SELL';
  283. this.showPassword = true;
  284. },
  285. submitTrade() { //提交挂单
  286. if (this.loading3) {
  287. return;
  288. }
  289. if (!this.payPassword) {
  290. this.$message.error(this.$t('请输入支付密码!'));
  291. return;
  292. }
  293. if (!this.payPassword) {
  294. this.$message.error(this.$t('请输入验证码!'));
  295. return;
  296. }
  297. this.loading3 = true;
  298. let params = {
  299. symbolId: this.currentPair.symbolId, //交易对
  300. caseCode: this.currentPair.caseCode,
  301. dealType: this.dealDirection, //交易方向 买 卖
  302. priceType: this.dealType, //交易类型 限价 市价 止盈止损
  303. price: this.dealDirection == 'E_I_D_T_BUY' ? this.buyPrice : this.sellPrice, //单价
  304. amount: this.dealDirection == 'E_I_D_T_BUY' ? this.buyVolumn : this.sellVolumn, //数量
  305. triggerPrice: this.dealDirection == 'E_I_D_T_BUY' ? this.buyTriggerPrice : this.sellTriggerPrice,
  306. payPwd: this.payPassword,
  307. noteVerifyCode: this.verifyCode,
  308. }
  309. console.log(JSON.stringify(params))
  310. this.postAxios('/api/entrust/info/putup', params)
  311. .then(() => {
  312. this.$message.success('挂单成功!');
  313. this.closePassword();
  314. this.clearData();
  315. this.$emit('updateOrder');
  316. })
  317. .catch(() => {
  318. this.loading3 = false;
  319. })
  320. },
  321. closePassword() { //关闭密码弹窗
  322. this.showPassword = false;
  323. //清除数据
  324. this.payPassword = '';
  325. this.verifyCode = '';
  326. this.loading1 = false;
  327. this.loading2 = false;
  328. this.loading3 = false;
  329. },
  330. clearData() { //清除数据
  331. this.buyVolumn = '';
  332. this.buyPercent = 0;
  333. this.sellVolumn = '';
  334. this.sellPercent = 0;
  335. },
  336. getCode() { //获取验证码
  337. if (this.isCodeSend) {
  338. this.$message.error(this.$t('请勿频繁获取验证码!'))
  339. return;
  340. }
  341. this.isCodeSend = true;
  342. this.getAxios(`/user/api/user/verify/get?verifyType=0`)
  343. .then(() => {
  344. this.$message.success(this.$t('验证码发送成功!'));
  345. this.countdownTimer();
  346. })
  347. .catch(() => {
  348. this.isCodeSend = false;
  349. });
  350. },
  351. countdownTimer() { //短信发送开始计时60s
  352. if (this.iTime === 0) {
  353. clearTimeout(Countdown);
  354. this.isCodeSend = false;
  355. this.iTime = 60;
  356. } else {
  357. Countdown = setTimeout(this.countdownTimer, 1000);
  358. this.iTime = this.iTime - 1;
  359. }
  360. },
  361. },
  362. mounted() {
  363. this.buyPrice = this.currentPair.price;
  364. this.sellPrice = this.currentPair.price;
  365. }
  366. }
  367. </script>
  368. <style>
  369. </style>