pledge.vue 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460
  1. <template>
  2. <view class="all">
  3. <view class="navList flex">
  4. <view v-for="(item, index) in navList" :key="index" class="navItem"
  5. :class="{ activeItem: tabCurrentIndex === index,tip:index == 0 }" @click="tabClick(index)">{{ item }}
  6. </view>
  7. </view>
  8. <view style="padding-top: 44px;" v-if="tabCurrentIndex == 0">
  9. <view class="listBox">
  10. <view class="titleTetx">数量</view>
  11. <view class="flex listTpl">
  12. <input type="number" class="inputBox" v-model="number" placeholder="请输入数量" />
  13. <view class="flex_item">
  14. <view class="listTip">USDT</view>
  15. <view class="listAll" @click="number=money">全部</view>
  16. </view>
  17. </view>
  18. <view class="flex tipBox">
  19. <view class="tip1">可用余额{{money}}USDT</view>
  20. <view class="tip1">限额{{baseData.min_sell}}到{{baseData.max_sell}}个</view>
  21. </view>
  22. </view>
  23. <view class="listBox" style="padding-top: 0rpx;">
  24. <view class="listTpl">
  25. <input type="number" class="inputBox" v-model="price" placeholder="请输入单价" />
  26. </view>
  27. <view class="flex tipBox">
  28. <view class="tip1">单价不得大于参考汇率</view>
  29. </view>
  30. </view>
  31. <view class="submission">
  32. <button class="golden" type="golden" hover-class="none" @click="submission">一键卖币</button>
  33. </view>
  34. <view class="tips">*参考汇率{{baseData.us_price}}</view>
  35. </view>
  36. <view class="listItemBox" v-if="tabCurrentIndex == 1">
  37. <view class="listItem" v-for="item,index in list" :key="index">
  38. <view class="itemInfo flex">
  39. <view class="flex_item">
  40. <image src="/static/image/img20.png" style="width: 55rpx;height: 55rpx;" mode="widthFix"></image>
  41. <view class="name">{{item.real_name}}</view>
  42. </view>
  43. <image src="/static/image/img21.png" style="width: 40rpx;height: 31rpx;" mode="widthFix"></image>
  44. </view>
  45. <view class="itemTpl">{{item.price}}</view>
  46. <view class="itemTip flex">
  47. <view class="tipBox">
  48. <view class="tipText">数量:{{item.num}}</view>
  49. <view class="tipText">{{item.add_time|dateFormat}}</view>
  50. </view>
  51. <view class="tipBtn" @click="commitorder(item)">买入</view>
  52. </view>
  53. </view>
  54. <uni-load-more :status="loadingType"></uni-load-more>
  55. </view>
  56. <u-action-sheet :show="showBank" :actions="bankList" title="请选择银行卡"
  57. @close="showBank = false" @select="bankSelect">
  58. </u-action-sheet>
  59. </view>
  60. </template>
  61. <script>
  62. import {
  63. getsell,
  64. sellPush,
  65. sellBuy
  66. } from '@/api/game.js';
  67. import {
  68. getIndex
  69. } from '@/api/index.js';
  70. import {
  71. mapState,
  72. } from 'vuex';
  73. import {
  74. qianBao
  75. } from '@/api/wallet.js';
  76. import {
  77. getBank
  78. } from '@/api/set.js';
  79. import dayjs from '@/libs/dayjs/dayjs.min.js';
  80. export default {
  81. computed: {
  82. ...mapState('user', ['hasLogin','userInfo'])
  83. },
  84. filters: {
  85. dateFormat: function(value) {
  86. return dayjs(value * 1000).format('YYYY/MM/DD HH:mm');
  87. }
  88. },
  89. data() {
  90. return {
  91. tabCurrentIndex: 0,
  92. navList: ['卖出', '买入'],
  93. number: '',
  94. money:'',
  95. price: '',
  96. page: 1,
  97. limit: 10,
  98. list: [],
  99. loadingType: 'more',
  100. baseData:{
  101. min_sell:'',
  102. max_sell:''
  103. },
  104. loaded:false,
  105. showBank:false,
  106. bankList:[],
  107. bank_id:'',
  108. }
  109. },
  110. onNavigationBarButtonTap(res) {
  111. uni.navigateTo({
  112. url: '/pages/index/order'
  113. })
  114. },
  115. onShow() {
  116. this.init();
  117. },
  118. onLoad() {
  119. this.getIndex()
  120. },
  121. methods: {
  122. qianBao() {
  123. const that = this;
  124. qianBao().then((res) => {
  125. that.money = +res.data.like_usdt;
  126. })
  127. },
  128. getBank() {
  129. const obj = this;
  130. getBank().then((res) => {
  131. let data = res.data.list
  132. let reg = /^(.{4})(?:\d+)(.{4})$/
  133. data.forEach(item => {
  134. item.bank_code1 = item.bank_code.replace(reg, "**** $2")
  135. item.name = item.bank+' '+item.bank_code1
  136. })
  137. obj.bankList = data
  138. console.log(obj.bankList,'obj.bankList')
  139. })
  140. },
  141. bankSelect(e){
  142. const obj = this;
  143. this.bank_id = e.id
  144. if(this.bank_id){
  145. uni.showModal({
  146. title: '请输入支付密码',
  147. editable:true,
  148. success: res => {
  149. if(res.confirm){
  150. sellPush({
  151. type: 'USDT',
  152. num: obj.number,
  153. price: obj.price,
  154. phone: obj.userInfo.phone || '',
  155. trade_psw: res.content,
  156. sell_type: 'money',
  157. bank_id:obj.bank_id
  158. }).then((
  159. data
  160. ) => {
  161. obj.qianBao();
  162. uni.showToast({
  163. title: data.msg,
  164. icon:'none'
  165. });
  166. })
  167. .catch(e => {
  168. console.log(e);
  169. });
  170. }
  171. },
  172. fail: () => {},
  173. complete: () => {}
  174. });
  175. }
  176. },
  177. getIndex(){
  178. getIndex({})
  179. .then(({
  180. data
  181. }) => {
  182. this.baseData = data
  183. console.log(data);
  184. })
  185. .catch(e => {});
  186. },
  187. // 购买订单
  188. commitorder(item) {
  189. uni.showModal({
  190. title: '请输入支付密码',
  191. editable:true,
  192. success: res => {
  193. if (res.confirm) {
  194. if (res.content) {
  195. uni.showLoading({
  196. title: '支付中。。。',
  197. mask: true
  198. });
  199. sellBuy({
  200. id: item.id,
  201. trade_psw: res.content,
  202. }).then((
  203. data
  204. ) => {
  205. uni.hideLoading();
  206. uni.showModal({
  207. title: '提示',
  208. content: data.msg,
  209. showCancel: false,
  210. });
  211. })
  212. .catch(e => {
  213. uni.hideLoading()
  214. console.log(e);
  215. });
  216. }
  217. }
  218. },
  219. });
  220. },
  221. // 挂出
  222. submission() {
  223. let obj = this;
  224. if(obj.bankList.length > 0){
  225. if(!obj.number){
  226. uni.showToast({
  227. title: '请输入数量',
  228. icon:'none'
  229. });
  230. return
  231. }
  232. if(!obj.price){
  233. uni.showToast({
  234. title: '请输入单价',
  235. icon:'none'
  236. });
  237. return
  238. }
  239. obj.showBank = true
  240. }else{
  241. uni.showModal({
  242. title: '请先去添加银行卡',
  243. success: res => {
  244. if (res.confirm) {
  245. uni.navigateTo({
  246. url:'/pages/user/set/bindBank'
  247. })
  248. }
  249. },
  250. });
  251. }
  252. },
  253. init() {
  254. this.page = 1;
  255. this.list = [];
  256. this.loadingType = 'more';
  257. this.loadData();
  258. this.qianBao();
  259. this.getBank();
  260. },
  261. tabClick(index) {
  262. this.tabCurrentIndex = index;
  263. },
  264. async loadData(source) {
  265. const that = this;
  266. //这里是将订单挂载到tab列表下
  267. let navItem = that;
  268. if (source === 'tabChange' && navItem.loaded === true) {
  269. //tab切换只有第一次需要加载数据
  270. return;
  271. }
  272. if (navItem.loadingType === 'loading') {
  273. //防止重复加载
  274. return;
  275. }
  276. if (navItem.loadingType === 'noMore') {
  277. //防止重复加载
  278. return;
  279. }
  280. // 修改当前对象状态为加载中
  281. navItem.loadingType = 'loading';
  282. getsell({
  283. page: navItem.page,
  284. limit: navItem.limit
  285. })
  286. .then(({
  287. data
  288. }) => {
  289. // 保存我的总金额
  290. let arr = data.list.map(e => {
  291. e.num = e.num * 1;
  292. e.price = e.price * 1;
  293. return e;
  294. });
  295. navItem.list = navItem.list.concat(arr);
  296. if (navItem.limit == data.length) {
  297. navItem.page++;
  298. //判断是否还有数据, 有改为 more, 没有改为noMore
  299. navItem.loadingType = 'more';
  300. return;
  301. } else {
  302. //判断是否还有数据, 有改为 more, 没有改为noMore
  303. navItem.loadingType = 'noMore';
  304. }
  305. uni.hideLoading();
  306. that.loaded = true;
  307. })
  308. .catch(e => {
  309. console.log(e);
  310. });
  311. },
  312. }
  313. };
  314. </script>
  315. <style lang="scss">
  316. .all {
  317. width: 750rpx;
  318. height: 100%;
  319. background-color: #051137;
  320. padding-top: var(--status-bar-height);
  321. color: #fff;
  322. }
  323. .navList {
  324. padding: 20rpx 50rpx;
  325. background: #1F2A4A;
  326. line-height: 1;
  327. position: fixed;
  328. top: 44px;
  329. left: 0;
  330. width: 100%;
  331. z-index: 9;
  332. .navItem {
  333. color: #fff;
  334. font-size: 30rpx;
  335. text-align: center;
  336. width: 50%;
  337. &.activeItem {
  338. color: #0C5AFA;
  339. position: relative;
  340. &:after {
  341. content: '';
  342. position: absolute;
  343. left: 36%;
  344. bottom: -20rpx;
  345. width: 30%;
  346. height: 8rpx;
  347. // transform: translateX(-50%);
  348. border-bottom: 4rpx solid #0C5AFA;
  349. border-radius: 0rpx 20rpx 0rpx 0rpx;
  350. }
  351. }
  352. &.tip {
  353. border-right: 1rpx solid #333D5B;
  354. }
  355. }
  356. }
  357. .listBox {
  358. padding: 62rpx 32rpx;
  359. .titleTetx {
  360. font-weight: bold;
  361. font-size: 24rpx;
  362. color: #FFFFFF;
  363. padding-bottom: 25rpx;
  364. }
  365. .tipBox {
  366. padding-top: 15rpx;
  367. font-size: 24rpx;
  368. }
  369. }
  370. .listTpl {
  371. border-bottom: 1rpx solid #6A7288;
  372. padding-bottom: 25rpx;
  373. .inputBox {
  374. font-size: 35rpx;
  375. color: #FFFFFF;
  376. }
  377. .listTip {}
  378. .listAll {
  379. padding-left: 30rpx;
  380. font-size: 24rpx;
  381. color: #0C5AFA;
  382. }
  383. }
  384. .submission {
  385. padding: 80rpx 25rpx;
  386. padding-bottom: 25rpx;
  387. .golden {
  388. background: #0C5AFA;
  389. color: #ffffff;
  390. }
  391. }
  392. .tips {
  393. text-align: center;
  394. }
  395. .listItemBox {
  396. padding-top: 44px;
  397. .listItem {
  398. padding: 34rpx 34rpx;
  399. border-bottom: 1rpx solid #6A7288;
  400. .name {
  401. font-family: PingFang SC;
  402. font-weight: bold;
  403. font-size: 30rpx;
  404. color: #FFFFFF;
  405. padding-left: 25rpx;
  406. }
  407. .itemTpl {
  408. font-family: PingFang SC;
  409. font-weight: bold;
  410. font-size: 36rpx;
  411. color: #0C5AFA;
  412. padding-top: 25rpx;
  413. }
  414. .itemTip {
  415. .tipText {
  416. font-family: PingFang SC;
  417. font-weight: 500;
  418. font-size: 24rpx;
  419. color: #C1C1C1;
  420. padding-top: 15rpx;
  421. }
  422. .tipBtn {
  423. font-family: PingFang SC;
  424. font-weight: bold;
  425. font-size: 24rpx;
  426. color: #FFFFFF;
  427. background: linear-gradient(90deg, #0C5AFA, #1356FF);
  428. border-radius: 7rpx;
  429. padding: 15rpx 35rpx;
  430. }
  431. }
  432. }
  433. }
  434. </style>