sign.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542
  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 headerBg = sheep.$url.css('/static/img/shop/app/sign.png');
  155. const state = reactive({
  156. data: {
  157. days: [], //日历
  158. rules: {}, //规则
  159. },
  160. cur_year: 0, //当前选的年
  161. cur_month: 0, //当前选的月
  162. cur_day: 0, //当前选择的天
  163. weeks_ch: [
  164. {
  165. title: '日',
  166. value: '0',
  167. },
  168. {
  169. title: '一',
  170. value: '1',
  171. },
  172. {
  173. title: '二',
  174. value: '2',
  175. },
  176. {
  177. title: '三',
  178. value: '3',
  179. },
  180. {
  181. title: '四',
  182. value: '4',
  183. },
  184. {
  185. title: '五',
  186. value: '5',
  187. },
  188. {
  189. title: '六',
  190. value: '6',
  191. },
  192. ], //星期
  193. showModel: false, //签到弹框
  194. continue_days: 0, //连续签到天数
  195. signin: {}, // 签到
  196. showRetroactive: false, //补签弹框
  197. date: '', //补签选中日期
  198. isSign: 0, //今天是否签到
  199. loading: true,
  200. });
  201. async function onSign() {
  202. const { error, data } = await sheep.$api.activity.signAdd();
  203. if (error === 0) {
  204. state.showModel = true;
  205. state.signin = data;
  206. // getData();
  207. }
  208. }
  209. function onShowRetroactive(e) {
  210. state.showRetroactive = true;
  211. state.date = e;
  212. }
  213. //签到确认刷新页面
  214. function onConfirm() {
  215. state.showModel = false;
  216. getData();
  217. }
  218. //补签
  219. async function onRetroactive() {
  220. const { error, data } = await sheep.$api.activity.replenish({
  221. date: state.date,
  222. });
  223. if (error === 0) {
  224. state.showRetroactive = false;
  225. getData();
  226. }
  227. }
  228. async function getData(mouth) {
  229. const { error, data } = await sheep.$api.activity.signList(mouth);
  230. if (error === 0) {
  231. state.data = data;
  232. } else {
  233. state.data = null;
  234. }
  235. state.loading = false;
  236. if (state.data) {
  237. state.data.days.forEach((i, index) => {
  238. if (index < i.week) {
  239. index++;
  240. var obj = {
  241. day: null,
  242. is_sign: false,
  243. };
  244. state.data.days.unshift(obj);
  245. }
  246. if (index == 1) {
  247. let arr = i.date.split('-');
  248. state.cur_year = arr[0];
  249. state.cur_month = arr[1];
  250. }
  251. });
  252. if (state.data.days[0].day == null) {
  253. state.data.days.forEach((i, index) => {
  254. if (i.current == 'today') {
  255. state.isSign = i.is_sign;
  256. }
  257. });
  258. }
  259. state.continue_days = data.continue_days;
  260. }
  261. }
  262. onReady(() => {
  263. getData();
  264. });
  265. // 切换控制年月,上一个月,下一个月
  266. const handleCalendar = (type) => {
  267. const cur_year = parseInt(state.cur_year);
  268. const cur_month = parseInt(state.cur_month);
  269. var newMonth;
  270. var newYear = cur_year;
  271. if (type === 0) {
  272. //上个月
  273. newMonth = cur_month - 1;
  274. if (newMonth < 1) {
  275. newYear = cur_year - 1;
  276. newMonth = 12;
  277. } else if (newMonth < 10) {
  278. newMonth = '0' + newMonth;
  279. }
  280. } else {
  281. newMonth = cur_month + 1;
  282. if (newMonth > 12) {
  283. newYear = cur_year + 1;
  284. newMonth = 1;
  285. } else if (newMonth < 10) {
  286. newMonth = '0' + newMonth;
  287. }
  288. }
  289. getData({
  290. month: newYear + '-' + newMonth,
  291. });
  292. };
  293. </script>
  294. <style lang="scss" scoped>
  295. .header-box {
  296. border-top: 2rpx solid rgba(#dfdfdf, 0.5);
  297. }
  298. // 日历
  299. .calendar {
  300. background: #fff;
  301. .sign-everyday {
  302. height: 100rpx;
  303. background: rgba(255, 255, 255, 1);
  304. border: 2rpx solid rgba(223, 223, 223, 0.4);
  305. .sign-everyday-title {
  306. font-size: 32rpx;
  307. color: rgba(51, 51, 51, 1);
  308. font-weight: 500;
  309. }
  310. .sign-num-box {
  311. font-size: 26rpx;
  312. font-weight: 500;
  313. color: rgba(153, 153, 153, 1);
  314. .sign-num {
  315. font-size: 30rpx;
  316. font-weight: 600;
  317. color: #ff6000;
  318. padding: 0 10rpx;
  319. font-family: OPPOSANS;
  320. }
  321. }
  322. }
  323. // 年月日
  324. .bar {
  325. height: 100rpx;
  326. .date {
  327. font-size: 30rpx;
  328. font-family: OPPOSANS;
  329. font-weight: 500;
  330. color: #333333;
  331. line-height: normal;
  332. }
  333. }
  334. .cicon-back {
  335. margin-top: 6rpx;
  336. font-size: 30rpx;
  337. color: #c4c4c4;
  338. line-height: normal;
  339. }
  340. .cicon-forward {
  341. margin-top: 6rpx;
  342. font-size: 30rpx;
  343. color: #c4c4c4;
  344. line-height: normal;
  345. }
  346. // 星期
  347. .week {
  348. .week-item {
  349. font-size: 24rpx;
  350. font-weight: 500;
  351. color: rgba(153, 153, 153, 1);
  352. flex: 1;
  353. }
  354. }
  355. // 日历表
  356. .myDateTable {
  357. display: flex;
  358. flex-wrap: wrap;
  359. .dateCell {
  360. width: calc(750rpx / 7);
  361. height: 80rpx;
  362. font-size: 26rpx;
  363. font-weight: 400;
  364. color: rgba(51, 51, 51, 1);
  365. }
  366. }
  367. }
  368. .is-sign {
  369. width: 48rpx;
  370. height: 48rpx;
  371. position: relative;
  372. .is-sign-num {
  373. font-size: 24rpx;
  374. font-family: OPPOSANS;
  375. font-weight: 500;
  376. line-height: normal;
  377. }
  378. .is-sign-image {
  379. position: absolute;
  380. left: 0;
  381. top: 0;
  382. width: 48rpx;
  383. height: 48rpx;
  384. }
  385. }
  386. .cell-num {
  387. font-size: 24rpx;
  388. font-family: OPPOSANS;
  389. font-weight: 500;
  390. color: #333333;
  391. line-height: normal;
  392. }
  393. .cicon-title {
  394. position: absolute;
  395. right: -10rpx;
  396. top: -6rpx;
  397. font-size: 20rpx;
  398. color: red;
  399. }
  400. // 签到按钮
  401. .sign-box {
  402. height: 140rpx;
  403. width: 100%;
  404. .sign-btn {
  405. width: 710rpx;
  406. height: 80rpx;
  407. border-radius: 35rpx;
  408. font-size: 30rpx;
  409. font-weight: 500;
  410. box-shadow: 0 0.2em 0.5em rgba(#ff6000, 0.4);
  411. background: linear-gradient(90deg, #ff6000, #fe832a);
  412. color: #fff;
  413. }
  414. .already-btn {
  415. width: 710rpx;
  416. height: 80rpx;
  417. border-radius: 35rpx;
  418. font-size: 30rpx;
  419. font-weight: 500;
  420. }
  421. }
  422. .model-box {
  423. width: 520rpx;
  424. // height: 590rpx;
  425. background: linear-gradient(177deg, #ff6000 0%, #fe832a 100%);
  426. // background: linear-gradient(177deg, var(--ui-BG-Main), var(--ui-BG-Main-gradient));
  427. border-radius: 10rpx;
  428. .cicon-check-round {
  429. font-size: 70rpx;
  430. color: #fff;
  431. }
  432. .score-title {
  433. font-size: 34rpx;
  434. font-family: OPPOSANS;
  435. font-weight: 500;
  436. color: #fcff00;
  437. }
  438. .model-title {
  439. font-size: 28rpx;
  440. font-weight: 500;
  441. color: #ffffff;
  442. }
  443. .model-bg {
  444. width: 520rpx;
  445. height: 344rpx;
  446. background-size: 100% 100%;
  447. background-image: v-bind(headerBg);
  448. background-repeat: no-repeat;
  449. border-radius: 0 0 10rpx 10rpx;
  450. .title {
  451. font-size: 34rpx;
  452. font-weight: bold;
  453. // color: var(--ui-BG-Main);
  454. color: #ff6000;
  455. }
  456. .subtitle {
  457. font-size: 26rpx;
  458. font-weight: 500;
  459. color: #999999;
  460. }
  461. .cancel-btn {
  462. width: 220rpx;
  463. height: 70rpx;
  464. border: 2rpx solid #ff6000;
  465. border-radius: 35rpx;
  466. font-size: 28rpx;
  467. font-weight: 500;
  468. color: #ff6000;
  469. line-height: normal;
  470. margin-right: 10rpx;
  471. }
  472. .confirm-btn {
  473. width: 220rpx;
  474. height: 70rpx;
  475. background: linear-gradient(90deg, #ff6000, #fe832a);
  476. box-shadow: 0 0.2em 0.5em rgba(#ff6000, 0.4);
  477. border-radius: 35rpx;
  478. font-size: 28rpx;
  479. font-weight: 500;
  480. color: #ffffff;
  481. line-height: normal;
  482. }
  483. }
  484. }
  485. //签到说明
  486. .activity-title {
  487. font-size: 32rpx;
  488. font-weight: 500;
  489. color: #333333;
  490. line-height: normal;
  491. }
  492. .activity-des {
  493. font-size: 26rpx;
  494. font-weight: 500;
  495. color: #666666;
  496. line-height: 40rpx;
  497. }
  498. </style>