calendar.vue 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  1. <template>
  2. <div>
  3. <van-nav-bar title="查看日报" left-text="返回" @click-left="back" fixed left-arrow/>
  4. <div class="login_form">
  5. <van-calendar
  6. :show-title="false"
  7. :poppable="false"
  8. :min-date="minDate"
  9. :show-confirm="false"
  10. :formatter="formatter"
  11. :style="{ height: tableHeight+'px' }"
  12. :className="'van-calendar__top-info'"
  13. @select="selectDate"
  14. />
  15. </div>
  16. </div>
  17. </template>
  18. <script>
  19. export default {
  20. data() {
  21. return {
  22. hasWaiting: false,
  23. state: 0,
  24. user: JSON.parse(localStorage.userInfo),
  25. minDate: new Date(2020, 0, 1),
  26. maxDate: new Date(new Date().getFullYear(),new Date().getMonth()+1,new Date().getDate()),
  27. currentDate: new Date(),
  28. nowTime: this.format(new Date(new Date()),"yyyy-MM-dd"),
  29. showPicker: false,
  30. report: [],
  31. statusTxt:["待审核", "已通过", "已驳回", "待提交"],
  32. statusStyle:["waiting", "filledReportStyle", "RejectStyle", ""],
  33. tableHeight:0,
  34. };
  35. },
  36. created() {
  37. let height = window.innerHeight;
  38. this.tableHeight = height - 46;
  39. const that = this;
  40. window.onresize = function temp() {
  41. that.tableHeight = window.innerHeight - 46;
  42. };
  43. },
  44. methods: {
  45. selectDate(value) {
  46. console.log(this.format(value));
  47. sessionStorage.targetDate = this.format(value);
  48. this.$router.push('/view');
  49. },
  50. formatter(day) {
  51. const month = day.date.getMonth() + 1;
  52. const date = day.date.getDate();
  53. if (this.format(day.date) == this.nowTime) {
  54. day.text = "今天";
  55. }
  56. //找到那一天的数据状态
  57. let targetDate = this.format(day.date);
  58. this.report.forEach(r=>{
  59. if (r.createDate == targetDate) {
  60. if (r.missReport) {
  61. day.bottomInfo = '漏填';
  62. day.className = 'RejectStyle';
  63. } else {
  64. day.bottomInfo = this.statusTxt[r.state];
  65. day.className = this.statusStyle[r.state];
  66. }
  67. }
  68. })
  69. return day;
  70. },
  71. // 返回
  72. back() {
  73. history.back();
  74. },
  75. // 时间转换
  76. format(date, pattern) {
  77. pattern = pattern || "yyyy-MM-dd";
  78. var _this = this;
  79. return pattern.replace(/([yMdhsm])(\1*)/g, function ($0) {
  80. switch ($0.charAt(0)) {
  81. case 'y': return _this.padding(date.getFullYear(), $0.length);
  82. case 'M': return _this.padding(date.getMonth() + 1, $0.length);
  83. case 'd': return _this.padding(date.getDate(), $0.length);
  84. case 'w': return date.getDay() + 1;
  85. case 'h': return _this.padding(date.getHours(), $0.length);
  86. case 'm': return _this.padding(date.getMinutes(), $0.length);
  87. case 's': return _this.padding(date.getSeconds(), $0.length);
  88. }
  89. });
  90. },
  91. padding(s, len) {
  92. var len = len - (s + '').length;
  93. for (var i = 0; i < len; i++) { s = '0' + s; }
  94. return s;
  95. },
  96. // 改变时间
  97. changeTime(time) {
  98. this.nowTime = this.format(new Date(time),"yyyy-MM-dd");
  99. this.currentDate = time;
  100. this.showPicker = false;
  101. this.getReport();
  102. },
  103. // 获取日报
  104. getReport() {
  105. this.hasWaiting = false;
  106. const toast = this.$toast.loading({
  107. forbidClick: true,
  108. duration: 0
  109. });
  110. var startDate = new Date();
  111. startDate.setMonth(startDate.getMonth() -2);
  112. this.$axios.post("/report/getReportFillStatus", {startDate: this.format(startDate), endDate:this.format(this.maxDate), userId: this.user.id})
  113. .then(res => {
  114. if(res.code == "ok") {
  115. this.$toast.clear();
  116. this.report = res.data;
  117. } else {
  118. this.$toast.clear();
  119. this.$toast.fail('获取失败');
  120. }
  121. }).catch(err=> {this.$toast.clear();});
  122. },
  123. },
  124. mounted() {
  125. this.getReport();
  126. }
  127. };
  128. </script>
  129. <style lang="less" scoped>
  130. // 日历备注
  131. .van-calendar__top-info {
  132. background: linear-gradient(86deg, rgba(212, 165, 116, 0.98), rgba(238, 202, 163, 0.98));
  133. }
  134. .login_form {
  135. margin-top: 46px;
  136. }
  137. .one_report {
  138. margin-bottom: 15px;
  139. font-size:14px;
  140. }
  141. .form_text {
  142. margin: 15px 0 15px;
  143. padding: 0 12px;
  144. }
  145. .form_btn {
  146. text-align: right;
  147. }
  148. .form_btn button {
  149. margin-left: 10px;
  150. }
  151. .one_report_data {
  152. margin-bottom: 10px;
  153. padding: 0 22px;
  154. div {
  155. line-height: 30px;
  156. }
  157. }
  158. </style>
  159. <style >
  160. .waiting {
  161. color:orange;
  162. }
  163. .filledReportStyle {
  164. color:#32CD32;
  165. }
  166. .RejectStyle {
  167. color:red;
  168. }
  169. .van-calendar__bottom-info {
  170. -webkit-transform: scale(0.8);
  171. }
  172. </style>
  173. <style lang="less">
  174. .van-nav-bar .van-icon , .van-nav-bar__text {
  175. color: #20a0ff;
  176. }
  177. .button {
  178. float: right;
  179. width: 50px;
  180. height: 25px;
  181. line-height: 25px;
  182. text-align: center;
  183. border: 1px solid red;
  184. color: red;
  185. box-sizing: border-box;
  186. border-radius: 10px;
  187. font-size: 14px;
  188. display: flex;
  189. justify-content: center;
  190. align-items: center;
  191. }
  192. </style>