sign.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514
  1. <!-- 页面 -->
  2. <template>
  3. <s-layout :title="$t('app.sign.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">{{$t('app.sign.calendar')}}</text>
  10. <view class="sign-num-box">
  11. {{$t('app.sign.msg1')}}
  12. <text class="sign-num">{{ state.continue_days }}</text>
  13. {{$t('app.sign.day')}}
  14. </view>
  15. </view>
  16. <!-- 切换年月 -->
  17. <view class="bar ss-flex ss-col-center ss-row-center">
  18. <view class="previous" @tap="handleCalendar(0)"><text class="cicon-back"></text></view>
  19. <view class="date ss-m-x-20">{{ state.cur_year || '--' }} {{$t('app.sign.year')}} {{ state.cur_month || '--' }} {{$t('app.sign.month')}}</view>
  20. <view class="next" @tap="handleCalendar(1)"><text class="cicon-forward"></text></view>
  21. </view>
  22. <!-- 显示星期 -->
  23. <view class="week ss-flex">
  24. <view class="week-item ss-flex ss-row-center" v-for="(item, index) in state.weeks_ch" :key="index">
  25. {{ item.title }}
  26. </view>
  27. </view>
  28. <!-- 日历表 -->
  29. <view class="myDateTable">
  30. <view v-for="(item, j) in state.data.days" :key="j" 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.is_sign" 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" :src="sheep.$url.static('/assets/addons/shopro/uniapp/app/correct.png')">
  40. </image>
  41. </view>
  42. <!-- 未签到日期 -->
  43. <view class="is-sign ss-flex ss-row-center" v-if="item.is_replenish == 1"
  44. @tap="onShowRetroactive(item.date)">
  45. <view class="cell-num">{{ item.day < 10 ? '0' + item.day : item.day }}</view>
  46. <text class="cicon-title"></text>
  47. </view>
  48. <view class="is-sign ss-flex ss-row-center" v-if="item.is_replenish == 0 && !item.is_sign">
  49. <view class="cell-num">{{ item.day < 10 ? '0' + item.day : item.day }}</view>
  50. </view>
  51. </view>
  52. </view>
  53. <!-- 签到按钮 -->
  54. <view class="ss-flex ss-col-center ss-row-center sign-box ss-m-y-40">
  55. <button class="ss-reset-button sign-btn" v-if="state.isSign === 0" @tap="onSign">{{$t('app.sign.sign')}}</button>
  56. <button class="ss-reset-button already-btn" v-if="state.isSign === 1" disabled>{{$t('app.sign.signed')}}</button>
  57. </view>
  58. </view>
  59. </view>
  60. <view class="bg-white ss-m-t-16 ss-p-t-30 ss-p-b-60 ss-p-x-40">
  61. <view class="activity-title ss-m-b-30">{{$t('app.sign.intro')}}</view>
  62. <view class="activity-des">
  63. {{$t('app.sign.msg2')}} {{ state.data.rules.everyday }} {{$t('app.sign.msg3')}}
  64. <text v-if="state.data.rules.is_inc == '1'">
  65. ,{{$t('app.sign.msg4')}} {{ state.data.rules.inc_num }} {{$t('app.sign.msg5')}}
  66. {{ state.data.rules.until_day }} {{$t('app.sign.msg6')}}
  67. </text>
  68. </view>
  69. <view class="activity-des" v-if="state.data.rules.discounts?.length > 0">
  70. {{$t('app.sign.msg7')}}<text class="" v-for="i in state.data.rules.discounts" :key="i">{{$t('app.sign.msg8')}}{{ i.full }} {{$t('app.sign.msg9')}} {{ i.value }}
  71. {{$t('app.sign.msg10')}}</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' }}{{$t('app.sign.msg11')}}
  75. {{ state.data.rules.replenish_limit }} {{$t('app.sign.msg12')}}
  76. {{ state.data.rules.replenish_days }} {{$t('app.sign.msg13')}}
  77. {{ state.data.rules.replenish_num }}{{$t('app.sign.msg3')}}
  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 }}{{$t('app.sign.point')}}</view>
  88. <view class="model-title ss-flex ss-col-center ss-m-t-22 ss-m-b-30">
  89. {{$t('app.sign.msg14')}}{{ state.continue_days }}{{$t('app.sign.day')}}
  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">{{$t('app.sign.signSuccess')}}</view>
  94. <view class="ss-m-b-40">
  95. <button class="ss-reset-button confirm-btn" @tap="onConfirm">{{$t('app.sign.confirm')}}</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">{{$t('app.sign.msg15')}}{{ state.data?.rules.replenish_num }}{{$t('app.sign.point')}}</view>
  105. <view class="model-title ss-flex ss-col-center ss-m-t-22 ss-m-b-30">
  106. {{$t('app.sign.msg14')}}{{ state.continue_days }}{{$t('app.sign.day')}}
  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">{{$t('app.sign.msg15')}}</view>
  111. <view class="ss-m-b-40 ss-flex">
  112. <button class="ss-reset-button cancel-btn" @tap="state.showRetroactive = false">{{$t('app.sign.cancle')}}</button>
  113. <button class="ss-reset-button confirm-btn" @tap="onRetroactive">{{$t('app.sign.confirm')}}</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('/assets/addons/shopro/uniapp/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 { code, data } = await sheep.$api.activity.signAdd();
  173. if (code === 1) {
  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 { code, data } = await sheep.$api.activity.replenish({
  191. date: state.date,
  192. });
  193. if (code === 1) {
  194. state.showRetroactive = false;
  195. getData();
  196. }
  197. }
  198. async function getData(mouth) {
  199. const { code, data } = await sheep.$api.activity.signList(mouth);
  200. if (code === 1) {
  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 (i.current == 'today') {
  209. state.isSign = i.is_sign;
  210. }
  211. if (index < i.week) {
  212. index++;
  213. var obj = {
  214. day: null,
  215. is_sign: false,
  216. };
  217. state.data.days.unshift(obj);
  218. }
  219. if (index == 1) {
  220. let arr = i.date.split('-');
  221. state.cur_year = arr[0];
  222. state.cur_month = arr[1];
  223. }
  224. });
  225. if (state.data.days[0].day == null) {
  226. state.data.days.forEach((i, index) => {
  227. if (i.current == 'today') {
  228. state.isSign = i.is_sign;
  229. }
  230. });
  231. }
  232. state.continue_days = data.continue_days;
  233. }
  234. }
  235. onReady(() => {
  236. getData();
  237. });
  238. // 切换控制年月,上一个月,下一个月
  239. const handleCalendar = (type) => {
  240. const cur_year = parseInt(state.cur_year);
  241. const cur_month = parseInt(state.cur_month);
  242. var newMonth;
  243. var newYear = cur_year;
  244. if (type === 0) {
  245. //上个月
  246. newMonth = cur_month - 1;
  247. if (newMonth < 1) {
  248. newYear = cur_year - 1;
  249. newMonth = 12;
  250. } else if (newMonth < 10) {
  251. newMonth = '0' + newMonth;
  252. }
  253. } else {
  254. newMonth = cur_month + 1;
  255. if (newMonth > 12) {
  256. newYear = cur_year + 1;
  257. newMonth = '01';
  258. } else if (newMonth < 10) {
  259. newMonth = '0' + newMonth;
  260. }
  261. }
  262. getData({
  263. month: newYear + '-' + newMonth,
  264. });
  265. };
  266. </script>
  267. <style lang="scss" scoped>
  268. .header-box {
  269. border-top: 2rpx solid rgba(#dfdfdf, 0.5);
  270. }
  271. // 日历
  272. .calendar {
  273. background: #fff;
  274. .sign-everyday {
  275. height: 100rpx;
  276. background: rgba(255, 255, 255, 1);
  277. border: 2rpx solid rgba(223, 223, 223, 0.4);
  278. .sign-everyday-title {
  279. font-size: 32rpx;
  280. color: rgba(51, 51, 51, 1);
  281. font-weight: 500;
  282. }
  283. .sign-num-box {
  284. font-size: 26rpx;
  285. font-weight: 500;
  286. color: rgba(153, 153, 153, 1);
  287. .sign-num {
  288. font-size: 30rpx;
  289. font-weight: 600;
  290. color: #ff6000;
  291. padding: 0 10rpx;
  292. font-family: OPPOSANS;
  293. }
  294. }
  295. }
  296. // 年月日
  297. .bar {
  298. height: 100rpx;
  299. .date {
  300. font-size: 30rpx;
  301. font-family: OPPOSANS;
  302. font-weight: 500;
  303. color: #333333;
  304. line-height: normal;
  305. }
  306. }
  307. .cicon-back {
  308. margin-top: 6rpx;
  309. font-size: 30rpx;
  310. color: #c4c4c4;
  311. line-height: normal;
  312. }
  313. .cicon-forward {
  314. margin-top: 6rpx;
  315. font-size: 30rpx;
  316. color: #c4c4c4;
  317. line-height: normal;
  318. }
  319. // 星期
  320. .week {
  321. .week-item {
  322. font-size: 24rpx;
  323. font-weight: 500;
  324. color: rgba(153, 153, 153, 1);
  325. flex: 1;
  326. }
  327. }
  328. // 日历表
  329. .myDateTable {
  330. display: flex;
  331. flex-wrap: wrap;
  332. .dateCell {
  333. width: calc(750rpx / 7);
  334. height: 80rpx;
  335. font-size: 26rpx;
  336. font-weight: 400;
  337. color: rgba(51, 51, 51, 1);
  338. }
  339. }
  340. }
  341. .is-sign {
  342. width: 48rpx;
  343. height: 48rpx;
  344. position: relative;
  345. .is-sign-num {
  346. font-size: 24rpx;
  347. font-family: OPPOSANS;
  348. font-weight: 500;
  349. line-height: normal;
  350. }
  351. .is-sign-image {
  352. position: absolute;
  353. left: 0;
  354. top: 0;
  355. width: 48rpx;
  356. height: 48rpx;
  357. }
  358. }
  359. .cell-num {
  360. font-size: 24rpx;
  361. font-family: OPPOSANS;
  362. font-weight: 500;
  363. color: #333333;
  364. line-height: normal;
  365. }
  366. .cicon-title {
  367. position: absolute;
  368. right: -10rpx;
  369. top: -6rpx;
  370. font-size: 20rpx;
  371. color: red;
  372. }
  373. // 签到按钮
  374. .sign-box {
  375. height: 140rpx;
  376. width: 100%;
  377. .sign-btn {
  378. width: 710rpx;
  379. height: 80rpx;
  380. border-radius: 35rpx;
  381. font-size: 30rpx;
  382. font-weight: 500;
  383. box-shadow: 0 0.2em 0.5em rgba(#ff6000, 0.4);
  384. background: linear-gradient(90deg, #ff6000, #fe832a);
  385. color: #fff;
  386. }
  387. .already-btn {
  388. width: 710rpx;
  389. height: 80rpx;
  390. border-radius: 35rpx;
  391. font-size: 30rpx;
  392. font-weight: 500;
  393. }
  394. }
  395. .model-box {
  396. width: 520rpx;
  397. // height: 590rpx;
  398. background: linear-gradient(177deg, #ff6000 0%, #fe832a 100%);
  399. // background: linear-gradient(177deg, var(--ui-BG-Main), var(--ui-BG-Main-gradient));
  400. border-radius: 10rpx;
  401. .cicon-check-round {
  402. font-size: 70rpx;
  403. color: #fff;
  404. }
  405. .score-title {
  406. font-size: 34rpx;
  407. font-family: OPPOSANS;
  408. font-weight: 500;
  409. color: #fcff00;
  410. }
  411. .model-title {
  412. font-size: 28rpx;
  413. font-weight: 500;
  414. color: #ffffff;
  415. }
  416. .model-bg {
  417. width: 520rpx;
  418. height: 344rpx;
  419. background-size: 100% 100%;
  420. background-image: v-bind(headerBg);
  421. background-repeat: no-repeat;
  422. border-radius: 0 0 10rpx 10rpx;
  423. .title {
  424. font-size: 34rpx;
  425. font-weight: bold;
  426. // color: var(--ui-BG-Main);
  427. color: #ff6000;
  428. }
  429. .subtitle {
  430. font-size: 26rpx;
  431. font-weight: 500;
  432. color: #999999;
  433. }
  434. .cancel-btn {
  435. width: 220rpx;
  436. height: 70rpx;
  437. border: 2rpx solid #ff6000;
  438. border-radius: 35rpx;
  439. font-size: 28rpx;
  440. font-weight: 500;
  441. color: #ff6000;
  442. line-height: normal;
  443. margin-right: 10rpx;
  444. }
  445. .confirm-btn {
  446. width: 220rpx;
  447. height: 70rpx;
  448. background: linear-gradient(90deg, #ff6000, #fe832a);
  449. box-shadow: 0 0.2em 0.5em rgba(#ff6000, 0.4);
  450. border-radius: 35rpx;
  451. font-size: 28rpx;
  452. font-weight: 500;
  453. color: #ffffff;
  454. line-height: normal;
  455. }
  456. }
  457. }
  458. //签到说明
  459. .activity-title {
  460. font-size: 32rpx;
  461. font-weight: 500;
  462. color: #333333;
  463. line-height: normal;
  464. }
  465. .activity-des {
  466. font-size: 26rpx;
  467. font-weight: 500;
  468. color: #666666;
  469. line-height: 40rpx;
  470. }
  471. </style>