index.vue 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277
  1. <template>
  2. <v-page>
  3. <v-header class="nav-head" :title="$t('flash.a1')">
  4. <template #right>
  5. <v-link to="./record">
  6. <van-icon class="fn-20 m-t-xs" name="todo-list-o" />
  7. </v-link>
  8. </template>
  9. </v-header>
  10. <view class="layout-main p-x-lg p-t-lg">
  11. <view class="panel-box rounded p-x-md bg-panel-3 box-shadow p-t-md p-b-lg">
  12. <view style="position: relative;">
  13. <view class="label fn-sm color-gray-6">{{$t('flash.a2')}}</view>
  14. <view >
  15. <view class="d-flex rounded-xs">
  16. <v-picker :list="fromList" @change="changeFromIndex" :value="fromList[fromIndex]&&fromList[fromIndex].expend_coin_name" range-value="expend_coin_name" range-label="expend_coin_name" class="form-input p-y-xs w-80 m-r-xs ">
  17. <view class="d-flex align-center justify-between">
  18. {{fromList[fromIndex]&&fromList[fromIndex].expend_coin_name}}
  19. <van-icon name="arrow-down" />
  20. </view>
  21. </v-picker>
  22. <view class="border-b flex-fill d-flex align-center">
  23. <v-input :placeholder="`${fromList[fromIndex]&&fromList[fromIndex].convert_min}-${fromList[fromIndex]&&fromList[fromIndex].convert_max}`" v-model="form.amount" type="number" class="flex-fill color-light form-input w-max p-y-xs d-flex" />
  24. <view class="all color-theme-1 m-l-md flex-shrink" @click="form.amount = fromList[fromIndex]&&fromList[fromIndex].balance">{{ $t("assets.c3") }}</view>
  25. </view>
  26. </view>
  27. <view class="label fn-sm color-gray-6 p-y-xs">{{$t('flash.a3')}}:{{fromList[fromIndex]&&fromList[fromIndex].balance}}</view>
  28. </view>
  29. <view class="label fn-sm color-gray-6" style="padding-top:40px;">{{$t('flash.a4')}}</view>
  30. <view class="d-flex rounded-xs">
  31. <v-picker :list="toList" @change="changeToIndex" :value="toList[toIndex]&&toList[toIndex].value" range-value="value" range-label="label" class="form-input p-y-xs w-80 m-r-xs ">
  32. <view class="d-flex align-center justify-between" v-if="toList[toIndex]&&toList[toIndex].label">
  33. {{toList[toIndex].label}}
  34. <van-icon name="arrow-down" />
  35. </view>
  36. </v-picker>
  37. <view class="border-b flex-fill">
  38. <v-input disabled type="number" class="color-light form-input w-max p-y-xs d-flex" />
  39. </view>
  40. </view>
  41. <!-- <view class="exchange d-flex justify-center align-center bg-panel-3 box-shadow link-active"
  42. @click="swap">
  43. <van-icon style="transform:rotateZ(90deg)" class="fn-22 color-light" name="exchange" />
  44. </view> -->
  45. </view>
  46. <view class="btn d-flex justify-center align-center fn-15" style="margin-top:60rpx;" @click="show()">{{$t('flash.a5')}}</view>
  47. </view>
  48. </view>
  49. <van-popup
  50. :show="showPopup"
  51. round
  52. closeable
  53. custom-style="min-height: 20%"
  54. position="bottom"
  55. @close="showPopup=false"
  56. >
  57. <view class="fn-15" style="padding:60rpx 40rpx 80rpx;">
  58. <view class="fn-15 d-flex justify-center" style="font-weight: bold;">{{$t('flash.b1')}}</view>
  59. <div class="item m-md rounded-sm">
  60. <div class="p-x-md p-y-xs">
  61. <div class="row d-flex m-y-mini justify-between p-y-xs">
  62. <div class="label ">{{$t('flash.b2')}}</div>
  63. <div class="color-light d-flex align-center">
  64. <div style="color: green;">{{data.amount}}</div>
  65. </div>
  66. </div>
  67. <div class="row d-flex m-y-mini justify-between p-y-xs">
  68. <div class="label ">{{$t('flash.b3')}}</div>
  69. <div class="color-light d-flex align-center">
  70. <div style="color: green;">{{data.realtime}}</div>
  71. </div>
  72. </div>
  73. <div class="row d-flex m-y-mini justify-between p-y-xs">
  74. <div class="label">{{$t('flash.b4')}}</div>
  75. <div class="color-light">{{$t('flash.b5')}}</div>
  76. </div>
  77. <div class="row d-flex m-y-mini justify-between p-y-xs">
  78. <div class="label">{{$t('flash.b6')}}</div>
  79. <div class="color-light">{{$t('flash.b7')}}</div>
  80. </div>
  81. <div class="row d-flex m-y-mini justify-between p-y-xs">
  82. <div class="label">{{$t('flash.b8')}}</div>
  83. <div class="color-light">1{{data.expend_coin_name}}≈{{data.unit}}{{data.receipt_coin_name}}</div>
  84. </div>
  85. </div>
  86. </div>
  87. <view class="d-flex align-center justify-around" v-if="data.status == 1">
  88. <view class="btn d-flex justify-center align-center fn-15" style="margin-top:60rpx;background: #DD3F62;width:100%" @click="setStore()">
  89. <view>{{$t('flash.b9')}}</view>
  90. <view v-if="countdowns" style="margin-left:20rpx">{{countdowns}}sec</view>
  91. </view>
  92. </view>
  93. <view class="d-flex align-center justify-around" v-if="data.status == 0">
  94. <view class="btn d-flex justify-center align-center fn-15" style="margin-top:60rpx;background: #ccc;width:100%">{{$t('flash.c1')}}</view>
  95. </view>
  96. <view class="d-flex align-center justify-around" v-if="data.status == 3">
  97. <view class="btn d-flex justify-center align-center fn-15" style="margin-top:60rpx;background: #ccc;width:40%" @click="showPopup=false">{{$t('flash.c2')}}</view>
  98. <view class="btn d-flex justify-center align-center fn-15" style="margin-top:60rpx;background: #DD3F62;width:40%" @click="show()">{{$t('flash.c3')}}</view>
  99. </view>
  100. </view>
  101. </van-popup>
  102. </v-page>
  103. </template>
  104. <script>
  105. import Convert from "@/api/convert.js";
  106. import {
  107. mapGetters
  108. } from "vuex";
  109. import lodash from "lodash";
  110. export default {
  111. data() {
  112. return {
  113. showPopup:false,
  114. form: {
  115. from_account: 1,
  116. to_account: 2,
  117. amount: ''
  118. },
  119. fromList:[],
  120. fromIndex:0,
  121. toIndex:0,
  122. toList:[],
  123. data:[],
  124. ttl:0,
  125. timer: null, //重复执行
  126. countdowns:0
  127. };
  128. },
  129. onLoad() {
  130. this.getList()
  131. },
  132. methods: {
  133. getList(){
  134. Convert.walletList().then(res=>{
  135. this.fromList = res.data
  136. this.fromIndex = 0
  137. for (let i in this.fromList) {
  138. if(this.fromList[i].receipt_coin_name&&this.fromList[i].receipt_coin_name.length){
  139. this.fromList[i].toList = []
  140. for (let j in this.fromList[i].receipt_coin_name) {
  141. this.fromList[i].toList.push({
  142. value:j,
  143. label:this.fromList[i].receipt_coin_name[j]
  144. })
  145. }
  146. }
  147. }
  148. this.toList = this.fromList[this.fromIndex].toList
  149. this.toIndex = 0
  150. })
  151. },
  152. changeFromIndex(value,index){
  153. this.fromIndex = index
  154. this.toList = this.fromList[this.fromIndex].toList
  155. this.toIndex = 0
  156. },
  157. changeToIndex(value,index){
  158. this.toIndex = index
  159. },
  160. show(){
  161. let convert_min = this.fromList[this.fromIndex].convert_min*1;
  162. let convert_max = this.fromList[this.fromIndex].convert_max*1;
  163. let expend_coin_name = this.fromList[this.fromIndex].expend_coin_name;
  164. let label = this.toList[this.toIndex].label;
  165. let amount = this.form.amount * 1;
  166. if(amount == null || amount==undefined || amount==''){
  167. this.$toast(this.$t('flash.c4'))
  168. return false;
  169. }
  170. if(amount < convert_min|| amount>convert_max){
  171. this.$toast(this.$t('flash.c4'))
  172. return false;
  173. }
  174. if(expend_coin_name === label){
  175. this.$toast(this.$t('flash.c5'))
  176. return false;
  177. }
  178. Convert.getPriceRate({expend_coin_name:expend_coin_name,receipt_coin_name:label,amount:amount}).then((res)=>{
  179. if(res.code == 200){
  180. this.data = res.data
  181. this.ttl = res.data.ttl
  182. this.countdowns = this.ttl
  183. if(res.data.status==1 && res.data.ttl){
  184. this.showtime(this.ttl)
  185. }
  186. this.showPopup = true
  187. }
  188. })
  189. },
  190. showtime (ttl) {
  191. this.timer = setInterval(()=>{
  192. ttl-=1
  193. this.countdowns = ttl
  194. if(ttl<=0){
  195. this.data.status = 3;
  196. clearInterval(this.timer)
  197. }
  198. },1000)
  199. },
  200. setStore(){
  201. let data = {
  202. expend_coin_name:this.fromList[this.fromIndex].expend_coin_name,
  203. receipt_coin_name:this.toList[this.toIndex].label,
  204. amount:this.form.amount * 1,
  205. co:this.data.co
  206. };
  207. Convert.setStore(data).then((res)=>{
  208. if(res.code == 200){
  209. this.getList()
  210. this.showPopup = false
  211. this.$toast(this.$t('flash.c6'))
  212. }
  213. })
  214. }
  215. }
  216. }
  217. </script>
  218. <style lang="scss" scoped>
  219. .panel-box {
  220. position: relative;
  221. .line {
  222. position: absolute;
  223. height: 100%;
  224. width: 1px;
  225. background: $border-color;
  226. transform: scale(0.5);
  227. top: 0;
  228. &::before,
  229. &::after {
  230. content: "";
  231. display: inline-block;
  232. position: absolute;
  233. left: 50%;
  234. transform: translateX(-50%);
  235. width: 12px;
  236. height: 12px;
  237. border-radius: 50%;
  238. }
  239. &::before {
  240. top: 0;
  241. background: $blue;
  242. }
  243. &::after {
  244. bottom: 0;
  245. background: $red;
  246. }
  247. }
  248. .exchange {
  249. position: absolute;
  250. left: 50%;
  251. top: 56%;
  252. height: 40px;
  253. width: 40px;
  254. border-radius: 50%;
  255. transform: translate(-50%,-50%);
  256. }
  257. }
  258. .btn{
  259. background: #DD3F62;
  260. border-radius: 20rpx;
  261. min-height:80rpx;
  262. color: #fff;
  263. }
  264. </style>