restrict.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449
  1. <template>
  2. <uni-popup ref="popupRef" type="bottom" @change="change">
  3. <view class="popups-box" :rise-fall="stocksColor">
  4. <view class="popups-title">
  5. {{ restrictOrder ? '持仓止盈止损修改' : '设置止盈止损' }}
  6. <text class="close-icon iconfont" @click.stop="close()">&#xeca0;</text>
  7. </view>
  8. <view class="popups-content">
  9. <template v-if="restrictOrder">
  10. <view class="content-item">
  11. <text class="content-lable">合约名称</text>
  12. <view class="content-val">
  13. <text class="val-name">{{ restrictOrder.symbol }}</text>
  14. <text class="val-lever">{{ restrictOrder.multiple }}倍杠杆</text>
  15. <text class="val-tag">{{ restrictOrder.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. {{ restrictOrder.origin_price }}
  22. </view>
  23. </view>
  24. <view class="content-item">
  25. <text class="content-lable">标记价格(USDT)</text>
  26. <view class="content-val">
  27. {{ restrictOrder.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="restrictOrder">
  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="restrictOrder" :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="restrictOrder">
  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="restrictOrder" :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. restrictOrder: {
  116. handler(newOrder) {
  117. console.log('this.stop_loss_price restrictOrder ' , newOrder)
  118. if (newOrder) {
  119. this.calculateProfitPrice(this.target_profit_price)
  120. this.calculateLossPrice(this.stop_loss_price)
  121. }
  122. },
  123. immediate: true,
  124. deep: true
  125. },
  126. target_profit_price: {
  127. handler(newPrice) {
  128. this.calculateProfitPrice(newPrice)
  129. },
  130. immediate: true
  131. },
  132. stop_loss_price: {
  133. handler(newPrice) {
  134. this.calculateLossPrice(newPrice)
  135. },
  136. immediate: true
  137. },
  138. },
  139. computed: {
  140. ...mapGetters([
  141. "stocksColor",
  142. 'restrictOrder'
  143. ])
  144. },
  145. mounted() {
  146. // this.open()
  147. },
  148. methods: {
  149. calculateProfitPrice(newPrice) {
  150. if (newPrice && this.restrictOrder && newPrice > Number(this.restrictOrder
  151. .update_price)) {
  152. this.profitPrice = ((newPrice - this.restrictOrder.update_price) * 100 / this
  153. .restrictOrder.update_price * this.restrictOrder.caution_money).toFixed(2);
  154. } else {
  155. this.profitPrice = ''
  156. }
  157. },
  158. calculateLossPrice(newPrice) {
  159. if (newPrice && this.restrictOrder && newPrice < Number(this.restrictOrder.update_price)) {
  160. // console.log('this.calculateLossPrice = ' , newPrice , this.restrictOrder.update_price)
  161. this.lossPrice = ((newPrice - this.restrictOrder.update_price) * 100 / this
  162. .restrictOrder.update_price * this.restrictOrder.caution_money).toFixed(2);
  163. } else {
  164. this.lossPrice = ''
  165. }
  166. },
  167. open(item = null) {
  168. this.target_profit_price = '';
  169. this.stop_loss_price = '';
  170. // this.content = item;
  171. this.$nextTick(() => {
  172. this.$refs.popupRef.open();
  173. })
  174. },
  175. close() {
  176. this.$refs.popupRef.close()
  177. },
  178. change(e) {
  179. if (!e.show) {
  180. this.$store.commit('websocket/set_restrictOrder', null)
  181. }
  182. },
  183. // this.$emit('change', {
  184. // show: false,
  185. // type: this.type
  186. // })
  187. // confirm() {
  188. // this.close();
  189. // this.$emit('confirm')
  190. // },
  191. //
  192. setLeverStop() {
  193. if (this.restrictOrder) {
  194. // 单个持仓修改
  195. Api_setLeverStop({
  196. id: this.restrictOrder.id,
  197. target_profit_price: this.target_profit_price,
  198. stop_loss_price: this.stop_loss_price
  199. }).then(res => {
  200. this.close();
  201. this.$emit('setSuccess')
  202. })
  203. } else {
  204. // 全局下单设置
  205. this.close();
  206. this.$eventBus.$emit('placeOrder', {
  207. target_profit_price: this.target_profit_price,
  208. stop_loss_price: this.stop_loss_price
  209. });
  210. }
  211. }
  212. }
  213. }
  214. </script>
  215. <style lang="scss" scoped>
  216. .popups-box {
  217. width: 100%;
  218. .popups-title {
  219. text-align: center;
  220. width: 100%;
  221. height: 100rpx;
  222. line-height: 100rpx;
  223. background-color: $box-bg;
  224. position: relative;
  225. font-size: 30rpx;
  226. font-weight: bold;
  227. border-radius: 40rpx 40rpx 0 0;
  228. .close-icon {
  229. position: absolute;
  230. right: 30rpx;
  231. top: 50%;
  232. transform: translateY(-50%);
  233. }
  234. }
  235. }
  236. .popups-content {
  237. width: 100%;
  238. background-color: #fff;
  239. .content-item {
  240. width: 100%;
  241. display: flex;
  242. justify-content: space-between;
  243. align-items: center;
  244. padding: 20rpx $pages-padding;
  245. font-size: 22rpx;
  246. .content-lable {
  247. color: $SizeColor;
  248. }
  249. .content-val {
  250. color: #000;
  251. font-weight: bold;
  252. // <text class="val-name">LTC/USDT</text>
  253. // <text class="val-lever">100倍杠杆</text>
  254. // <text class="val-tag">逐仓做多</text>
  255. .val-name {}
  256. .val-tag,
  257. .val-lever {
  258. padding: 5rpx 4rpx;
  259. color: #fff;
  260. font-size: 20rpx;
  261. border-radius: 4rpx;
  262. margin-left: 6rpx;
  263. }
  264. .val-lever {
  265. background-color: $Theme-Color;
  266. }
  267. .val-tag {
  268. background-color: $Theme-Color1;
  269. }
  270. }
  271. &:last-child {
  272. border-bottom: 10rpx solid $border-color;
  273. }
  274. }
  275. .content-restrict {
  276. width: 100%;
  277. padding: 0 $pages-padding;
  278. .restrict-item {
  279. width: 100%;
  280. padding-top: 30rpx;
  281. display: flex;
  282. justify-content: space-between;
  283. align-items: center;
  284. font-size: 26rpx;
  285. font-weight: bold;
  286. .restrict-btn {
  287. .iconfont {
  288. font-size: 28rpx;
  289. color: $Theme-Color;
  290. margin-right: 10rpx;
  291. }
  292. }
  293. }
  294. .restrict-input-box {
  295. margin-top: 20rpx;
  296. width: 100%;
  297. display: flex;
  298. align-items: center;
  299. font-size: 26rpx;
  300. height: 80rpx;
  301. border: 1rpx solid $border-color;
  302. border-radius: 10rpx;
  303. padding-right: 20rpx;
  304. text {
  305. flex-shrink: 0;
  306. }
  307. .restrict-input {
  308. flex: 1;
  309. height: 100%;
  310. border: none;
  311. padding: 0 20rpx;
  312. }
  313. .placeholder-class {
  314. font-size: 26rpx;
  315. font-weight: bold;
  316. }
  317. .restrict-tag {
  318. color: $SizeColor2;
  319. }
  320. .restrict-btn {
  321. color: $Theme-Color;
  322. padding-left: 20rpx;
  323. }
  324. }
  325. .input-type {
  326. background-color: $box-bg;
  327. .restrict-input {
  328. flex: 1;
  329. height: auto;
  330. padding: 0 20rpx;
  331. color: #000;
  332. font-weight: bold;
  333. }
  334. .restrict-btn {
  335. line-height: 1;
  336. border-left: 1px solid $Theme-Color;
  337. margin-left: 10rpx;
  338. padding-left: 10rpx;
  339. }
  340. }
  341. // <view class="restrict-hint">
  342. // <text class="iconfont">&#xe8ec;</text>
  343. // <text>市价单的成交价格可能偏离用户下单时看到的成交价格</text>
  344. // </view>
  345. // <view class="restrict-hint2">
  346. // <text>当标价价格触达{{ target_profit_price || '--'}}时,将会触发市价委托平仓</text>
  347. // <text>预计盈亏--</text>
  348. // </view>
  349. .restrict-hint {
  350. width: 100%;
  351. display: flex;
  352. align-items: center;
  353. padding-top: 10rpx;
  354. text {
  355. font-size: 22rpx;
  356. }
  357. .iconfont {
  358. font-size: 26rpx;
  359. margin-right: 6rpx;
  360. color: #000;
  361. }
  362. }
  363. .restrict-hint2 {
  364. width: 100%;
  365. display: flex;
  366. align-items: center;
  367. justify-content: space-between;
  368. font-size: 20rpx;
  369. color: $SizeColor;
  370. padding-top: 10rpx;
  371. text+text {
  372. flex-shrink: 0;
  373. padding-left: 10px;
  374. }
  375. }
  376. }
  377. }
  378. .content-btns {
  379. width: 100%;
  380. display: flex;
  381. justify-content: space-between;
  382. align-items: stretch;
  383. padding-top: 60rpx;
  384. .content-btn {
  385. flex: 1;
  386. height: 80rpx;
  387. line-height: 80rpx;
  388. background-color: $Theme-Color;
  389. margin-bottom: 40rpx;
  390. color: #fff;
  391. text-align: center;
  392. font-size: 30rpx;
  393. letter-spacing: 1px;
  394. border-radius: 6rpx;
  395. }
  396. .cancel-btn {
  397. margin-right: 20rpx;
  398. border: 1rpx solid $Theme-Color;
  399. background-color: #fff;
  400. color: $Theme-Color;
  401. }
  402. }
  403. </style>