calculator.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493
  1. <template>
  2. <view>
  3. <headContent borderBottom>
  4. <template #left>
  5. <reverse-back />
  6. </template>
  7. <template #content>
  8. <view class="haed-title">
  9. 合约计算器
  10. </view>
  11. </template>
  12. </headContent>
  13. <view class="pages-lable">
  14. <text @click.stop="lableIndex = 0" :class="['lable-val' , lableIndex === 0 ? 'active-lable-val' : '']">收益</text>
  15. <text @click.stop="lableIndex = 1" :class="['lable-val' , lableIndex === 1 ? 'active-lable-val' : '']">平仓价格</text>
  16. <text @click.stop="lableIndex = 2" :class="['lable-val' , lableIndex === 2 ? 'active-lable-val' : '']">强平价格</text>
  17. </view>
  18. <view class="pages-content">
  19. <view class="currency">
  20. BTC/USDT 永续 <text class="currency-moer iconfont">&#xe8b5;</text>
  21. </view>
  22. <view class="type-box hold-position" v-show="[ 2].includes(lableIndex)">
  23. <view class="type-btn" @click.stop="storehouse === 1 ? storehouse = 2 : storehouse = 1">
  24. <text>{{ storehouse === 1 ? '逐仓' : '全仓'}}</text>
  25. <text :class="['iconfont' , true ? 'active-iconfont' : '']">&#xe672;</text>
  26. </view>
  27. <view class="type-btn" @click.stop="oddEven === 1 ? oddEven = 2 : oddEven = 1">
  28. <!-- oddEven:1 , // 1 单向持仓 2 -->
  29. <text>{{ oddEven === 1 ? '单向持仓' : '双向持仓' }}</text>
  30. <text :class="['iconfont' , storehouse === 2 ? 'active-iconfont' : '']">&#xe672;</text>
  31. </view>
  32. </view>
  33. <!-- 收益 / 强行平仓才有 -->
  34. <view class="type-box more-empty">
  35. <view :class="['type-btn' , more_empty === 1 ? 'active-more' : '']">
  36. <text>做多</text>
  37. </view>
  38. <view :class="['type-btn' , more_empty === 1 ? 'active-few' : '']">
  39. <text>做空</text>
  40. </view>
  41. </view>
  42. <view class="content-nums">
  43. <!-- @click.stop="changeLeverNum('minus')" -->
  44. <text class="nums-alter iconfont">-</text>
  45. <view class="nums-box">
  46. <!-- @input="patternNumChange" @focus="setCursorNum"
  47. @blur="cursorNum = 0" :cursor="cursorNum" -->
  48. <input ref="numsInpRef" class="nums-inp" v-model="pattern.num">
  49. </view>
  50. <!-- @click.stop="changeLeverNum('add')" -->
  51. <text class="nums-alter iconfont">+</text>
  52. </view>
  53. <view class="content-nums-item">
  54. <text v-for="item in LeverArr" :key="`lever_${item}`" @click.stop="changeLeverItem(item)"
  55. :class="['nums-item', pattern.num == item ? 'active-nums-item' : '']">{{item}}</text>
  56. </view>
  57. <view class="selected">
  58. 当前杠杆倍数已选:{{ pattern.num }}
  59. </view>
  60. <view class="inp-item">
  61. <text class="inp-item-lable">开仓价格</text>
  62. <view class="inp-item-val">
  63. <input class="inp-item-inp" type="text" placeholder-class="placeholder-class" placeholder="0.0">
  64. <text class="inp-item-tag">USDT</text>
  65. </view>
  66. </view>
  67. <view class="inp-item">
  68. <text class="inp-item-lable">平仓价格</text>
  69. <view class="inp-item-val">
  70. <input class="inp-item-inp" type="text" placeholder-class="placeholder-class" placeholder="0.0">
  71. <text class="inp-item-tag">USDT</text>
  72. </view>
  73. </view>
  74. <view class="inp-item">
  75. <text class="inp-item-lable">开仓数量</text>
  76. <view class="inp-item-val">
  77. <input class="inp-item-inp" type="text" placeholder-class="placeholder-class" placeholder="0.0">
  78. <text class="inp-item-tag">张</text>
  79. </view>
  80. </view>
  81. <view class="result">
  82. <text class="result-lable">计算结果</text>
  83. <view class="result-item">
  84. <text class="result-item-lable">保证金</text>
  85. <text>0 <text class="item-lable-tag">USDT</text> </text>
  86. </view>
  87. <view class="result-item">
  88. <text class="result-item-lable">收益</text>
  89. <text>0 <text class="item-lable-tag">USDT</text> </text>
  90. </view>
  91. <view class="result-item">
  92. <text class="result-item-lable">收益率</text>
  93. <text>0.0</text>
  94. </view>
  95. <view class="result-hint">
  96. <text class="result-hint-star">*</text>
  97. <text>以上计算结果仅供参考</text>
  98. </view>
  99. </view>
  100. <view class="count-btn">计算</view>
  101. </view>
  102. </view>
  103. </template>
  104. <script>
  105. export default {
  106. data() {
  107. return {
  108. lableIndex: 0,
  109. more_empty: 1, // 1: 做多 , 2: 做空
  110. pattern: {
  111. num: '', // 杠杆
  112. },
  113. storehouse:1 , // 1 逐仓 2 全仓
  114. oddEven:1 , // 1 单向持仓 2 双向全仓
  115. LeverArr: ['5X', '10X', '20X', '50X', '100X'],
  116. };
  117. },
  118. watch: {
  119. "pattern.num": {
  120. handler(newVal, oldVal) {
  121. if (newVal !== oldVal) {
  122. let numStr = newVal
  123. console.log('numStr = ', numStr)
  124. if (numStr.indexOf('X') >= 0) {
  125. numStr = numStr.split('X')[0]
  126. }
  127. numStr = newVal.replace(/[^0-9]/ig, "");
  128. console.log('numStr = ', numStr)
  129. if (numStr > 100) {
  130. numStr = 100
  131. } else if (numStr < 1) {
  132. numStr = 1
  133. }
  134. setTimeout(() => {
  135. this.$set(this.pattern, 'num', `${numStr}X`);
  136. }, 0)
  137. }
  138. },
  139. immediate: true
  140. }
  141. },
  142. methods: {
  143. changeLeverItem(e) {
  144. this.pattern.num = e;
  145. },
  146. }
  147. }
  148. </script>
  149. <style lang="scss" scoped>
  150. // <view class="pages-lable">
  151. // <text class="lable-val">收益</text>
  152. // <text class="lable-val">平仓价格</text>
  153. // <text class="lable-val">强平价格</text>
  154. // </view>
  155. .pages-lable {
  156. width: 100%;
  157. height: 90rpx;
  158. border-bottom: 1rpx solid $border-color;
  159. padding: 0 80rpx;
  160. display: flex;
  161. justify-content: space-between;
  162. align-items: stretch;
  163. .lable-val {
  164. display: flex;
  165. align-items: center;
  166. font-size: 28rpx;
  167. }
  168. .active-lable-val {
  169. position: relative;
  170. color: $Theme-Color;
  171. &::before {
  172. content: '';
  173. position: absolute;
  174. left: 50%;
  175. bottom: 0;
  176. transform: translateX(-50%);
  177. width: 30rpx;
  178. height: 8rpx;
  179. border-radius: 4rpx;
  180. background-color: $Theme-Color;
  181. }
  182. }
  183. }
  184. .pages-content {
  185. padding: 0 $pages-padding;
  186. .currency {
  187. width: 100%;
  188. height: 90rpx;
  189. font-size: 26rpx;
  190. padding-bottom: 14rpx;
  191. line-height: 1;
  192. font-weight: bold;
  193. display: flex;
  194. align-items: center;
  195. .currency-moer {
  196. font-size: 28rpx;
  197. color: $Theme-Color;
  198. transform: rotate(-180deg);
  199. }
  200. }
  201. // <view class="type-box">
  202. // <view class="type-btn">
  203. // <text>逐仓</text>
  204. // <text class="iconfont">&#xe672;</text>
  205. // </view>
  206. // <view class="type-btn">
  207. // <text>逐仓</text>
  208. // <text class="iconfont">&#xe672;</text>
  209. // </view>
  210. // </view>
  211. // <view class="type-box">
  212. // <view class="type-btn">
  213. // <text>做多</text>
  214. // </view>
  215. // <view class="type-btn">
  216. // <text>做空</text>
  217. // </view>
  218. // </view>
  219. .type-box {
  220. width: 100%;
  221. height: 70rpx;
  222. margin-bottom: 30rpx;
  223. display: flex;
  224. align-items: stretch;
  225. justify-content: space-between;
  226. .type-btn {
  227. flex: 1;
  228. flex-shrink: 0;
  229. display: flex;
  230. justify-content: center;
  231. align-items: center;
  232. background-color: $bg_01;
  233. border-radius: 8rpx;
  234. font-size: 30rpx;
  235. position: relative;
  236. color: $SizeColor;
  237. .iconfont {
  238. position: absolute;
  239. right: 20rpx;
  240. top: 50%;
  241. transform: translateY(-50%);
  242. font-size: 24rpx;
  243. color: $SizeColor1;
  244. }
  245. .active-iconfont {
  246. color: $Theme-Color;
  247. }
  248. }
  249. }
  250. .hold-position {
  251. .type-btn+.type-btn {
  252. margin-left: 10rpx;
  253. }
  254. }
  255. .more-empty {
  256. .active-more {
  257. background-color: $Theme-Color;
  258. color: #fff;
  259. }
  260. .active-few {
  261. background-color: $Theme-Color3;
  262. color: #fff;
  263. }
  264. }
  265. .content-nums {
  266. width: 100%;
  267. display: flex;
  268. justify-content: space-between;
  269. align-items: stretch;
  270. padding: 0 0 20rpx;
  271. .nums-alter {
  272. flex-shrink: 0;
  273. width: 80rpx;
  274. height: 80rpx;
  275. text-align: center;
  276. line-height: 80rpx;
  277. border: 1px solid $border-color6;
  278. font-size: 26rpx;
  279. color: $Theme-Color;
  280. &:last-child {
  281. border-radius: 0 10rpx 10rpx 0;
  282. }
  283. &:first-child {
  284. border-radius: 10rpx 0 0 10rpx;
  285. }
  286. }
  287. .nums-box {
  288. flex: 1;
  289. border-top: 1px solid $border-color6;
  290. border-bottom: 1px solid $border-color6;
  291. position: relative;
  292. .nums-inp {
  293. width: 100%;
  294. height: 100%;
  295. text-align: center;
  296. font-size: 28rpx;
  297. font-weight: bold;
  298. }
  299. .nums-t {
  300. position: absolute;
  301. left: 0;
  302. top: 0;
  303. width: 100%;
  304. height: 100%;
  305. }
  306. }
  307. }
  308. .content-nums-item {
  309. width: 100%;
  310. display: flex;
  311. justify-content: space-between;
  312. align-items: stretch;
  313. .nums-item {
  314. width: calc((100% - 40rpx) / 5);
  315. height: 60rpx;
  316. border: 1rpx solid $border-color4;
  317. border-radius: 6rpx;
  318. text-align: center;
  319. line-height: 58rpx;
  320. font-size: 26rpx;
  321. }
  322. .active-nums-item {
  323. background-color: $Theme-Color;
  324. border-color: $Theme-Color;
  325. color: #fff;
  326. }
  327. }
  328. .selected {
  329. font-size: 20rpx;
  330. height: 80rpx;
  331. line-height: 80rpx;
  332. }
  333. // <view class="inp-item">
  334. // <text class="inp-item-lable">开仓价格</text>
  335. // <view class="inp-item-val">
  336. // <input class="inp-item-inp" type="text">
  337. // <text class="inp-item-tag">USDT</text>
  338. // </view>
  339. // </view>
  340. .inp-item {
  341. width: 100%;
  342. margin-bottom: 30rpx;
  343. .inp-item-lable {
  344. display: inline-block;
  345. font-size: 24rpx;
  346. line-height: 1;
  347. margin-bottom: 16rpx;
  348. }
  349. .inp-item-val {
  350. width: 100%;
  351. height: 76rpx;
  352. border: 1rpx solid $border-color;
  353. display: flex;
  354. justify-content: space-between;
  355. align-items: center;
  356. padding: 0 20rpx;
  357. border-radius: 8rpx;
  358. font-size: 26rpx;
  359. .inp-item-inp {
  360. font-size: 26rpx;
  361. }
  362. .placeholder-class {
  363. font-size: 26rpx;
  364. color: $SizeColor1;
  365. }
  366. .inp-item-tag {
  367. font-size: 24rpx;
  368. font-weight: bold;
  369. color: $SizeColor;
  370. }
  371. }
  372. }
  373. // <view class="result">
  374. // <text class="result-lable">计算结果</text>
  375. // <view class="result-item">
  376. // <text>保证金</text>
  377. // <text>0 <text>USDT</text> </text>
  378. // </view>
  379. // <view class="result-item">
  380. // <text>收益</text>
  381. // <text>0 <text>USDT</text> </text>
  382. // </view>
  383. // <view class="result-item">
  384. // <text>收益率</text>
  385. // <text>0.0</text>
  386. // </view>
  387. // <view class="result-item">
  388. // <text>*</text>
  389. // <text>以上计算结果仅供参考</text>
  390. // </view>
  391. // </view>
  392. .result {
  393. width: 100%;
  394. // display: flex;
  395. .result-lable {
  396. font-size: 28rpx;
  397. }
  398. .result-item {
  399. display: flex;
  400. justify-content: space-between;
  401. padding: 30rpx 0 10rpx;
  402. color: $SizeColor;
  403. font-size: 26rpx;
  404. .result-item-lable {
  405. font-size: 28rpx;
  406. }
  407. .item-lable-tag {
  408. color: #000;
  409. font-size: 24rpx;
  410. font-weight: bold;
  411. padding-left: 20rpx;
  412. }
  413. }
  414. // <view class="result-hint">
  415. // <text class="result-hint-star">*</text>
  416. // <text>以上计算结果仅供参考</text>
  417. // </view>
  418. .result-hint{
  419. font-size: 22rpx;
  420. color: $SizeColor;
  421. padding: 20rpx 0;
  422. .result-hint-star{
  423. padding-right: 6rpx;
  424. }
  425. }
  426. }
  427. .count-btn{
  428. width: 100%;
  429. height: 90rpx;
  430. background-color: $btnBgColor;
  431. border-radius: 10rpx;
  432. text-align: center;
  433. line-height: 90rpx;
  434. font-size: 30rpx;
  435. color: #fff;
  436. margin-bottom: 30rpx;
  437. }
  438. }
  439. </style>