community.vue 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285
  1. <template>
  2. <view class="container">
  3. <navBar :show-title="true" :title="$t('home.共创社区')" url="/pages/index/index"></navBar>
  4. <view class="text-center border-linear-gradient">
  5. <image class="contentImg" src="../../static/img/itemListMax.png" mode="widthFix"></image>
  6. <view class="title flex-center">
  7. <view>{{$t('home.认购价')}}:</view>
  8. <view class="num text-linear-gradient">{{num}}U</view>
  9. </view>
  10. <!-- <view class="title flex-center">
  11. <view>{{$t('home.认购数')}}:</view>
  12. <view class="num text-linear-gradient">10000个</view>
  13. </view> -->
  14. <!-- <view class="title flex-center">
  15. <view>{{$t('home.社区建设')}}</view>
  16. </view> -->
  17. <view class="buttom" @click="openPayMoney">
  18. {{$t('home.立即认购')}}
  19. </view>
  20. </view>
  21. <view class="detail border-linear-gradient">
  22. <view class="flex top">
  23. <view class="item">
  24. <view class="text-linear-gradient">
  25. {{order_num||0}}
  26. </view>
  27. <view class="tipText margin-t-20">
  28. {{$t('home.已认购')}}
  29. </view>
  30. </view>
  31. <view class="lineH">
  32. </view>
  33. <view class="item">
  34. <view class="text-linear-gradient">
  35. {{wait||0}}
  36. </view>
  37. <view class="tipText margin-t-20">
  38. {{$t('home.待释放')}}
  39. </view>
  40. </view>
  41. </view>
  42. <view class="flex padding-c-30 padding-v-20">
  43. <view class="flex">
  44. <view class="imageTip margin-r-10">
  45. <image class="nodeImg" src="../../static/img/nodeIcon.png" mode=""></image>
  46. </view>
  47. <view class="typename">
  48. {{$t('home.释放记录')}}
  49. </view>
  50. </view>
  51. <navigator url="./communityDetail">
  52. <view class="flex-center">
  53. <view class="rightTip margin-r-10">
  54. {{$t('home.查看详细')}}
  55. </view>
  56. <image class="nextImg" src="../../static/img/mininext.png" mode="scaleToFill"></image>
  57. </view>
  58. </navigator>
  59. </view>
  60. </view>
  61. </view>
  62. </template>
  63. <script>
  64. import {
  65. loadIndexs,
  66. creatorOrder,
  67. payOrder,
  68. orderCalculator,
  69. orderList
  70. } from '@/api/index.js';
  71. import {
  72. mapMutations
  73. } from "vuex";
  74. import {
  75. getUserInfo
  76. } from '@/api/user.js';
  77. import navBar from "@/components/nav/nav.vue"
  78. export default {
  79. data() {
  80. return {
  81. num: 300,
  82. order_num:'',
  83. wait:'',
  84. }
  85. },
  86. components: {
  87. navBar
  88. },
  89. onLoad(option) {
  90. this.getUserInfo();
  91. },
  92. methods: {
  93. ...mapMutations('user', ['setUserInfo']),
  94. // 获取更新用户信息
  95. getUserInfo() {
  96. getUserInfo().then((res) => {
  97. this.setUserInfo(res.data);
  98. }).catch((res) => {
  99. console.log(res);
  100. })
  101. // loadIndexs().then((res) => {
  102. // this.num = res.data.point_num
  103. // }).catch((res) => {
  104. // console.log(res);
  105. // })
  106. orderList().then(({data}) => {
  107. this.order_num = data.order_num;
  108. this.wait = data.wait;
  109. }).catch((res) => {
  110. console.log(res);
  111. })
  112. },
  113. // 报单
  114. openPayMoney() {
  115. const that = this;
  116. uni.showActionSheet({
  117. title: that.$t("home.请选择支付方式"),
  118. itemList: ['USDT', that.$t("home.余额")],
  119. success(res) {
  120. uni.showLoading({
  121. mask: true
  122. });
  123. that.creatorOrder(res.tapIndex)
  124. }
  125. })
  126. },
  127. // 生成订单
  128. creatorOrder(index) {
  129. creatorOrder({
  130. num: this.num * 1,
  131. }).then(({
  132. data
  133. }) => {
  134. this.payOrder(index + 1, data.id)
  135. }).catch((res) => {
  136. console.log(res);
  137. })
  138. },
  139. // 支付订单
  140. async payOrder(ind, id) {
  141. const that = this;
  142. let pushData = {
  143. num: this.num * 1,
  144. type: ind
  145. }
  146. try {
  147. if (ind == 1) {
  148. const {
  149. data
  150. } = await orderCalculator({
  151. id
  152. });
  153. const txHash = await ethereum.request({
  154. method: 'eth_sendTransaction',
  155. params: [{
  156. from: that.userInfo.address, // The user's active address.
  157. to: data.data.to,
  158. value: 0,
  159. data: data.data.data,
  160. }]
  161. })
  162. const req = await payOrder(id, {
  163. type: ind,
  164. transactionHash: txHash,
  165. });
  166. }
  167. if (ind == 2) {
  168. const req = await payOrder(id, {
  169. type: ind
  170. });
  171. }
  172. that.getUserInfo();
  173. uni.showToast({
  174. title: that.$t('home.认购成功')
  175. })
  176. } catch (e) {
  177. console.log(e, 'err');
  178. uni.showToast({
  179. title: that.$t('home.认购失败'),
  180. icon: 'error'
  181. })
  182. }
  183. },
  184. },
  185. }
  186. </script>
  187. <style lang="scss">
  188. .contentImg {
  189. margin: 0 auto;
  190. width: 100%;
  191. margin-top: -200rpx;
  192. }
  193. .container {
  194. width: 100%;
  195. line-height: 1;
  196. background-color: rgb(12, 8, 21);
  197. min-height: 100vh;
  198. }
  199. .detail {
  200. margin: 30rpx 30rpx 0 30rpx;
  201. border-radius: 30rpx;
  202. .top {
  203. justify-content: space-around;
  204. padding: 30rpx;
  205. color: #FFF;
  206. font-weight: 500;
  207. border-bottom: 1px solid #E1E1E1;
  208. margin: 0 30rpx;
  209. .item {
  210. text-align: center;
  211. font-weight: bold;
  212. font-size: 38rpx;
  213. .tipText {
  214. font-size: 22rpx;
  215. opacity: 0.8;
  216. }
  217. }
  218. .lineH {
  219. height: 92rpx;
  220. width: 2px;
  221. background: linear-gradient(0deg, rgba(255, 255, 255, 0), #FFFFFF, rgba(255, 255, 255, 0));
  222. }
  223. }
  224. .typename {
  225. font-size: 30rpx;
  226. color: #FFF;
  227. }
  228. .imageTip {
  229. .nodeImg {
  230. width: 36rpx;
  231. height: 33rpx;
  232. }
  233. }
  234. .rightTip {
  235. color: #FFF;
  236. font-size: 24rpx;
  237. }
  238. .nextImg {
  239. width: 8rpx;
  240. height: 14rpx;
  241. }
  242. }
  243. .text-center {
  244. border-radius: 30rpx;
  245. margin: 100rpx 30rpx 0 30rpx;
  246. color: #FFF;
  247. padding: 80rpx 50rpx;
  248. .title {
  249. font-weight: 500;
  250. font-size: 33rpx;
  251. padding-bottom: 50rpx;
  252. // align-items: flex-end;
  253. }
  254. .num {
  255. font-weight: bold;
  256. font-size: 52rpx;
  257. }
  258. }
  259. .buttom {
  260. font-weight: bold;
  261. font-size: 32rpx;
  262. border-radius: 20rpx;
  263. padding: 30rpx;
  264. background: linear-gradient(to right, #7D32FF 0%, #3EE0FF 100%);
  265. }
  266. </style>