index.vue 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  1. <template>
  2. <view class="container">
  3. <navBar title="充值次数" :back="true" color="#333333" background="#FFFFFF" />
  4. <view class="addBg" :style="{'background-image':`url(${picBase+'chargeBg.png'})`}">
  5. <view class="topBox">
  6. <view class="userBox">
  7. <image class="avatar" :src="!userInfo.avatar?picBase+'defaultAvatar.png':userInfo.avatar" mode="">
  8. </image>
  9. <view class="right">
  10. <view class="nickname">
  11. {{userInfo.name?userInfo.name:'默认用户'}}
  12. </view>
  13. <view class="bot">
  14. <image class="icon" :src="picBase+'charge_yibiao.png'" mode=""></image>
  15. 绘画次数:{{userInfo.diamond}}
  16. </view>
  17. </view>
  18. </view>
  19. <view class="btn" @click="toRecord">
  20. 记录
  21. </view>
  22. </view>
  23. <view class="mainBox">
  24. <view class="tagLine">
  25. </view>
  26. <view class="carItem " :class="[index==curIndex?'bor':'']" v-for="(item,index) in list"
  27. @click="selTaocan(index,item.id)">
  28. <view class="left">
  29. <view class="name">
  30. {{item.title}}
  31. </view>
  32. <view class="count">
  33. 次数:{{item.diamond}}
  34. </view>
  35. </view>
  36. <view class="right">
  37. ¥{{item.amount}}
  38. </view>
  39. </view>
  40. </view>
  41. </view>
  42. <view class="btnBox">
  43. <view class="btn" @click="goumai">
  44. 立即购买
  45. </view>
  46. </view>
  47. </view>
  48. </template>
  49. <script>
  50. // import navBar from '@/components/navBar/index.vue'
  51. import {
  52. payConfig,
  53. getUserInfo,
  54. submitOrder
  55. } from '@/api/index/index.js'
  56. export default {
  57. // components: {
  58. // navBar
  59. // },
  60. data() {
  61. return {
  62. picBase: this.$picBase2,
  63. curIndex: 0,
  64. list: [],
  65. userInfo: null,
  66. seledId: -1,
  67. from: ''
  68. }
  69. },
  70. onLoad(o) {
  71. if (o.from) {
  72. this.from = o.from
  73. }
  74. this.payConfig()
  75. this.getUserInfo()
  76. },
  77. methods: {
  78. async getUserInfo() {
  79. let res1 = await getUserInfo()
  80. console.log('用户信息返回值--------2', res1);
  81. if (res1.code == 0) {
  82. uni.setStorageSync('userInfo', res1.data)
  83. this.userInfo = res1.data
  84. } else {
  85. this.$toast(res1.message)
  86. }
  87. },
  88. async payConfig() {
  89. let res1 = await payConfig()
  90. console.log('套餐配置返回值--------2', res1);
  91. if (res1.code == 0) {
  92. this.list = res1.data
  93. this.seledId = res1.data[0].id
  94. } else {
  95. this.$toast(res1.message)
  96. }
  97. },
  98. selTaocan(i, id) {
  99. this.curIndex = i
  100. this.seledId = id
  101. },
  102. toRecord() {
  103. uni.navigateTo({
  104. url: '/pages/my/myRecord/index?tabIndex=0'
  105. })
  106. },
  107. async goumai() {
  108. let res = wx.getSystemInfoSync();
  109. if (res.platform == 'ios') {
  110. return wx.showModal({
  111. title: '提示',
  112. content: '【由于相关规范,iOS功能暂不可用】',
  113. success(res) {
  114. if (res.confirm) {
  115. console.log('用户点击确定')
  116. } else if (res.cancel) {
  117. console.log('用户点击取消')
  118. }
  119. }
  120. })
  121. }
  122. // this.$toast('购买成功')
  123. // setTimeout(() => {
  124. // uni.navigateTo({
  125. // url: '/pages/my/myRecord/index?tabIndex=0'
  126. // })
  127. // }, 1500)
  128. // return console.log('套餐下单参数', {
  129. // id: this.seledId
  130. // });
  131. let res1 = await submitOrder({
  132. id: this.seledId
  133. })
  134. console.log('套餐下单返回值--------2', res1);
  135. if (res1.code == 0) {
  136. console.log('微信支付参数:', res1.data.config);
  137. // this.$toast('购买成功', 'success')
  138. // setTimeout(() => {
  139. // uni.navigateTo({
  140. // url: '/pages/my/myRecord/index?tabIndex=0'
  141. // })
  142. // }, 1500)
  143. this.pay(res1.data.config)
  144. } else {
  145. this.$toast(res1.message)
  146. }
  147. },
  148. pay(p) {
  149. let _this = this
  150. console.log('pay---p', p);
  151. wx.requestPayment({
  152. "timeStamp": p.timeStamp,
  153. "nonceStr": p.nonceStr,
  154. "package": p.package,
  155. "signType": p.signType,
  156. "paySign": p.paySign,
  157. "success": function(res) {
  158. wx.showToast({
  159. title: '支付成功',
  160. icon: 'success'
  161. })
  162. setTimeout(res => {
  163. if (_this.from == 'gen') {
  164. // wx.navigateTo({
  165. // url: '/pages/my/myRecord/index?tabIndex=0',
  166. // })
  167. uni.navigateBack()
  168. } else {
  169. wx.redirectTo({
  170. url: '/pages/my/myRecord/index?tabIndex=0',
  171. })
  172. }
  173. }, 1500)
  174. },
  175. "fail": function(res) {
  176. console.log('res', res);
  177. wx.showToast({
  178. title: '支付失败',
  179. icon: 'error'
  180. })
  181. // setTimeout(res => {
  182. // wx.navigateTo({
  183. // url: '/pages/order/order?status=0',
  184. // })
  185. // }, 2000)
  186. },
  187. "complete": function(res) {}
  188. })
  189. }
  190. }
  191. }
  192. </script>
  193. <style lang="scss" scoped>
  194. @import "./index.scss";
  195. </style>