authVip.vue 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306
  1. <template>
  2. <view>
  3. <view class="lz-modal lz-modal-show">
  4. <view class="lz-modal-dialog">
  5. <view class="lz-list">
  6. <view class="lz-list-header" style="display: flex;flex-direction: row;">
  7. <view>温馨提示</view>
  8. <view class="iconfont icon-cuo1" @tap="hideAuthVip()"></view>
  9. </view>
  10. <view class="lz-list-body">
  11. <view class="lz-list-item lz-list-item-middle">
  12. <view class="lz-list-line">
  13. <view class="ktvip">
  14. <image src="../static/img/zs.png" mode="" class="ktvip-img"></image>
  15. <view class="ktvip-flex"><text>请激活VIP</text>(当前科目:{{subject.subject_name}})</view>
  16. <view class="ktvip-flex">价格:{{subject.price}}</view>
  17. </view>
  18. <!-- <view class="index-bm-title">
  19. <input class="uni-input" v-model="vipnum" confirm-type="search"
  20. placeholder="请输入激活码" />
  21. </view> -->
  22. <view class="ktvip-b">
  23. <!-- #ifdef H5 || APP-PLUS -->
  24. <button @tap="$openrul('/pages/my/about?id=1')">联系客服</button>
  25. <!-- #endif -->
  26. <!-- #ifdef MP-WEIXIN -->
  27. <button open-type="contact">联系客服</button>
  28. <!-- #endif -->
  29. <!-- <button @tap="authVip()" class="ktvip-b-r">确认激活</button> -->
  30. <button @tap="gobuy" class="ktvip-b-r" v-if="auth != 1">立即购买</button>
  31. </view>
  32. </view>
  33. </view>
  34. </view>
  35. </view>
  36. <view class="lz-margin--b-md"></view>
  37. </view>
  38. </view>
  39. </view>
  40. </template>
  41. <script>
  42. // #ifdef H5
  43. import weichatObj from '@/plugin/jweixin-module/index.js';
  44. // #endif
  45. import {
  46. mapState
  47. } from 'vuex';
  48. export default {
  49. name: "auth-vip",
  50. data() {
  51. return {
  52. // #ifdef H5
  53. auth: 0,
  54. // #endif
  55. // #ifdef MP
  56. auth: 1,
  57. // #endif
  58. vipnum: '',
  59. mode: '',
  60. }
  61. },
  62. computed: {
  63. ...mapState(['subject', 'userinfo', 'subjectVip']),
  64. },
  65. mounted() {
  66. this.mode = this.$myConfig.mode
  67. // #ifdef MP
  68. this.getSh()
  69. // #endif
  70. },
  71. methods: {
  72. async getSh() {
  73. let res = await this.$myHttp.get({
  74. url: this.$myHttp.urlMap.sh,
  75. data: {},
  76. needLogin: false,
  77. })
  78. if (res.code == 1) {
  79. // this.navList = res.data.data
  80. console.log(res)
  81. this.auth = res.data.auth
  82. }
  83. },
  84. hideAuthVip() {
  85. this.$emit('hideAuthVip', false)
  86. },
  87. async authVip() {
  88. let res = await this.$myHttp.post({
  89. url: this.$myHttp.urlMap.exchangesubject,
  90. data: {
  91. code: this.vipnum,
  92. subject_id: this.subject.id
  93. },
  94. needLogin: true
  95. })
  96. if (res.code == 1) {
  97. uni.showToast({
  98. title: '激活成功',
  99. icon: 'none',
  100. duration: 1000
  101. })
  102. this.$myUserLogin.getSubvip(this.subject.id)
  103. this.hideAuthVip()
  104. } else {
  105. uni.showToast({
  106. title: res.msg,
  107. icon: 'none',
  108. duration: 1000
  109. })
  110. }
  111. },
  112. //获取获取解密手机号
  113. // async userDecryptData(encryptedData,iv,code) {
  114. // let res = await this.$myHttp.post({
  115. // url: this.$myHttp.urlMap.decryptData,
  116. // data: {
  117. // encryptedData:encryptedData,
  118. // iv:iv,
  119. // code:code,
  120. // },
  121. // needLogin: true
  122. // })
  123. // if (res.code == 1) {
  124. // let jmPnumber = res.data
  125. // let myPhone = jmPnumber.phoneNumber
  126. // console.log(myPhone);
  127. // }
  128. // },
  129. // getPhoneNumber(e) {
  130. // let enc = e.detail.encryptedData
  131. // let iv = e.detail.iv
  132. // this.userDecryptData(enc,iv,this.cod)
  133. // },
  134. async gobuy() {
  135. console.log(this.subject)
  136. let that = this
  137. var pages = getCurrentPages() // 获取栈实例
  138. let currentRoute = pages[pages.length - 1].route; // 获取当前页面路由
  139. let qdata = {
  140. returnurl: currentRoute,
  141. pay_type: 'wechat',
  142. subject_id: this.subject.id,
  143. // #ifdef MP
  144. user_type: 'mini'
  145. // #endif
  146. // #ifdef H5
  147. user_type: 'mp'
  148. // #endif
  149. }
  150. let res = await this.$myHttp.post({
  151. url: this.$myHttp.urlMap.buyJhm,
  152. data: qdata,
  153. needLogin: true
  154. })
  155. console.log(res)
  156. if (res.code == 1) {
  157. let da = res.data
  158. // #ifdef MP
  159. uni.requestPayment({
  160. provider: 'wxpay',
  161. timeStamp: da.timeStamp,
  162. nonceStr: da.nonceStr,
  163. package: da.package,
  164. signType: da.signType,
  165. paySign: da.paySign,
  166. success: function(res) {
  167. console.log('success:' + JSON.stringify(res));
  168. uni.showToast({
  169. title: '激活成功',
  170. icon: 'none',
  171. duration: 1000
  172. })
  173. that.$myUserLogin.getSubvip(that.subject.id)
  174. that.hideAuthVip()
  175. },
  176. fail: function(err) {
  177. console.log('fail:' + JSON.stringify(err));
  178. }
  179. });
  180. // #endif
  181. // #ifdef H5
  182. // weichatObj.chooseWXPay(rdata);
  183. WeixinJSBridge.invoke(
  184. 'getBrandWCPayRequest', {
  185. "appId": da.appId, //公众号ID,由商户传入
  186. "timeStamp": da.timeStamp, //时间戳,自1970年以来的秒数
  187. "nonceStr": da.nonceStr, //随机串
  188. "package": da.package,
  189. "signType": da.signType, //微信签名方式:
  190. "paySign": da.paySign //微信签名
  191. },
  192. function(res) {
  193. if (res.err_msg == "get_brand_wcpay_request:ok") {
  194. // 使用以上方式判断前端返回,微信团队郑重提示:
  195. //res.err_msg将在用户支付成功后返回ok,但并不保证它绝对可靠。
  196. uni.showToast({
  197. title: '激活成功',
  198. icon: 'none',
  199. duration: 1000
  200. })
  201. that.$myUserLogin.getSubvip(that.subject.id)
  202. that.hideAuthVip()
  203. }
  204. });
  205. // #endif
  206. // uni.showToast({
  207. // title: '激活成功',
  208. // icon: 'none',
  209. // duration: 1000
  210. // })
  211. // this.$myUserLogin.getSubvip(this.subject.id)
  212. // this.hideAuthVip()
  213. } else {
  214. uni.showToast({
  215. title: res.msg,
  216. icon: 'none',
  217. duration: 1000
  218. })
  219. }
  220. }
  221. }
  222. }
  223. </script>
  224. <style>
  225. .ktvip {
  226. color: #848484;
  227. font-size: 15px;
  228. }
  229. .ktvip-flex {
  230. width: 84%;
  231. margin: 0px auto;
  232. }
  233. .ktvip-flex text {
  234. color: #000;
  235. font-weight: bold;
  236. }
  237. .ktvip-img {
  238. width: 68px;
  239. height: 68px;
  240. margin-bottom: 3px;
  241. }
  242. .ktvip-b {
  243. display: flex;
  244. align-items: center;
  245. justify-content: center;
  246. font-size: 14px;
  247. margin: 14px 0;
  248. }
  249. .ktvip-b button {
  250. font-size: 14px;
  251. margin: 0 8px;
  252. border: solid 1px #ebebeb;
  253. }
  254. .ktvip-b-r {
  255. font-size: 14px;
  256. background: #3c7bfc;
  257. border: solid 1px #3c7bfc !important;
  258. color: #fff;
  259. }
  260. .ktvip-b-r button::after,
  261. .ktvip-b button::after {
  262. border: none;
  263. }
  264. .index-bm-title {
  265. width: 86%;
  266. margin: 12px auto 10px;
  267. }
  268. .index-bm-content {
  269. margin-top: 10px;
  270. }
  271. .index-bm-flex {
  272. display: flex;
  273. font-size: 15px;
  274. align-items: center;
  275. margin-bottom: 8px;
  276. }
  277. .index-bm-title input {
  278. border-radius: 5px;
  279. border: none;
  280. padding: 10px;
  281. flex: 1;
  282. font-size: 15px;
  283. color: #000;
  284. text-align: left;
  285. border: 1px #eee solid;
  286. }
  287. </style>