restrict - 副本.vue 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417
  1. <template>
  2. <uni-popup ref="popupRef" type="bottom">
  3. <view class="popups-box" :rise-fall="stocksColor">
  4. <view class="popups-title">
  5. {{ content ? '持仓止盈止损修改' : '设置止盈止损' }}
  6. <text class="close-icon iconfont" @click.stop="close()">&#xeca0;</text>
  7. </view>
  8. <view class="popups-content">
  9. <template v-if="content">
  10. <view class="content-item">
  11. <text class="content-lable">合约名称</text>
  12. <view class="content-val">
  13. <text class="val-name">{{ content.symbol }}</text>
  14. <text class="val-lever">{{ content.multiple }}倍杠杆</text>
  15. <text class="val-tag">{{ content.type_name }}</text>
  16. </view>
  17. </view>
  18. <view class="content-item">
  19. <text class="content-lable">开仓价格(USDT)</text>
  20. <view class="content-val">
  21. {{ content.origin_price }}
  22. </view>
  23. </view>
  24. <view class="content-item">
  25. <text class="content-lable">标记价格(USDT)</text>
  26. <view class="content-val">
  27. {{ content.update_price }}
  28. </view>
  29. </view>
  30. </template>
  31. <view class="content-restrict">
  32. <view class="restrict-item">
  33. <text class="restrict-lable">止盈</text>
  34. <view class="restrict-btn" v-if="content">
  35. <text class="iconfont">&#xe672;</text>
  36. <text>按比例设置</text>
  37. </view>
  38. </view>
  39. <view class="restrict-input-box">
  40. <input class="restrict-input" v-model="target_profit_price" type="number"
  41. placeholder-class="placeholder-class" placeholder="请输入触发价">
  42. <text class="restrict-tag">USDT</text>
  43. <text class="restrict-btn" @click.stop="target_profit_price = ''">清空</text>
  44. </view>
  45. <view class="restrict-input-box input-type">
  46. <text class="restrict-input">市价</text>
  47. <text class="restrict-tag">USDT</text>
  48. <text class="restrict-btn">市价</text>
  49. </view>
  50. <view class="restrict-hint">
  51. <text class="iconfont">&#xe8ec;</text>
  52. <text>市价单的成交价格可能偏离用户下单时看到的成交价格</text>
  53. </view>
  54. <view class="restrict-hint2" v-if="content" :class="$setColor(profitPrice)">
  55. <text>当标价价格触达{{ target_profit_price || '--'}}时,将会触发市价委托平仓</text>
  56. <text>预计盈亏 <text class="color">{{ profitPrice || '--'}}</text> </text>
  57. </view>
  58. <view class="restrict-item">
  59. <text class="restrict-lable">止损</text>
  60. <view class="restrict-btn" v-if="content">
  61. <text class="iconfont">&#xe672;</text>
  62. <text>按比例设置</text>
  63. </view>
  64. </view>
  65. <view class="restrict-input-box">
  66. <input class="restrict-input" v-model="stop_loss_price" type="number"
  67. placeholder-class="placeholder-class" placeholder="请输入触发价">
  68. <text class="restrict-tag">USDT</text>
  69. <text class="restrict-btn" @click.stop="stop_loss_price = ''">清空</text>
  70. </view>
  71. <view class="restrict-input-box input-type">
  72. <text class="restrict-input">市价</text>
  73. <text class="restrict-tag">USDT</text>
  74. <text class="restrict-btn">市价</text>
  75. </view>
  76. <view class="restrict-hint">
  77. <text class="iconfont">&#xe8ec;</text>
  78. <text>市价单的成交价格可能偏离用户下单时看到的成交价格</text>
  79. </view>
  80. <view class="restrict-hint2" v-if="content" :class="$setColor(lossPrice)">
  81. <text>当标价价格触达{{ stop_loss_price || '--'}}时,将会触发市价委托平仓</text>
  82. <text>预计盈亏 <text class="color">{{ lossPrice || '--'}}</text></text>
  83. </view>
  84. <view class="content-btns">
  85. <view class="content-btn cancel-btn" @click.stop="close()">
  86. 取消
  87. </view>
  88. <view class="content-btn" @click.stop="setLeverStop()">
  89. 确定
  90. </view>
  91. </view>
  92. </view>
  93. </view>
  94. </view>
  95. </uni-popup>
  96. </template>
  97. <script>
  98. import {
  99. Api_setLeverStop
  100. } from "@/api/index.js"
  101. import {
  102. mapGetters
  103. } from 'vuex'
  104. export default {
  105. data() {
  106. return {
  107. content: null, // null : 下单时设置 , 否则为但是仓位设置
  108. target_profit_price: '',
  109. stop_loss_price: '',
  110. profitPrice:"",
  111. lossPrice:''
  112. };
  113. },
  114. watch:{
  115. target_profit_price:{
  116. handler(newPrice){
  117. if(newPrice && newPrice > Number(this.content.origin_price)){
  118. this.profitPrice = ((newPrice - this.content.origin_price) * 100 / this.content.origin_price *this.content.caution_money).toFixed(2);
  119. }else{
  120. this.profitPrice = ''
  121. }
  122. },
  123. immediate:true
  124. },
  125. stop_loss_price:{
  126. handler(newPrice){
  127. if(newPrice && newPrice < Number(this.content.origin_price)){
  128. this.lossPrice = ((newPrice - this.content.origin_price) * 100 / this.content.origin_price *this.content.caution_money).toFixed(2);
  129. }else{
  130. this.lossPrice = ''
  131. }
  132. },
  133. immediate:true
  134. },
  135. },
  136. computed: {
  137. ...mapGetters([
  138. "stocksColor"
  139. ])
  140. },
  141. mounted() {
  142. // this.open()
  143. },
  144. methods: {
  145. open(item = null) {
  146. this.target_profit_price = '';
  147. this.stop_loss_price = '';
  148. this.content = item;
  149. this.$nextTick(() => {
  150. this.$refs.popupRef.open();
  151. })
  152. },
  153. close() {
  154. this.$refs.popupRef.close()
  155. },
  156. // confirm() {
  157. // this.close();
  158. // this.$emit('confirm')
  159. // },
  160. //
  161. setLeverStop() {
  162. if (this.content) {
  163. // 单个持仓修改
  164. Api_setLeverStop({
  165. id: this.content.id,
  166. target_profit_price: this.target_profit_price,
  167. stop_loss_price: this.stop_loss_price
  168. }).then(res => {
  169. this.close();
  170. this.$emit('setSuccess')
  171. })
  172. } else {
  173. // 全局下单设置
  174. this.close();
  175. this.$eventBus.$emit('placeOrder', {
  176. target_profit_price: this.target_profit_price,
  177. stop_loss_price: this.stop_loss_price
  178. });
  179. }
  180. }
  181. }
  182. }
  183. </script>
  184. <style lang="scss" scoped>
  185. .popups-box {
  186. width: 100%;
  187. .popups-title {
  188. text-align: center;
  189. width: 100%;
  190. height: 100rpx;
  191. line-height: 100rpx;
  192. background-color: $box-bg;
  193. position: relative;
  194. font-size: 30rpx;
  195. font-weight: bold;
  196. border-radius: 40rpx 40rpx 0 0;
  197. .close-icon {
  198. position: absolute;
  199. right: 30rpx;
  200. top: 50%;
  201. transform: translateY(-50%);
  202. }
  203. }
  204. }
  205. .popups-content {
  206. width: 100%;
  207. background-color: #fff;
  208. .content-item {
  209. width: 100%;
  210. display: flex;
  211. justify-content: space-between;
  212. align-items: center;
  213. padding: 20rpx $pages-padding;
  214. font-size: 22rpx;
  215. .content-lable {
  216. color: $SizeColor;
  217. }
  218. .content-val {
  219. color: #000;
  220. font-weight: bold;
  221. // <text class="val-name">LTC/USDT</text>
  222. // <text class="val-lever">100倍杠杆</text>
  223. // <text class="val-tag">逐仓做多</text>
  224. .val-name {}
  225. .val-tag,
  226. .val-lever {
  227. padding: 5rpx 4rpx;
  228. color: #fff;
  229. font-size: 20rpx;
  230. border-radius: 4rpx;
  231. margin-left: 6rpx;
  232. }
  233. .val-lever {
  234. background-color: $Theme-Color;
  235. }
  236. .val-tag {
  237. background-color: $Theme-Color1;
  238. }
  239. }
  240. &:last-child {
  241. border-bottom: 10rpx solid $border-color;
  242. }
  243. }
  244. .content-restrict {
  245. width: 100%;
  246. padding: 0 $pages-padding;
  247. .restrict-item {
  248. width: 100%;
  249. padding-top: 30rpx;
  250. display: flex;
  251. justify-content: space-between;
  252. align-items: center;
  253. font-size: 26rpx;
  254. font-weight: bold;
  255. .restrict-btn {
  256. .iconfont {
  257. font-size: 28rpx;
  258. color: $Theme-Color;
  259. margin-right: 10rpx;
  260. }
  261. }
  262. }
  263. .restrict-input-box {
  264. margin-top: 20rpx;
  265. width: 100%;
  266. display: flex;
  267. align-items: center;
  268. font-size: 26rpx;
  269. height: 80rpx;
  270. border: 1rpx solid $border-color;
  271. border-radius: 10rpx;
  272. padding-right: 20rpx;
  273. text {
  274. flex-shrink: 0;
  275. }
  276. .restrict-input {
  277. flex: 1;
  278. height: 100%;
  279. border: none;
  280. padding: 0 20rpx;
  281. }
  282. .placeholder-class {
  283. font-size: 26rpx;
  284. font-weight: bold;
  285. }
  286. .restrict-tag {
  287. color: $SizeColor2;
  288. }
  289. .restrict-btn {
  290. color: $Theme-Color;
  291. padding-left: 20rpx;
  292. }
  293. }
  294. .input-type {
  295. background-color: $box-bg;
  296. .restrict-input {
  297. flex: 1;
  298. height: auto;
  299. padding: 0 20rpx;
  300. color: #000;
  301. font-weight: bold;
  302. }
  303. .restrict-btn {
  304. line-height: 1;
  305. border-left: 1px solid $Theme-Color;
  306. margin-left: 10rpx;
  307. padding-left: 10rpx;
  308. }
  309. }
  310. // <view class="restrict-hint">
  311. // <text class="iconfont">&#xe8ec;</text>
  312. // <text>市价单的成交价格可能偏离用户下单时看到的成交价格</text>
  313. // </view>
  314. // <view class="restrict-hint2">
  315. // <text>当标价价格触达{{ target_profit_price || '--'}}时,将会触发市价委托平仓</text>
  316. // <text>预计盈亏--</text>
  317. // </view>
  318. .restrict-hint {
  319. width: 100%;
  320. display: flex;
  321. align-items: center;
  322. padding-top: 10rpx;
  323. text {
  324. font-size: 22rpx;
  325. }
  326. .iconfont {
  327. font-size: 26rpx;
  328. margin-right: 6rpx;
  329. color: #000;
  330. }
  331. }
  332. .restrict-hint2 {
  333. width: 100%;
  334. display: flex;
  335. align-items: center;
  336. justify-content: space-between;
  337. font-size: 20rpx;
  338. color: $SizeColor;
  339. padding-top: 10rpx;
  340. text + text{
  341. flex-shrink: 0;
  342. padding-left: 10px;
  343. }
  344. }
  345. }
  346. }
  347. .content-btns {
  348. width: 100%;
  349. display: flex;
  350. justify-content: space-between;
  351. align-items: stretch;
  352. padding-top: 60rpx;
  353. .content-btn {
  354. flex: 1;
  355. height: 80rpx;
  356. line-height: 80rpx;
  357. background-color: $Theme-Color;
  358. margin-bottom: 40rpx;
  359. color: #fff;
  360. text-align: center;
  361. font-size: 30rpx;
  362. letter-spacing: 1px;
  363. border-radius: 6rpx;
  364. }
  365. .cancel-btn {
  366. margin-right: 20rpx;
  367. border: 1rpx solid $Theme-Color;
  368. background-color: #fff;
  369. color: $Theme-Color;
  370. }
  371. }
  372. </style>