sign.vue 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425
  1. <template>
  2. <view class="center">
  3. <view class="status_bar"><!-- 这里是状态栏 --></view>
  4. <view class="content-money">
  5. <view class="body-title">
  6. <view class="goback-box" @click="toBack"><image class="goback" src="../../static/icon/fanhui.png" mode=""></image></view>
  7. <view class="header">每日签到</view>
  8. </view>
  9. <view class="content-bg"><image src="../../static/img/sign-bg.png" mode=""></image></view>
  10. <view class="sign" @click="integral()">
  11. <image class="sign-bg" src="../../static/img/sign-main.png" mode=""></image>
  12. <view class="sign-font">{{ signTrue ? '已签到' : '签到' }}</view>
  13. </view>
  14. <view class="sign-tip">{{ signTrue ? '明日' : '今日' }}签到可得{{ today_integral }}{{today_type}}</view>
  15. </view>
  16. <view class="nav">
  17. <view class="nav-item">
  18. <view class="num">{{ allSign }}</view>
  19. <view class="font">签到天数</view>
  20. </view>
  21. <view class="xian"></view>
  22. <view class="nav-item">
  23. <view class="num">{{ actionDay }}</view>
  24. <view class="font">连续签到天数</view>
  25. </view>
  26. </view>
  27. <view class="rili"><calendar class="sign-date-box" :checks="signList" checksClass="" :checkTextShow="true"></calendar></view>
  28. <!-- <view class="explain">
  29. <view class="explain-left">
  30. 签到说明
  31. </view>
  32. <view class="explain-right">
  33. </view>
  34. </view> -->
  35. <uni-popup ref="popup" type="center">
  36. <view class="popup">
  37. <view class="popup-dox"><image class="popup-logo" src="../../static/img/sign-popup.png"></image></view>
  38. <view class="popup-title">
  39. 获得
  40. <text>{{ today_integral }}</text>
  41. {{today_type}}
  42. </view>
  43. <view class="popup-tip">
  44. 明天签到可得
  45. <text>{{ tom_integral }}</text>
  46. {{tom_type}}
  47. </view>
  48. <view class="popup-btn" @click="close">知道了</view>
  49. </view>
  50. <view class="close_icon" @click="close"><image src="../../static/img/Close.png"></image></view>
  51. </uni-popup>
  52. </view>
  53. </template>
  54. <script>
  55. import uniPopup from '@/components/uni-popup/uni-popup.vue';
  56. import calendar from '../../components/ss-calendar/ss-calendar.vue';
  57. import { signList, integral, signUser, signConfig } from '@/api/functionalUnit.js';
  58. export default {
  59. components: {
  60. calendar,
  61. uniPopup
  62. },
  63. data() {
  64. return {
  65. money: '', //保存当前月份
  66. year: '', //保存当前年份
  67. day: '', //保存当前日期
  68. signList: [], //签到日子列表
  69. actionDay: 0, //连续签到天数
  70. allSign: 0, //累计签到
  71. sum_integral: 0, //累计获得积分
  72. today_integral:0,//今天签到可以获得积分
  73. today_type:'',//今日签到的单位
  74. tom_type:'',//明天签到可以获得积分
  75. tom_integral:0,//明天签到可以获得积分
  76. signTrue: false
  77. };
  78. },
  79. onShow() {
  80. uni.showLoading({
  81. title: '加载中'
  82. });
  83. this.signUser();
  84. this.getData();
  85. this.loadList();
  86. },
  87. methods: {
  88. // 点击返回 我的页面
  89. toBack() {
  90. uni.navigateBack({});
  91. },
  92. signConfig(){
  93. signConfig().then(({data}) =>{
  94. let lun = data.length;
  95. console.log(this.actionDay)
  96. let index = (this.actionDay + 1) % lun;
  97. console.log(index,lun)
  98. if (index == 0){
  99. this.today_integral = data[lun-1].sign_num;
  100. this.today_type = data[lun-1].money_type
  101. this.tom_integral = data[0].sign_num;
  102. this.tom_type = data[0].money_type
  103. }else {
  104. this.today_integral = data[index-1].sign_num;
  105. this.today_type = data[index-1].money_type
  106. console.log(this.today_integral)
  107. this.tom_integral = data[index].sign_num;
  108. this.tom_type = data[index].money_type
  109. }
  110. })
  111. uni.hideLoading();
  112. },
  113. integral() {
  114. if(this.signTrue) {
  115. this.$api.msg('今天您已经签到了!')
  116. return
  117. }
  118. integral({})
  119. .then(e => {
  120. // 改为已签到
  121. this.signTrue = true;
  122. this.actionDay++;
  123. // 保存签到成功
  124. this.signList.push(this.day);
  125. this.$refs.popup.open();
  126. })
  127. .catch(e => {
  128. console.log(e);
  129. });
  130. },
  131. close() {
  132. this.signConfig();
  133. this.$refs.popup.close();
  134. },
  135. // 获取签到列表
  136. loadList() {
  137. let obj = this;
  138. let present = this.day; //保存当前天数用于后续计算
  139. let actionDay = 0; //用于计算活跃天数
  140. let arr = []; //保存返回数组;
  141. signList({
  142. page: 1,
  143. limit: 31
  144. }).then(e => {
  145. arr = e.data.map((e, ind) => {
  146. let time = e.add_time.split('-');
  147. let day = parseInt(time[2].replace(/^0/i, ''));
  148. let year = time[0];
  149. let month = +time[1];
  150. if (obj.year == year && obj.month == month) {
  151. return day;
  152. }
  153. });
  154. this.signList = arr;
  155. console.log(arr,this.day,"123456789")
  156. // 判断今天是否已经签到
  157. if (arr[0] == this.day) {
  158. this.signTrue = true;
  159. }
  160. });
  161. }, // 获取当前时间
  162. getData(current) {
  163. const date = current ? new Date(current) : new Date();
  164. this.year = date.getFullYear(); //保存当前年份
  165. this.month = date.getMonth() + 1; //保存当前月份
  166. this.day = date.getDate(); //保存当前日期
  167. },
  168. //获取签到用户信息
  169. signUser() {
  170. uni.showLoading({
  171. title: '加载中'
  172. });
  173. signUser({ all: 1 }).then(({ data }) => {
  174. console.log(111)
  175. this.actionDay = data.sign_num; //连续签到天数
  176. this.allSign = data.sum_sgin_day; //累计签到天数
  177. this.sum_integral = data.sum_integral; //累计总积分
  178. this.today_integral = data.today_integral; //今日签到可以获得多少积分
  179. this.signConfig();
  180. });
  181. }
  182. }
  183. };
  184. </script>
  185. <style lang="scss">
  186. .center,
  187. page {
  188. padding-bottom: 20rpx;
  189. }
  190. .status_bar {
  191. height: var(--status-bar-height);
  192. width: 100%;
  193. }
  194. .content-money {
  195. padding-bottom: 30rpx;
  196. position: relative;
  197. height: 526rpx;
  198. .content-bg {
  199. position: absolute;
  200. top: 0;
  201. left: 0;
  202. right: 0;
  203. width: 750rpx;
  204. height: 526rpx;
  205. image {
  206. width: 100%;
  207. height: 100%;
  208. }
  209. }
  210. .body-title {
  211. height: 80rpx;
  212. text-align: center;
  213. font-size: 35rpx;
  214. position: relative;
  215. .header {
  216. position: absolute;
  217. left: 0;
  218. top: 0;
  219. width: 100%;
  220. font-size: 36rpx;
  221. font-family: PingFang SC;
  222. font-weight: bold;
  223. color: #fffeff;
  224. height: 80rpx;
  225. font-size: 36rpx;
  226. font-weight: 700;
  227. z-index: 9;
  228. display: flex;
  229. justify-content: center;
  230. align-items: center;
  231. }
  232. .goback-box {
  233. position: absolute;
  234. left: 18rpx;
  235. top: 0;
  236. height: 80rpx;
  237. display: flex;
  238. align-items: center;
  239. }
  240. .goback {
  241. z-index: 100;
  242. width: 34rpx;
  243. height: 34rpx;
  244. }
  245. }
  246. .sign {
  247. width: 200rpx;
  248. height: 200rpx;
  249. margin: 40rpx auto 0;
  250. text-align: center;
  251. position: relative;
  252. z-index: 10;
  253. .sign-bg {
  254. position: absolute;
  255. top: 0;
  256. left: 0;
  257. right: 0;
  258. width: 100%;
  259. height: 100%;
  260. }
  261. .sign-font {
  262. position: relative;
  263. z-index: 11;
  264. line-height: 200rpx;
  265. font-size: 46rpx;
  266. font-family: PingFang SC;
  267. font-weight: 500;
  268. color: #ffffff;
  269. }
  270. }
  271. .sign-tip {
  272. margin: 14rpx auto 0;
  273. font-size: 32rpx;
  274. font-family: PingFang SC;
  275. font-weight: 500;
  276. color: #ffffff;
  277. position: relative;
  278. z-index: 10;
  279. text-align: center;
  280. }
  281. }
  282. .nav {
  283. position: relative;
  284. z-index: 10;
  285. width: 710rpx;
  286. height: 192rpx;
  287. display: flex;
  288. align-items: center;
  289. background: #ffffff;
  290. border-radius: 10rpx;
  291. margin: -86rpx auto 0;
  292. .nav-item {
  293. width: 50%;
  294. display: flex;
  295. flex-direction: column;
  296. align-items: center;
  297. justify-content: center;
  298. line-height: 1;
  299. .num {
  300. font-size: 56rpx;
  301. font-family: PingFang SC;
  302. font-weight: bold;
  303. color: #666666;
  304. }
  305. .font {
  306. margin-top: 28rpx;
  307. font-size: 30rpx;
  308. font-family: PingFang SC;
  309. font-weight: 500;
  310. color: #333333;
  311. opacity: 0.6;
  312. }
  313. }
  314. .xian {
  315. width: 2rpx;
  316. height: 152rpx;
  317. background-color: #efefef;
  318. }
  319. }
  320. .explain {
  321. margin: 20rpx auto 0;
  322. padding: 24rpx 28rpx;
  323. display: flex;
  324. align-items: center;
  325. justify-content: space-between;
  326. width: 694rpx;
  327. background: #ffffff;
  328. box-shadow: 0px 0px 20rpx 0px rgba(50, 50, 52, 0.06);
  329. border-radius: 20rpx;
  330. .explain-left {
  331. font-size: 28rpx;
  332. font-family: PingFang SC;
  333. font-weight: bold;
  334. color: #333333;
  335. }
  336. .explain-right {
  337. position: relative;
  338. bottom: 14rpx;
  339. right: 28rpx;
  340. }
  341. .explain-right:after,
  342. .explain-right:before {
  343. border: 12rpx solid transparent;
  344. border-left: 12rpx solid #fff;
  345. width: 0;
  346. height: 0;
  347. position: absolute;
  348. top: 0;
  349. right: -20px;
  350. content: ' ';
  351. }
  352. .explain-right:before {
  353. border-left-color: #333333;
  354. right: -21px;
  355. }
  356. }
  357. .popup {
  358. width: 560rpx;
  359. padding-bottom: 45rpx;
  360. background-color: #ffffff;
  361. border-radius: 15rpx;
  362. text-align: center;
  363. line-height: 1;
  364. .popup-dox {
  365. position: relative;
  366. .popup-logo {
  367. margin: -160rpx auto 0;
  368. width: 400rpx;
  369. height: 200rpx;
  370. }
  371. }
  372. .popup-title {
  373. margin-top: 85rpx;
  374. font-size: 40rpx;
  375. font-family: PingFang SC;
  376. font-weight: bold;
  377. color: #2a2a2a;
  378. text {
  379. font-size: 56rpx;
  380. color: #e83f30;
  381. }
  382. }
  383. .popup-tip {
  384. margin-top: 20rpx;
  385. font-size: 28rpx;
  386. font-family: PingFang SC;
  387. font-weight: 500;
  388. color: #8c8c8c;
  389. text {
  390. color: #e83f30;
  391. }
  392. }
  393. .popup-btn {
  394. margin: 58rpx auto 0;
  395. width: 270rpx;
  396. height: 66rpx;
  397. background: #f0c838;
  398. border-radius: 34rpx;
  399. text-align: center;
  400. line-height: 66rpx;
  401. font-size: 36rpx;
  402. font-family: Source Han Sans CN;
  403. font-weight: 500;
  404. color: #ffffff;
  405. }
  406. }
  407. .close_icon {
  408. width: 60rpx;
  409. height: 60rpx;
  410. margin: 88rpx auto 0;
  411. image {
  412. width: 100%;
  413. height: 100%;
  414. }
  415. }
  416. .rili {
  417. margin-top: 20rpx;
  418. padding: 0 20rpx;
  419. }
  420. </style>