otc.vue 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294
  1. <template>
  2. <view class="d-flex flex-col page-otc" @click="menu = false">
  3. <v-header :left-arrow="false" title="OTC" :left-click="leftClick">
  4. <template #left>
  5. <v-link to="/pages/otc/send-ad">{{$t('otc.a0')}}</v-link>
  6. </template>
  7. <template #right>
  8. <view @click.stop="menu = !menu">{{$t('otc.a1')}}</view>
  9. </template>
  10. </v-header>
  11. <view class="d-flex border">
  12. <view class="w-6/12 border-r p-x-md p-y-xs box-size color-light">
  13. <v-picker :list="coinList" v-model="virtual_coin" @input="changeCoin">
  14. {{$t('otc.a2')}}:{{ activeCoin.label }}
  15. <van-icon name="arrow-down" />
  16. </v-picker>
  17. </view>
  18. </view>
  19. <!-- menu -->
  20. <view
  21. class="menu rounded-xs bg-panel-4 box-shadow"
  22. v-show="menu"
  23. @click.stop
  24. >
  25. <view @click="_router.push('/pages/otc/order')" class="p-xs border-b">
  26. {{$t('otc.a3')}}
  27. </view>
  28. <view @click="_router.push('/pages/otc/ad')" class="p-xs">
  29. {{$t('otc.a4')}}
  30. </view>
  31. </view>
  32. <van-tabs
  33. :ellipsis="false"
  34. :border="false"
  35. class="border-b"
  36. :active="tab"
  37. @change="tabChange($event.detail.name)"
  38. >
  39. <van-tab :title="$t('otc.a5')" :name="2"></van-tab>
  40. <van-tab :title="$t('otc.a6')" :name="1"></van-tab>
  41. </van-tabs>
  42. <v-paging
  43. :ajax="tradingEntrusts"
  44. :data="{ side: tab, virtual_coin, pay_type: 'all' }"
  45. ref="scroll"
  46. class="layout-main"
  47. >
  48. <template #box="list">
  49. <van-empty v-if="!$list(list).length" description="" />
  50. <view class="list">
  51. <view
  52. class="item bg-panel-3 box-shadow rounded-sm p-md m-md"
  53. v-for="item in $list(list)"
  54. :key="item.id"
  55. >
  56. <view class="row d-flex align-center">
  57. <view
  58. class="w-50 h-50 border rounded-max border-light bg-primary color-plain d-flex justify-center align-center fn-30"
  59. >
  60. {{ userName(item.user.username) }}
  61. </view>
  62. <view class="flex-fill fn-right"> {{ item.user.username }} </view>
  63. </view>
  64. <view class="row m-t-sm d-flex align-center">
  65. <view class="label"> {{$t('otc.a7')}} </view>
  66. <view class="flex-fill fn-right color-light">
  67. {{ item.amount }}
  68. </view>
  69. </view>
  70. <view class="row m-t-sm d-flex align-center">
  71. <view class="label"> {{$t('otc.a8')}} </view>
  72. <view class="flex-fill fn-right color-light">
  73. {{ item.cur_amount }}
  74. </view>
  75. </view>
  76. <view class="row m-t-sm d-flex align-center">
  77. <view class="label"> {{$t('otc.a9')}} </view>
  78. <view class="flex-fill fn-right color-light">
  79. {{ item.min_num * 1 }} - {{ item.max_num * 1 || "∞" }}
  80. </view>
  81. </view>
  82. <view class="row m-t-sm d-flex align-center">
  83. <view class="label"> {{$t('otc.b0')}} </view>
  84. <view class="flex-fill fn-right color-light">
  85. {{ item.price * 1 }} CNY
  86. </view>
  87. </view>
  88. <view class="row m-t-sm d-flex align-center">
  89. <view class="label"> {{$t('otc.b1')}} </view>
  90. <view class="flex-fill fn-right color-light">
  91. <template v-for="minItem in item.pay_type">
  92. {{ payTypeMap[minItem] }},
  93. </template>
  94. </view>
  95. </view>
  96. <view class="row m-t-sm d-flex align-center">
  97. <view class="label"> {{$t('otc.b2')}} </view>
  98. <view class="flex-fill fn-right color-light">
  99. <v-button
  100. type="green"
  101. size="mini"
  102. class="rounded-xs"
  103. @click="clickItem(item)"
  104. >
  105. {{ item.side == 2 ? $t('otc.a5') : $t('otc.a6') }}
  106. </v-button>
  107. </view>
  108. </view>
  109. </view>
  110. </view>
  111. </template>
  112. </v-paging>
  113. <van-popup
  114. :show="buyShow"
  115. @close="buyShow = false"
  116. closeable
  117. close-on-popstate
  118. position="center"
  119. custom-style="height:70%;width:70%;border-radius:8px;"
  120. >
  121. <view class="p-md">
  122. <view class="fn-center color-light"> {{ activeItem.side == 2 ? $t('otc.a5') : $t('otc.a6') }} </view>
  123. <view
  124. class="m-x-auto m-t-sm w-50 h-50 border rounded-max border-light bg-primary color-plain d-flex justify-center align-center fn-30"
  125. >
  126. {{userName(activeItem.user&&activeItem.user.username||'')}}
  127. </view>
  128. <view class="fn-center"> {{activeItem.user.username}} </view>
  129. <view class="row d-flex m-t-sm">
  130. <view class="label">{{$t('otc.b3')}}</view>
  131. <view class="color-light flex-fill fn-right">{{ activeItem.amount }}</view>
  132. </view>
  133. <view class="row d-flex m-t-sm">
  134. <view class="label">{{$t('otc.a8')}}</view>
  135. <view class="color-light flex-fill fn-right">{{ activeItem.cur_amount }}</view>
  136. </view>
  137. <view class="row d-flex m-t-sm">
  138. <view class="label">{{$t('otc.a9')}}</view>
  139. <view class="color-light flex-fill fn-right">{{ activeItem.min_num * 1 }} - {{
  140. activeItem.max_num * 1||'∞'
  141. }}</view>
  142. </view>
  143. <view class="row d-flex m-t-sm">
  144. <view class="label">{{$t('otc.b0')}}</view>
  145. <view class="color-light flex-fill fn-right">{{ activeItem.price * 1 }}CNY</view>
  146. </view>
  147. <view>
  148. <v-picker :list="paysList" v-model="form.pay_type">
  149. <template #default="{label}">
  150. <view class="p-xs rounded-xs bg-panel-1 m-t-sm d-flex align-center box-shadow">
  151. <view class="flex-fill">
  152. {{label||$t('otc.b4')}}
  153. </view>
  154. <van-icon name="arrow-down" />
  155. </view>
  156. </template>
  157. </v-picker>
  158. </view>
  159. <view>
  160. <v-input
  161. :placeholder="$t('otc.b5')"
  162. class="p-xs rounded-xs bg-panel-1 m-t-sm box-shadow"
  163. type="number"
  164. v-model="form.amount"
  165. ></v-input>
  166. </view>
  167. <view class="m-t-sm">
  168. <v-button
  169. type="green"
  170. block
  171. size="small"
  172. class="rounded-xs"
  173. @click="storeOrder"
  174. >{{$t('otc.b6')}}</v-button>
  175. </view>
  176. </view>
  177. </van-popup>
  178. </view>
  179. </template>
  180. <script>
  181. import Otc from "@/api/otc";
  182. export default {
  183. name: "otc",
  184. props: ["isShow"],
  185. watch: {
  186. isShow() {
  187. this.menu = false;
  188. },
  189. },
  190. data() {
  191. return {
  192. tab: 2,
  193. buyShow: false,
  194. list: [],
  195. menu: false,
  196. virtual_coin: "USDT",
  197. coinList: [],
  198. activeItem: {
  199. user:{}
  200. },
  201. form: {
  202. entrust_id: "",
  203. amount: "",
  204. pay_type: "",
  205. },
  206. };
  207. },
  208. computed: {
  209. payTypeMap() {
  210. return {
  211. alipay: this.$t('otc.b7'),
  212. wechat: this.$t('otc.b8'),
  213. bank_card: this.$t('otc.b9'),
  214. };
  215. },
  216. activeCoin() {
  217. return (
  218. this.coinList.find((item) => item.value == this.virtual_coin) || {}
  219. );
  220. },
  221. paysList(){
  222. if(this.activeItem.pay_type){
  223. return this.activeItem.pay_type.map(item=>({value:item,label:this.payTypeMap[item]}))
  224. }else{
  225. return []
  226. }
  227. }
  228. },
  229. created() {
  230. this.otcTicker();
  231. },
  232. methods: {
  233. otcTicker() {
  234. Otc.otcTicker().then((res) => {
  235. this.coinList = res.data.map((item) => {
  236. return {
  237. value: item.coin_name,
  238. label: item.coin_name,
  239. };
  240. });
  241. });
  242. },
  243. tradingEntrusts: Otc.tradingEntrusts,
  244. userName(name) {
  245. return name.substring(0, 1);
  246. },
  247. changeCoin() {
  248. this.$nextTick(() => {
  249. this.$refs.scroll.ref();
  250. });
  251. },
  252. // tab切换
  253. tabChange(idx) {
  254. this.tab = idx;
  255. this.$nextTick(() => {
  256. this.$refs.scroll.ref();
  257. });
  258. },
  259. clickItem(item) {
  260. this.activeItem = item;
  261. this.form.entrust_id = this.activeItem.id;
  262. this.form.pay_type = this.activeItem.pay_type[0];
  263. this.buyShow = true;
  264. },
  265. // 下单
  266. storeOrder() {
  267. let data = {
  268. ...this.form,
  269. };
  270. Otc.storeOrder(data).then((res) => {
  271. this.$toast(this.$t('otc.c0'));
  272. this.buyShow = false;
  273. this.form.amount=''
  274. // this.$router.push({ path: "/pages/otc/detail", query: { id: res.data.id } });
  275. uni.navigateTo({
  276. url:"/pages/otc/detail?id=" + res.data.id
  277. })
  278. });
  279. },
  280. leftClick() {},
  281. },
  282. };
  283. </script>
  284. <style lang="scss" scoped>
  285. .page-otc {
  286. position: relative;
  287. .menu {
  288. position: absolute;
  289. z-index: 999;
  290. top: calc(44px + var(--status-bar-height));
  291. right: $padding-md;
  292. }
  293. }
  294. </style>