金诚优选前端代码
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

351 lines
7.6 KiB

  1. <template>
  2. <view class="page">
  3. <lf-nav title="会员码" bgColor="transparent" :spreadOut="false" titleColor="#fff" :showIcon="true"></lf-nav>
  4. <view class="bg-viewleft"></view>
  5. <view class="bg-viewright"></view>
  6. <view class="content">
  7. <view class="top">
  8. <view class="lf-flex">
  9. <view class="avatar">
  10. <image :src="userInfo.avatar"></image>
  11. </view>
  12. <view class="phone">{{ userInfo.mobile_replace }}</view>
  13. </view>
  14. <!-- <view class="card">
  15. <text class="lf-iconfont icon-daifukuan"></text>
  16. </view> -->
  17. </view>
  18. <view class="balance">余额 ¥{{ centerInfo.balance }}</view>
  19. <block v-if="show_code">
  20. <view class="barcode">
  21. <lf-barcode :options="config.bar"></lf-barcode>
  22. </view>
  23. <view class="qrcode">
  24. <lf-qrcode :options="config.qrc"></lf-qrcode>
  25. </view>
  26. <view class="tips">{{ num }}s后自动刷新</view>
  27. </block>
  28. </view>
  29. </view>
  30. </template>
  31. <script>
  32. import lfBarcode from '@/components/lf-code/lf-barcode.vue';
  33. import lfQrcode from '@/components/lf-code/lf-qrcode.vue';
  34. export default {
  35. components: {
  36. lfBarcode,
  37. lfQrcode
  38. },
  39. data(){
  40. return {
  41. config: {
  42. bar: {
  43. code: '',
  44. color: '#000', // 条形码的颜色
  45. bgColor: '#FFFFFF', // 背景色
  46. width: 586, // 宽度
  47. height: 210 // 高度
  48. },
  49. qrc: {
  50. code: "",
  51. size: 352, // 二维码大小
  52. level: 4, //等级 0~4
  53. bgColor: '#FFFFFF', //二维码背景色 默认白色
  54. color: '#000000', //边框颜色支持渐变色
  55. }
  56. },
  57. timer: null,
  58. num: 120,
  59. refresh: 120,
  60. token: '',
  61. userInfo: {},
  62. centerInfo: {balance: 0},
  63. show_code: false,
  64. show_code_count: 0,
  65. show_count: 0,
  66. is_scan_code: false,
  67. first_http: 0
  68. }
  69. },
  70. onLoad(){
  71. var token = this.$cookieStorage.get('user_token');
  72. this.token = token;
  73. this.getIsSetPayPwd();
  74. this.getMeInfo();
  75. this.getUcenter();
  76. },
  77. onShow(){
  78. this.show_count++;
  79. if(this.show_count > 1){
  80. this.first_http = 0;
  81. this.is_scan_code = false;
  82. this.getIsSetPayPwd();
  83. }
  84. // 设置手机屏幕亮度
  85. uni.getScreenBrightness({
  86. success: (res) => {
  87. this.brightness = res.value;
  88. let value = res.value < 0.7 ? 0.7 : res.value;
  89. uni.setScreenBrightness({
  90. value: value
  91. })
  92. }
  93. })
  94. },
  95. onHide(){
  96. uni.setScreenBrightness({
  97. value: this.brightness
  98. })
  99. },
  100. onUnload(){
  101. if(this.timer){
  102. clearInterval(this.timer);
  103. this.timer = null;
  104. }
  105. uni.setScreenBrightness({
  106. value: this.brightness
  107. })
  108. },
  109. methods: {
  110. // 获取用户是否设置了支付密码
  111. getIsSetPayPwd(){
  112. this.$http.post({
  113. api: 'api/user/isset_pay_pwd',
  114. header: {
  115. Authorization: this.token
  116. }
  117. }).then(res => {
  118. console.log("====",res)
  119. if(res.data.status){
  120. this.refreshCode();
  121. }else{
  122. uni.showModal({
  123. title: '温馨提示',
  124. content: res.data.message,
  125. showCancel: false,
  126. confirmColor: '#1c8482',
  127. confirmText: '去设置',
  128. success: result => {
  129. if(result.confirm){
  130. this.$url('/pages/user/my/setPassword');
  131. }
  132. }
  133. })
  134. }
  135. })
  136. },
  137. // 获取页面信息
  138. getMeInfo(){
  139. this.$http.get({
  140. api: 'api/me',
  141. header: {
  142. Authorization: this.token
  143. }
  144. }).then(res => {
  145. this.userInfo = res.data.data;
  146. })
  147. },
  148. // 获取积分等信息
  149. getUcenter(){
  150. this.$http.get({
  151. api: 'api/users/ucenter',
  152. header: {
  153. Authorization: this.token
  154. }
  155. }).then(res => {
  156. this.centerInfo = res.data.data;
  157. })
  158. },
  159. // rpx 转 px
  160. rpxTransformPx(num){
  161. let systemInfo = uni.getSystemInfoSync();
  162. let pxWidth = num / 750 * systemInfo.windowWidth;
  163. return pxWidth;
  164. },
  165. // 刷新code
  166. refreshCode(){
  167. if(this.timer){
  168. clearInterval(this.timer);
  169. this.timer = null;
  170. }
  171. this.getPay();
  172. this.timer = setInterval(() => {
  173. this.num--;
  174. if(this.num % 5 === 0){
  175. this.getPay({silence: true});
  176. }
  177. if(this.num <= 0){
  178. clearInterval(this.timer);
  179. this.timer = null;
  180. this.num = this.refresh;
  181. this.refreshCode(); // 重新执行
  182. }
  183. }, 1000);
  184. },
  185. getPay(options = {}){
  186. if(!options.silence){
  187. if(this.show_code_count >= 1){
  188. uni.showLoading({
  189. title: '正在刷新'
  190. })
  191. }else{
  192. uni.showLoading({
  193. title: '正在拉取数据'
  194. })
  195. }
  196. }
  197. this.first_http++;
  198. this.$http.get({
  199. api: 'api/offline/get_pay',
  200. data: {
  201. refresh: this.first_http <= 1 ? 1 : 0
  202. },
  203. header: {
  204. Authorization: this.token
  205. }
  206. }).then(res => {
  207. if(res.data.code == 200){
  208. let detail = res.data.data;
  209. let u_id = this.userInfo.id;
  210. if(!options.silence){
  211. let str = JSON.stringify({
  212. rand: detail.rand,
  213. time: detail.time,
  214. u_id: u_id
  215. });
  216. this.config.bar.code = str;
  217. this.config.qrc.code = str;
  218. this.show_code = true;
  219. this.show_code_count++;
  220. }
  221. if(detail.clerk_id){
  222. // 商家已扫码, 跳转至确认金额页
  223. let amount = detail.amount;
  224. let brand_id = detail.brand_id;
  225. let clerk_id = detail.clerk_id;
  226. let url = '/pages/aboutpay/confirmcash';
  227. url += `?clerk_id=${clerk_id}`;
  228. url += `&brand_id=${brand_id}`;
  229. url += `&amount=${amount}`;
  230. if(this.timer){
  231. clearInterval(this.timer);
  232. this.timer = null;
  233. }
  234. if(!this.is_scan_code){
  235. this.$url(url);
  236. }
  237. this.is_scan_code = true;
  238. }
  239. }
  240. if(!options.silence){
  241. uni.hideLoading();
  242. }
  243. }).catch(err => {
  244. if(!options.silence){
  245. uni.hideLoading();
  246. }
  247. });
  248. }
  249. }
  250. }
  251. </script>
  252. <style>
  253. page{
  254. overflow: hidden;
  255. }
  256. </style>
  257. <style lang="scss" scoped="scoped">
  258. .page{
  259. width: 100vw;
  260. height: 100vh;
  261. background: linear-gradient(270deg, #187B7A 0%, #2FAAA7 100%, #22A2A0 100%);
  262. position: relative;
  263. overflow: hidden;
  264. .bg-viewleft{
  265. position: absolute;
  266. left: -100rpx;
  267. top: 59rpx;
  268. width: 585rpx;
  269. height: 585rpx;
  270. border-radius: 50%;
  271. background-color: rgba(255,255,255,0.04);
  272. }
  273. .bg-viewright{
  274. position: absolute;
  275. right: -38rpx;
  276. top: 102rpx;
  277. width: 127rpx;
  278. height: 127rpx;
  279. border-radius: 50%;
  280. background-color: rgba(255,255,255,0.04);
  281. }
  282. .content{
  283. position: absolute;
  284. top: 260rpx;
  285. left: calc(50% - 343rpx);
  286. width: 686rpx;
  287. height: 986rpx;
  288. background: #FFFFFF;
  289. border-radius: 20rpx;
  290. .top{
  291. display: flex;
  292. justify-content: space-between;
  293. padding: 0 40rpx;
  294. width: 100%;
  295. box-sizing: border-box;
  296. align-items: center;
  297. margin-top: -20rpx;
  298. .avatar{
  299. width: 160rpx;
  300. height: 160rpx;
  301. border-radius: 50%;
  302. background-color: #FFFFFF;
  303. box-shadow: 0rpx 2rpx 8rpx 1rpx rgba(21, 113, 110, 0.2);
  304. border: 5rpx solid #FFFFFF;
  305. display: flex;
  306. justify-content: center;
  307. align-items: center;
  308. margin-right: 20rpx;
  309. &>image{
  310. width: 148rpx;
  311. height: 148rpx;
  312. border-radius: 50%;
  313. }
  314. }
  315. .phone{
  316. font-size: 36rpx;
  317. font-weight: bold;
  318. color: #15716E;
  319. }
  320. .card{
  321. padding: 10rpx 20rpx;
  322. &>text{
  323. font-size: 40rpx;
  324. color: #15716E;
  325. }
  326. }
  327. }
  328. .balance{
  329. font-size: 32rpx;
  330. color: #555555;
  331. text-align: center;
  332. font-weight: bold;
  333. margin-top: 60rpx;
  334. line-height: 1;
  335. }
  336. .barcode, .qrcode{
  337. display: flex;
  338. justify-content: center;
  339. margin-top: 30rpx;
  340. }
  341. .tips{
  342. font-size: 24rpx;
  343. color: #777777;
  344. text-align: center;
  345. margin-top: 30rpx;
  346. }
  347. }
  348. }
  349. </style>