多租户商城-商户小程序端
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

462 lines
12 KiB

2 years ago
  1. <template>
  2. <view>
  3. <global-loading />
  4. <view class="signBox" v-if="ifShow">
  5. <view class="signBg">
  6. <view class="signDayNumBox flex-center" v-if="continuousNum">
  7. <view class="signDayNum fs28">
  8. 当前周期已连续签到
  9. <text class="fs40">{{ continuousNum || '0' }}</text>
  10. </view>
  11. </view>
  12. <view v-if="currentDay == lastDay" class="signState flex-center mar-top-30">
  13. <view class="signStateBg flex-items flex-center noSign">
  14. <text class="fs48">已签到</text>
  15. </view>
  16. </view>
  17. <view v-if="currentDay != lastDay" class="signState flex-center mar-top-30" @click="signInFn" >
  18. <view class="signStateBg flex-items flex-center">
  19. <text class="fs48">未签到</text>
  20. </view>
  21. </view>
  22. <view class="calendarBox">
  23. <view class="calendarBg">
  24. <view class="calendar-box">
  25. <view class="month">
  26. <view class="u-arrow u-arrow-left" @click="lastMonth"></view>
  27. <view>{{year}}{{month}}</view>
  28. <view class="u-arrow u-arrow-right" @click="nextMonth"></view>
  29. <picker v-if="checkDate" class="picker" mode="date" fields="month" @change="changeDate" />
  30. </view>
  31. <view class="week">
  32. <view :style="'color:'+(weeks==weeked?bgweek:'')+';'" v-for="weeks in weekArr">{{weeks}}</view>
  33. </view>
  34. <view class="day">
  35. <view
  36. class="dayItem"
  37. v-for="(days,index) in dayArr"
  38. :key="index"
  39. @click="signToday(days,index)"
  40. >
  41. <view
  42. :class="[
  43. {'checkday':days.date==''},
  44. {'choose':days.date==currentDay},
  45. {'select': days.select === 1}
  46. ]"
  47. class="dayValue"
  48. >{{days.day}}</view>
  49. </view>
  50. </view>
  51. </view>
  52. </view>
  53. </view>
  54. </view>
  55. <view class="redEnvelope mar-top-20">
  56. <view class="redEnvelopeBg flex-items flex-end">
  57. <view>
  58. <view class="fs32 font-color-333">积分兑换红包优惠券</view>
  59. <view class="fs24 font-color-999 mar-top-10">各种大额红包等你兑换哦</view>
  60. <view class="fs24 font-color-FFF exchangeBtn mar-top-20" @click="goToexchange">马上兑换</view>
  61. </view>
  62. </view>
  63. </view>
  64. <!-- 签到弹窗 -->
  65. <tui-modal :show="signTips" :custom="true" :fadein="true">
  66. <view class="Put-box1">
  67. <view class="text-align fs34 fs-bold">
  68. 签到成功
  69. </view>
  70. <view class="mar-top-40 text-align">
  71. 今日签到成功签到积分可以在我的积分内兑换商品
  72. </view>
  73. <view class="flex-display flex-sp-between">
  74. <view class="btn" @click="signTips = false">
  75. 取消
  76. </view>
  77. <view class="btn submit" @click="signTips = false">
  78. 确定
  79. </view>
  80. </view>
  81. </view>
  82. </tui-modal>
  83. </view>
  84. </view>
  85. </template>
  86. <script>
  87. import tuiModal from "@/components/modal/modal";
  88. import dateUtil from "@/utils/dateUtil"
  89. const NET = require('../../utils/request')
  90. const API = require('../../config/api')
  91. export default {
  92. components: {
  93. tuiModal
  94. },
  95. name: "sign",
  96. data() {
  97. return {
  98. signList: [],
  99. year: new Date().getFullYear(), // 当前年
  100. month: new Date().getMonth() + 1, // 当前月
  101. continuousNum: '', // 连续签到天数
  102. currentDay: dateUtil.formatDate(),
  103. currentMonth: dateUtil.formatMonth(),
  104. lastDay: '',
  105. weeked: '', // 今天周几
  106. dayArr: [], // 当前月每日
  107. day: new Date().getDate(), // 当前日
  108. weekArr: ['日', '一', '二', '三', '四', '五', '六'], // 每周
  109. type: 'sign',
  110. checkDate: true,
  111. bgweek: '#C5AA7B',
  112. bgday: '#C5AA7B',
  113. signTips: false,
  114. ifShow: false
  115. }
  116. },
  117. onLoad() {
  118. this.getSignData()
  119. },
  120. methods: {
  121. getSignData() {
  122. // uni.showLoading({
  123. // mask: true,
  124. // title: '请稍等...',
  125. // })
  126. let selectMonth = this.year + '-' + this.formatNum(this.month)
  127. const that = this
  128. NET.request(API.selectByMonth,
  129. {
  130. month: `${this.year}-${this.formatNum(this.month)}`
  131. },
  132. 'POST')
  133. .then(res => {
  134. // uni.hideLoading()
  135. that.ifShow = true
  136. that.signList = res.data
  137. // 初始日期
  138. that.initDate()
  139. // 今天日期
  140. if (that.currentMonth === selectMonth) {
  141. that.continuousNum = that.signList[that.signList.length - 1].continueDay || 0;
  142. that.lastDay = that.signList[that.signList.length - 1].createTime.substring(0,10);
  143. }
  144. // 今天周几
  145. that.weeked = that.weekArr[new Date().getDay()];
  146. // 签到功能
  147. if (that.type !== 'calendar') {
  148. for (let i in that.dayArr) {
  149. that.$set(this.dayArr[i], 'flag', false);
  150. }
  151. }
  152. that.signList.forEach((item) => {
  153. item['day'] = parseInt(item.createTime.slice(8, 10))
  154. })
  155. for (let i = 0; i < that.signList.length; i++) {
  156. for (let j = 0; j < that.dayArr.length; j++) {
  157. if (that.signList[i].day === that.dayArr[j].day && that.dayArr[j].date !== '') {
  158. that.dayArr[j].select = 1
  159. }
  160. }
  161. }
  162. }).catch(res => {})
  163. },
  164. signDate(event) {
  165. },
  166. // 签到
  167. signInFn() {
  168. // uni.showLoading({
  169. // mask: true,
  170. // title: '请稍等...',
  171. // })
  172. NET.request(API.creditSignIn, {}, 'POST').then(res => {
  173. // uni.hideLoading()
  174. this.getSignData()
  175. this.signTips = true
  176. }).catch(res => {})
  177. },
  178. // 格式化日期位数
  179. formatNum(num) {
  180. return num < 10 ? ('0' + num) : num;
  181. },
  182. // 选择年月
  183. changeDate(e) {
  184. let that = this;
  185. that.year = parseInt(e.detail.value.split('-')[0]);
  186. that.month = parseInt(e.detail.value.split('-')[1]);
  187. this.getSignData()
  188. },
  189. // 点击签到
  190. signToday(obj, index) {
  191. },
  192. // 初始化日期
  193. initDate() {
  194. let that = this;
  195. that.dayArr = [];
  196. // 当前月总天数
  197. let totalDay = new Date(that.year, that.month, 0).getDate();
  198. // 遍历总天数将日期逐个添加至数组
  199. for (let i = 1; i <= totalDay; i++) {
  200. // 得到需补充天数
  201. let value = (new Date(that.year, that.month - 1, i)).getDay();
  202. // 补充前面空白日期
  203. if (i === 1 && value !== 0) that.addBefore(value);
  204. // 添加本月日期
  205. let obj = {};
  206. obj.date = that.year + '-' + that.formatNum(that.month) + '-' + that.formatNum(i);
  207. obj.day = i;
  208. obj.select = 0
  209. that.dayArr.push(obj);
  210. // 补充后面空白日期
  211. if (i === totalDay && value !== 6) that.addAfter(value);
  212. }
  213. },
  214. // 补充前面空白日期
  215. addBefore(value) {
  216. let that = this;
  217. let totalDay = new Date(that.year, that.month - 1, 0).getDate();
  218. for (let i = 0; i < value; i++) {
  219. let obj = {};
  220. obj.date = '';
  221. obj.day = totalDay - (value - i) + 1;
  222. that.dayArr.push(obj);
  223. }
  224. },
  225. // 补充后空白日期
  226. addAfter(value) {
  227. let that = this;
  228. for (let i = 0; i < (6 - value); i++) {
  229. let obj = {};
  230. obj.date = '';
  231. obj.day = i + 1;
  232. that.dayArr.push(obj);
  233. }
  234. },
  235. // 上一个月
  236. lastMonth() {
  237. let that = this;
  238. if (that.month === 1) {
  239. that.year -= 1;
  240. that.month = 12;
  241. } else {
  242. that.month -= 1;
  243. }
  244. that.getSignData();
  245. },
  246. // 下一个月
  247. nextMonth() {
  248. let that = this;
  249. if (that.month === 12) {
  250. that.year += 1;
  251. that.month = 1;
  252. } else {
  253. that.month += 1;
  254. }
  255. that.getSignData();
  256. },
  257. goToexchange() {
  258. uni.navigateTo({
  259. url: '../../pages_category_page1/integral/index?tabActive=2'
  260. })
  261. }
  262. }
  263. }
  264. </script>
  265. <style lang="scss" scoped>
  266. page {
  267. background: #F8F8F8;
  268. }
  269. .signBox {
  270. padding-bottom: 50rpx;
  271. .signBg {
  272. background: url("https://ceres.zkthink.com/static/images/signBg.png") no-repeat left top;
  273. background-size: contain;
  274. min-height: 702rpx;
  275. padding-top: 160rpx;
  276. .signDayNumBox {
  277. width: 100%;
  278. .signDayNum {
  279. color: #93866F;
  280. text {
  281. color: #FDF3D0;
  282. margin: 0 10rpx;
  283. }
  284. }
  285. }
  286. .signState {
  287. .signStateBg {
  288. width: 300rpx;
  289. height: 300rpx;
  290. background: url("https://ceres.zkthink.com/static/images/signState.png") no-repeat left top;
  291. background-size: contain;
  292. text {
  293. color: #C83732;
  294. }
  295. }
  296. .noSign {
  297. background: url("https://ceres.zkthink.com/static/images/signState1.png") no-repeat left top;
  298. background-size: contain;
  299. text {
  300. color: #FFFFFF;
  301. }
  302. }
  303. }
  304. .checked {
  305. .signStateBg {
  306. text {
  307. color: #FFFFFF;
  308. }
  309. }
  310. }
  311. .calendarBox {
  312. padding: 0 20rpx;
  313. min-height: 300rpx;
  314. .calendarBg {
  315. border-radius: 16rpx;
  316. background: #FFFFFF;
  317. box-shadow: 0 10rpx 20rpx rgba(0, 0, 0, 0.05);
  318. overflow: hidden;
  319. }
  320. }
  321. }
  322. .redEnvelope {
  323. padding: 0 20rpx;
  324. .redEnvelopeBg {
  325. height: 230rpx;
  326. background: url("https://ceres.zkthink.com/static/images/redEnvelopeBg.png") no-repeat left top;
  327. background-size: contain;
  328. padding-right: 50rpx;
  329. .exchangeBtn {
  330. width: 160rpx;
  331. height: 56rpx;
  332. line-height: 56rpx;
  333. background: #C83732;
  334. border-radius: 8rpx;
  335. text-align: center;
  336. }
  337. }
  338. }
  339. }
  340. .calendar-box {
  341. width: 100%;
  342. flex-direction: column;
  343. justify-content: center;
  344. }
  345. .calendar-box,
  346. .month,
  347. .week,
  348. .day {
  349. display: flex;
  350. align-items: center;
  351. justify-content: space-between;
  352. }
  353. .month,
  354. .week,
  355. .day {
  356. width: 100%;
  357. }
  358. .month {
  359. height: 96rpx;
  360. padding: 0 50rpx;
  361. position: relative;
  362. background: #FAF6ED;
  363. .u-arrow {
  364. border-top: 4rpx solid #666;
  365. border-right: 4rpx solid #666;
  366. }
  367. }
  368. .picker {
  369. width: 160rpx;
  370. height: 40rpx;
  371. position: absolute;
  372. top: 20rpx;
  373. left: 50%;
  374. transform: translate(-50%, -50%);
  375. }
  376. .day {
  377. flex-wrap: wrap;
  378. .dayValue {
  379. }
  380. }
  381. .week>view,
  382. .day>view.dayItem {
  383. width: 100rpx;
  384. height: 100rpx;
  385. position: relative;
  386. line-height: 100rpx;
  387. display: flex;
  388. justify-content: center;
  389. align-items: center;
  390. }
  391. .dayValue {
  392. width: 60rpx;
  393. height: 60rpx;
  394. text-align: center;
  395. position: relative;
  396. line-height: 60rpx;
  397. }
  398. .checkday {
  399. color: #999;
  400. }
  401. .select {
  402. background: #FAF6ED;
  403. color: #C5AA7B;
  404. border-radius: 50%;
  405. }
  406. .choose {
  407. color: #FFFFFF;
  408. background: #C5AA7B;
  409. border-radius: 50%;
  410. }
  411. .circle {
  412. width: 10rpx;
  413. height: 10rpx;
  414. border-radius: 50%;
  415. position: absolute;
  416. bottom: 10%;
  417. left: 50%;
  418. transform: translate(-50%, -50%);
  419. }
  420. .sign {
  421. background-color: #0089fe;
  422. }
  423. .repair {
  424. background-color: #f4a01a;
  425. }
  426. .Put-box1 {
  427. .btn {
  428. text-align: center;
  429. margin-top: 40rpx;
  430. border: 2rpx solid #333333;
  431. height: 80upx;
  432. line-height: 80upx;
  433. width: 240upx;
  434. color: #333333;
  435. }
  436. .submit {
  437. background-color: #333333;
  438. color: #FFEBC4;
  439. }
  440. }
  441. </style>