account-pay.vue 7.1 KB

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