exchange-operation.vue 6.5 KB

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