buy-option-form.vue 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270
  1. <template>
  2. <view>
  3. <view class="icon fn-center m-t-md">
  4. <img :src="$localImgUrl('Turn.png')" @click="$emit('close')" class="w-30" alt="">
  5. </view>
  6. <view class="title fn-15 p-y-sm p-x-md fn-center">
  7. {{$t('option.a5')}}({{query.pair_time_name}})
  8. <text v-if="type==1" class="color-buy">{{$t('miao.a2')}}</text>
  9. <text v-if="type==2" class="color-sell">{{$t('miao.a3')}}</text>
  10. </view>
  11. <!-- <view class="form-item">
  12. <view class="label p-l-md fn-13 color-light m-b-xs">当前价格</view>
  13. <view class="box income-box p-l-md">
  14. <view class="item fn-center d-inline-block rounded-xs bg-panel-4 w-80 m-r-md active">
  15. <view class="label p-y-xs color-light fn-11">价格</view>
  16. <view class="income fn-10 color-light bg-panel-1">25.25469</view>
  17. <img class="tips w-22" src="static/img/active_tips.png"/>
  18. </view>
  19. </view>
  20. </view> -->
  21. <view class="d-flex align-center m-t-sm" v-if="timeList.length">
  22. <view class="label p-x-md fn-13 color-light w-80">{{$t('miao.a4')}}</view>
  23. <v-picker :list="timeList" range-value="id" @change="changeTimeId" range-label="time_name" v-model="timeId" class="form-input p-y-xs m-r-xs flex-1 border-b">
  24. <view class="d-flex align-center justify-between" v-if="timeIndex!=-1">
  25. <view class="d-flex align-center flex-1">
  26. <view class="flex-1 d-flex justify-center">{{timeList[timeIndex].time_name}}</view>
  27. <view class="flex-1 d-flex justify-center">{{timeList[timeIndex].lv}}</view>
  28. </view>
  29. <van-icon name="arrow-down" />
  30. </view>
  31. </v-picker>
  32. </view>
  33. <view class="d-flex align-center m-t-md">
  34. <view class="label p-x-md fn-13 color-light w-80">{{$t('miao.a5')}}</view>
  35. <view class="border-b flex-fill">
  36. <v-input :placeholder="$t('option.b4')" v-model="num" type="number" class="color-light form-input w-max p-y-xs d-flex" />
  37. </view>
  38. </view>
  39. <view class="fn-sm d-flex justify-between p-x-md p-y-xs">
  40. <view>{{$t('miao.a6')}}:{{data.fee}}%</view>
  41. <view>{{$t('miao.a7')}}:{{data.account}}</view>
  42. </view>
  43. <view class="p-md">
  44. <v-button block :type="type==1?'green':'red'" class="w-max rounded-lg" @click="buy" ref="btn">{{$t('option.b7')}}</v-button>
  45. </view>
  46. </view>
  47. </template>
  48. <script>
  49. import Option from "@/api/option";
  50. import Contract from "@/api/contract";
  51. import math from "@/utils/class/math";
  52. export default {
  53. props: ["currentAndNext", "type", "query"],
  54. watch: {
  55. type() {
  56. // 调用接口
  57. },
  58. query() {
  59. // this.getOddsList();
  60. },
  61. currentAndNext() {
  62. // this.getOddsList();
  63. },
  64. },
  65. computed: {
  66. // 类型
  67. typeObj() {
  68. let typeObj = new Object();
  69. switch (this.type) {
  70. }
  71. return typeObj;
  72. },
  73. // 选中倍率
  74. activeRange() {
  75. return (
  76. this.typeObj.rangeList.find((item) => item.uuid == this.rangeUuid) || {}
  77. );
  78. },
  79. // 当前场次
  80. current_scene() {
  81. return this.currentAndNext.current_scene || {};
  82. },
  83. // 下一场
  84. next_scene() {
  85. return this.currentAndNext.next_scene || {};
  86. },
  87. // 选中币种
  88. activeCoin() {
  89. return this.coinList.find((item) => item.id == this.activeCoinId) || {};
  90. },
  91. // 使用资产所占总资产额度
  92. moneyStep() {
  93. if (!this.activeCoin.balance || !this.activeCoin.balance * 1) return 3;
  94. let rate = this.num / (this.activeCoin.balance * 1);
  95. if (rate < 0.25) return 0;
  96. if (rate < 0.5) return 1;
  97. if (rate < 0.75) return 2;
  98. if (rate < 1) return 3;
  99. return 4;
  100. },
  101. // 涨跌幅列表
  102. rangeList() {
  103. return this.typeObj.rangeList.map((item) => {
  104. return {
  105. value: item.uuid,
  106. label: `${this.typeObj.typeText}≥${item.range}% ${this.$t("option.a4")} ${item.odds}`,
  107. };
  108. });
  109. },
  110. },
  111. data() {
  112. return {
  113. detail: {},
  114. rangeUuid: "",
  115. num: "",
  116. coinList: [],
  117. activeCoinId: "",
  118. selectAmount:[
  119. 100,200,300,1000
  120. ],
  121. timeList:[],
  122. timeId:1,
  123. timeIndex:0,
  124. data:[]
  125. };
  126. },
  127. methods: {
  128. changeTimeId(val,index,item){
  129. this.timeId = val
  130. this.timeIndex = index
  131. this.$forceUpdate()
  132. },
  133. // 获取预计收益
  134. expected(num1, num2) {
  135. if (!num1 || !num2) return "0";
  136. return math.multiple(num1, num2);
  137. },
  138. getOddsList() {
  139. let data = {
  140. pair_id: this.query.pair_id,
  141. time_id: this.query.time_id,
  142. };
  143. // Option.getOddsList(data).then((res) => {
  144. // this.detail = res.data;
  145. // this.rangeUuid = this.typeObj.rangeList[0].uuid;
  146. // });
  147. },
  148. selectCoin() {
  149. let arr = this.coinList.map((item) => {
  150. return {
  151. value: item.id,
  152. label: item.coin_name,
  153. };
  154. });
  155. this.$picker(arr, { value: this.activeCoinId })
  156. .then((res) => {
  157. this.activeCoinId = res;
  158. this.checkCoin(this.activeCoin);
  159. })
  160. .catch(() => { });
  161. },
  162. // 获取期权交易币种
  163. getBetCoinList() {
  164. Option.getBetCoinList()
  165. .then((res) => {
  166. this.coinList = res.data;
  167. this.activeCoinId = this.coinList[0].id;
  168. this.checkCoin(this.coinList[0]);
  169. })
  170. .catch(() => { });
  171. },
  172. // 选中交易币种 (需要登录)
  173. checkCoin(item) {
  174. let data = {
  175. coin_id: item.coin_id,
  176. };
  177. if (!localStorage.getItem("token")) return;
  178. Option.getUserCoinBalance(data)
  179. .then((res) => {
  180. this.$set(item, "balance", res.data.usable_balance);
  181. })
  182. .catch(() => { });
  183. },
  184. getinfo(){
  185. Contract.marketInfoM({coin_name:this.query.pair_time_name}).then((res)=>{
  186. this.data = res.data
  187. let reteList = res.data.rate.split(",")
  188. let miaoList = res.data.time.split(",")
  189. this.timeList = []
  190. for (let i in reteList) {
  191. this.timeList.push({
  192. lv:reteList[i]+"%",
  193. time_name:miaoList[i]+" "+"sec",
  194. lv_value:reteList[i],
  195. time_value:miaoList[i],
  196. id:i
  197. })
  198. }
  199. })
  200. },
  201. // 购买
  202. buy() {
  203. if(!this.num){
  204. return this.$toast(this.$t('option.b4'))
  205. }
  206. let data = {
  207. trade_money: this.num, //下单金额
  208. type: this.type, //1涨2跌
  209. time: this.timeList[this.timeIndex].time_value, //时间
  210. rate: this.timeList[this.timeIndex].lv_value,//赔率
  211. coin_name:this.query.pair_time_name //币种名称
  212. };
  213. Contract.createOrderM(data).then((res)=>{
  214. if(res.code == 200){
  215. this.getinfo()
  216. this.$toast.success(this.$t("miao.a8"));
  217. // 刷新购买记录
  218. this.$emit('refreshRecord')
  219. this.$emit('close')
  220. }
  221. })
  222. },
  223. },
  224. created() {
  225. this.getOddsList();
  226. this.getBetCoinList();
  227. this.getinfo()
  228. },
  229. };
  230. </script>
  231. <style lang="scss" scoped>
  232. ::v-deep .van-step--horizontal .van-step__circle-container {
  233. background: transparent;
  234. }
  235. .income-box {
  236. width: 100%;
  237. white-space: nowrap;
  238. overflow: auto;
  239. box-sizing: border-box;
  240. .item{
  241. overflow: hidden;
  242. position: relative;
  243. box-sizing: border-box;
  244. .income{
  245. padding: 2px 0;
  246. }
  247. .tips{
  248. position: absolute;
  249. top: 0;
  250. right: 0;
  251. display: none;
  252. }
  253. &.active{
  254. border: 1px solid $red;
  255. .tips{
  256. display: block;
  257. }
  258. }
  259. }
  260. }
  261. .select-amount{
  262. .item{
  263. padding: 5px 0;
  264. }
  265. }
  266. </style>