sign.vue 14 KB

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