sign_in_voucher.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656
  1. <template>
  2. <view class="voucher">
  3. <image src="../../static/imgs/sign_in_before.jpg" class="bgImg"></image>
  4. <view class="voucher_con">
  5. <view class="line"></view>
  6. <view class="title">第{{ signInfo.season ? signInfo.season : '' }}届大卫博士创业密训{{ signInfo.type == 1 ? '密训' : '实训' }}营</view>
  7. <view class="voucher_icon">
  8. <image src="../../static/imgs/written_off.png"></image>
  9. <view>有效凭证</view>
  10. </view>
  11. <view class="info">
  12. <view class="flexS">
  13. <text>报名人:</text>
  14. <view>{{ signInfo.nickname }}</view>
  15. </view>
  16. <view class="flexS">
  17. <text>手机号:</text>
  18. <view>{{ signInfo.phone }}</view>
  19. </view>
  20. <view class="flexS">
  21. <text>报名时间:</text>
  22. <view>{{ signInfo.created_at }}</view>
  23. </view>
  24. </view>
  25. <view class="btn flexC" @click="signIn">确认签到</view>
  26. </view>
  27. <view class="auth_login flexC" v-if="isAuthLogin"><button open-type="getUserInfo" @getuserinfo="userLogin" class="auth_btn">点击登录</button></view>
  28. <view class="phone_login" v-if="isPhoneLogin">
  29. <view class="phone_container">
  30. <view class="close" @click="isPhoneLogin = false"></view>
  31. <view class="top">
  32. <text>手机号验证</text>
  33. <div class="userImg"><open-data type="userAvatarUrl" class="getImgBtn"></open-data></div>
  34. </view>
  35. <view class="bottom">
  36. <input v-model="phone" type="text" placeholder="请输入手机号" class="input" maxlength="11" />
  37. <view class="bottom_eqcode">
  38. <input v-model="code" type="text" placeholder="输入验证码" class="input eqcode_input" />
  39. <view class="eqcode" @click="getCode">{{ countDown ? `重新获取(${countDown}s)` : '获取验证码' }}</view>
  40. </view>
  41. </view>
  42. <view class="submit_btn" @click="phoneLogin">提交</view>
  43. </view>
  44. </view>
  45. </view>
  46. </template>
  47. <script>
  48. import { wecatLogin, getUserInfo, phoneLogin, sendCode } from '../../api/index.js';
  49. import { getUser, sureSign } from '../../api/sign_in.js';
  50. export default {
  51. data() {
  52. return {
  53. userInfo: {}, //用户信息
  54. id: '', //扫码获取的id
  55. signInfo: {}, //报名人信息
  56. isAuthLogin: false, //是否显示登陆授权按钮
  57. isPhoneLogin: false, //是否显示手机登陆弹窗
  58. wechatInfo: {
  59. latitude: '',
  60. longitude: '',
  61. avatarUrl: '',
  62. nickName: ''
  63. }, //微信信息
  64. phone: '', //手机号
  65. code: '', //验证码
  66. countDown: 0, //验证码倒计时
  67. loginStatus: true //登陆状态
  68. };
  69. },
  70. onLoad(options) {
  71. if (options.scene) {
  72. this.id = options.scene;
  73. uni.setStorageSync('id', options.scene);
  74. }
  75. if (options.id) {
  76. this.id = options.id;
  77. uni.setStorageSync('id', options.id);
  78. }
  79. },
  80. onShow() {
  81. let that = this;
  82. that.getSetting();
  83. if (!uni.getStorageSync('token')) {
  84. that.isAuthLogin = true;
  85. } else {
  86. this.getUser();
  87. this.getUserInfo();
  88. }
  89. },
  90. watch: {
  91. isAuthLogin(a) {
  92. if (!a) {
  93. let that = this;
  94. wx.login({
  95. success({ code }) {
  96. that.wechatInfo.code = code;
  97. }
  98. });
  99. }
  100. },
  101. isPhoneLogin(a) {
  102. if (!a) {
  103. this.phone = '';
  104. this.code = '';
  105. }
  106. }
  107. },
  108. methods: {
  109. //判断用户是否打开定位权限
  110. getSetting() {
  111. let that = this;
  112. uni.getSetting({
  113. success: res => {
  114. // 从未触发过授权的情况
  115. if (typeof res.authSetting['scope.userLocation'] == 'undefined') {
  116. this.getLocation();
  117. return false;
  118. }
  119. //位置授权关闭 引导开启
  120. if (!res.authSetting['scope.userLocation']) {
  121. uni.showModal({
  122. title: '是否授权当前位置',
  123. content: '如需正常使用本程序,请在授权管理中选中“地理位置”,然后点按返回即可正常使用',
  124. showCancel: false,
  125. success: res => {
  126. if (res.confirm) {
  127. that.openSetting();
  128. }
  129. }
  130. });
  131. return false;
  132. }
  133. //位置授权开启,获取当前位置
  134. if (res.authSetting['scope.userLocation']) {
  135. this.getLocation();
  136. }
  137. },
  138. fail: err => {
  139. console.log(err);
  140. }
  141. });
  142. },
  143. openSetting() {
  144. wx.openSetting({
  145. success: res => {
  146. let that = this;
  147. if (res.authSetting['scope.userLocation']) {
  148. this.getLocation();
  149. }
  150. },
  151. fail: err => {
  152. uni.showModal({
  153. content: '开启位置权限失败,请手动开启',
  154. showCancel: false
  155. });
  156. }
  157. });
  158. },
  159. getLocation() {
  160. let that = this;
  161. uni.getLocation({
  162. // 用户同意授权地理位置
  163. success: ({ latitude, longitude }) => {
  164. that.wechatInfo.latitude = latitude;
  165. that.wechatInfo.longitude = longitude;
  166. },
  167. fail: function(err) {
  168. // 授权地理位置调用失败
  169. // if (err.errMsg == 'getLocation:fail system permission denied') {
  170. // uni.showModal({
  171. // content: '获取位置失败,请检查手机GPS或者微信使用手机定位权限是否开启',
  172. // showCancel: false
  173. // });
  174. // return false;
  175. // }
  176. if (err.errMsg == 'getLocation:fail auth deny') {
  177. uni.showModal({
  178. title: '是否授权当前位置',
  179. content: '取消位置授权,将影响您使用小程序,请重新开启授权',
  180. showCancel: false,
  181. success: res => {
  182. if (res.confirm) {
  183. that.openSetting();
  184. }
  185. }
  186. });
  187. }
  188. }
  189. });
  190. },
  191. // 获取验证码
  192. getCode() {
  193. let that = this;
  194. if (that.countDown) {
  195. uni.showModal({
  196. content: '验证码已发送,请稍后重试',
  197. showCancel: false
  198. });
  199. return false;
  200. }
  201. if (!that.phone) {
  202. uni.showModal({
  203. content: '请输入手机号',
  204. showCancel: false
  205. });
  206. return false;
  207. }
  208. sendCode({
  209. phone: that.phone
  210. }).then(res => {
  211. if (res.code != 200) {
  212. uni.showModal({
  213. content: res.message || '获取验证码失败',
  214. showCancel: false
  215. });
  216. return false;
  217. }
  218. if (res.code == 200) {
  219. uni.showModal({
  220. content: '验证码发送成功',
  221. showCancel: false
  222. });
  223. this.countDown = 60;
  224. this.timer = setInterval(() => {
  225. this.countDown--;
  226. if (!this.countDown) {
  227. this.countDown = 0;
  228. clearInterval(this.timer);
  229. }
  230. }, 1000);
  231. }
  232. });
  233. },
  234. /*微信登录获取 token
  235. * @params openid用户openid 传空
  236. * @params avatar 用户头像
  237. * @params nickname 用户昵称
  238. * @params code 微信登录code
  239. * @params longitude 用户位置经度
  240. * @params latitude 用户位置维度
  241. */
  242. userLogin({ detail }) {
  243. let that = this;
  244. if (detail.errMsg === 'getUserInfo:ok') {
  245. that.wechatInfo.avatarUrl = detail.userInfo.avatarUrl;
  246. that.wechatInfo.nickName = detail.userInfo.nickName;
  247. uni.login({
  248. success: ({ code }) => {
  249. that.wechatInfo.code = code;
  250. // if (!that.wechatInfo.longitude && !that.wechatInfo.latitude) {
  251. // uni.showModal({
  252. // content: '获取位置失败,请检查手机GPS或者微信使用手机定位权限是否开启',
  253. // showCancel: false
  254. // });
  255. // return false;
  256. // }
  257. let { avatarUrl, nickName, latitude, longitude } = that.wechatInfo;
  258. wecatLogin({
  259. openid: '',
  260. avatar: avatarUrl,
  261. nickname: nickName,
  262. code: code,
  263. longitude: longitude,
  264. latitude: latitude
  265. })
  266. .then(res => {
  267. if (res.code === 300) {
  268. that.isAuthLogin = false;
  269. that.isPhoneLogin = true;
  270. } else if (res.code === 200) {
  271. uni.setStorageSync('token', res.data.token);
  272. that.getUserInfo();
  273. } else {
  274. uni.showModal({
  275. content: res.message,
  276. showCancel: false
  277. });
  278. }
  279. })
  280. .catch(e => {})
  281. .finally(() => {
  282. that.isAuthLogin = false;
  283. });
  284. }
  285. });
  286. } else {
  287. uni.showModal({
  288. content: '不授权将无法获取到您的信息,请手动开启授权',
  289. showCancel: false,
  290. success: res => {
  291. if (res.confirm) {
  292. wx.openSetting({
  293. success: res => {
  294. let that = this;
  295. if (res.authSetting['scope.userInfo']) {
  296. uni.showModal({
  297. content: '用户权限已开启',
  298. showCancel: false
  299. });
  300. } else {
  301. uni.showModal({
  302. content: '您未开启用户信息权限',
  303. showCancel: false
  304. });
  305. }
  306. },
  307. fail: err => {
  308. uni.showModal({
  309. content: '开启用户信息权限失败',
  310. showCancel: false
  311. });
  312. }
  313. });
  314. }
  315. }
  316. });
  317. }
  318. },
  319. // 手机验证码登陆
  320. phoneLogin() {
  321. let that = this;
  322. if (!that.phone) {
  323. uni.showModal({
  324. content: '手机号不存在',
  325. showCancel: false
  326. });
  327. return false;
  328. }
  329. if (!that.code) {
  330. uni.showModal({
  331. content: '验证码不存在',
  332. showCancel: false
  333. });
  334. return false;
  335. }
  336. if (!that.loginStatus) return false;
  337. that.loginStatus = false;
  338. uni.login({
  339. success: ({ code }) => {
  340. phoneLogin({
  341. phone: that.phone,
  342. phone_code: that.code,
  343. avatar: that.wechatInfo.avatarUrl,
  344. nickname: that.wechatInfo.nickName,
  345. longitude: that.wechatInfo.longitude,
  346. latitude: that.wechatInfo.latitude,
  347. code
  348. })
  349. .then(res => {
  350. if (res.code === 200) {
  351. this.isPhoneLogin = false;
  352. uni.setStorageSync('token', res.data.token);
  353. that.getUserInfo();
  354. that.getUser();
  355. } else {
  356. uni.showModal({
  357. content: res.message || '请求失败',
  358. showCancel: false
  359. });
  360. }
  361. })
  362. .catch(e => {})
  363. .finally(() => {
  364. that.loginStatus = true;
  365. });
  366. }
  367. });
  368. },
  369. // 获取用户信息
  370. getUserInfo() {
  371. var that = this;
  372. if (!that.wechatInfo.latitude && that.wechatInfo.longitude) {
  373. that.getSetting();
  374. return false;
  375. }
  376. let { latitude, longitude } = that.wechatInfo;
  377. getUserInfo({ latitude, longitude })
  378. .then(res => {
  379. if (res.code === 200) {
  380. this.userInfo = res.data;
  381. uni.setStorageSync('userInfo', res.data);
  382. this.getUser();
  383. } else {
  384. uni.showModal({
  385. content: res.message || '请求失败',
  386. showCancel: false
  387. });
  388. }
  389. })
  390. .catch(e => {});
  391. },
  392. /*获取用户的报名信息
  393. * @params:id 扫码获得的id
  394. */
  395. getUser() {
  396. getUser({ id: this.id || uni.getStorageSync('id') }).then(res => {
  397. if (res.code != 200) {
  398. uni.showModal({
  399. content: res.message,
  400. showCancel: false,
  401. success: function(res) {
  402. if (res.confirm) {
  403. uni.switchTab({
  404. url: '../index/index'
  405. });
  406. }
  407. }
  408. });
  409. return false;
  410. }
  411. if (res.code == 200) {
  412. this.signInfo = res.data;
  413. }
  414. });
  415. },
  416. /*确认签到
  417. * @params:id 扫码获得的id
  418. */
  419. signIn() {
  420. sureSign({ id: this.signInfo.id }).then(res => {
  421. if (res.code == 200) {
  422. let { nickname, created_at, phone, season, type } = this.signInfo;
  423. uni.showToast({
  424. title: '签到成功!',
  425. duration: 2000,
  426. success: res => {
  427. uni.reLaunch({
  428. url:
  429. '../written_off/written_off?nickname=' +
  430. nickname +
  431. '&created_at=' +
  432. created_at +
  433. '&phone=' +
  434. phone +
  435. '&path=' +
  436. 1 +
  437. '&season=' +
  438. season +
  439. '&type=' +
  440. type
  441. });
  442. }
  443. });
  444. } else {
  445. uni.showModal({
  446. content: res.message || '请求失败',
  447. showCancel: false,
  448. success: res => {
  449. uni.redirectTo({
  450. url: '../sign_in/sign_in'
  451. });
  452. }
  453. });
  454. }
  455. });
  456. }
  457. }
  458. };
  459. </script>
  460. <style lang="scss" scoped>
  461. .phone_login {
  462. position: fixed;
  463. top: 0;
  464. bottom: 0;
  465. left: 0;
  466. right: 0;
  467. z-index: 999;
  468. display: flex;
  469. align-items: center;
  470. justify-content: center;
  471. background-color: rgba(0, 0, 0, 0.3);
  472. .phone_container {
  473. width: 570rpx;
  474. background-color: #ffffff;
  475. border-radius: 10rpx;
  476. overflow: hidden;
  477. position: relative;
  478. .close {
  479. &::before {
  480. position: absolute;
  481. top: 26rpx;
  482. right: 26rpx;
  483. content: '\2716';
  484. display: block;
  485. width: 30rpx;
  486. height: 30rpx;
  487. color: #ffffff;
  488. z-index: 9999;
  489. }
  490. }
  491. .top {
  492. width: 100%;
  493. height: 220rpx;
  494. background-color: #fa6342;
  495. color: #ffffff;
  496. font-size: 40rpx;
  497. padding-top: 50rpx;
  498. font-weight: blod;
  499. box-sizing: border-box;
  500. display: flex;
  501. justify-content: flex-start;
  502. flex-direction: column;
  503. align-items: center;
  504. position: relative;
  505. .userImg {
  506. position: absolute;
  507. width: 138rpx;
  508. height: 138rpx;
  509. border-radius: 50%;
  510. bottom: -69rpx;
  511. overflow: hidden;
  512. .getImgBtn {
  513. width: 138rpx;
  514. height: 138rpx;
  515. }
  516. }
  517. }
  518. .bottom {
  519. padding: 100rpx 60rpx 30rpx;
  520. background-color: #ffffff;
  521. .input {
  522. width: 100%;
  523. height: 70rpx;
  524. padding: 0 17rpx;
  525. box-sizing: border-box;
  526. color: #000000;
  527. font-size: 30rpx;
  528. background-color: #eeeeee;
  529. border-radius: 2rpx;
  530. }
  531. .bottom_eqcode {
  532. display: flex;
  533. justify-content: space-between;
  534. align-items: center;
  535. margin-top: 60rpx;
  536. .eqcode_input {
  537. width: 240rpx;
  538. }
  539. .eqcode {
  540. width: calc(100% - 240rpx);
  541. color: #fa6342;
  542. font-size: 32rpx;
  543. text-align: right;
  544. }
  545. }
  546. }
  547. .submit_btn {
  548. width: 100%;
  549. height: 86rpx;
  550. line-height: 86rpx;
  551. text-align: center;
  552. background-color: rgba(250, 99, 66, 0.2);
  553. color: #fa6342;
  554. font-size: 32rpx;
  555. }
  556. }
  557. }
  558. .auth_login {
  559. position: fixed;
  560. top: 0;
  561. bottom: 0;
  562. left: 0;
  563. right: 0;
  564. z-index: 999;
  565. background-color: rgba(0, 0, 0, 0.8);
  566. .auth_btn {
  567. width: 80%;
  568. height: 88rpx;
  569. background: #ea4a41;
  570. color: #fff;
  571. }
  572. }
  573. .voucher {
  574. hieght: 100vh;
  575. min-height: 100vh;
  576. width: 100vw;
  577. position: relative;
  578. .bgImg {
  579. height: 100vh;
  580. width: 100vw;
  581. position: fixed;
  582. top: 0;
  583. left: 0;
  584. }
  585. .voucher_con {
  586. position: fixed;
  587. height: 80%;
  588. width: 100%;
  589. bottom: 0;
  590. left: 0;
  591. background: #fff;
  592. border-top-left-radius: 60rpx;
  593. border-top-right-radius: 60rpx;
  594. .line {
  595. width: 128rpx;
  596. height: 8rpx;
  597. background: #f1f3f5;
  598. margin: 36rpx auto 0;
  599. }
  600. .title {
  601. color: #333;
  602. font-size: 42rpx;
  603. margin: 48rpx auto 101rpx;
  604. text-align: center;
  605. font-weight: bold;
  606. }
  607. .voucher_icon {
  608. text-align: center;
  609. image {
  610. height: 192rpx;
  611. width: 192rpx;
  612. margin-bottom: 51rpx;
  613. }
  614. view {
  615. font-size: 48rpx;
  616. color: #07b159;
  617. }
  618. }
  619. .info {
  620. margin: 30rpx 0 40rpx 100rpx;
  621. > view {
  622. margin-top: 34rpx;
  623. font-size: 28rpx;
  624. text {
  625. color: #656565;
  626. }
  627. view {
  628. color: #333333;
  629. }
  630. }
  631. }
  632. .btn {
  633. width: 640rpx;
  634. margin: 0 auto;
  635. height: 88rpx;
  636. color: #fff;
  637. background-color: #07b159;
  638. border-radius: 44rpx;
  639. letter-spacing: 2rpx;
  640. }
  641. }
  642. }
  643. </style>