sign.vue 14 KB

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