lever.vue 7.3 KB

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