index.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476
  1. <template>
  2. <view>
  3. <view class="">
  4. <view class="margin-lr margin-top" style="position: relative;border-radius: 10upx;overflow: hidden;">
  5. <image src="../static/vip/vip.png" style="width: 100%;height: 250rpx;"></image>
  6. <view class=" u-flex u-p-l-30 u-p-t-80 u-p-b-30" style="position: absolute;top: 0;width: 100%;">
  7. <view class="u-m-r-20">
  8. <u-avatar :src="avatar" size="100"></u-avatar>
  9. </view>
  10. <view class="u-flex-1 ">
  11. <view class="u-font-18 text-white text-bold">{{userName}}</view>
  12. <view class="u-font-10 text-bold" style="margin-top: 10rpx;color: #999999;" v-if="vipExpirationTime && isVip">有效期:{{vipExpirationTime}}</view>
  13. <view class="u-font-14 u-m-t-10 u-tips-color" style="color: #C59D7C;" v-if="!isVip">您目前还未开通会员
  14. </view>
  15. </view>
  16. </view>
  17. </view>
  18. <!-- <view class="flex justify-center margin-top-sm flex-wrap padding-lr-sm">
  19. <view style="display: inline-block;width: 216rpx;height: 250rpx;margin: 10rpx 10rpx;">
  20. <view class="text-center flex flex-direction justify-between padding-tb radius active"
  21. style="color: #DFC5A7;width: 216rpx;height: 250rpx;background: linear-gradient(-30deg, #2B2A30, #4A4A4A);border: 1px;">
  22. <view class="text-bold">月会员</view>
  23. <view class="text-bold">¥<text class="text-xxl">{{vipList.value}}</text></view>
  24. <view>立即购买</view>
  25. </view>
  26. </view>
  27. </view> -->
  28. <view class="flex justify-center align-center margin-top" v-if="!isVip">
  29. <view class="" @click="showpay=true"
  30. style="position: relative;left: 0;right: 0;border-radius: 10upx;overflow: hidden;display: inline-block;margin: auto;">
  31. <image src="../static/vip/bg.png" style="width: 459rpx;height: 129rpx;"></image>
  32. <view class="flex align-center"
  33. style="position: absolute;top: -10rpx;left:30rpx;bottom: 0;margin: auto; width: 100%;height: 100%;">
  34. <view class="text-bold">¥<text class="text-xxl">{{vipList.value}}</text></view>
  35. </view>
  36. </view>
  37. </view>
  38. <view class="padding-tb radius margin-top margin-lr"
  39. style="background-color: #343339;border-radius: 10upx;">
  40. <view class="text-center text-xl text-bold " style="color: #CAB49C;">会员特权</view>
  41. <view class="flex flex-wrap">
  42. <view v-for="(item,index) in MemberList" :key="index"
  43. style="width: 33%;text-align: center;margin-top: 34upx;">
  44. <image :src="item.memberImg" mode="" style="margin: 0 auto;height: 45rpx;width: 45rpx;"></image>
  45. <view class="grid-text margin-top-sm" style="color: #DFC5A7;">{{item.memberName}}</view>
  46. </view>
  47. </view>
  48. </view>
  49. </view>
  50. <view style="height: 110rpx;"></view>
  51. <view class="flex justify-between cu-bar foot bg padding-lr" v-if="!isVip">
  52. <view style="color: #DFC5A7;">
  53. 实付:<text style="font-size: 38upx;margin-top: 8upx;">{{price}}</text>元
  54. </view>
  55. <view class="">
  56. <u-button :custom-style="customStyle" @click="showpay=true" shape="circle" :hair-line="false">立即开通
  57. </u-button>
  58. </view>
  59. </view>
  60. <!-- 支付方式 -->
  61. <u-popup v-model="showpay" mode="bottom" :closeable="closeable">
  62. <view class="popup_pay">
  63. <view style="background-color: #fff;">
  64. <view style="padding: 0 20upx;margin-top: 60rpx;margin-bottom: 20rpx;">
  65. <view
  66. style="display: flex;height: 100upx;align-items: center;padding: 20upx 0;justify-content: center;"
  67. v-for="(item,index) in openLists" :key='index'>
  68. <image :src="item.image" style="width: 55upx;height: 55upx;border-radius: 50upx;">
  69. </image>
  70. <view style="font-size: 30upx;margin-left: 20upx;width: 70%;">
  71. {{item.text}}
  72. </view>
  73. <radio-group name="openWay" style="margin-left: 45upx;" @tap='selectWay(item)'>
  74. <label class="tui-radio">
  75. <radio color="#1777FF" :checked="openWay === item.id ? true : false" />
  76. </label>
  77. </radio-group>
  78. </view>
  79. </view>
  80. </view>
  81. <view class="pay_btn" @click="pay()">确认支付</view>
  82. </view>
  83. </u-popup>
  84. </view>
  85. </template>
  86. <script>
  87. export default {
  88. data() {
  89. return {
  90. vipExpirationTime:'',
  91. showpay: false,
  92. closeable: true,
  93. openLists: [],
  94. customStyle: {
  95. width: '250rpx',
  96. color: '#402321',
  97. background: "#DFC5A7",
  98. border: 0,
  99. fontWeight: '700'
  100. },
  101. gridData: [{
  102. title: '专享折上折',
  103. image: '../static/1.png'
  104. },
  105. {
  106. title: '特权礼物',
  107. image: '../static/2.png'
  108. },
  109. {
  110. title: '身份标识',
  111. image: '../static/3.png'
  112. },
  113. {
  114. title: '超值专享券',
  115. image: '../static/4.png'
  116. },
  117. {
  118. title: '商家特权',
  119. image: '../static/5.png'
  120. },
  121. {
  122. title: '定制挂件',
  123. image: '../static/6.png'
  124. }
  125. ],
  126. avatar: '',
  127. userName: '匿名',
  128. vipList: [],
  129. selNum: 1,
  130. newPrice: 0,
  131. money: 0,
  132. price: 0,
  133. MemberList: [],
  134. isVip: false,
  135. openWay: 2
  136. }
  137. },
  138. onLoad() {
  139. // #ifdef APP
  140. this.openLists = [{
  141. image: '../../static/images/my/weixin.png',
  142. text: '微信',
  143. id: 2
  144. }, {
  145. image: '../../static/images/my/zhifubao.png',
  146. text: '支付宝',
  147. id: 3
  148. },{
  149. image: '../../static/images/my/jinbi.png',
  150. text: '零钱',
  151. id: 1
  152. }]
  153. // #endif
  154. // #ifdef MP-WEIXIN
  155. this.openLists = [{
  156. image: '../../static/images/my/weixin.png',
  157. text: '微信',
  158. id: 2
  159. },{
  160. image: '../../static/images/my/jinbi.png',
  161. text: '零钱',
  162. id: 1
  163. }]
  164. // #endif
  165. // #ifdef H5
  166. this.openLists = [{
  167. image: '../../static/images/my/weixin.png',
  168. text: '微信',
  169. id: 2
  170. },{
  171. image: '../../static/images/my/zhifubao.png',
  172. text: '支付宝',
  173. id: 3
  174. },{
  175. image: '../../static/images/my/jinbi.png',
  176. text: '零钱',
  177. id: 1
  178. }]
  179. // #endif
  180. this.avatar = uni.getStorageSync('avatar')
  181. this.userName = uni.getStorageSync('userName')
  182. this.getVipList()
  183. this.getMemberList()
  184. this.getMoney()
  185. this.getIsVip()
  186. this.getUserInfo()
  187. },
  188. methods: {
  189. selectWay: function(item) {
  190. this.openWay = item.id;
  191. },
  192. getUserInfo() {
  193. this.$Request.get("/app/user/selectUserById").then(res => {
  194. if (res.code == 0) {
  195. this.avatar = res.data.avatar ? res.data.avatar : '../../static/logo.png'
  196. uni.setStorageSync('avatar', res.data.avatar)
  197. }
  198. });
  199. },
  200. //获取VIP列表
  201. getVipList() {
  202. this.$Request.get('/app/common/type/313').then(res => {
  203. if (res.code == 0) {
  204. this.vipList = res.data
  205. this.price = this.vipList.value
  206. }
  207. })
  208. },
  209. // 获取特权列表
  210. getMemberList() {
  211. this.$Request.get('/app/member/selectMemberList').then(res => {
  212. if (res.code == 0) {
  213. this.MemberList = res.data
  214. }
  215. })
  216. },
  217. getIsVip() {
  218. this.$Request.get("/app/user/selectUserMessage").then(res => {
  219. if (res.code == 0) {
  220. this.vipExpirationTime = res.data.vipExpirationTime;
  221. this.isVip = res.data.isVip==1?true:false
  222. }
  223. });
  224. },
  225. // 我的金币
  226. getMoney() {
  227. this.$Request.get("/app/userMoney/selectMyMoney").then(res => {
  228. if (res.code == 0 && res.data) {
  229. this.money = res.data.money
  230. }
  231. });
  232. },
  233. select(e) {
  234. this.selNum = e.id
  235. this.price = e.money
  236. },
  237. pay() {
  238. let userId = uni.getStorageSync('userId')
  239. this.showpay = false
  240. if (this.openWay == 1) { //余额支付
  241. this.$Request.post("/app/wxPay/balanceBuyVip").then(res => {
  242. if (res.code == 0) {
  243. this.$queue.showToast('支付成功');
  244. setTimeout(function() {
  245. uni.navigateBack()
  246. }, 1000)
  247. }else {
  248. this.$queue.showToast(res.msg);
  249. }
  250. });
  251. } else if (this.openWay == 2) { //微信支付
  252. // #ifdef MP-WEIXIN
  253. let data = {
  254. type: 3
  255. }
  256. this.$Request.post('/app/wxPay/wxPayJsApiBuyVip', data).then(res => {
  257. console.log(res)
  258. if (res.code == 0) {
  259. uni.requestPayment({
  260. provider: 'wxpay',
  261. timeStamp: res.data.timestamp,
  262. nonceStr: res.data.noncestr,
  263. package: res.data.package,
  264. signType: res.data.signType,
  265. paySign: res.data.sign,
  266. success: function(res) {
  267. console.log(res)
  268. uni.showLoading({
  269. title: '支付成功',
  270. icon: 'none'
  271. });
  272. setTimeout(function() {
  273. uni.navigateBack()
  274. }, 1000)
  275. },
  276. fail: function(err) {
  277. uni.showLoading({
  278. title: '支付失败',
  279. icon: 'nones'
  280. });
  281. }
  282. });
  283. }
  284. });
  285. // #endif
  286. // #ifdef H5
  287. let data = {
  288. userId: userId,
  289. type: 2
  290. }
  291. this.$Request.post('/app/wxPay/wxPayJsApiBuyVip', data).then(res => {
  292. this.showpay = false
  293. this.callPay(res);
  294. });
  295. // #endif
  296. // #ifdef APP
  297. let data = {
  298. type: 1
  299. }
  300. this.$Request.post('/app/wxPay/wxPayJsApiBuyVip', data).then(res => {
  301. console.log(res)
  302. this.showpay = false
  303. if (res.code == 0) {
  304. this.isCheckPay(res.code, 'wxpay', JSON.stringify(res.data));
  305. }
  306. });
  307. // #endif
  308. } else if (this.openWay == 3) { //支付宝支付
  309. // #ifdef H5
  310. let data = {
  311. type: 5
  312. }
  313. this.$Request.post('/app/wxPay/wxPayJsApiBuyVip', data).then(
  314. res => {
  315. this.showpay = false
  316. const div = document.createElement('div')
  317. div.innerHTML = res.data //此处form就是后台返回接收到的数据
  318. document.body.appendChild(div)
  319. document.forms[0].submit()
  320. });
  321. // #endif
  322. // #ifdef APP-PLUS
  323. let data = {
  324. type: 4
  325. }
  326. this.$Request.post('/app/wxPay/wxPayJsApiBuyVip', data).then(res => {
  327. this.showpay = false
  328. this.setPayment('alipay', res.data);
  329. });
  330. // #endif
  331. }
  332. },
  333. callPay: function(response) {
  334. if (typeof WeixinJSBridge === "undefined") {
  335. if (document.addEventListener) {
  336. document.addEventListener('WeixinJSBridgeReady', this.onBridgeReady(response), false);
  337. } else if (document.attachEvent) {
  338. document.attachEvent('WeixinJSBridgeReady', this.onBridgeReady(response));
  339. document.attachEvent('onWeixinJSBridgeReady', this.onBridgeReady(response));
  340. }
  341. } else {
  342. this.onBridgeReady(response);
  343. }
  344. },
  345. onBridgeReady: function(response) {
  346. let that = this;
  347. console.log(response)
  348. if (!response.package) {
  349. return;
  350. }
  351. WeixinJSBridge.invoke(
  352. 'getBrandWCPayRequest', {
  353. "appId": response.appid, //公众号名称,由商户传入
  354. "timeStamp": response.timestamp, //时间戳,自1970年以来的秒数
  355. "nonceStr": response.noncestr, //随机串
  356. "package": response.package,
  357. "signType": response.signType, //微信签名方式:
  358. "paySign": response.sign //微信签名
  359. },
  360. function(res) {
  361. if (res.err_msg === "get_brand_wcpay_request:ok") {
  362. // 使用以上方式判断前端返回,微信团队郑重提示:
  363. //res.err_msg将在用户支付成功后返回ok,但并不保证它绝对可靠。
  364. uni.showLoading({
  365. title: '支付成功'
  366. });
  367. uni.hideLoading();
  368. uni.navigateTo({
  369. url: '/pages/my/index'
  370. })
  371. } else {
  372. uni.hideLoading();
  373. }
  374. WeixinJSBridge.log(response.err_msg);
  375. }
  376. );
  377. },
  378. isCheckPay(code, name, order) {
  379. if (code == 0) {
  380. console.log('999999999999')
  381. this.setPayment(name, order);
  382. } else {
  383. uni.hideLoading();
  384. uni.showToast({
  385. title: '支付信息有误'
  386. });
  387. }
  388. },
  389. setPayment(name, order) {
  390. console.log(777777777, name, order)
  391. uni.requestPayment({
  392. provider: name,
  393. orderInfo: order, //微信、支付宝订单数据
  394. success: function(res) {
  395. uni.hideLoading();
  396. uni.showLoading({
  397. title: '支付成功',
  398. icon: 'none'
  399. });
  400. setTimeout(function() {
  401. uni.navigateBack()
  402. }, 1000)
  403. },
  404. fail: function(err) {
  405. uni.hideLoading();
  406. },
  407. complete() {
  408. uni.hideLoading();
  409. }
  410. });
  411. }
  412. },
  413. computed: {
  414. }
  415. }
  416. </script>
  417. <style>
  418. .bg {
  419. background-color: #1E1F31;
  420. }
  421. .btn {
  422. width: 100%;
  423. height: 88upx;
  424. background: linear-gradient(0deg, #af8262 0%, #cab49c 100%);
  425. border-radius: 44upx;
  426. text-align: center;
  427. line-height: 88upx;
  428. margin-top: 40upx;
  429. font-size: 34upx;
  430. font-weight: 600;
  431. color: #402321;
  432. }
  433. .active {
  434. border: 1px solid #cab49c !important;
  435. border-radius: ;
  436. }
  437. .popup_pay {
  438. width: 100%;
  439. position: relative;
  440. padding-bottom: 45rpx;
  441. }
  442. .pay_btn {
  443. width: 90%;
  444. margin: 0 auto;
  445. text-align: center;
  446. background: #FCD202;
  447. height: 80rpx;
  448. border-radius: 16rpx;
  449. color: #ffffff;
  450. line-height: 80rpx;
  451. }
  452. </style>