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

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