buyCalculation.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444
  1. <template>
  2. <view class="container">
  3. <image class="logo-img" src="../../static/img/img01.png"></image>
  4. <view class="list-box">
  5. <scroll-view scroll-x class="list-title">
  6. <view
  7. class="title"
  8. v-for="(ls, index) in moneyTypeList"
  9. :key="index"
  10. :class="{ blue: tabCurrent == ls.code, grey: ls.has_mining == 0 }"
  11. @click="tabClick(ls.code, ls.has_mining)"
  12. v-if="ls.name !== 'USDT'"
  13. >
  14. {{ ls.name }}
  15. </view>
  16. </scroll-view>
  17. <view class="flex_item list-name">
  18. <view class="name" :class="{ black: tabType == 1 }" @click="tabTypeClick(1)">算力包</view>
  19. <view class="name" :class="{ black: tabType == 2 }" @click="tabTypeClick(2)">独享矿机</view>
  20. <!-- <view class='name' :class="{'black':tabType==3}" @click="tabTypeClick(3)">联合挖矿</view> -->
  21. <!-- <view class='name' :class="{'black':tabCurrent==4}">分类名称</view> -->
  22. </view>
  23. <view class="list-cell" v-if="list.length > 0" v-for="(ls, index) in list" :key="index">
  24. <view class="flex">
  25. <view>
  26. <view class="cell-title flex">
  27. <image :src="ls.logo"></image>
  28. <view class="title">{{ ls.name }}</view>
  29. </view>
  30. <view class="tags">
  31. <!-- <view class="cell-tip">{{ ls.first_step_time + ls.second_step_time + ls.third_step_time }}天矿机</view> -->
  32. <template v-if="ls.tags[0] !== '0'">
  33. <view class="cell-tip" v-for="item in ls.tags" :key="item">{{item}}</view>
  34. <!-- <view class="cell-tag">特价</view> -->
  35. </template>
  36. </view>
  37. </view>
  38. <image v-if="ls.stock == 0" class="all-list" src="../../static/img/img51.png"></image>
  39. </view>
  40. <view class="flex cell-tpl">
  41. <view class="tpl">
  42. <view class="">单价</view>
  43. <view class="">{{ ls._cost_money }}/T</view>
  44. </view>
  45. <view class="tpl">
  46. <view class="">有效算力</view>
  47. <view class="">{{ ls.step }}T</view>
  48. </view>
  49. <view class="tpl">
  50. <view class="">合约周期</view>
  51. <view class="">{{ ls.first_step_time + ls.second_step_time + ls.third_step_time }}天</view>
  52. </view>
  53. <!-- <view class="tpl">
  54. <view class="">上架期</view>
  55. <view class="">{{ ls.stand_time }}天</view>
  56. </view> -->
  57. </view>
  58. <view class="cell-info flex">
  59. <!-- <view class="tip">剩余数量:{{ls.stock}}/{{ls.all_stock}}T</view> -->
  60. <view class="tip">剩余数量:{{ ls | dataStock }}</view>
  61. <view class="zhiya-btn" v-if="ls.stock > 0" @click="ToBuy(ls)">{{ ls.type == 3 ? '立即质押' : '立即购买' }}</view>
  62. <view class="zhiya-btn grey" v-if="ls.stock == 0">已售罄</view>
  63. </view>
  64. <!-- <view class="list-tip" v-if="ls.detail"><rich-text :nodes="ls.detail"></rich-text></view> -->
  65. </view>
  66. <view class="empty-box" v-show="list.length === 0"><empty></empty></view>
  67. </view>
  68. <uni-popup ref="popup" type="center">
  69. <view class="popup">
  70. <view class="cancel flex" @click="close">
  71. <view></view>
  72. <view class="tip">x</view>
  73. </view>
  74. <view class="list-box">
  75. <view class="popup-text">购买数量:</view>
  76. <view class="password"><input type="number" v-model="num" /></view>
  77. <view class="popup-text">支付密码:</view>
  78. <view class="password"><input type="password" v-model="password" /></view>
  79. <view class="confirm-btn" @click="pay"><text>确认购买</text></view>
  80. </view>
  81. </view>
  82. </uni-popup>
  83. </view>
  84. </template>
  85. <script>
  86. import { mining, buyMining } from '@/api/calculation.js';
  87. import { moneyType } from '@/api/index.js';
  88. import empty from '@/components/empty';
  89. export default {
  90. components: {
  91. empty
  92. },
  93. filters: {
  94. dataStock: function(ls) {
  95. let type = 'T';
  96. // if (+ls.stock >= 1024) {
  97. // // type = 'P';
  98. // return `${ls.stock/1024 }/${ls.all_stock/1024 }${type}`;
  99. // } else {
  100. // return `${ls.stock}/${ls.all_stock}${type}`;
  101. // }
  102. return `${+ls.stock}${type}/${+ls.all_stock}${type}`;
  103. }
  104. },
  105. data() {
  106. return {
  107. tabCurrent: 'XCH',
  108. tabType: 1,
  109. moneyTypeList: [
  110. {
  111. code: 'XCH',
  112. name: 'XCH',
  113. has_mining: 1
  114. },
  115. {
  116. code: 'USDT',
  117. name: 'USDT',
  118. has_mining: 0
  119. },
  120. {
  121. code: 'BTC',
  122. name: 'BTC',
  123. has_mining: 0
  124. },
  125. {
  126. code: 'ETH',
  127. name: 'ETH',
  128. has_mining: 0
  129. },
  130. {
  131. code: 'FIL',
  132. name: 'FIL',
  133. has_mining: 0
  134. }
  135. ],
  136. list: [],
  137. buyId: '',
  138. password: '',
  139. num: ''
  140. };
  141. },
  142. onLoad(option) {
  143. this.moneyType();
  144. this.loadData();
  145. },
  146. onShow() {},
  147. //下拉刷新
  148. onPullDownRefresh() {
  149. this.moneyType();
  150. },
  151. methods: {
  152. // 所有币种
  153. async moneyType() {
  154. let obj = this;
  155. console.log(obj.moneyTypeList);
  156. moneyType({}).then(({ data }) => {
  157. // console.log(data,"+++++++moneyTypeList++++++++++")
  158. obj.moneyTypeList = data;
  159. // console.log(obj.moneyTypeList,'moneyTypeList----------')
  160. // if(obj.moneyTypeList.length > 0){
  161. // obj.tabCurrent = obj.moneyTypeList[0].code
  162. // }
  163. });
  164. },
  165. // 请求载入数据
  166. async loadData() {
  167. let obj = this;
  168. uni.showLoading({
  169. title: '加载中...'
  170. });
  171. mining({
  172. page: 1,
  173. limit: 1000,
  174. type: obj.tabType,
  175. get_money_type: obj.tabCurrent
  176. }).then(({ data }) => {
  177. console.log(data, '1111');
  178. obj.list = data.data.map(e => {
  179. e.step = +e.step;
  180. e._cost_money = +e._cost_money.replace(e.cost_money_type, '') + e.cost_money_type;
  181. return e;
  182. });
  183. console.log(obj.list, 'obj.list++++++++++++');
  184. let len = obj.list.length;
  185. for (let i = 0; i < len; i++) {
  186. // obj.list[i].tags = obj.list[i].tags.splice(',')
  187. for (let j = 0; j < len; j++) {
  188. if (obj.list[i].step > obj.list[j].step) {
  189. let z = obj.list[i];
  190. obj.list[i] = obj.list[j];
  191. obj.list[j] = z;
  192. }
  193. }
  194. }
  195. console.log(obj.list, 'new obj.list-------------');
  196. uni.hideLoading();
  197. });
  198. },
  199. ToBuy(ls) {
  200. // let obj = this;
  201. // obj.buyId = id;
  202. // this.$refs.popup.open();
  203. uni.navigateTo({
  204. url: '/pages/calculation/details?id=' + ls.id + '&type=' + ls.type
  205. });
  206. },
  207. pay() {
  208. let obj = this;
  209. buyMining(
  210. {
  211. num: obj.num,
  212. trade_psw: obj.password
  213. },
  214. obj.buyId
  215. )
  216. .then(({ data }) => {
  217. obj.$api.msg('购买成功!');
  218. obj.loadData();
  219. obj.password = '';
  220. obj.num = '';
  221. obj.$refs.popup.close();
  222. })
  223. .catch(e => {
  224. obj.loadData();
  225. obj.password = '';
  226. obj.num = '';
  227. obj.$refs.popup.close();
  228. });
  229. },
  230. close() {
  231. this.$refs.popup.close();
  232. },
  233. tabClick(index, has_mining) {
  234. if (has_mining == 0) {
  235. this.$api.msg('敬请期待!');
  236. } else {
  237. this.tabCurrent = index;
  238. this.loadData();
  239. }
  240. },
  241. tabTypeClick(index) {
  242. this.tabType = index;
  243. this.loadData();
  244. }
  245. }
  246. };
  247. </script>
  248. <style lang="scss">
  249. page {
  250. min-height: 100%;
  251. background-color: #ffffff;
  252. .container {
  253. width: 100%;
  254. }
  255. }
  256. .logo-img {
  257. margin: 40rpx 6%;
  258. width: 88%;
  259. height: 209rpx;
  260. }
  261. .list-box {
  262. .list-title {
  263. overflow: hidden;
  264. white-space: nowrap;
  265. .title {
  266. display: inline-block;
  267. background-color: #bac1ef;
  268. font-size: 30rpx;
  269. font-weight: bold;
  270. color: #ffffff;
  271. width: 24.49%;
  272. margin-right: 5rpx;
  273. text-align: center;
  274. line-height: 60rpx;
  275. }
  276. .blue {
  277. background-color: #5771df;
  278. }
  279. .grey {
  280. background-color: #dbdbdb !important;
  281. }
  282. }
  283. .list-name {
  284. padding: 24rpx 50rpx;
  285. .name {
  286. font-size: 28rpx;
  287. margin-right: 20%;
  288. font-weight: 500;
  289. color: #666666;
  290. }
  291. .black {
  292. color: #333333;
  293. border-bottom: 2rpx solid #5771df;
  294. padding-bottom: 10rpx;
  295. font-size: 30rpx;
  296. }
  297. }
  298. }
  299. .more {
  300. color: #606266;
  301. font-size: 24rpx;
  302. font-weight: normal;
  303. border-bottom: 1rpx solid #606266;
  304. }
  305. .all-list {
  306. width: 180rpx;
  307. height: 180rpx;
  308. }
  309. .list-cell {
  310. box-sizing: border-box;
  311. width: 670rpx;
  312. margin: 0 auto;
  313. padding: 40rpx 40rpx;
  314. border-radius: 30rpx 30rpx;
  315. background-color: #f7f6fb;
  316. margin-bottom: 20rpx;
  317. .cell-title {
  318. padding: 29rpx 38rpx 29rpx 15rpx;
  319. font-size: 38rpx;
  320. font-weight: bold;
  321. color: #333333;
  322. image {
  323. width: 40rpx;
  324. height: 40rpx;
  325. margin-right: 15rpx;
  326. }
  327. }
  328. .tags {
  329. .cell-tip {
  330. display: inline-block;
  331. padding: 11rpx 18rpx 9rpx 20rpx;
  332. font-size: 30rpx;
  333. font-weight: bold;
  334. color: #0ec1a1;
  335. background-color: #e3f6fa;
  336. border-radius: 24rpx 24rpx;
  337. margin-right: 20rpx;
  338. }
  339. .cell-tag {
  340. display: inline-block;
  341. margin-left: 20rpx;
  342. padding: 4rpx 18rpx 3rpx 20rpx;
  343. font-size: 30rpx;
  344. font-weight: bold;
  345. color: red;
  346. // background-color: #fff;
  347. // border-radius: 24rpx 24rpx;
  348. border: 4rpx red solid;
  349. }
  350. }
  351. .cell-tpl {
  352. padding: 50rpx 0rpx 34rpx;
  353. font-size: 30rpx;
  354. font-weight: bold;
  355. color: #333333;
  356. line-height: 40rpx;
  357. // text-align: center;
  358. }
  359. .cell-info {
  360. .tip {
  361. font-size: 34rpx;
  362. font-weight: bold;
  363. color: #5771df;
  364. line-height: 55px;
  365. }
  366. .zhiya-btn {
  367. background-color: #5771df;
  368. width: 150rpx;
  369. text-align: center;
  370. line-height: 60rpx;
  371. font-size: 26rpx;
  372. border-radius: 50rpx;
  373. color: #ffffff;
  374. }
  375. .grey {
  376. background-color: #999999;
  377. }
  378. }
  379. .list-tip {
  380. background-color: #bac1ef !important;
  381. word-wrap: break-word;
  382. font-size: 26rpx;
  383. font-weight: 500;
  384. color: #333333;
  385. padding: 36rpx 32rpx;
  386. margin-top: 15rpx;
  387. border-bottom-left-radius: 15rpx;
  388. border-bottom-right-radius: 15rpx;
  389. }
  390. }
  391. .empty-box {
  392. width: 100%;
  393. height: 500rpx;
  394. }
  395. //弹窗
  396. .popup {
  397. background-color: #ffffff;
  398. border-radius: 25rpx;
  399. font-size: 30rpx;
  400. .cancel {
  401. text-align: center;
  402. width: 100%;
  403. line-height: 60rpx;
  404. .tip {
  405. background-color: #5771df;
  406. color: #ffffff;
  407. width: 70rpx;
  408. height: 70rpx;
  409. border-top-right-radius: 25rpx;
  410. }
  411. }
  412. .list-box {
  413. padding: 0rpx 80rpx;
  414. .password {
  415. padding: 50rpx 0rpx;
  416. width: 100%;
  417. input {
  418. width: 70%;
  419. height: 80rpx;
  420. border: 2rpx solid #999999;
  421. padding-left: 25rpx;
  422. box-shadow: 0px 3px 5px 0px rgba(0, 0, 0, 0.27);
  423. border-radius: 11rpx;
  424. }
  425. }
  426. .confirm-btn {
  427. padding-bottom: 120rpx;
  428. padding-top: 30rpx;
  429. text {
  430. background-color: #5771df;
  431. color: #ffffff;
  432. width: 70%;
  433. text-align: center;
  434. padding: 25rpx 90rpx;
  435. border-radius: 15rpx;
  436. }
  437. }
  438. }
  439. }
  440. </style>