recharge.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479
  1. <template>
  2. <view class="pd16_15">
  3. <view class="box over-hide">
  4. <view class="recharge-header">
  5. <image :src="statics.moneyRecharge"></image>
  6. <view class="main pd24_20">
  7. <view class="ft16 cl-w9">当前{{hbmc}}</view>
  8. <view class="mt16 ftw600 ft32 cl-w">{{userinfo.money}}</view>
  9. </view>
  10. </view>
  11. <navigator url="/pages/client/vipcard/moneylog">
  12. <view class="pd16_15 flex alcenter space">
  13. <text class="ft14 ftw600 cl-main">{{hbmc}}明细 </text>
  14. <text class="iconfont iconicon_arrow_circle ft20" :style="{color:tempColor}"></text>
  15. </view>
  16. </navigator>
  17. </view>
  18. <radio-group @change="changeNum">
  19. <view class="flex wrap space mt16">
  20. <view v-for="(item,index) in moneyList" :key="index" :class="index > 1 ? 'mt16' : ''" class="box pd20_15" style="width: 48%;">
  21. <view class="flex alcenter space">
  22. <view class="ft16 cl-main ftw600">¥{{item.money*1}}</view>
  23. <radio :value="item.money" :checked="money == item.money" :color="tempColor" />
  24. </view>
  25. <view v-if="item.num!=item.money" class="ft14 mt10 cl-main ftw400">
  26. {{hbmc}}{{item.num*1}}
  27. <text v-if="item.coupon*1>0" class="ft14">+送{{item.coupon*1}}</text>
  28. </view>
  29. </view>
  30. </view>
  31. </radio-group>
  32. <radio-group @change="changetd" style="display: none;">
  33. <view class="mt16">
  34. <view v-for="(item,index) in tdList" :key="index" :class="index >= 1 ? 'mt16' : ''" class="box pd20_15 flex alcenter space">
  35. <text class="ft16 cl-main ftw600">{{item.name}}</text>
  36. <radio :value="item.num" :checked="tdnum == item.num" :color="tempColor" />
  37. </view>
  38. </view>
  39. </radio-group>
  40. <view v-if="getCoupon > 0 " class="mt16 tag-coupon" :style="getTagStyle">
  41. ¥{{money}} 充值{{hbmc}} {{getnum*1}} 再送{{getCoupon*1}}
  42. </view>
  43. <view class="list-call" style="margin-top: 40upx; display: none;">
  44. <input class="sl-input tdadf" v-model="money" type="digit" placeholder="自定义金额" />
  45. </view>
  46. <view class="form-footer-h">
  47. <view class="form-footer form-footer-h">
  48. <view class="form-footer-main pd10_15">
  49. <!-- <button style="width: 49%; float: left;" @click="paykami" class="btn-big">卡密充值</button> -->
  50. <button style="width: 100%; float: right;" @click="paySuccess" class="btn-big" :style="getBtnStyle">支付 {{money>0?'¥'+money:''}}</button>
  51. </view>
  52. </view>
  53. </view>
  54. <hFormAlert v-if="cancelShow" title="卡密充值" name="cancel_desc" placeholder="请输入卡密卡号" @confirm="confirm" @cancel="cancel"></hFormAlert>
  55. <dialog-couponshare v-if="showCouponInvite" @closed="closedInvite"></dialog-couponshare>
  56. </view>
  57. </template>
  58. <script>
  59. import hFormAlert from '@/components/h-form-alert/h-form-alert.vue';
  60. export default{
  61. components: {hFormAlert},
  62. data(){
  63. return {
  64. money:'',
  65. moneyList:[],
  66. tdnum:'901',
  67. openid:'',
  68. tdList:[
  69. {num:'901',name:'微信H5(50-100-200)'},
  70. {num:'904',name:'支付宝H5(30-50-100-200)'},
  71. ],
  72. numa:'',
  73. num:0,
  74. userinfo:'',
  75. showCouponInvite:false,
  76. cancelShow:false,
  77. hbmc:'',
  78. czid:0
  79. }
  80. },
  81. computed:{
  82. getnum(){
  83. for(var a in this.moneyList){
  84. if(this.moneyList[a].money == this.money){
  85. return this.moneyList[a].num;
  86. }
  87. }
  88. },
  89. getCoupon(){
  90. for(var a in this.moneyList){
  91. if(this.moneyList[a].money == this.money){
  92. return this.moneyList[a].coupon;
  93. }
  94. }
  95. return 0;
  96. }
  97. },
  98. onLoad(e){
  99. this.hbmc=uni.getStorageSync("config").site.hbmc
  100. if(e.price){
  101. this.money=e.price
  102. }
  103. //#ifdef MP-WEIXIN
  104. this.wxlogin()
  105. //#endif
  106. },
  107. onShow() {
  108. this.ongrzlTap();
  109. this.cztc();
  110. },
  111. onShareAppMessage(e){
  112. },
  113. onShareTimeline(e){
  114. },
  115. methods:{
  116. cztc(){
  117. let data = {};
  118. data.token = uni.getStorageSync("userinfo").token;
  119. data.uid = uni.getStorageSync("userinfo").id;
  120. uni.request({
  121. url: this.configs.webUrl+'/api/user/cztc',
  122. data: data,
  123. success: res =>{
  124. console.log(res.data)
  125. this.moneyList=res.data
  126. },
  127. fail: (data, code) => {
  128. //console.log('fail' + JSON.stringify(data));
  129. }
  130. });
  131. },
  132. changeNum(e){
  133. this.money = parseInt(e.detail.value);
  134. //this.num = this.moneyList[a].coupon;
  135. },
  136. changetd(e){
  137. this.tdnum = e.detail.value;
  138. },
  139. paykami(){
  140. this.cancelShow=true
  141. },
  142. cancel(){
  143. this.cancelShow=false
  144. },
  145. confirm(e){
  146. console.log(e.cancel_desc);
  147. if(!e.cancel_desc){
  148. this.cancelShow=false
  149. uni.showToast({ title: '请输入卡密',icon:"none" });
  150. return false
  151. }
  152. let data = {};
  153. data.token = uni.getStorageSync("userinfo").token;
  154. data.uid = uni.getStorageSync("userinfo").id;
  155. data.crd = e.cancel_desc;
  156. uni.request({
  157. url: this.configs.webUrl+'/api/user/kami',
  158. data: data,
  159. success: res =>{
  160. if(res.data.code==1){
  161. this.userinfo.money=res.data.data.userinfo.money
  162. uni.showToast({ title: res.data.msg,icon:"none" });
  163. }else{
  164. uni.showToast({ title: res.data.msg,icon:"none" });
  165. }
  166. },
  167. fail: (data, code) => {
  168. //console.log('fail' + JSON.stringify(data));
  169. }
  170. });
  171. this.cancelShow=false
  172. },
  173. paySuccess(){
  174. for(var a in this.moneyList){
  175. if(this.moneyList[a].money == this.money){
  176. this.czid=this.moneyList[a].id;
  177. }
  178. }
  179. console.log(this.czid);
  180. //#ifdef MP-WEIXIN
  181. this.paywxxcx()
  182. //#endif
  183. //#ifdef MP-TOUTIAO
  184. // this.payttxcx()
  185. //#endif
  186. //#ifndef MP-WEIXIN || MP-TOUTIAO
  187. this.paySuccessa()
  188. //#endif
  189. },
  190. paywxxcx(){
  191. if(!this.money){
  192. uni.showToast({ title:'金额不对',icon:"none" });
  193. return false
  194. }
  195. if(!this.openid){
  196. uni.showToast({ title:'Openid味加载',icon:"none" });
  197. return false
  198. }
  199. uni.showLoading({
  200. title: 'Loading'
  201. });
  202. let data = {};
  203. data.token = uni.getStorageSync("userinfo").token;
  204. data.total = this.money;
  205. data.czid = this.czid;
  206. data.tdnum = this.tdnum;
  207. data.openid = this.openid;
  208. uni.request({
  209. url: this.configs.webUrl+'/api/paywx/paywxxcx',
  210. data: data,
  211. success: res =>{
  212. console.log(res.data);
  213. if(res.data.code==1){
  214. uni.hideLoading();
  215. uni.requestPayment({
  216. "provider": 'wxpay',
  217. "appId": res.data.data.appId,
  218. "timeStamp": res.data.data.timeStamp+'',
  219. "nonceStr": res.data.data.nonceStr,
  220. "package": res.data.data.package,
  221. "signType": 'MD5',
  222. "paySign": res.data.data.sign,
  223. success: function (res1) {
  224. uni.showModal({
  225. title: '温馨提示',
  226. content: '支付成功',
  227. showCancel: false,
  228. confirmText: "确定",
  229. success: function (res) {
  230. if (res.confirm) {
  231. this.ongrzlTap();
  232. } else if (res.cancel) {
  233. }
  234. }
  235. });
  236. //uni.showToast({ title: '支付成功',icon:"none" });
  237. console.log('success:' + JSON.stringify(res1));
  238. },
  239. fail: function (err1) {
  240. uni.showModal({
  241. title: '支付失败',
  242. content: JSON.stringify(err1),
  243. showCancel: false,
  244. confirmText: "确定",
  245. success: function (res) {
  246. if (res.confirm) {
  247. //uni.navigateBack();
  248. } else if (res.cancel) {
  249. }
  250. }
  251. });
  252. //uni.showToast({ title: JSON.stringify(err1),icon:"none" });
  253. console.log('fail:' + JSON.stringify(err1));
  254. }
  255. });
  256. }else{
  257. uni.hideLoading();
  258. uni.showModal({
  259. title: '温馨提示',
  260. content: JSON.stringify(res.data),
  261. showCancel: false,
  262. confirmText: "确定",
  263. success: function (res) {
  264. if (res.confirm) {
  265. uni.navigateBack();
  266. } else if (res.cancel) {
  267. }
  268. }
  269. });
  270. }
  271. },
  272. fail: (data, code) => {
  273. //console.log('fail' + JSON.stringify(data));
  274. }
  275. });
  276. },
  277. paySuccessa(){
  278. if(!this.num){
  279. uni.showToast({ title:'金额不对',icon:"none" });
  280. return false
  281. }
  282. uni.showLoading({
  283. title: 'Loading'
  284. });
  285. let data = {};
  286. data.iswx = '';
  287. //#ifdef H5
  288. var ua = window.navigator.userAgent.toLowerCase();
  289. if(ua.match(/MicroMessenger/i) == 'micromessenger'){
  290. data.iswx = 'wxgzh';
  291. }
  292. //#endif
  293. data.token = uni.getStorageSync("userinfo").token;
  294. data.total = this.num;
  295. data.tdnum = this.tdnum;
  296. // uni.showToast({ title:data.iswx,icon:"none" });
  297. // return false
  298. uni.request({
  299. url: this.configs.webUrl+'/api/paywx/paywxh5',
  300. data: data,
  301. success: res =>{
  302. console.log(res);
  303. if(res.data.code==1){
  304. uni.hideLoading();
  305. console.log(res.data.data);
  306. // #ifdef APP-PLUS
  307. uni.navigateTo({
  308. url:'/pages/client/webva?url='+res.data.data
  309. })
  310. //plus.runtime.openURL(res.data.data);
  311. // #endif
  312. // #ifdef H5
  313. window.open(res.data.data, "_self")
  314. // #endif
  315. ///index/paydsf?out_trade_no=2206131027251
  316. //uni.showToast({ title: res.data.msg,icon:"none" });
  317. }else{
  318. uni.hideLoading();
  319. uni.showToast({ title: res.data.msg,icon:"none" });
  320. }
  321. },
  322. fail: (data, code) => {
  323. //console.log('fail' + JSON.stringify(data));
  324. }
  325. });
  326. },
  327. async ongrzlTap(){
  328. let data = {};
  329. data.token = uni.getStorageSync("userinfo").token;
  330. data.uid = uni.getStorageSync("userinfo").id;
  331. uni.request({
  332. url: this.configs.webUrl+'/api/user/index',
  333. data: data,
  334. success: res =>{
  335. if(res.data.code==1){
  336. let ionfo=res.data.data
  337. ionfo.isLogin=true
  338. this.userinfo=ionfo
  339. this.jfdt=ionfo.config.jfdt?ionfo.config.jfdt:''
  340. uni.setStorage({//缓存配置信息
  341. key: 'userinfo',
  342. data: res.data.data
  343. })
  344. if(res.data.data.avatar){
  345. var str = res.data.data.avatar;
  346. if(str.indexOf("data:image") != -1){
  347. this.avatar='';
  348. }else{
  349. if(str.indexOf("http") != -1){
  350. this.avatar=res.data.data.avatar;
  351. }else{
  352. this.avatar=this.configs.imgUrl+res.data.data.avatar;
  353. }
  354. }
  355. }else{
  356. this.avatar='';
  357. }
  358. uni.setStorage({//缓存配置信息
  359. key: 'avatar',
  360. data: this.avatar
  361. })
  362. }else{
  363. uni.showToast({ title: res.data.msg,icon:"none" });
  364. }
  365. },
  366. fail: (data, code) => {
  367. //console.log('fail' + JSON.stringify(data));
  368. }
  369. });
  370. },
  371. closedInvite(){
  372. this.showCouponInvite = false;
  373. let pages = getCurrentPages();
  374. uni.navigateBack({
  375. delta:pages.length
  376. });
  377. },
  378. wxlogin(){
  379. var this_=this
  380. uni.login({
  381. timeout: 10000,
  382. provider: 'weixin', //如果是uniapp,在这里需要标明平台的类型,支持的参数请查阅uniapp官网的uni.login()文档
  383. success: (res) => {
  384. //console.log(res);
  385. //登陆成功的回调
  386. uni.request({
  387. url: this.configs.webUrl+'/api/user/getOpenid',
  388. method:'GET',
  389. data: {
  390. token: uni.getStorageSync("userinfo").token, //你的小程序的secret,
  391. code: res.code //wx.login 登录成功后的code
  392. },
  393. success: (cts) => {
  394. console.log(cts.data.data);
  395. if(cts.data.code==1){
  396. this_.openid=cts.data.data.openid
  397. }else{
  398. uni.showModal({
  399. title: '温馨提示',
  400. content: JSON.stringify(cts.data),
  401. showCancel: false,
  402. confirmText: "确定",
  403. success: function (res) {
  404. if (res.confirm) {
  405. uni.navigateBack();
  406. } else if (res.cancel) {
  407. }
  408. }
  409. });
  410. }
  411. },
  412. fail: (err1) => {
  413. console.log(err1);
  414. //失败的回调
  415. }
  416. });
  417. },
  418. fail: (err) => {
  419. console.log(err);
  420. //登陆失败的回调
  421. }
  422. })
  423. }
  424. }
  425. }
  426. </script>
  427. <style>
  428. .tag-coupon{
  429. width: 100%;
  430. height: 80rpx;
  431. border-radius: 16rpx;
  432. text-align: center;
  433. line-height: 80rpx;
  434. font-size: 28rpx;
  435. }
  436. .recharge-header{
  437. height: 240rpx;
  438. width: 100%;
  439. position: relative;
  440. }
  441. .recharge-header image{
  442. width: 100%;
  443. height: 240rpx;
  444. }
  445. .recharge-header .main{
  446. position: absolute;
  447. width: 100%;
  448. height: 240rpx;
  449. left: 0;
  450. top: 0;
  451. }
  452. .tdadf{
  453. border: 1px solid #f8f8f8;
  454. padding: 10px 10px;
  455. text-align: center;
  456. height: 80upx;
  457. background: #ffffff;
  458. border-radius: 8px;
  459. box-shadow: 0px 4px 20px 0px rgba(0,0,0,0.04);
  460. font-size: 30upx;
  461. color: #666;
  462. }
  463. </style>