payment-code.vue 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  1. <template>
  2. <view class="scroll-box bg-white">
  3. <!-- 主体内容 -->
  4. <block v-if="data_list_loding_status == 3">
  5. <!-- 条码 -->
  6. <view class="brcode auto">
  7. <w-barcode :options="barcode"></w-barcode>
  8. <view class="fw-b tc margin-top text-size-lg">{{payment_code}}</view>
  9. </view>
  10. <!-- 二维码 -->
  11. <view class="qrcode auto br radius">
  12. <w-qrcode :options="qrcode"></w-qrcode>
  13. </view>
  14. <!-- 提示信息 -->
  15. <view class="cr-grey tc margin-top-xxxl">如遇到扫码失败请将屏幕调至最亮重新扫码</view>
  16. <!-- 倒计时 -->
  17. <view class="margin-top-xxxl cr-yellow tc">({{scheduled_value}})秒后自动刷新付款码</view>
  18. <!-- 导航 -->
  19. <view v-if="(plugins_membershiplevelvip || null) != null" class="bottom-fixed padding-main">
  20. <view class="bottom-line-exclude oh">
  21. <view class="bg-gray round oh">
  22. <button type="default" class="bg-gray br-gray cr-base round text-size fl" size="mini" :data-value="'/pages/plugins/membershiplevelvip/member-code/member-code?screen_brightness_value='+screen_brightness_value" data-redirect="1" @tap="url_event">会员码</button>
  23. <button type="default" class="bg-main br-main cr-white round text-size fr" size="mini">钱包付款码</button>
  24. </view>
  25. </view>
  26. </view>
  27. </block>
  28. <!-- 错误提示 -->
  29. <component-no-data :propStatus="data_list_loding_status" :propMsg="data_list_loding_msg"></component-no-data>
  30. <view v-if="is_to_login == 1" class="margin-top-lg tc">
  31. <button type="default" class="bg-main br-main cr-white" size="mini" data-value="/pages/login/login" @tap="url_event">去登录</button>
  32. </view>
  33. </view>
  34. </template>
  35. <script>
  36. const app = getApp();
  37. import componentNoData from "../../../../components/no-data/no-data";
  38. export default {
  39. data() {
  40. return {
  41. data_list_loding_status: 1,
  42. data_list_loding_msg: '',
  43. is_to_login: 0,
  44. screen_brightness_value: 0,
  45. plugins_membershiplevelvip: null,
  46. scheduled_timer: null,
  47. scheduled_value: 0,
  48. payment_code: '',
  49. barcode:{
  50. width: 660,
  51. height: 120,
  52. code: ''
  53. },
  54. qrcode:{
  55. code: '',
  56. size: 450,
  57. }
  58. }
  59. },
  60. components: {
  61. componentNoData
  62. },
  63. // 页面加载初始化
  64. onLoad(params) {
  65. // 获取屏幕亮度
  66. // #ifndef H5
  67. var self = this;
  68. if((params || null) != null && (params.screen_brightness_value || null) == null) {
  69. uni.getScreenBrightness({
  70. success: function (res) {
  71. self.setData({
  72. screen_brightness_value: res.value
  73. });
  74. }
  75. });
  76. } else {
  77. self.setData({
  78. screen_brightness_value: params.screen_brightness_value
  79. });
  80. }
  81. // #endif
  82. },
  83. onShow() {
  84. // 数据加载
  85. this.init();
  86. // 初始化配置
  87. this.init_config();
  88. },
  89. methods: {
  90. // 初始化配置
  91. init_config(status) {
  92. if ((status || false) == true) {
  93. this.setData({
  94. plugins_membershiplevelvip: app.globalData.get_config('plugins_base.membershiplevelvip', null)
  95. });
  96. } else {
  97. app.globalData.is_config(this, 'init_config');
  98. }
  99. },
  100. // 获取数据
  101. init() {
  102. var user = app.globalData.get_user_info(this, 'init');
  103. if (user != false) {
  104. // 用户未绑定用户则转到登录页面
  105. if (app.globalData.user_is_need_login(user)) {
  106. uni.redirectTo({
  107. url: "/pages/login/login?event_callback=init"
  108. });
  109. this.setData({
  110. data_list_loding_status: 0,
  111. data_list_loding_msg: '请先绑定手机',
  112. is_to_login: 1
  113. });
  114. return false;
  115. } else {
  116. // 获取付款码
  117. this.get_data();
  118. // #ifndef H5
  119. // 设置屏幕亮度
  120. uni.setScreenBrightness({
  121. value: 1
  122. });
  123. // #endif
  124. }
  125. } else {
  126. this.setData({
  127. data_list_loding_status: 0,
  128. data_list_loding_msg: '请先登录',
  129. is_to_login: 1
  130. });
  131. }
  132. },
  133. // 获取付款码
  134. get_data() {
  135. clearInterval(this.scheduled_timer);
  136. var self = this;
  137. uni.request({
  138. url: app.globalData.get_request_url("paymentcode", "user", "wallet"),
  139. method: 'POST',
  140. data: {},
  141. dataType: 'json',
  142. success: res => {
  143. if(res.data.code == 0) {
  144. var time = parseInt(res.data.data.time || 30);
  145. var timer = setInterval(function() {
  146. if(time <= 1) {
  147. self.get_data();
  148. } else {
  149. time--;
  150. self.setData({scheduled_value: time});
  151. }
  152. }, 1000);
  153. // 付款码数据
  154. var barcode = this.barcode;
  155. var qrcode = this.qrcode;
  156. barcode['code'] = res.data.data.code;
  157. qrcode['code'] = res.data.data.code;
  158. this.setData({
  159. data_list_loding_status: 3,
  160. is_to_login: 0,
  161. barcode: barcode,
  162. qrcode: qrcode,
  163. payment_code: res.data.data.code,
  164. scheduled_timer: timer,
  165. scheduled_value: time,
  166. });
  167. } else {
  168. this.setData({
  169. data_list_loding_status: 0,
  170. data_list_loding_msg: res.data.msg,
  171. is_to_login: 0
  172. });
  173. }
  174. },
  175. fail: () => {
  176. this.setData({
  177. data_list_loding_status: 2,
  178. data_list_loding_msg: '服务器请求出错',
  179. is_to_login: 0
  180. });
  181. app.globalData.showToast('服务器请求出错');
  182. }
  183. });
  184. },
  185. // url事件
  186. url_event(e) {
  187. app.globalData.url_event(e);
  188. }
  189. },
  190. // 页面销毁时执行
  191. onUnload: function() {
  192. clearInterval(this.scheduled_timer);
  193. // #ifndef H5
  194. // 恢复屏幕原始亮度
  195. if(this.screen_brightness_value > 0) {
  196. uni.setScreenBrightness({
  197. value: this.screen_brightness_value
  198. });
  199. }
  200. // #endif
  201. }
  202. }
  203. </script>
  204. <style>
  205. @import './payment-code.css';
  206. </style>