sign.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594
  1. <!-- 页面 -->
  2. <template>
  3. <s-layout :title="t('sign.check_in_gift')">
  4. <view v-if="state.loading"></view>
  5. <view class="sign-wrap" v-else-if="state.data && !state.loading">
  6. <!-- 签到日历 -->
  7. <view class="content-box calendar">
  8. <view class="sign-everyday ss-flex ss-col-center ss-row-between ss-p-x-30">
  9. <text class="sign-everyday-title">{{t('sign.check_in')}}</text>
  10. <view class="sign-num-box">
  11. {{t('sign.consecutive_check_ins')}}
  12. <text class="sign-num">{{ state.continue_days }}</text>
  13. {{t('sign.days')}}
  14. </view>
  15. </view>
  16. <!-- 切换年月 -->
  17. <view class="bar ss-flex ss-col-center ss-row-center">
  18. <view class="previous" @tap="handleCalendar(0)"><text class="cicon-back"></text></view>
  19. <view class="date ss-m-x-20"> {{t('sign.month_year',{year:state.cur_year || '--',month:state.cur_month || '--'})}}</view>
  20. <view class="next" @tap="handleCalendar(1)"><text class="cicon-forward"></text></view>
  21. </view>
  22. <!-- 显示星期 -->
  23. <view class="week ss-flex">
  24. <view class="week-item ss-flex ss-row-center" v-for="(item, index) in state.weeks_ch" :key="index">
  25. {{ item.title }}
  26. </view>
  27. </view>
  28. <!-- 日历表 -->
  29. <view class="myDateTable">
  30. <view v-for="(item, j) in state.data.days" :key="j"
  31. class="dateCell ss-flex ss-row-center ss-col-center">
  32. <!-- 空格 -->
  33. <view class="ss-flex ss-row-center ss-col-center">
  34. <text :decode="true">&nbsp;&nbsp;</text>
  35. </view>
  36. <view>
  37. <!-- 已签到日期 -->
  38. <view v-if="item.isSign" class="is-sign ss-flex ss-row-center">
  39. <view class="is-sign-num">{{ item.day < 10 ? '0' + item.day : item.day }}</view>
  40. <image class="is-sign-image"
  41. :src="sheep.$url.static('/static/images/correct.png')">
  42. </image>
  43. </view>
  44. <!-- 未签到日期 -->
  45. <!-- <view class="is-sign ss-flex ss-row-center" v-if="item.isReplenish == 1"
  46. @tap="onShowRetroactive(item.date)"> -->
  47. <view class="is-sign ss-flex ss-row-center" v-if="item.isReplenish == 1">
  48. <view class="cell-num">{{ item.day < 10 ? '0' + item.day : item.day }}</view>
  49. <text class="cicon-title"></text>
  50. </view>
  51. <view class="is-sign ss-flex ss-row-center" v-if="item.isReplenish == 0 && !item.isSign">
  52. <view class="cell-num">{{ item.day < 10 ? '0' + item.day : item.day }}</view>
  53. </view>
  54. </view>
  55. </view>
  56. <!-- 签到按钮 -->
  57. <view class="ss-flex ss-col-center ss-row-center sign-box ss-m-y-40">
  58. <button class="ss-reset-button sign-btn" v-if="state.isSign === 0" @tap="onSign">{{t('sign.check_in')}}</button>
  59. <button class="ss-reset-button already-btn" v-if="state.isSign === 1" disabled>{{t('sign.already_checked_in')}}</button>
  60. </view>
  61. </view>
  62. </view>
  63. <view class="bg-white ss-m-t-16 ss-p-t-30 ss-p-b-60 ss-p-x-40">
  64. <view class="activity-title ss-m-b-30">{{t('sign.check_in_description')}}</view>
  65. <view class="activity-des">
  66. 1.{{t('sign.daily_check_in_fixed',{social:state.data.signInSocialStatus})}}
  67. <!-- <text v-if="state.data.rules.is_inc == '1'">
  68. ,次日递增奖励 {{ state.data.rules.inc_num }} 身价,直到
  69. {{ state.data.rules.until_day }} 天之后不再增加
  70. </text> -->
  71. </view>
  72. <!-- <view class="activity-des" v-if="state.data.rules.discounts?.length > 0">
  73. 2、<text class="" v-for="i in state.data.rules.discounts" :key="i">
  74. 连续签到 {{ i.full }} 天,奖励 {{ i.value }} 身价;
  75. </text>
  76. </view> -->
  77. <!-- <view class="activity-des" v-if="state.data.rules.is_replenish == '1'">
  78. {{ state.data.rules.discounts?.length > 0 ? '3' : '2' }}、用户在
  79. {{ state.data.rules.replenish_limit }} 天内,可补签
  80. {{ state.data.rules.replenish_days }} 天,每次补签消耗
  81. {{ state.data.rules.replenish_num }}身价
  82. </view> -->
  83. </view>
  84. </view>
  85. <s-empty v-else-if="!state.data && !state.loading" icon="/static/data-empty.png" :text="t('sign.check_in_not_started')">
  86. </s-empty>
  87. <su-popup :show="state.showModel" type="center" round="10" :isMaskClick="false">
  88. <view class="model-box ss-flex-col">
  89. <view class="ss-m-t-56 ss-flex-col ss-col-center">
  90. <text class="cicon-check-round"></text>
  91. <view class="score-title">{{t('sign.congratulations_on_check_in')}}</view>
  92. <view class="model-title ss-flex ss-col-center ss-m-t-22 ss-m-b-30">
  93. {{t('sign.daily_check_in_reward',{social:state.signin.social})}}
  94. </view>
  95. <view class="model-title ss-flex ss-col-center ss-m-b-30" v-if="state?.upgradeOrNot ">
  96. {{t('sign.level_upgraded',{level:state?.socialStatusName})}}
  97. </view>
  98. </view>
  99. <view class="model-bg ss-flex-col ss-col-center ss-row-right">
  100. <!-- <view class="title ss-m-b-64">签到成功</view> -->
  101. <view class="ss-m-b-40">
  102. <button class="ss-reset-button confirm-btn" @click="onConfirm()">{{t('common.confirm')}}</button>
  103. </view>
  104. </view>
  105. </view>
  106. </su-popup>
  107. <!--<su-popup :show="state.showRetroactive" type="center" round="10" :isMaskClick="false">
  108. <view class="model-box ss-flex-col">
  109. <view class="ss-m-t-56 ss-flex-col ss-col-center">
  110. <text class="cicon-check-round"></text>
  111. <view class="score-title">消耗{{ state.data?.rules.replenish_num }}身价</view>
  112. <view class="model-title ss-flex ss-col-center ss-m-t-22 ss-m-b-30">
  113. 已连续打卡{{ state.continue_days }}天
  114. </view>
  115. </view>
  116. <view class="model-bg ss-flex-col ss-col-center ss-row-right">
  117. <view class="title ss-m-b-64">确认补签</view>
  118. <view class="ss-m-b-40 ss-flex">
  119. <button class="ss-reset-button cancel-btn" @tap="state.showRetroactive = false">取消</button>
  120. <button class="ss-reset-button confirm-btn" @tap="onRetroactive">确认</button>
  121. </view>
  122. </view>
  123. </view>
  124. </su-popup>-->
  125. </s-layout>
  126. </template>
  127. <script setup>
  128. import sheep from '@/sheep';
  129. import {
  130. onLoad,
  131. onReady
  132. } from '@dcloudio/uni-app';
  133. import {
  134. computed,
  135. reactive,
  136. watchEffect,
  137. watch,
  138. onMounted
  139. } from 'vue';
  140. import SignInApi from '@/sheep/api/member/signin';
  141. import { t } from '@/locale'
  142. const headerBg = sheep.$url.css('/static/images/sign.png');
  143. const state = reactive({
  144. data: {
  145. days: [], //日历
  146. rules: {}, //规则
  147. },
  148. cur_year: 0, //当前选的年
  149. cur_month: 0, //当前选的月
  150. cur_day: 0, //当前选择的天
  151. weeks_ch: [{
  152. title: t('sign.sunday'),
  153. value: '0',
  154. },
  155. {
  156. title: t('sign.monday'),
  157. value: '1',
  158. },
  159. {
  160. title: t('sign.tuesday'),
  161. value: '2',
  162. },
  163. {
  164. title: t('sign.wednesday'),
  165. value: '3',
  166. },
  167. {
  168. title: t('sign.thursday'),
  169. value: '4',
  170. },
  171. {
  172. title: t('sign.friday'),
  173. value: '5',
  174. },
  175. {
  176. title: t('sign.saturday'),
  177. value: '6',
  178. },
  179. ], //星期
  180. showModel: false, //签到弹框
  181. continue_days: 0, //连续签到天数
  182. signin: {}, // 签到
  183. showRetroactive: false, //补签弹框
  184. date: '', //补签选中日期
  185. isSign: 0, //今天是否签到
  186. loading: true,
  187. });
  188. async function onSign() {
  189. const {
  190. code,
  191. data
  192. } = await SignInApi.createSignInRecord();
  193. if (code === 0) {
  194. state.showModel = true;
  195. state.signin = data;
  196. state.isSign = 1;
  197. uni.setStorageSync('isSign', true);
  198. }
  199. }
  200. function onShowRetroactive(e) {
  201. state.showRetroactive = true;
  202. state.date = e;
  203. }
  204. // 监听签到成功 3s之后自动关闭
  205. watch(() => state.showModel, (newValue) => {
  206. if(newValue){
  207. setTimeout(onConfirm,3000)
  208. }
  209. })
  210. //签到确认刷新页面
  211. function onConfirm() {
  212. state.showModel = false;
  213. getData({
  214. month: formatDate(new Date()).substring(0, 7)
  215. });
  216. }
  217. //补签
  218. // async function onRetroactive() {
  219. // const {
  220. // error,
  221. // data
  222. // } = await sheep.$api.activity.replenish({
  223. // date: state.date,
  224. // });
  225. // if (error === 0) {
  226. // state.showRetroactive = false;
  227. // getData();
  228. // }
  229. // }
  230. function formatDate(t) {
  231. let date = new Date(t);
  232. let year = date.getFullYear();
  233. let month = String(date.getMonth() + 1).padStart(2, '0');
  234. let day = String(date.getDate()).padStart(2, '0');
  235. let dateString = `${year}-${month}-${day}`;
  236. return dateString
  237. }
  238. async function getData(mouth) {
  239. const {
  240. code,
  241. data
  242. } = await SignInApi.getOwnSignInMoon(mouth);
  243. if (code === 0) {
  244. // console.log(state.data)
  245. data.days.forEach((i, index) => {
  246. if (i.week == 'SUNDAY') {
  247. i.week = 0
  248. } else if (i.week == 'MONDAY') {
  249. i.week = 1
  250. } else if (i.week == 'TUESDAY') {
  251. i.week = 2
  252. } else if (i.week == 'WEDNESDAY') {
  253. i.week = 3
  254. } else if (i.week == 'THURSDAY') {
  255. i.week = 4
  256. } else if (i.week == 'FRIDAY') {
  257. i.week = 5
  258. } else if (i.week == 'SATURDAY') {
  259. i.week = 6
  260. }
  261. i.date = formatDate(i.date)
  262. })
  263. state.data = data;
  264. // console.log(state)
  265. } else {
  266. state.data = null;
  267. }
  268. state.loading = false;
  269. if (state.data) {
  270. state.data.days.forEach((i, index) => {
  271. if (index < i.week) {
  272. index++;
  273. var obj = {
  274. day: null,
  275. isSign: false,
  276. };
  277. state.data.days.unshift(obj);
  278. }
  279. if (index == 1) {
  280. let arr = i.date.split('-');
  281. state.cur_year = arr[0];
  282. state.cur_month = arr[1];
  283. }
  284. });
  285. if (state.data.days[0].day == null) {
  286. state.data.days.forEach((i, index) => {
  287. // console.log(i.current)
  288. if (i.current == 'today') {
  289. // console.log(state.isSign)
  290. state.isSign = i.isSign;
  291. }
  292. });
  293. }
  294. state.continue_days = data.continueDays;
  295. }
  296. }
  297. onReady(() => {
  298. getData({
  299. month: formatDate(new Date()).substring(0, 7)
  300. });
  301. });
  302. // 切换控制年月,上一个月,下一个月
  303. const handleCalendar = (type) => {
  304. const cur_year = parseInt(state.cur_year);
  305. const cur_month = parseInt(state.cur_month);
  306. // console.log(cur_year,cur_month)
  307. var newMonth;
  308. var newYear = cur_year;
  309. if (type === 0) {
  310. //上个月
  311. newMonth = cur_month - 1;
  312. if (newMonth < 1) {
  313. newYear = cur_year - 1;
  314. newMonth = 12;
  315. } else if (newMonth < 10) {
  316. newMonth = '0' + newMonth;
  317. }
  318. } else {
  319. newMonth = cur_month + 1;
  320. if (newMonth > 12) {
  321. newYear = cur_year + 1;
  322. newMonth = "01";
  323. } else if (newMonth < 10) {
  324. newMonth = '0' + newMonth;
  325. }
  326. }
  327. // console.log(newYear + '-' + newMonth)
  328. getData({
  329. month: newYear + '-' + newMonth,
  330. });
  331. };
  332. </script>
  333. <style lang="scss" scoped>
  334. .header-box {
  335. border-top: 2rpx solid rgba(#dfdfdf, 0.5);
  336. }
  337. // 日历
  338. .calendar {
  339. background: #fff;
  340. .sign-everyday {
  341. height: 100rpx;
  342. background: rgba(255, 255, 255, 1);
  343. border: 2rpx solid rgba(223, 223, 223, 0.4);
  344. .sign-everyday-title {
  345. font-size: 32rpx;
  346. color: rgba(51, 51, 51, 1);
  347. font-weight: 500;
  348. }
  349. .sign-num-box {
  350. font-size: 26rpx;
  351. font-weight: 500;
  352. color: rgba(153, 153, 153, 1);
  353. .sign-num {
  354. font-size: 30rpx;
  355. font-weight: 600;
  356. color: #ff6000;
  357. padding: 0 10rpx;
  358. font-family: OPPOSANS;
  359. }
  360. }
  361. }
  362. // 年月日
  363. .bar {
  364. height: 100rpx;
  365. .date {
  366. font-size: 30rpx;
  367. font-family: OPPOSANS;
  368. font-weight: 500;
  369. color: #333333;
  370. line-height: normal;
  371. }
  372. }
  373. .cicon-back {
  374. margin-top: 6rpx;
  375. font-size: 30rpx;
  376. color: #c4c4c4;
  377. line-height: normal;
  378. }
  379. .cicon-forward {
  380. margin-top: 6rpx;
  381. font-size: 30rpx;
  382. color: #c4c4c4;
  383. line-height: normal;
  384. }
  385. // 星期
  386. .week {
  387. .week-item {
  388. font-size: 24rpx;
  389. font-weight: 500;
  390. color: rgba(153, 153, 153, 1);
  391. flex: 1;
  392. }
  393. }
  394. // 日历表
  395. .myDateTable {
  396. display: flex;
  397. flex-wrap: wrap;
  398. .dateCell {
  399. width: calc(750rpx / 7);
  400. height: 80rpx;
  401. font-size: 26rpx;
  402. font-weight: 400;
  403. color: rgba(51, 51, 51, 1);
  404. }
  405. }
  406. }
  407. .is-sign {
  408. width: 48rpx;
  409. height: 48rpx;
  410. position: relative;
  411. .is-sign-num {
  412. font-size: 24rpx;
  413. font-family: OPPOSANS;
  414. font-weight: 500;
  415. line-height: normal;
  416. }
  417. .is-sign-image {
  418. position: absolute;
  419. left: 0;
  420. top: 0;
  421. width: 48rpx;
  422. height: 48rpx;
  423. }
  424. }
  425. .cell-num {
  426. font-size: 24rpx;
  427. font-family: OPPOSANS;
  428. font-weight: 500;
  429. color: #333333;
  430. line-height: normal;
  431. }
  432. .cicon-title {
  433. position: absolute;
  434. right: -10rpx;
  435. top: -6rpx;
  436. font-size: 20rpx;
  437. color: red;
  438. }
  439. // 签到按钮
  440. .sign-box {
  441. height: 140rpx;
  442. width: 100%;
  443. .sign-btn {
  444. width: 710rpx;
  445. height: 80rpx;
  446. border-radius: 35rpx;
  447. font-size: 30rpx;
  448. font-weight: 500;
  449. box-shadow: 0 0.2em 0.5em rgba(#ff6000, 0.4);
  450. background: linear-gradient(90deg, #ff6000, #fe832a);
  451. color: #fff;
  452. }
  453. .already-btn {
  454. width: 710rpx;
  455. height: 80rpx;
  456. border-radius: 35rpx;
  457. font-size: 30rpx;
  458. font-weight: 500;
  459. }
  460. }
  461. .model-box {
  462. width: 520rpx;
  463. // height: 590rpx;
  464. background: linear-gradient(177deg, #ff6000 0%, #fe832a 100%);
  465. // background: linear-gradient(177deg, var(--ui-BG-Main), var(--ui-BG-Main-gradient));
  466. border-radius: 10rpx;
  467. .cicon-check-round {
  468. font-size: 70rpx;
  469. color: #fff;
  470. }
  471. .score-title {
  472. font-size: 34rpx;
  473. font-family: OPPOSANS;
  474. font-weight: 500;
  475. color: #fcff00;
  476. }
  477. .model-title {
  478. font-size: 28rpx;
  479. font-weight: 500;
  480. color: #ffffff;
  481. }
  482. .model-bg {
  483. width: 520rpx;
  484. height: 6.75rem;
  485. background-size: 100% 100%;
  486. background-image: v-bind(headerBg);
  487. background-repeat: no-repeat;
  488. border-radius: 0 0 10rpx 10rpx;
  489. .title {
  490. font-size: 34rpx;
  491. font-weight: bold;
  492. // color: var(--ui-BG-Main);
  493. color: #ff6000;
  494. }
  495. .subtitle {
  496. font-size: 26rpx;
  497. font-weight: 500;
  498. color: #999999;
  499. }
  500. .cancel-btn {
  501. width: 220rpx;
  502. height: 70rpx;
  503. border: 2rpx solid #ff6000;
  504. border-radius: 35rpx;
  505. font-size: 28rpx;
  506. font-weight: 500;
  507. color: #ff6000;
  508. line-height: normal;
  509. margin-right: 10rpx;
  510. }
  511. .confirm-btn {
  512. width: 300rpx;
  513. height: 70rpx;
  514. background: linear-gradient(90deg, #ff6000, #fe832a);
  515. box-shadow: 0 0.2em 0.5em rgba(#ff6000, 0.4);
  516. border-radius: 35rpx;
  517. font-size: 28rpx;
  518. font-weight: 500;
  519. color: #ffffff;
  520. line-height: normal;
  521. }
  522. }
  523. }
  524. //签到说明
  525. .activity-title {
  526. font-size: 32rpx;
  527. font-weight: 500;
  528. color: #333333;
  529. line-height: normal;
  530. }
  531. .activity-des {
  532. font-size: 26rpx;
  533. font-weight: 500;
  534. color: #666666;
  535. line-height: 40rpx;
  536. }
  537. </style>