offlineSignin.vue 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. <template>
  2. <view class="sign-in" v-loading="loading">
  3. <view class="sign-in-box">
  4. <view class="sign-in-box-divider"></view>
  5. <view class="sign-in-box-datetime">
  6. <view class="sibd-time">
  7. <clock-learn />
  8. </view>
  9. <view class="sibd-date">
  10. {{ $u.timeFormat(new Date(), 'mm月dd日') }}
  11. {{ getDateString() }}
  12. </view>
  13. </view>
  14. <view class="sign-in-box-button">
  15. <u-button type="primary" class="sign-in-btn" :loading="signLoading" @click="signImmediately">立即签到
  16. </u-button>
  17. <!-- <u-button type="info">签到记录</u-button> -->
  18. </view>
  19. </view>
  20. <u-toast ref="uToast" />
  21. </view>
  22. </template>
  23. <script>
  24. import clockLearn from '@/components/clock-learn/index.vue'
  25. export default {
  26. components: {
  27. clockLearn
  28. },
  29. data() {
  30. return {
  31. loading: false,
  32. memberInfo: {},
  33. signLoading: false,
  34. id: undefined,
  35. code: undefined
  36. }
  37. },
  38. onLoad(page) {
  39. const {
  40. id,
  41. code
  42. } = page;
  43. if (id && code) {
  44. this.id = id;
  45. this.code = code
  46. } else {
  47. uni.showToast({
  48. title: '参数丢失,请重新扫码!',
  49. duration: 2000,
  50. icon: 'error'
  51. });
  52. }
  53. },
  54. onShow() {
  55. this.getMemberInfo();
  56. },
  57. methods: {
  58. /**
  59. * 获取用户信息
  60. */
  61. getMemberInfo() {
  62. this.loading = true;
  63. this.$u.api
  64. .getmemberinfo()
  65. .then((res) => {
  66. this.memberInfo = res?.data ?? {}
  67. this.loading = false;
  68. })
  69. .catch(() => {
  70. this.loading = false;
  71. })
  72. },
  73. /**
  74. * 立即签到
  75. */
  76. signImmediately() {
  77. this.signLoading = true;
  78. this.$u.api.mine.signInNowApi({
  79. id: this.id
  80. })
  81. .then(res => {
  82. if (res.code === 200) {
  83. // this.$refs.uToast.show({
  84. // title: res.msg || '签到成功!',
  85. // type: 'success',
  86. // duration: 3000
  87. // });
  88. uni.showModal({
  89. title: '提示',
  90. content: `${res.msg || '签到成功'}, 是否返回首页?`,
  91. showCancel: false,
  92. success: function(res) {
  93. if (res.confirm) {
  94. uni.switchTab({
  95. url: '/pages/index/index'
  96. })
  97. }
  98. }
  99. });
  100. } else {
  101. this.$refs.uToast.show({
  102. title: '签到失败!' + res.msg,
  103. type: 'error'
  104. });
  105. this.signLoading = false;
  106. }
  107. })
  108. .catch(() => {
  109. this.signLoading = false;
  110. })
  111. },
  112. /**
  113. * 获取星期几
  114. */
  115. getDateString() {
  116. const weekList = ['星期日', '星期一', '星期二', '星期三', '星期四', '星期五', '星期六'],
  117. currentDate = new Date(),
  118. week = currentDate.getDay();
  119. return weekList[week]
  120. }
  121. },
  122. }
  123. </script>
  124. <style lang="scss" scoped>
  125. @import './offlineSignin.scss';
  126. </style>