sign.vue 13 KB

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