Subscribe.vue 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  1. <template>
  2. <view class="d-flex flex-col">
  3. <view style="height: var(--status-bar-height)"></view>
  4. <view class="d-flex justify-center p-t-md">
  5. <view class="d-flex bg-form-panel-4 rounded-lg overflow-scroll">
  6. <view
  7. :class="{ 'bg-gradient-blue color-plain rounded-lg': tab == 0 }"
  8. @click="tab = 0"
  9. class="p-y-xs p-x-lg min-w-60 fn-center"
  10. >{{$t('exchange.a0')}}</view
  11. >
  12. <view
  13. :class="{ 'bg-gradient-blue color-plain rounded-lg': tab == 1 }"
  14. @click="tab = 1"
  15. class="p-y-xs p-x-lg min-w-60 fn-center"
  16. v-if="true"
  17. >{{$t('exchange.a1')}}</view
  18. >
  19. </view>
  20. </view>
  21. <!-- 币币 -->
  22. <template v-if="tab == 0">
  23. <!-- 币币交易 -->
  24. <view
  25. class="coin-exchange-box flex-fill d-flex flex-col overflow-hidden border-b"
  26. >
  27. <van-tabs
  28. :ellipsis="false"
  29. :border="false"
  30. :active="tab1"
  31. @change="tab1 = $event.detail.name"
  32. >
  33. <van-tab class="height-max" :title="$t('exchange.a3')"></van-tab>
  34. <van-tab class="height-max" :title="$t('exchange.a4')"></van-tab>
  35. <van-tab class="height-max" :title="$t('exchange.a5')"></van-tab>
  36. </van-tabs>
  37. <!-- 交易表单 -->
  38. <exchange-transaction
  39. @symbol="symbolListShow = true"
  40. :marketList="marketList"
  41. :collect="collect"
  42. :query="query"
  43. @option="option"
  44. :isShow="isShow"
  45. class="layout-main"
  46. v-if="tab1 == 0 && query.symbol"
  47. />
  48. <!-- 当前委托 -->
  49. <current-commission class="layout-main" v-if="tab1 == 1" />
  50. <!-- 历史委托 -->
  51. <history-commisson class="layout-main" v-if="tab1 == 2" />
  52. </view>
  53. </template>
  54. <!-- 申购 -->
  55. <template v-if="tab == 1">
  56. <purchase />
  57. </template>
  58. <!-- 左侧的弹窗 -->
  59. <van-popup
  60. :show="symbolListShow"
  61. @close="symbolListShow = false"
  62. close-on-popstate
  63. position="left"
  64. custom-style="height:100%;width:70%"
  65. >
  66. <symbol-list
  67. :collect="collect"
  68. :marketList="marketList"
  69. @check-symbol="checkSymbol"
  70. />
  71. </van-popup>
  72. <van-toast id="van-toast" />
  73. </view>
  74. </template>
  75. <script>
  76. import exchangeTransaction from "@/pages/exchange/exchange-transaction";
  77. import currentCommission from "@/pages/exchange/current-commission";
  78. import historyCommisson from "@/pages/exchange/history-commisson";
  79. import symbolList from "@/pages/exchange/symbol-list";
  80. import purchase from "@/pages/purchase/index";
  81. import Market from "@/api/market";
  82. import Home from "@/api/home";
  83. import { mapState } from "vuex";
  84. export default {
  85. name: "exchange-operation",
  86. props: ["isShow"],
  87. components: {
  88. exchangeTransaction,
  89. currentCommission,
  90. historyCommisson,
  91. symbolList,
  92. purchase,
  93. },
  94. data() {
  95. return {
  96. tab: 1,
  97. tab1: 0,
  98. symbolListShow: false,
  99. marketList: [],
  100. collect: [],
  101. query: {},
  102. msg: "exchangeMarketList",
  103. };
  104. },
  105. watch: {
  106. isShow(n) {
  107. if (n) {
  108. setTimeout(() => {
  109. this.ws.send({
  110. cmd: "sub",
  111. msg: this.msg,
  112. });
  113. }, 200);
  114. } else {
  115. this.ws.send({
  116. cmd: "unsub",
  117. msg: this.msg,
  118. });
  119. }
  120. },
  121. },
  122. computed: {
  123. ...mapState({
  124. ws: "ws",
  125. }),
  126. isLogin() {
  127. return Boolean(uni.getStorageSync("token"));
  128. },
  129. },
  130. methods: {
  131. // 获取市场行情
  132. getMarketList() {
  133. Market.getMarketList().then((res) => {
  134. this.marketList = res.data;
  135. this.$nextTick(() => {
  136. this.linkSocket();
  137. });
  138. if (!this.query.symbol) {
  139. let parentItem = this.marketList[0].marketInfoList[0];
  140. this.checkSymbol(parentItem);
  141. }
  142. });
  143. },
  144. // 获取自选列表
  145. getCollect() {
  146. if (!this.isLogin) return;
  147. Home.getCollect()
  148. .then((res) => {
  149. this.collect = res.data || [];
  150. })
  151. .catch(() => {});
  152. },
  153. //
  154. checkSymbol(obj) {
  155. this.symbolListShow = false;
  156. if (obj.pair_name == this.query.symbol) return;
  157. this.query = { symbol: obj.pair_name };
  158. // this._router.replace({ query: { symbol: obj.pair_name } });
  159. },
  160. // 添加自选
  161. option() {
  162. let data = {
  163. pair_name: this.query.symbol,
  164. };
  165. Home.option(data)
  166. .then((res) => {
  167. this.getCollect();
  168. if (res.data) {
  169. this.$toast(this.$t("exchange.a6"));
  170. } else {
  171. this.$toast(this.$t("exchange.a7"));
  172. }
  173. })
  174. .catch(() => {});
  175. },
  176. // 链接socket
  177. linkSocket() {
  178. let msg = this.msg;
  179. this.ws.send({
  180. cmd: "sub",
  181. msg,
  182. });
  183. this.ws.on("message", (res) => {
  184. let { data, sub } = res;
  185. if (sub == msg) {
  186. this.marketList = data;
  187. }
  188. });
  189. },
  190. // 获取参数
  191. getQuery() {
  192. let curPage = getCurPage();
  193. let curParam = curPage.options || curPage.$route.query;
  194. function getCurPage() {
  195. let pages = getCurrentPages();
  196. let curPage = pages[pages.length - 1];
  197. return curPage;
  198. }
  199. return curParam;
  200. },
  201. },
  202. created() {
  203. this.query = this.getQuery();
  204. if (this.query.symbol) {
  205. this.query.symbol = decodeURIComponent(this.query.symbol);
  206. }
  207. this.getMarketList();
  208. this.getCollect();
  209. },
  210. destroyed() {
  211. // this.ws.send({
  212. // cmd: "unsub",
  213. // msg: 'exchangeMarketList',
  214. // })
  215. },
  216. };
  217. </script>
  218. <style lang="scss" scoped>
  219. </style>