lever.vue 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342
  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. console.log('this.pattern.num' , this.pattern.num)
  71. },
  72. immediate: true
  73. },
  74. leverName: {
  75. handler(newVal) {
  76. this.pattern.name = newVal
  77. },
  78. immediate: true
  79. },
  80. "pattern.num"(newVal, oldVal) {
  81. if (newVal !== oldVal) {
  82. let numStr = newVal
  83. console.log('numStr = ' , numStr)
  84. if (numStr.indexOf('X') >= 0) {
  85. numStr = numStr.split('X')[0]
  86. }
  87. numStr = newVal.replace(/[^0-9]/ig, "");
  88. if (numStr > 100) {
  89. numStr = 100
  90. } else if (numStr < 1) {
  91. numStr = 1
  92. }
  93. setTimeout(() => {
  94. this.$set(this.pattern , 'num' , `${numStr}X`);
  95. }, 0)
  96. }
  97. }
  98. },
  99. mounted() {
  100. // this.open();
  101. },
  102. methods: {
  103. popupChange(e) {
  104. try {
  105. if (e && e.show) {
  106. uni.hideTabBar()
  107. } else {
  108. setTimeout(() => {
  109. uni.showTabBar()
  110. }, 10)
  111. }
  112. } catch (e) {
  113. //TODO handle the exception
  114. }
  115. },
  116. // close(type) {
  117. // this.showTrans = false
  118. // this.$emit('change', {
  119. // show: false,
  120. // type: this.type
  121. // })
  122. open() {
  123. // this.pattern.num = this.leverNum;
  124. // this.pattern.name = this.leverName;
  125. this.$nextTick(() => {
  126. this.$refs.popupRef.open();
  127. })
  128. },
  129. close() {
  130. this.$refs.popupRef.close();
  131. },
  132. confirm() {
  133. let nums = this.pattern.num
  134. if ( nums.indexOf('X') >= 0) {
  135. nums = nums.split('X')[0] - 0
  136. }
  137. this.$emit('update:leverNum', nums);
  138. this.$emit('update:leverName', this.pattern.name);
  139. this.close()
  140. },
  141. changeLeverItem(e) {
  142. this.pattern.num = e;
  143. },
  144. setCursorNum() {
  145. // this.$refs.numsInpRef
  146. console.log('eee')
  147. // this.leverNum.length - 1
  148. setTimeout(() => {
  149. this.cursorNum = 1
  150. }, 1)
  151. },
  152. // 输入修改
  153. patternNumChange() {
  154. // this.$set()
  155. },
  156. //
  157. changeLeverNum(type) {
  158. let nums = this.pattern.num
  159. if (this.pattern.num.indexOf('X') >= 0) {
  160. nums = nums.split('X')[0]
  161. }
  162. if (type === 'minus') {
  163. // 减
  164. if (nums > 1) {
  165. nums = nums - 1
  166. } else {
  167. nums = 1
  168. }
  169. } else if (type === 'add') {
  170. // 加
  171. if (nums < 100) {
  172. // - 0 是防止出现字符串
  173. nums = nums - 0 + 1
  174. } else {
  175. nums = 100
  176. }
  177. };
  178. this.pattern.num = `${nums}X`
  179. },
  180. }
  181. }
  182. </script>
  183. <style lang="scss" scoped>
  184. .popup-content {
  185. padding: 0 $pages-padding;
  186. .content-tab {
  187. padding: 20rpx 0;
  188. display: flex;
  189. justify-content: space-between;
  190. align-items: center;
  191. .tab-item {
  192. width: 48%;
  193. height: 70rpx;
  194. text-align: center;
  195. border: 1rpx solid $border-color4;
  196. line-height: 70rpx;
  197. font-size: 26rpx;
  198. border-radius: 10rpx;
  199. // font-weight: bold;
  200. }
  201. .active-tab-item {
  202. border-color: $Theme-Color;
  203. color: $Theme-Color;
  204. }
  205. }
  206. .content-nums {
  207. width: 100%;
  208. display: flex;
  209. justify-content: space-between;
  210. align-items: stretch;
  211. padding: 40rpx 0 20rpx;
  212. .nums-alter {
  213. flex-shrink: 0;
  214. width: 80rpx;
  215. height: 80rpx;
  216. text-align: center;
  217. line-height: 80rpx;
  218. border: 1px solid $border-color6;
  219. font-size: 26rpx;
  220. color: $Theme-Color;
  221. &:last-child {
  222. border-radius: 0 10rpx 10rpx 0;
  223. }
  224. &:first-child {
  225. border-radius: 10rpx 0 0 10rpx;
  226. }
  227. }
  228. .nums-box {
  229. flex: 1;
  230. border-top: 1px solid $border-color6;
  231. border-bottom: 1px solid $border-color6;
  232. position: relative;
  233. .nums-inp {
  234. width: 100%;
  235. height: 100%;
  236. text-align: center;
  237. font-size: 28rpx;
  238. font-weight: bold;
  239. }
  240. .nums-t {
  241. position: absolute;
  242. left: 0;
  243. top: 0;
  244. width: 100%;
  245. height: 100%;
  246. }
  247. // <input class="nums-inp" type="text" v-model="leverNum">
  248. // <text class="nums-inp-tag">X</text>
  249. }
  250. }
  251. .content-nums-item {
  252. width: 100%;
  253. display: flex;
  254. justify-content: space-between;
  255. align-items: stretch;
  256. .nums-item {
  257. width: calc((100% - 40rpx) / 5);
  258. height: 54rpx;
  259. border: 1rpx solid $border-color4;
  260. border-radius: 6rpx;
  261. text-align: center;
  262. line-height: 52rpx;
  263. font-size: 26rpx;
  264. }
  265. .active-nums-item {
  266. background-color: $Theme-Color;
  267. border-color: $Theme-Color;
  268. color: #fff;
  269. }
  270. }
  271. .content-hint {
  272. width: 100%;
  273. font-size: 24rpx;
  274. color: #8d8a8a;
  275. line-height: 1.8;
  276. padding-top: 20rpx;
  277. .hint-lable {
  278. font-size: 24rpx;
  279. color: $Theme-Color;
  280. font-weight: bold;
  281. }
  282. }
  283. .footer-btns {
  284. padding: 80rpx 0 26rpx;
  285. display: flex;
  286. justify-content: space-between;
  287. align-items: stretch;
  288. .footer-btn {
  289. width: 47.5%;
  290. height: 70rpx;
  291. text-align: center;
  292. border: 1rpx solid $Theme-Color;
  293. line-height: 68rpx;
  294. font-size: 30rpx;
  295. border-radius: 10rpx;
  296. color: $Theme-Color;
  297. &:last-child {
  298. color: #fff;
  299. background-color: $Theme-Color;
  300. }
  301. }
  302. }
  303. // <view class="footer-btns">
  304. // <view class="footer-btn">取消</view>
  305. // <view class="footer-btn">确定</view>
  306. // </view>
  307. }
  308. </style>