金诚优选前端代码
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.

348 lines
7.5 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. },
  106. methods: {
  107. // 获取用户是否设置了支付密码
  108. getIsSetPayPwd(){
  109. this.$http.post({
  110. api: 'api/user/isset_pay_pwd',
  111. header: {
  112. Authorization: this.token
  113. }
  114. }).then(res => {
  115. console.log("====",res)
  116. if(res.data.status){
  117. this.refreshCode();
  118. }else{
  119. uni.showModal({
  120. title: '温馨提示',
  121. content: res.data.message,
  122. showCancel: false,
  123. confirmColor: '#1c8482',
  124. confirmText: '去设置',
  125. success: result => {
  126. if(result.confirm){
  127. this.$url('/pages/user/my/setPassword');
  128. }
  129. }
  130. })
  131. }
  132. })
  133. },
  134. // 获取页面信息
  135. getMeInfo(){
  136. this.$http.get({
  137. api: 'api/me',
  138. header: {
  139. Authorization: this.token
  140. }
  141. }).then(res => {
  142. this.userInfo = res.data.data;
  143. })
  144. },
  145. // 获取积分等信息
  146. getUcenter(){
  147. this.$http.get({
  148. api: 'api/users/ucenter',
  149. header: {
  150. Authorization: this.token
  151. }
  152. }).then(res => {
  153. this.centerInfo = res.data.data;
  154. })
  155. },
  156. // rpx 转 px
  157. rpxTransformPx(num){
  158. let systemInfo = uni.getSystemInfoSync();
  159. let pxWidth = num / 750 * systemInfo.windowWidth;
  160. return pxWidth;
  161. },
  162. // 刷新code
  163. refreshCode(){
  164. if(this.timer){
  165. clearInterval(this.timer);
  166. this.timer = null;
  167. }
  168. this.getPay();
  169. this.timer = setInterval(() => {
  170. this.num--;
  171. if(this.num % 5 === 0){
  172. this.getPay({silence: true});
  173. }
  174. if(this.num <= 0){
  175. clearInterval(this.timer);
  176. this.timer = null;
  177. this.num = this.refresh;
  178. this.refreshCode(); // 重新执行
  179. }
  180. }, 1000);
  181. },
  182. getPay(options = {}){
  183. if(!options.silence){
  184. if(this.show_code_count >= 1){
  185. uni.showLoading({
  186. title: '正在刷新'
  187. })
  188. }else{
  189. uni.showLoading({
  190. title: '正在拉取数据'
  191. })
  192. }
  193. }
  194. this.first_http++;
  195. this.$http.get({
  196. api: 'api/offline/get_pay',
  197. data: {
  198. refresh: this.first_http <= 1 ? 1 : 0
  199. },
  200. header: {
  201. Authorization: this.token
  202. }
  203. }).then(res => {
  204. if(res.data.code == 200){
  205. let detail = res.data.data;
  206. let u_id = this.userInfo.id;
  207. if(!options.silence){
  208. let str = JSON.stringify({
  209. rand: detail.rand,
  210. time: detail.time,
  211. u_id: u_id
  212. });
  213. this.config.bar.code = str;
  214. this.config.qrc.code = str;
  215. this.show_code = true;
  216. this.show_code_count++;
  217. }
  218. if(detail.clerk_id){
  219. // 商家已扫码, 跳转至确认金额页
  220. let amount = detail.amount;
  221. let brand_id = detail.brand_id;
  222. let clerk_id = detail.clerk_id;
  223. let url = '/pages/aboutpay/confirmcash';
  224. url += `?clerk_id=${clerk_id}`;
  225. url += `&brand_id=${brand_id}`;
  226. url += `&amount=${amount}`;
  227. if(this.timer){
  228. clearInterval(this.timer);
  229. this.timer = null;
  230. }
  231. if(!this.is_scan_code){
  232. this.$url(url);
  233. }
  234. this.is_scan_code = true;
  235. }
  236. }
  237. if(!options.silence){
  238. uni.hideLoading();
  239. }
  240. }).catch(err => {
  241. if(!options.silence){
  242. uni.hideLoading();
  243. }
  244. });
  245. }
  246. }
  247. }
  248. </script>
  249. <style>
  250. page{
  251. overflow: hidden;
  252. }
  253. </style>
  254. <style lang="scss" scoped="scoped">
  255. .page{
  256. width: 100vw;
  257. height: 100vh;
  258. background: linear-gradient(270deg, #187B7A 0%, #2FAAA7 100%, #22A2A0 100%);
  259. position: relative;
  260. overflow: hidden;
  261. .bg-viewleft{
  262. position: absolute;
  263. left: -100rpx;
  264. top: 59rpx;
  265. width: 585rpx;
  266. height: 585rpx;
  267. border-radius: 50%;
  268. background-color: rgba(255,255,255,0.04);
  269. }
  270. .bg-viewright{
  271. position: absolute;
  272. right: -38rpx;
  273. top: 102rpx;
  274. width: 127rpx;
  275. height: 127rpx;
  276. border-radius: 50%;
  277. background-color: rgba(255,255,255,0.04);
  278. }
  279. .content{
  280. position: absolute;
  281. top: 260rpx;
  282. left: calc(50% - 343rpx);
  283. width: 686rpx;
  284. height: 986rpx;
  285. background: #FFFFFF;
  286. border-radius: 20rpx;
  287. .top{
  288. display: flex;
  289. justify-content: space-between;
  290. padding: 0 40rpx;
  291. width: 100%;
  292. box-sizing: border-box;
  293. align-items: center;
  294. margin-top: -20rpx;
  295. .avatar{
  296. width: 160rpx;
  297. height: 160rpx;
  298. border-radius: 50%;
  299. background-color: #FFFFFF;
  300. box-shadow: 0rpx 2rpx 8rpx 1rpx rgba(21, 113, 110, 0.2);
  301. border: 5rpx solid #FFFFFF;
  302. display: flex;
  303. justify-content: center;
  304. align-items: center;
  305. margin-right: 20rpx;
  306. &>image{
  307. width: 148rpx;
  308. height: 148rpx;
  309. border-radius: 50%;
  310. }
  311. }
  312. .phone{
  313. font-size: 36rpx;
  314. font-weight: bold;
  315. color: #15716E;
  316. }
  317. .card{
  318. padding: 10rpx 20rpx;
  319. &>text{
  320. font-size: 40rpx;
  321. color: #15716E;
  322. }
  323. }
  324. }
  325. .balance{
  326. font-size: 32rpx;
  327. color: #555555;
  328. text-align: center;
  329. font-weight: bold;
  330. margin-top: 60rpx;
  331. line-height: 1;
  332. }
  333. .barcode, .qrcode{
  334. display: flex;
  335. justify-content: center;
  336. margin-top: 30rpx;
  337. }
  338. .tips{
  339. font-size: 24rpx;
  340. color: #777777;
  341. text-align: center;
  342. margin-top: 30rpx;
  343. }
  344. }
  345. }
  346. </style>