pay.vue 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253
  1. <template>
  2. <view class="content">
  3. <view class="store-info flex">
  4. <image :src="store_logo" mode="" class="store-logo"></image>
  5. <view class="store-name">
  6. {{store_name}}
  7. </view>
  8. </view>
  9. <view class="money-box">
  10. <input type="text" value="" v-model="money" placeholder="请输入充值金额" placeholder-class="place"/>
  11. </view>
  12. <view class="sub" @click="!payLoding ? confirm() : ''" :class="{'disable': payLoding}">
  13. 确认付款
  14. </view>
  15. </view>
  16. </template>
  17. <script>
  18. // #ifdef H5
  19. import { rechargeWechat ,userBalance} from '@/api/wallet.js';
  20. // #endif
  21. // #ifdef MP
  22. import { rechargeRoutine ,userBalance} from '@/api/wallet.js';
  23. // #endif
  24. export default {
  25. data() {
  26. return {
  27. type: 'weixin',
  28. money: '',
  29. store_name: '',
  30. store_logo: '',
  31. store_id: '',
  32. payLoding: false
  33. }
  34. },
  35. onLoad(opt) {
  36. console.log(opt.store_name)
  37. this.store_name = opt.store_name
  38. this.store_logo = opt.store_logo
  39. this.store_id = opt.store_id
  40. },
  41. methods: {
  42. // 提交
  43. confirm() {
  44. let obj = this;
  45. if(obj.money == 0){
  46. return this.$api.msg('请输入充值金额');
  47. }
  48. console.log(obj.money,'ddddddddddddddddddddddddddddddddddddddddddd')
  49. // if(!this.isSect) {
  50. // return this.$api.msg('请选择支付方式');
  51. // }
  52. if (wx.requestSubscribeMessage) {
  53. wx.requestSubscribeMessage({
  54. tmplIds: ['HgPU5FHUTwqGNSkJ7IsAP0XkJZV3UUf9fjUWUD3ebZY'],
  55. success(res) {
  56. console.log(res,'订阅消息')
  57. },
  58. fail(err) {
  59. console.log(err)
  60. },
  61. complete() {
  62. obj.payLoding = true;
  63. // #ifdef H5
  64. console.log('H5++++++++++++++++')
  65. rechargeWechat({
  66. price: obj.money,
  67. from: obj.type,
  68. store_id: obj.store_id
  69. })
  70. .then(e => {
  71. let da = e.data.data;
  72. obj.weichatObj.chooseWXPay({
  73. timestamp: da.timestamp,
  74. nonceStr: da.nonceStr,
  75. package: da.package,
  76. signType: da.signType,
  77. paySign: da.paySign,
  78. success: function(res) {
  79. uni.showToast({
  80. title: '充值成功',
  81. duration: 2000,
  82. position: 'top'
  83. });
  84. }
  85. });
  86. obj.payLoding = false;
  87. })
  88. .catch(e => {
  89. obj.payLoding = false;
  90. console.log(e);
  91. });
  92. // #endif
  93. // #ifdef MP
  94. console.log('MP++++++++++++++++')
  95. rechargeRoutine({
  96. price: obj.money,
  97. store_id: obj.store_id
  98. })
  99. .then(e => {
  100. let da = e.data;
  101. wx.requestPayment({
  102. timeStamp: da.timestamp,
  103. nonceStr: da.nonceStr,
  104. package: da.package,
  105. signType: da.signType,
  106. paySign: da.paySign,
  107. success: function(res) {
  108. uni.redirectTo({
  109. url: '/pages/money/paySuccess?isshow=false'
  110. });
  111. }
  112. });
  113. obj.payLoding = false;
  114. })
  115. .catch(e => {
  116. obj.payLoding = false;
  117. console.log(e);
  118. });
  119. // #endif
  120. }
  121. })
  122. } else {
  123. obj.payLoding = true;
  124. // #ifdef H5
  125. console.log('H5++++++++++++++++')
  126. rechargeWechat({
  127. price: obj.money,
  128. from: obj.type,
  129. store_id: obj.store_id
  130. })
  131. .then(e => {
  132. let da = e.data.data;
  133. obj.weichatObj.chooseWXPay({
  134. timestamp: da.timestamp,
  135. nonceStr: da.nonceStr,
  136. package: da.package,
  137. signType: da.signType,
  138. paySign: da.paySign,
  139. success: function(res) {
  140. uni.showToast({
  141. title: '充值成功',
  142. duration: 2000,
  143. position: 'top'
  144. });
  145. }
  146. });
  147. obj.payLoding = false;
  148. })
  149. .catch(e => {
  150. obj.payLoding = false;
  151. console.log(e);
  152. });
  153. // #endif
  154. // #ifdef MP
  155. console.log('MP++++++++++++++++')
  156. rechargeRoutine({
  157. price: obj.money,
  158. store_id: obj.store_id
  159. })
  160. .then(e => {
  161. let da = e.data;
  162. wx.requestPayment({
  163. timeStamp: da.timestamp,
  164. nonceStr: da.nonceStr,
  165. package: da.package,
  166. signType: da.signType,
  167. paySign: da.paySign,
  168. success: function(res) {
  169. uni.redirectTo({
  170. url: '/pages/money/paySuccess?isshow=false'
  171. });
  172. }
  173. });
  174. obj.payLoding = false;
  175. })
  176. .catch(e => {
  177. obj.payLoding = false;
  178. console.log(e);
  179. });
  180. // #endif
  181. }
  182. },
  183. }
  184. }
  185. </script>
  186. <style lang="scss" scoped>
  187. .store-info {
  188. padding: 46rpx 30rpx;
  189. justify-content: flex-start;
  190. align-items: center;
  191. .store-logo {
  192. width: 82rpx;
  193. height: 82rpx;
  194. border-radius: 50%;
  195. background: #eee;
  196. border-radius: 5px;
  197. margin-right: 17rpx;
  198. }
  199. .store-name {
  200. font-size: 32rpx;
  201. font-family: PingFang SC;
  202. font-weight: bold;
  203. color: #000000;
  204. }
  205. }
  206. .money-box {
  207. font-size: 60rpx;
  208. font-family: PingFang SC;
  209. font-weight: bold;
  210. color: #000000;
  211. padding: 30rpx 30rpx;
  212. display: flex;
  213. justify-content: space-between;
  214. align-items: center;
  215. input {
  216. flex-grow: 1;
  217. padding-left: 20rpx;
  218. font-size: 40rpx;
  219. font-family: PingFang SC;
  220. font-weight: bold;
  221. color: #000000;
  222. // display: inline-block;
  223. }
  224. }
  225. .sub {
  226. margin:138rpx auto 0;
  227. width: 685rpx;
  228. line-height: 93rpx;
  229. background: #901B21;
  230. border-radius: 5px;
  231. text-align: center;
  232. font-size: 36rpx;
  233. font-family: PingFang SC;
  234. font-weight: bold;
  235. color: #FFFFFF;
  236. }
  237. .disable {
  238. background-color: #999;
  239. }
  240. .place {
  241. font-size: 24rpx;
  242. }
  243. </style>