buy-option-form copy.vue 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267
  1. <template>
  2. <view>
  3. <view class="title color-light fn-22 p-y-sm p-x-md">
  4. {{$t('option.a5')}}({{query.pair_time_name}}){{$t('option.a0')}} &nbsp;
  5. <text :class="typeObj.color">{{typeObj.typeText}}</text>
  6. </view>
  7. <view class="d-flex justify-between align-center p-x-md border-t border-b p-y-xs">
  8. <view>
  9. {{current_scene.begin_time_text}}
  10. <van-tag plain v-if="type==1" type="success">{{current_scene.status_text}}</van-tag>
  11. <van-tag plain v-else-if="type==2" type>{{current_scene.status_text}}</van-tag>
  12. <van-tag plain v-else-if="type==3" type="danger">{{current_scene.status_text}}</van-tag>
  13. </view>
  14. <view>
  15. <van-count-down class="color-default" :time="current_scene.lottery_time*1000" />
  16. </view>
  17. </view>
  18. <view class="form-item p-x-md m-y-md">
  19. <view class="label fn-lg color-light m-b-xs">{{$t('option.b1')}}</view>
  20. <v-picker class="form-input p-y-xs bg-panel-4 p-x-xs rounded-xs" :list="rangeList" v-model="rangeUuid">
  21. <view class="d-flex justify-between align-center">
  22. <view class="fn-lg color-light">
  23. <text
  24. :class="typeObj.color"
  25. >{{typeObj.direction}} | {{type==2?'±':'≥'}}{{activeRange.range}}%</text>
  26. ({{$t('option.b2')}}:
  27. <text class="color-warning-dark">{{expected(num,activeRange.odds)}}</text>)
  28. </view>
  29. <view>
  30. <van-icon name="arrow-down" />
  31. </view>
  32. </view>
  33. </v-picker>
  34. </view>
  35. <view class="form-item p-x-md m-t-md">
  36. <view class="label fn-lg color-light m-b-xs">{{$t('option.b3')}}</view>
  37. <view class="d-flex bg-panel-4 p-x-xs rounded-xs">
  38. <v-picker
  39. :list="coinList"
  40. range-value="id"
  41. range-label="coin_name"
  42. v-model="activeCoinId"
  43. class="form-input p-y-xs w-80 m-r-xs "
  44. >
  45. <view class="d-flex align-center justify-between">
  46. {{activeCoin.coin_name}}
  47. <van-icon name="arrow-down" />
  48. </view>
  49. </v-picker>
  50. <view class="border-b flex-fill">
  51. <v-input
  52. :placeholder="$t('option.b4')"
  53. v-model="num"
  54. type="number"
  55. class="color-light form-input w-max p-y-xs d-flex"
  56. />
  57. </view>
  58. </view>
  59. </view>
  60. <view class="p-x-xs">
  61. <van-steps :active="moneyStep" :steps="[
  62. {
  63. text:'0%'
  64. },
  65. {
  66. text:''
  67. },
  68. {
  69. text:''
  70. },
  71. {
  72. text:''
  73. },
  74. {
  75. text:'100%'
  76. },
  77. ]">
  78. <!-- <van-step>0%</van-step>
  79. <van-step></van-step>
  80. <van-step></van-step>
  81. <van-step></van-step>
  82. <van-step>100%</van-step> -->
  83. </van-steps>
  84. </view>
  85. <view class="fn-sm d-flex justify-between p-x-md p-y-xs">
  86. <view>{{$t('option.b5')}}:{{activeCoin.balance}}</view>
  87. <view>{{$t('option.b6')}}:{{expected(num,activeRange.odds)}}{{activeCoin.coin_name}}</view>
  88. </view>
  89. <view class="p-md">
  90. <v-button block :type="typeObj.btn" class="w-max rounded-lg" @click="buy" ref="btn">{{$t('option.b7')}}</v-button>
  91. </view>
  92. </view>
  93. </template>
  94. <script>
  95. import Option from "@/api/option";
  96. import math from "@/utils/class/math";
  97. export default {
  98. props: ["currentAndNext", "type", "query"],
  99. watch: {
  100. type() {
  101. if (!this.typeObj.rangeList[0]) return;
  102. this.rangeUuid = this.typeObj.rangeList[0].uuid;
  103. },
  104. query() {
  105. this.getOddsList();
  106. },
  107. currentAndNext() {
  108. this.getOddsList();
  109. },
  110. },
  111. computed: {
  112. // 类型
  113. typeObj() {
  114. let typeObj = new Object();
  115. switch (this.type) {
  116. case 1:
  117. typeObj.typeText = this.$t("option.b8");
  118. typeObj.direction = this.$t("option.a2");
  119. typeObj.color = "color-buy";
  120. typeObj.btn = "green";
  121. typeObj.rangeList = this.detail.up_odds || [];
  122. break;
  123. case 2:
  124. typeObj.typeText = this.$t("option.b9");
  125. typeObj.direction = this.$t("option.b0");
  126. typeObj.btn = "info";
  127. typeObj.rangeList = this.detail.draw_odds || [];
  128. break;
  129. case 3:
  130. typeObj.typeText = this.$t("option.c0");
  131. typeObj.direction = this.$t("option.a3");
  132. typeObj.color = "color-sell";
  133. typeObj.btn = "red";
  134. typeObj.rangeList = this.detail.down_odds || [];
  135. break;
  136. }
  137. return typeObj;
  138. },
  139. // 选中倍率
  140. activeRange() {
  141. return (
  142. this.typeObj.rangeList.find((item) => item.uuid == this.rangeUuid) || {}
  143. );
  144. },
  145. // 当前场次
  146. current_scene() {
  147. return this.currentAndNext.current_scene || {};
  148. },
  149. // 下一场
  150. next_scene() {
  151. return this.currentAndNext.next_scene || {};
  152. },
  153. // 选中币种
  154. activeCoin() {
  155. return this.coinList.find((item) => item.id == this.activeCoinId) || {};
  156. },
  157. // 使用资产所占总资产额度
  158. moneyStep() {
  159. if (!this.activeCoin.balance || !this.activeCoin.balance * 1) return 3;
  160. let rate = this.num / (this.activeCoin.balance * 1);
  161. if (rate < 0.25) return 0;
  162. if (rate < 0.5) return 1;
  163. if (rate < 0.75) return 2;
  164. if (rate < 1) return 3;
  165. return 4;
  166. },
  167. // 涨跌幅列表
  168. rangeList() {
  169. return this.typeObj.rangeList.map((item) => {
  170. return {
  171. value: item.uuid,
  172. label: `${this.typeObj.typeText}≥${item.range}% ${this.$t("option.a4")} ${item.odds}`,
  173. };
  174. });
  175. },
  176. },
  177. data() {
  178. return {
  179. detail: {},
  180. rangeUuid: "",
  181. num: "",
  182. coinList: [],
  183. activeCoinId: "",
  184. };
  185. },
  186. methods: {
  187. // 获取预计收益
  188. expected(num1, num2) {
  189. if (!num1 || !num2) return "0";
  190. return math.multiple(num1, num2);
  191. },
  192. getOddsList() {
  193. let data = {
  194. pair_id: this.query.pair_id,
  195. time_id: this.query.time_id,
  196. };
  197. Option.getOddsList(data).then((res) => {
  198. this.detail = res.data;
  199. this.rangeUuid = this.typeObj.rangeList[0].uuid;
  200. });
  201. },
  202. selectCoin() {
  203. let arr = this.coinList.map((item) => {
  204. return {
  205. value: item.id,
  206. label: item.coin_name,
  207. };
  208. });
  209. this.$picker(arr, { value: this.activeCoinId })
  210. .then((res) => {
  211. this.activeCoinId = res;
  212. this.checkCoin(this.activeCoin);
  213. })
  214. .catch(() => {});
  215. },
  216. // 获取期权交易币种
  217. getBetCoinList() {
  218. Option.getBetCoinList()
  219. .then((res) => {
  220. this.coinList = res.data;
  221. this.activeCoinId = this.coinList[0].id;
  222. this.checkCoin(this.coinList[0]);
  223. })
  224. .catch(() => {});
  225. },
  226. // 选中交易币种 (需要登录)
  227. checkCoin(item) {
  228. let data = {
  229. coin_id: item.coin_id,
  230. };
  231. if (!localStorage.getItem("token")) return;
  232. Option.getUserCoinBalance(data)
  233. .then((res) => {
  234. this.$set(item, "balance", res.data.usable_balance);
  235. })
  236. .catch(() => {});
  237. },
  238. // 购买
  239. buy() {
  240. let data = {
  241. bet_amount: this.num,
  242. bet_coin_id: this.activeCoinId,
  243. odds_uuid: this.rangeUuid,
  244. scene_id: this.next_scene.scene_id,
  245. };
  246. Option.betScene(data, { btn: this.$refs.btn }).then(() => {
  247. this.$emit("close");
  248. this.$emit("success");
  249. this.num = "";
  250. this.$toast.success(this.$t("option.c1"));
  251. this.checkCoin(this.activeCoin);
  252. });
  253. },
  254. },
  255. created() {
  256. this.getOddsList();
  257. this.getBetCoinList();
  258. },
  259. };
  260. </script>
  261. <style lang="scss" scoped>
  262. ::v-deep .van-step--horizontal .van-step__circle-container {
  263. background: transparent;
  264. }
  265. </style>