lever.vue 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341
  1. <template>
  2. <uni-popup ref="popupRef" type="bottom" @change="popupChange" :isMaskClick="false">
  3. <view class="popup-box">
  4. <view class="popup-title">
  5. <text class="title-side"></text>
  6. <text class="title-name">调整杠杆</text>
  7. <text @click.stop="close()" class="title-side iconfont">&#xeca0;</text>
  8. </view>
  9. <view class="popup-content">
  10. <view class="content-tab">
  11. <view @click.stop="pattern.name = '全仓'"
  12. :class="['tab-item' , pattern.name == '全仓' ? 'active-tab-item' : '']">全仓</view>
  13. <view @click.stop="pattern.name = '逐仓'"
  14. :class="['tab-item' , pattern.name == '逐仓' ? 'active-tab-item' : '']">逐仓</view>
  15. </view>
  16. <view class="content-nums">
  17. <text class="nums-alter iconfont" @click.stop="changeLeverNum('minus')">-</text>
  18. <view class="nums-box">
  19. <input ref="numsInpRef" class="nums-inp" @input="patternNumChange" @focus="setCursorNum"
  20. @blur="cursorNum = 0" :cursor="cursorNum" v-model="pattern.num">
  21. </view>
  22. <text class="nums-alter iconfont" @click.stop="changeLeverNum('add')">+</text>
  23. </view>
  24. <view class="content-nums-item">
  25. <text v-for="item in LeverArr" :key="`lever_${item}`" @click.stop="changeLeverItem(item)"
  26. :class="['nums-item', pattern.num == item ? 'active-nums-item' : '']">{{item}}</text>
  27. </view>
  28. <view class="content-hint" v-show="pattern.name == '全仓'">
  29. <text class="hint-lable">全仓模式:</text>
  30. 全仓模式下所有仓位将共享合约账户的可用保证金,若发生强平,交易者可能损失所有仓位和可用保证金,请注意仓位风险!
  31. </view>
  32. <view class="content-hint" v-show="pattern.name == '逐仓'">
  33. <text class="hint-lable">逐仓模式:</text>
  34. 逐仓模式下保证金被分配到单独的仓位上,如果该仓位保证金亏损到低于维持保证金的值,仓位将被强平。您可以通过为仓位添加和减少保证金来控制仓位风险。
  35. </view>
  36. <view class="footer-btns">
  37. <view class="footer-btn" @click.stop="close()">取消</view>
  38. <view class="footer-btn" @click.stop="confirm()">确定</view>
  39. </view>
  40. </view>
  41. </view>
  42. </uni-popup>
  43. </template>
  44. <script>
  45. export default {
  46. props: {
  47. leverNum: {
  48. type: Number,
  49. default: 1
  50. },
  51. leverName: {
  52. type: String,
  53. default: ''
  54. }
  55. },
  56. data() {
  57. return {
  58. pattern: {
  59. name: '全仓',
  60. num: '',
  61. },
  62. LeverArr: ['5X', '10X', '20X', '50X', '100X'],
  63. cursorNum: 0,
  64. };
  65. },
  66. watch: {
  67. leverNum: {
  68. handler(newVal) {
  69. this.pattern.num = newVal + 'X';
  70. },
  71. immediate: true
  72. },
  73. leverName: {
  74. handler(newVal) {
  75. this.pattern.name = newVal
  76. },
  77. immediate: true
  78. },
  79. "pattern.num"(newVal, oldVal) {
  80. if (newVal !== oldVal) {
  81. let numStr = newVal
  82. console.log('numStr = ' , numStr)
  83. if (numStr.indexOf('X') >= 0) {
  84. numStr = numStr.split('X')[0]
  85. }
  86. numStr = newVal.replace(/[^0-9]/ig, "");
  87. if (numStr > 100) {
  88. numStr = 100
  89. } else if (numStr < 1) {
  90. numStr = 1
  91. }
  92. setTimeout(() => {
  93. this.$set(this.pattern , 'num' , `${numStr}X`);
  94. }, 0)
  95. }
  96. }
  97. },
  98. mounted() {
  99. // this.open();
  100. },
  101. methods: {
  102. popupChange(e) {
  103. try {
  104. if (e && e.show) {
  105. uni.hideTabBar()
  106. } else {
  107. setTimeout(() => {
  108. uni.showTabBar()
  109. }, 10)
  110. }
  111. } catch (e) {
  112. //TODO handle the exception
  113. }
  114. },
  115. // close(type) {
  116. // this.showTrans = false
  117. // this.$emit('change', {
  118. // show: false,
  119. // type: this.type
  120. // })
  121. open() {
  122. // this.pattern.num = this.leverNum;
  123. // this.pattern.name = this.leverName;
  124. this.$nextTick(() => {
  125. this.$refs.popupRef.open();
  126. })
  127. },
  128. close() {
  129. this.$refs.popupRef.close();
  130. },
  131. confirm() {
  132. let nums = this.pattern.num
  133. if ( nums.indexOf('X') >= 0) {
  134. nums = nums.split('X')[0] - 0
  135. }
  136. this.$emit('update:leverNum', nums);
  137. this.$emit('update:leverName', this.pattern.name);
  138. this.close()
  139. },
  140. changeLeverItem(e) {
  141. this.pattern.num = e;
  142. },
  143. setCursorNum() {
  144. // this.$refs.numsInpRef
  145. console.log('eee')
  146. // this.leverNum.length - 1
  147. setTimeout(() => {
  148. this.cursorNum = 1
  149. }, 1)
  150. },
  151. // 输入修改
  152. patternNumChange() {
  153. // this.$set()
  154. },
  155. //
  156. changeLeverNum(type) {
  157. let nums = this.pattern.num
  158. if (this.pattern.num.indexOf('X') >= 0) {
  159. nums = nums.split('X')[0]
  160. }
  161. if (type === 'minus') {
  162. // 减
  163. if (nums > 1) {
  164. nums = nums - 1
  165. } else {
  166. nums = 1
  167. }
  168. } else if (type === 'add') {
  169. // 加
  170. if (nums < 100) {
  171. // - 0 是防止出现字符串
  172. nums = nums - 0 + 1
  173. } else {
  174. nums = 100
  175. }
  176. };
  177. this.pattern.num = `${nums}X`
  178. },
  179. }
  180. }
  181. </script>
  182. <style lang="scss" scoped>
  183. .popup-content {
  184. padding: 0 $pages-padding;
  185. .content-tab {
  186. padding: 20rpx 0;
  187. display: flex;
  188. justify-content: space-between;
  189. align-items: center;
  190. .tab-item {
  191. width: 48%;
  192. height: 70rpx;
  193. text-align: center;
  194. border: 1rpx solid $border-color4;
  195. line-height: 70rpx;
  196. font-size: 26rpx;
  197. border-radius: 10rpx;
  198. // font-weight: bold;
  199. }
  200. .active-tab-item {
  201. border-color: $Theme-Color;
  202. color: $Theme-Color;
  203. }
  204. }
  205. .content-nums {
  206. width: 100%;
  207. display: flex;
  208. justify-content: space-between;
  209. align-items: stretch;
  210. padding: 40rpx 0 20rpx;
  211. .nums-alter {
  212. flex-shrink: 0;
  213. width: 80rpx;
  214. height: 80rpx;
  215. text-align: center;
  216. line-height: 80rpx;
  217. border: 1px solid $border-color6;
  218. font-size: 26rpx;
  219. color: $Theme-Color;
  220. &:last-child {
  221. border-radius: 0 10rpx 10rpx 0;
  222. }
  223. &:first-child {
  224. border-radius: 10rpx 0 0 10rpx;
  225. }
  226. }
  227. .nums-box {
  228. flex: 1;
  229. border-top: 1px solid $border-color6;
  230. border-bottom: 1px solid $border-color6;
  231. position: relative;
  232. .nums-inp {
  233. width: 100%;
  234. height: 100%;
  235. text-align: center;
  236. font-size: 28rpx;
  237. font-weight: bold;
  238. }
  239. .nums-t {
  240. position: absolute;
  241. left: 0;
  242. top: 0;
  243. width: 100%;
  244. height: 100%;
  245. }
  246. // <input class="nums-inp" type="text" v-model="leverNum">
  247. // <text class="nums-inp-tag">X</text>
  248. }
  249. }
  250. .content-nums-item {
  251. width: 100%;
  252. display: flex;
  253. justify-content: space-between;
  254. align-items: stretch;
  255. .nums-item {
  256. width: calc((100% - 40rpx) / 5);
  257. height: 54rpx;
  258. border: 1rpx solid $border-color4;
  259. border-radius: 6rpx;
  260. text-align: center;
  261. line-height: 52rpx;
  262. font-size: 26rpx;
  263. }
  264. .active-nums-item {
  265. background-color: $Theme-Color;
  266. border-color: $Theme-Color;
  267. color: #fff;
  268. }
  269. }
  270. .content-hint {
  271. width: 100%;
  272. font-size: 24rpx;
  273. color: #8d8a8a;
  274. line-height: 1.8;
  275. padding-top: 20rpx;
  276. .hint-lable {
  277. font-size: 24rpx;
  278. color: $Theme-Color;
  279. font-weight: bold;
  280. }
  281. }
  282. .footer-btns {
  283. padding: 80rpx 0 26rpx;
  284. display: flex;
  285. justify-content: space-between;
  286. align-items: stretch;
  287. .footer-btn {
  288. width: 47.5%;
  289. height: 70rpx;
  290. text-align: center;
  291. border: 1rpx solid $Theme-Color;
  292. line-height: 68rpx;
  293. font-size: 30rpx;
  294. border-radius: 10rpx;
  295. color: $Theme-Color;
  296. &:last-child {
  297. color: #fff;
  298. background-color: $Theme-Color;
  299. }
  300. }
  301. }
  302. // <view class="footer-btns">
  303. // <view class="footer-btn">取消</view>
  304. // <view class="footer-btn">确定</view>
  305. // </view>
  306. }
  307. </style>