payCode.vue 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  1. <template>
  2. <view :style="[mainStyle]" v-if="isShowPage" class="pay-page">
  3. <!-- 码 -->
  4. <view class="card">
  5. <!-- 名称 -->
  6. <view class="card-header ddflex"><image :src="userInfos.avatar?userInfos.avatar:'../../static/pages/images/userimg.png'"></image>{{ userInfos.nickName }}</view>
  7. <!-- 码 -->
  8. <view class="card-code">
  9. <!-- 条形码 -->
  10. <!-- <view class="code1"><image class="code-image" :src="payment.barUri"></image></view> -->
  11. <!-- 二维码 -->
  12. <!-- <view class="code2"><image class="code-image" :src="payment.qrCodeUri"></image></view> -->
  13. <view class="code2"><image class="code-image" :src="payment.qrCodeUri"></image></view>
  14. <!-- <view class="code2"><image class="code-image" :src="replaceAll(payment.appletCodeUri,'https://apitest.tongyu99.com','http://192.168.110.59:8098')"></image></view> -->
  15. <!-- 刷新 -->
  16. <view class="refresh ddflex" @click="paymentInfo()">
  17. <image :class="'refresh-icon' + (isRefresh?' active':'')" src="../static/mine/images/refresh.png"></image>
  18. 点击刷新付款码
  19. </view>
  20. </view>
  21. <view class="line"></view>
  22. <!-- 余额 -->
  23. <view class="card-bottom">
  24. <view class="ddflex" @click="showPop">
  25. <view><image class="money-icon" src="../static/mine/images/money.png"></image></view>
  26. <view class="ddflex fflex" style="align-items: flex-end;">
  27. <view class="fflex">
  28. <viwe class="money-number">{{ payment.balance ? payment.balance : '0.00' }}</viwe>
  29. <view class="money-text ddflex">账户余额<view class="cz-btn ddflex" @click.stop="jumpUrl('/wallet/index/index')">去充值<image src="../static/mine/images/cz_ico.png"></image></view></view>
  30. </view>
  31. <image src="../../static/pages/images/bico.png" class="bico"></image>
  32. </view>
  33. </view>
  34. </view>
  35. </view>
  36. <view class="ceng" v-if="isShowPop" @click="hidePop"></view>
  37. <view class="popup" :style="'bottom:' + popBottom">
  38. <view class="pop-tit">选择优先支付方式 <text>如付款失败将尝试使用其他支付方式完成付款</text></view>
  39. <view class="pop-con">
  40. <view class="li ddflex" v-for="(item,index) in balanceList" :key="index" @click="switchType(index)">
  41. <image :src="'../static/mine/images/money_' + item.code + '.png'" class="money-ico"></image>
  42. <view class="fflex">{{item.name}}(剩余¥{{item.balance}})</view>
  43. <image :src="'../static/mine/images/' + (item.isCheck?'money_gou_h.png':'money_gou.png')" class="money-gou"></image>
  44. </view>
  45. </view>
  46. <view class="pop-btn ddflex">
  47. <view class="cancel" @click="hidePop">取消</view>
  48. <view class="confirm" @click="confirm()">确认</view>
  49. </view>
  50. </view>
  51. </view>
  52. </template>
  53. <script>
  54. const route = require('../../utils/route.js');
  55. const req = require('../../utils/request');
  56. const app = getApp();
  57. export default {
  58. data() {
  59. return {
  60. mainStyle: app.globalData.mainStyle,
  61. isShowPage: false,
  62. timer: [],
  63. money: '',
  64. userInfos: {},
  65. payment: '',
  66. isRefresh: false,
  67. isShowPop: false,
  68. popBottom: '-100%',
  69. balanceList: [],//用户可划款账户
  70. payAccountTypes: [],//用户选择的划款账户
  71. };
  72. },
  73. onLoad() {
  74. this.userInfos = req.getStorage('userInfo');
  75. this.paymentInfo();
  76. this.getBalance();
  77. //4.8分钟后刷新
  78. this.timer = setInterval(() => {
  79. this.paymentInfo();
  80. }, 1000 * 60 * 4.8);
  81. },
  82. /**
  83. * 生命周期函数--监听页面显示
  84. */
  85. onShow: function() {
  86. // this.extendNew();
  87. },
  88. onUnload() {
  89. if (this.timer) clearInterval(this.timer);
  90. },
  91. methods: {
  92. // 查询用户余额
  93. // extendNew() {
  94. // route.extendNew({}, res => {
  95. // this.money = res;
  96. // });
  97. // },
  98. getBalance(){
  99. req.getRequest('/api/v3/payment/getBalance',{},data=>{
  100. data.map(it=>{
  101. it.isCheck = false;
  102. return it;
  103. })
  104. this.balanceList = data;
  105. })
  106. },
  107. showPop(){
  108. this.isShowPop = true;
  109. this.popBottom = 0
  110. },
  111. hidePop(){
  112. this.isShowPop = false;
  113. this.popBottom = '-100%'
  114. this.balanceList.map(it=>{
  115. it.isCheck = false;
  116. return it;
  117. })
  118. },
  119. switchType(index){
  120. this.balanceList[index].isCheck = !this.balanceList[index].isCheck
  121. },
  122. confirm(){
  123. let arr = [];
  124. this.balanceList.filter(it=>{return it.isCheck}).map(it=>{
  125. arr.push(it.code);
  126. })
  127. this.payAccountTypes = arr;
  128. this.paymentInfo();
  129. this.isShowPop = false;
  130. this.popBottom = '-100%'
  131. },
  132. replaceAll(str, find, replace) {
  133. return str.replace(find, replace);
  134. },
  135. paymentInfo() {
  136. this.isRefresh = true;
  137. let params = {}
  138. console.log('payAccountTypes==',this.payAccountTypes)
  139. if(this.payAccountTypes&&this.payAccountTypes.length>0){
  140. params.payAccountTypes = JSON.stringify(this.payAccountTypes)
  141. }else delete params.payAccountTypes;
  142. params.appletCodePath = 'merchant/scanPay';
  143. req.getRequest('/api/v3/payment/user/info', params, data => {
  144. this.payment = data;
  145. this.isRefresh = false;
  146. this.openCode(); //设置亮度为最高
  147. this.isShowPage = true;
  148. });
  149. },
  150. //获取屏幕亮度
  151. getScreenBrightness() {
  152. //注意uni.getScreenBrightness为异步接口,所以需要使用Promise封装为异步执行
  153. return new Promise(function(resolve, reject) {
  154. uni.getScreenBrightness({
  155. success: function(res) {
  156. // console.log('屏幕亮度值:' + res.value);
  157. resolve(res.value);
  158. },
  159. fail: function(err) {
  160. reject(0.5); //如果获取失败设置亮度为中间值
  161. }
  162. });
  163. });
  164. },
  165. //打开二维码
  166. openCode() {
  167. this.getScreenBrightness()
  168. .then(function(res) {
  169. // console.log('当前亮度为', res);
  170. uni.setStorageSync('Brightness_key', res);
  171. })
  172. .catch(err => {
  173. uni.setStorageSync('Brightness_key', err);
  174. });
  175. this.updateScreenBrightness(1); //设置亮度为最高
  176. },
  177. //修改屏幕亮度
  178. updateScreenBrightness(valueNum) {
  179. uni.setScreenBrightness({
  180. value: valueNum,
  181. success: function() {
  182. console.log('成功修改屏幕亮度为', valueNum);
  183. }
  184. });
  185. },
  186. //关闭二维码
  187. closeCode() {
  188. let Brightness = uni.getStorageSync('Brightness_key');
  189. this.updateScreenBrightness(Brightness); //把屏幕亮度调回以前亮度
  190. console.log('closeCode成功修改屏幕亮度为', Brightness);
  191. },
  192. jumpUrl(url){
  193. uni.navigateTo({
  194. url: url
  195. })
  196. }
  197. },
  198. beforeDestroy() {
  199. this.closeCode();
  200. }
  201. };
  202. </script>
  203. <style>
  204. @import './payCode.css';
  205. </style>