account-pay.vue 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316
  1. <template>
  2. <view>
  3. <view class="top-bg"></view>
  4. <view class="top-box">
  5. <view class="top">
  6. <text class="num">{{account.totalMoney}}</text>
  7. <text class="p">账户余额</text>
  8. </view>
  9. <view class="bottom">
  10. <view class="t">
  11. <view class="p">账户:</view>
  12. <view class="num">{{account.accountNo}}</view>
  13. </view>
  14. </view>
  15. </view>
  16. <view class="item">
  17. <view class="l" style="margin-top: 15rpx;">
  18. 充值金额:
  19. </view>
  20. <view class="r">
  21. <u-input type="number" style="border: 1rpx solid;margin-left: 8rpx;" placeholder="充值金额"
  22. v-model="form.money">
  23. </u-input>
  24. </view>
  25. </view>
  26. <view v-if="money&&money>0" class="pay-money">
  27. 支付金额:<text>{{money}} 元</text>
  28. </view>
  29. <view class="btn-box">
  30. <view class="btn t" @click="chargeFn">立即充值</view>
  31. </view>
  32. <view class="discount" v-if="discountList.length>0">
  33. 活动:
  34. <view v-for="(item,index) in discountList">
  35. {{index+1}}、充值满{{item.money}}元
  36. <text v-if="item.discount<10">打{{item.discount}}折</text>
  37. <text v-if="item.subtract">减{{item.subtract}}元</text>
  38. </view>
  39. </view>
  40. </view>
  41. </template>
  42. <script>
  43. var jweixin = require('@/components/jweixin-module/index.js');
  44. export default {
  45. data() {
  46. return {
  47. account: {
  48. totalMoney: 0,
  49. lockMoney: 0,
  50. activeMoney: 0,
  51. deposit: 0
  52. },
  53. form: {
  54. money: ''
  55. },
  56. code: '',
  57. openid: '',
  58. discountList: []
  59. }
  60. },
  61. onLoad(options) {
  62. this.code = options.code;
  63. this.getOpenidByCode();
  64. },
  65. onBackPress() {
  66. this.$common.to('/pages/index/index');
  67. return true;
  68. },
  69. mounted() {
  70. this.getAccountInfo();
  71. this.getDiscountInfo();
  72. this.getWxConfig();
  73. },
  74. computed: {
  75. money() {
  76. let chargeMoney = this.form.money;
  77. if (chargeMoney) {
  78. let discountList = this.discountList;
  79. let sub = 999999;
  80. let obj = null;
  81. for (let i in discountList) {
  82. let discount = discountList[i];
  83. let m = discount.money;
  84. let diff = chargeMoney - m;
  85. if (diff < sub && diff >= 0) {
  86. sub = diff;
  87. obj = discount;
  88. }
  89. }
  90. if (obj != null) {
  91. if (obj.type == 1) {
  92. return (chargeMoney * (obj.discount / 10)).toFixed(2)
  93. }
  94. return chargeMoney - obj.subtract
  95. }
  96. }
  97. }
  98. },
  99. methods: {
  100. getWxConfig() {
  101. let url = window.location.href;
  102. this.$api.getWxConfig({
  103. url: url
  104. }).then(resp => {
  105. jweixin.config({
  106. //debug: true,
  107. appId: resp.data.appId,
  108. timestamp: resp.data.timestamp, // 必填,生成签名的时间戳
  109. nonceStr: resp.data.noncestr, // 必填,生成签名的随机串
  110. signature: resp.data.sign, // 必填,签名
  111. jsApiList: ['chooseWXPay'] // 必填,需要使用的JS接口列表
  112. });
  113. jweixin.ready(function() {
  114. });
  115. jweixin.error(function(res) {
  116. console.log(res)
  117. });
  118. })
  119. },
  120. getOpenidByCode() {
  121. let storeOpenid = uni.getStorageSync('openid');
  122. this.$api.getOpenidByCode({
  123. code: this.code,
  124. openid: storeOpenid
  125. }).then(resp => {
  126. let openid = resp.data;
  127. this.openid = openid;
  128. if (openid) {
  129. uni.setStorageSync('openid', openid)
  130. }
  131. })
  132. },
  133. getAccountInfo() {
  134. this.$api.getAccountInfo().then(resp => {
  135. this.account = resp.data;
  136. })
  137. },
  138. getDiscountInfo() {
  139. this.$api.getDiscountInfo().then(resp => {
  140. this.discountList = resp.data;
  141. })
  142. },
  143. chargeFn() {
  144. let money = this.form.money;
  145. if (!money) {
  146. this.$common.toast('请输入充值金额');
  147. }
  148. let a = {
  149. id: this.account.id,
  150. c: money
  151. }
  152. let p = {
  153. a: JSON.stringify(a),
  154. money: this.money>0?this.money:money,
  155. tradeType: "JSAPI",
  156. openid: this.openid
  157. }
  158. p.desc="A1-账户充值";
  159. this.$api.getPrePay(this.$common.removeNull(p)).then(resp => {
  160. let data = resp.data;
  161. let that = this;
  162. jweixin.chooseWXPay({
  163. timestamp: data
  164. .timeStamp, // 支付签名时间戳,注意微信jssdk中的所有使用timestamp字段均为小写。但最新版的支付后台生成签名使用的timeStamp字段名需大写其中的S字符
  165. nonceStr: data.nonceStr, // 支付签名随机串,不长于 32 位
  166. package: data.package, // 统一支付接口返回的prepay_id参数值,提交格式如:prepay_id=\*\*\*)
  167. signType: data.signType, // 微信支付V3的传入RSA,微信支付V2的传入格式与V2统一下单的签名格式保持一致
  168. paySign: data.paySign, // 支付签名
  169. success: function(res) {
  170. if (res.errMsg === "chooseWXPay:ok") {
  171. that.$common.toast('支付成功')
  172. that.cars = [];
  173. that.item.list = [];
  174. that.total = 0
  175. // wx.closeWindow();
  176. }
  177. }
  178. });
  179. })
  180. }
  181. }
  182. }
  183. </script>
  184. <style lang="scss">
  185. page {
  186. background-color: #fff;
  187. }
  188. .top-bg {
  189. width: 100%;
  190. height: 400rpx;
  191. position: absolute;
  192. z-index: 0;
  193. background-image: linear-gradient(0deg, #fff 0%, #0080ff 40%);
  194. }
  195. .top-box {
  196. position: relative;
  197. z-index: 1;
  198. .top {
  199. display: flex;
  200. flex-direction: column;
  201. align-items: center;
  202. justify-content: center;
  203. .num {
  204. color: #fff;
  205. font-size: 60rpx;
  206. margin-top: 50rpx;
  207. }
  208. .p {
  209. color: rgba(255, 255, 255, .7);
  210. margin-top: 10rpx;
  211. }
  212. }
  213. .bottom {
  214. display: flex;
  215. background-color: #fff;
  216. border-radius: 20rpx;
  217. margin: 40rpx;
  218. flex-direction: column;
  219. align-items: center;
  220. justify-content: center;
  221. .t {
  222. display: flex;
  223. width: 100%;
  224. padding: 40rpx 30rpx;
  225. box-sizing: border-box;
  226. border-bottom: 1px solid #eee;
  227. .p,
  228. .num {
  229. font-size: 30rpx;
  230. color: #191919;
  231. }
  232. .num {
  233. margin-left: 30rpx;
  234. }
  235. }
  236. .b {
  237. display: flex;
  238. width: 100%;
  239. padding-bottom: 60rpx;
  240. }
  241. }
  242. }
  243. .item {
  244. display: flex;
  245. margin-top: 100rpx;
  246. margin-left: 60rpx;
  247. }
  248. .btn-box {
  249. position: relative;
  250. z-index: 1;
  251. display: flex;
  252. border-radius: 20rpx;
  253. display: flex;
  254. margin: 30rpx;
  255. padding: 30rpx;
  256. flex-direction: column;
  257. .btn {
  258. height: 88rpx;
  259. width: 70%;
  260. color: #fff;
  261. margin: 20rpx auto;
  262. display: flex;
  263. align-items: center;
  264. justify-content: center;
  265. border-radius: 10rpx;
  266. }
  267. .t {
  268. background-color: #0080ff;
  269. }
  270. .b {
  271. background-color: #ffb400;
  272. }
  273. }
  274. .pay-money {
  275. margin: 20rpx 0 0 120rpx;
  276. font-size: 30rpx;
  277. text {
  278. color: red;
  279. font-weight: bold;
  280. }
  281. }
  282. .discount {
  283. margin: 0 0 0 60rpx;
  284. font-size: 27rpx;
  285. view {
  286. margin-left: 20rpx;
  287. padding-top: 10rpx;
  288. }
  289. }
  290. </style>