sign.vue 13 KB

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