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.

352 lines
7.8 KiB

9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
  1. <template>
  2. <view class="sigin-in bx">
  3. <navbar :leftClick="leftClick" :title="$t('page.signIn.title')"></navbar>
  4. <view class="sigin-in-content">
  5. <!-- <view class="title">{{ $t('page.signIn.title') }}</view> -->
  6. <view class="numberOfSays">{{ $t('page.signIn.sign',[numberOfSays]) }}</view>
  7. <view class="date-info">
  8. <view class="month-info">
  9. <view class="left-arrow">
  10. <image @click="changeMonth(0)" src="/static/signin/arrow.png" mode="widthFix"></image>
  11. </view>
  12. <view class="month">{{ $t(`page.signIn.${monthIndex}`) }}</view>
  13. <view class="right-arrow">
  14. <image @click="changeMonth(1)" src="/static/signin/arrow.png" mode="widthFix"></image>
  15. </view>
  16. </view>
  17. <view class="day-list">
  18. <view v-for="(item,index) in dayList" :key="index" class="day-item">
  19. <view v-if="item.sign" class="check-img">
  20. <image src="/static/signin/check.png" mode="widthFix"></image>
  21. </view>
  22. <view class="sort">{{ $t('page.signIn.day',[index + 1])}}</view>
  23. <view class="img-box">
  24. <image src="/static/signin/gift.png" mode="widthFix"></image>
  25. </view>
  26. <view class="day">{{ forMateDate(item) }}</view>
  27. </view>
  28. </view>
  29. <view class="tips">{{ tips[type[$i18n.locale]] }}</view>
  30. <view :class="{ signedIn : userInfo.sginState == 1 }" @click="submitSignin" class="submit">{{ $t('page.signIn.title') }}</view>
  31. </view>
  32. </view>
  33. </view>
  34. </template>
  35. <script>
  36. import navbar from '@/components/base/m-navbar.vue'
  37. export default {
  38. components: {
  39. navbar
  40. },
  41. data() {
  42. return {
  43. numberOfSays: 0, //签到天数
  44. dayList: [], //日期列表
  45. tips: '', //提示
  46. type: {
  47. en: 'keyEnglish',
  48. es: "keySpanish",
  49. "zh": "keyChinese"
  50. },
  51. monthIndex: 0, //当前月份(0-11)
  52. signinList : [], //签到列表
  53. userInfo : {}
  54. }
  55. },
  56. onShow() {
  57. this.initDate()
  58. this.getTips()
  59. this.getSigninList()
  60. this.getUserInfo()
  61. },
  62. methods: {
  63. leftClick() {
  64. uni.navigateTo({
  65. url: '/pages/home/home'
  66. })
  67. },
  68. //初始化日期列表
  69. initDate() {
  70. if(this.dayList.length >= 28) return
  71. //保存当前月份
  72. this.monthIndex = this.$dayjs().month();
  73. // 获取当前日期
  74. let now = this.$dayjs();
  75. // 获取当前月最后一天的日期
  76. let lastDayOfMonth = now.endOf('month');
  77. // 获取当前月的天数
  78. let daysInMonth = lastDayOfMonth.date();
  79. //获取当前月的第一天
  80. var firstDay = this.$dayjs().date(1)
  81. this.dayList.push(firstDay)
  82. //获取一个月的所有日期
  83. for (let i = 1; i < daysInMonth; i++) {
  84. this.dayList.push(this.$dayjs(firstDay).add(i, 'day'))
  85. }
  86. },
  87. //格式化时间
  88. forMateDate(day) {
  89. return this.$dayjs(day).format("MM-DD")
  90. },
  91. //获取已签到列表
  92. getSigninList() {
  93. this.request('getSignRecord').then(res => {
  94. if (res.code == 200) {
  95. this.signinList = res.result
  96. this.updateSigninState()
  97. }
  98. })
  99. },
  100. //获取提示签到说明
  101. getTips() {
  102. this.request('getTips').then(res => {
  103. if (res.code == 200) {
  104. this.tips = res.result
  105. }
  106. })
  107. },
  108. //签到
  109. submitSignin(day) {
  110. this.$play()
  111. if(this.userInfo.sginState == 1){
  112. return uni.$u.toast(this.$t('message.34'))
  113. }
  114. this.request('sign').then(res => {
  115. if (res.code == 200) {
  116. uni.$u.toast(this.$t('message.35'))
  117. this.getSigninList()
  118. }
  119. })
  120. },
  121. //修改当前月份
  122. changeMonth(type) {
  123. this.$play()
  124. if (!type) {
  125. if(this.monthIndex <= 0) return
  126. // 获取当前月份之前的月份
  127. this.monthIndex -= 1;
  128. this.getDays()
  129. } else {
  130. if(this.monthIndex >= 11) return
  131. //获取当前月份之后的月份
  132. this.monthIndex += 1
  133. this.getDays()
  134. }
  135. },
  136. //获取过去或者未来的月份所有天
  137. getDays(){
  138. // 使用当前年份和新的月份索引创建一个日期对象
  139. let firstDayOfMonth = this.$dayjs().year(this.$dayjs().year()).month(this.monthIndex).startOf('month');
  140. // 获取当前月之前月份的最后一天
  141. let lastDayOfMonth = firstDayOfMonth.endOf('month');
  142. // 获取当前月之前月份的天数
  143. let daysInMonth = lastDayOfMonth.date();
  144. // 初始化日期列表
  145. this.dayList = [];
  146. // 遍历这个月的每一天
  147. for (let i = 1; i <= daysInMonth; i++) {
  148. // 添加每一天到列表中
  149. this.dayList.push(firstDayOfMonth.add(i - 1, 'day'));
  150. }
  151. //更新签到状态
  152. this.updateSigninState()
  153. },
  154. //更新签到状态
  155. updateSigninState(){
  156. this.signinList.forEach(item => {
  157. let signDate = this.$dayjs(item.signTime).format("YYYY-MM-DD")
  158. this.dayList.forEach(day => {
  159. if (day.isSame(signDate, 'day')) {
  160. this.$set(day, 'sign', true)
  161. }
  162. })
  163. //统计用户选择的月份签到天数
  164. this.countSigninDayNum()
  165. })
  166. },
  167. //统计用户选择的月份签到天数
  168. countSigninDayNum(){
  169. this.numberOfSays = 0;
  170. let lastIndex = this.getLastDayIndex()
  171. //计算选择月份连续签到天数
  172. for(let j = lastIndex ; j >= 0 ; j--){
  173. if(this.dayList[j].sign){
  174. this.numberOfSays++
  175. }else{
  176. return
  177. }
  178. }
  179. },
  180. //获取用户选择月份最后一天签到的索引
  181. getLastDayIndex() {
  182. for (let i = this.dayList.length - 1; i >= 0; i--) {
  183. if (this.dayList[i].sign) {
  184. return i;
  185. }
  186. }
  187. },
  188. //获取用户信息(用户判断用户是否已签到)
  189. getUserInfo() {
  190. this.request('userInfo').then(res => {
  191. if (res.code == 200) {
  192. this.userInfo = res.result.userInfo
  193. }
  194. })
  195. },
  196. }
  197. }
  198. </script>
  199. <style lang="scss" scoped>
  200. .sigin-in {
  201. // background: black;
  202. padding-bottom: 80rpx;
  203. .sigin-in-content {
  204. width: 96%;
  205. margin: 0 auto;
  206. .numberOfSays {
  207. text-align: center;
  208. padding: 20rpx 0rpx;
  209. }
  210. .date-info {
  211. // background: $uni-bg-color-app;
  212. border-radius: 20rpx;
  213. box-sizing: border-box;
  214. padding: 20rpx;
  215. .month-info {
  216. display: flex;
  217. justify-content: center;
  218. align-items: center;
  219. margin-bottom: 20rpx;
  220. .month {
  221. background: $uni-bg-color-app;
  222. color: $uni-text-color-inverse;
  223. padding: 10rpx;
  224. border-radius: 10rpx;
  225. margin: 0rpx 15rpx;
  226. font-size: 30rpx;
  227. }
  228. image {
  229. width: 30rpx;
  230. }
  231. .right-arrow {
  232. image {
  233. transform: rotate(-180deg);
  234. }
  235. }
  236. }
  237. .day-list {
  238. display: flex;
  239. flex-wrap: wrap;
  240. .day-item {
  241. background: $uni-bg-color-app;
  242. color: $uni-text-color-inverse;
  243. position: relative;
  244. flex-shrink: 0;
  245. width: calc(20% - 7px);
  246. // background: #565656;
  247. border-radius: 20rpx;
  248. margin-bottom: 20rpx;
  249. margin-right: calc(35px / 4);
  250. box-sizing: border-box;
  251. padding: 10rpx;
  252. &:nth-child(5n) {
  253. margin-right: 0rpx;
  254. }
  255. .check-img {
  256. position: absolute;
  257. right: 4rpx;
  258. top: -4rpx;
  259. image {
  260. width: 30rpx;
  261. }
  262. }
  263. image {
  264. width: 40rpx;
  265. margin: 10rpx 0rpx;
  266. }
  267. .sort {
  268. font-size: 20rpx;
  269. }
  270. .day {
  271. font-size: 20rpx;
  272. border-radius: 20rpx;
  273. background: #66B53B;
  274. }
  275. view {
  276. display: flex;
  277. justify-content: center;
  278. }
  279. }
  280. }
  281. .tips {
  282. color: #888888;
  283. font-size: 20rpx;
  284. text-align: center;
  285. margin: 20rpx 0rpx;
  286. }
  287. .submit {
  288. display: flex;
  289. align-items: center;
  290. justify-content: center;
  291. height: 80rpx;
  292. background: $uni-bg-color-app;
  293. color: $uni-text-color-inverse;
  294. border-radius: 40rpx;
  295. margin-bottom: 20rpx;
  296. }
  297. .signedIn{
  298. background: #ccc;
  299. }
  300. }
  301. }
  302. }
  303. </style>