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

362 lines
7.8 KiB

4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
  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({first: true});
  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(options = {}){
  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(options);
  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(options){
  167. if(this.timer){
  168. clearInterval(this.timer);
  169. this.timer = null;
  170. }
  171. this.getPay(options);
  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. console.log("options------",options)
  187. if(!options.silence){
  188. if(this.show_code_count >= 1){
  189. uni.showLoading({
  190. title: '正在刷新'
  191. })
  192. }else{
  193. uni.showLoading({
  194. title: '正在拉取数据'
  195. })
  196. }
  197. }
  198. this.first_http++;
  199. let cancel = 0;
  200. if(this.first_http <= 1){
  201. cancel = 2;
  202. }
  203. if(options.first){
  204. cancel = 1;
  205. }
  206. this.$http.get({
  207. api: 'api/offline/get_pay',
  208. data: {
  209. cancel: cancel
  210. },
  211. header: {
  212. Authorization: this.token
  213. }
  214. }).then(res => {
  215. if(res.data.code == 200){
  216. let detail = res.data.data;
  217. let u_id = this.userInfo.id;
  218. let str = JSON.stringify({
  219. rand: detail.rand,
  220. time: detail.time,
  221. u_id: u_id
  222. });
  223. this.config.bar.code = str;
  224. this.config.qrc.code = str;
  225. if(!options.silence){
  226. this.show_code = true;
  227. this.show_code_count++;
  228. }
  229. if(detail.status == 1){
  230. // 商家已扫码, 跳转至确认金额页
  231. let amount = detail.amount;
  232. let brand_id = detail.brand_id;
  233. let clerk_id = detail.clerk_id;
  234. let url = '/pages/aboutpay/confirmcash';
  235. url += `?clerk_id=${clerk_id}`;
  236. url += `&brand_id=${brand_id}`;
  237. url += `&amount=${amount}`;
  238. if(this.timer){
  239. clearInterval(this.timer);
  240. this.timer = null;
  241. }
  242. if(!this.is_scan_code){
  243. this.$url(url);
  244. }
  245. this.is_scan_code = true;
  246. }
  247. }
  248. if(!options.silence){
  249. uni.hideLoading();
  250. }
  251. }).catch(err => {
  252. if(!options.silence){
  253. uni.hideLoading();
  254. }
  255. });
  256. }
  257. }
  258. }
  259. </script>
  260. <style>
  261. page{
  262. overflow: hidden;
  263. }
  264. </style>
  265. <style lang="scss" scoped="scoped">
  266. .page{
  267. width: 100vw;
  268. height: 100vh;
  269. background: linear-gradient(270deg, #187B7A 0%, #2FAAA7 100%, #22A2A0 100%);
  270. position: relative;
  271. overflow: hidden;
  272. .bg-viewleft{
  273. position: absolute;
  274. left: -100rpx;
  275. top: 59rpx;
  276. width: 585rpx;
  277. height: 585rpx;
  278. border-radius: 50%;
  279. background-color: rgba(255,255,255,0.04);
  280. }
  281. .bg-viewright{
  282. position: absolute;
  283. right: -38rpx;
  284. top: 102rpx;
  285. width: 127rpx;
  286. height: 127rpx;
  287. border-radius: 50%;
  288. background-color: rgba(255,255,255,0.04);
  289. }
  290. .content{
  291. position: absolute;
  292. top: 260rpx;
  293. left: calc(50% - 343rpx);
  294. width: 686rpx;
  295. height: 986rpx;
  296. background: #FFFFFF;
  297. border-radius: 20rpx;
  298. .top{
  299. display: flex;
  300. justify-content: space-between;
  301. padding: 0 40rpx;
  302. width: 100%;
  303. box-sizing: border-box;
  304. align-items: center;
  305. margin-top: -20rpx;
  306. .avatar{
  307. width: 160rpx;
  308. height: 160rpx;
  309. border-radius: 50%;
  310. background-color: #FFFFFF;
  311. box-shadow: 0rpx 2rpx 8rpx 1rpx rgba(21, 113, 110, 0.2);
  312. border: 5rpx solid #FFFFFF;
  313. display: flex;
  314. justify-content: center;
  315. align-items: center;
  316. margin-right: 20rpx;
  317. &>image{
  318. width: 148rpx;
  319. height: 148rpx;
  320. border-radius: 50%;
  321. }
  322. }
  323. .phone{
  324. font-size: 36rpx;
  325. font-weight: bold;
  326. color: #15716E;
  327. }
  328. .card{
  329. padding: 10rpx 20rpx;
  330. &>text{
  331. font-size: 40rpx;
  332. color: #15716E;
  333. }
  334. }
  335. }
  336. .balance{
  337. font-size: 32rpx;
  338. color: #555555;
  339. text-align: center;
  340. font-weight: bold;
  341. margin-top: 60rpx;
  342. line-height: 1;
  343. }
  344. .barcode, .qrcode{
  345. display: flex;
  346. justify-content: center;
  347. margin-top: 30rpx;
  348. }
  349. .tips{
  350. font-size: 24rpx;
  351. color: #777777;
  352. text-align: center;
  353. margin-top: 30rpx;
  354. }
  355. }
  356. }
  357. </style>