restrict.vue 11 KB

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