fa-signin.vue 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  1. <template>
  2. <view class="sign-wrap">
  3. <view class="date-wrap">
  4. <view class="cur-date u-flex u-row-between u-p-30">
  5. <view class="" @click="upDate"><u-icon name="arrow-left-double"></u-icon></view>
  6. <view class="">{{ year + '年' + (month + 1) + '月' }}</view>
  7. <view class="" @click="nextDate"><u-icon name="arrow-right-double"></u-icon></view>
  8. </view>
  9. <view class="title-item-box item-box">
  10. <view class="item" v-for="(item, index) in ['日', '一', '二', '三', '四', '五', '六']" :key="index">{{ item }}</view>
  11. </view>
  12. <view class="date-item-box item-box">
  13. <!-- -->
  14. <view class="item date-item" @tap="tapThis(item)" v-for="(item, index) in dateArray" :key="index">
  15. <text :style="[bgStyle(item)]" :class="{ isSign: item.isSign, active: item.isToday }" v-text="item.day"></text>
  16. </view>
  17. </view>
  18. </view>
  19. <u-modal v-model="show" title="确认是否补签?" :show-cancel-button="true" @confirm="confirm">
  20. <view class="u-p-30">
  21. <view class="">
  22. 确认进行补签日期:<text class="text-danger u-m-l-10 u-m-r-10">{{fill_date}}</text>?
  23. </view>
  24. <view class="u-m-t-10">
  25. 补签将消耗<text class="text-danger u-m-l-10 u-m-r-10">{{vuex_signin.fillupscore}}</text>积分
  26. </view>
  27. </view>
  28. </u-modal>
  29. </view>
  30. </template>
  31. <script>
  32. export default {
  33. name:'fa-signin',
  34. computed:{
  35. bgStyle(){
  36. return item=>{
  37. if(item.isToday && item.isSign){
  38. return {
  39. background:this.theme.bgColor,
  40. color: this.theme.color
  41. };
  42. }else{
  43. return {}
  44. }
  45. }
  46. }
  47. },
  48. data() {
  49. return {
  50. show:false,
  51. fill_date:'',
  52. itemStyle: {},
  53. dateArray: [],
  54. d_obj: null,
  55. year: '', //年(计算)
  56. month: '', //月(计算)
  57. today: '', //今天
  58. now_year: '', //年(当前)
  59. now_month: '', //月(当前)
  60. monthList: {}
  61. };
  62. },
  63. methods: {
  64. init: async function() {
  65. this.d_obj = new Date();
  66. this.year = this.now_year = this.d_obj.getFullYear();
  67. this.month = this.d_obj.getMonth();
  68. this.today = this.d_obj.getDate(); //今天
  69. this.now_month = this.month + 1;
  70. this.today = this.today < 10 ? `0${this.today}` : this.today.toString();
  71. this.monthList = await this.getmonthSign();
  72. this.getCurDate(this.year, this.month);
  73. },
  74. upDate: async function() {
  75. this.month--;
  76. if (this.month == -1) {
  77. this.month = 11;
  78. this.year--;
  79. }
  80. this.monthList = await this.getmonthSign();
  81. this.getCurDate(this.year, this.month);
  82. },
  83. nextDate: async function() {
  84. this.month++;
  85. if (this.month == 12) {
  86. this.month = 0;
  87. this.year++;
  88. }
  89. this.monthList = await this.getmonthSign();
  90. this.getCurDate(this.year, this.month);
  91. },
  92. //获取签到情况
  93. getmonthSign() {
  94. return new Promise((reject, resolve) => {
  95. this.$api.monthSign({ date: this.year + '-' + (this.month + 1) }).then(res => {
  96. if (res.code) {
  97. reject(res.data);
  98. } else {
  99. reject({});
  100. }
  101. });
  102. });
  103. },
  104. //渲染日历
  105. getCurDate(y, m) {
  106. let week = new Date(y, m, 1).getDay(); //一号是周几
  107. let max = new Date(y, m + 1, 0).getDate(); //本月最大天
  108. this.dateArray = [];
  109. // 1号之前留白,对应正确的周几
  110. for (let i = 0; i < week; i++) {
  111. let obj = {
  112. year: '',
  113. month: '',
  114. day: '',
  115. isSign: false,
  116. isToday: false
  117. };
  118. this.dateArray.push(obj);
  119. }
  120. m = m + 1; //月份格式化
  121. for (let i = 0; i < max; i++) {
  122. let day = i + 1;
  123. day = day < 10 ? `0${day}` : day.toString(); //日期格式化
  124. let obj = {
  125. year: y,
  126. month: m,
  127. day: day,
  128. isSign: this.monthList[day] != undefined,
  129. isToday: y == this.now_year && m == this.now_month && day == this.today
  130. };
  131. this.dateArray.push(obj);
  132. }
  133. },
  134. //点击日期
  135. tapThis(e) {
  136. if (!e.day) return;
  137. //今天已签到
  138. if (e.isToday && e.isSign) {
  139. this.$u.toast('今天已签到,请明天再来哦');
  140. return;
  141. }
  142. //今天未签,签到
  143. if(e.isToday && !e.isSign){
  144. this.$emit('dosign');
  145. return;
  146. }
  147. //可以补签
  148. let chaDay = this.dateminus(e);//大于0为过去日期,小于0为未来日期
  149. if (chaDay > 0 && chaDay < parseInt(this.vuex_signin.fillupdays) && !e.isSign) {
  150. this.fill_date = `${e.year}-${e.month}-${e.day}`;
  151. this.show = true;
  152. return;
  153. }
  154. this.$emit('dates', e);
  155. },
  156. //日期相减,
  157. dateminus(e) {
  158. return (new Date(`${this.now_year}-${this.now_month}-${this.today}`) - new Date(`${e.year}-${e.month}-${e.day}`)) / 1000 / 86400;
  159. },
  160. //确认补签
  161. confirm(){
  162. this.$emit('fillup',{fill_date:this.fill_date});
  163. }
  164. },
  165. mounted() {
  166. //设置日期
  167. this.init();
  168. }
  169. };
  170. </script>
  171. <style scoped lang="scss">
  172. .date-wrap {
  173. width: 100%;
  174. padding: 2% 0;
  175. border-radius: 16upx;
  176. background: #fff;
  177. box-sizing: border-box;
  178. text-align: center;
  179. box-shadow: 0px 0px 5px 0px rgba(0, 34, 144, 0.1);
  180. .cur-date {
  181. font-size: 30upx;
  182. }
  183. .item-box {
  184. display: flex;
  185. color: #777;
  186. flex-wrap: wrap;
  187. font-size: 28upx;
  188. justify-content: flex-start;
  189. .item {
  190. width: 14.28%;
  191. padding: 25rpx 0;
  192. text{
  193. padding: 5rpx 25rpx;
  194. border-radius: 100upx;
  195. }
  196. .isSign {
  197. background: #efefef;
  198. color: #999;
  199. }
  200. }
  201. }
  202. }
  203. .text-danger {
  204. color: #e74c3c;
  205. }
  206. </style>