calendar.vue 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  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(2010, 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. day.bottomInfo = this.statusTxt[r.state];
  61. day.className = this.statusStyle[r.state];
  62. }
  63. })
  64. return day;
  65. },
  66. // 返回
  67. back() {
  68. history.back();
  69. },
  70. // 时间转换
  71. format(date, pattern) {
  72. pattern = pattern || "yyyy-MM-dd";
  73. var _this = this;
  74. return pattern.replace(/([yMdhsm])(\1*)/g, function ($0) {
  75. switch ($0.charAt(0)) {
  76. case 'y': return _this.padding(date.getFullYear(), $0.length);
  77. case 'M': return _this.padding(date.getMonth() + 1, $0.length);
  78. case 'd': return _this.padding(date.getDate(), $0.length);
  79. case 'w': return date.getDay() + 1;
  80. case 'h': return _this.padding(date.getHours(), $0.length);
  81. case 'm': return _this.padding(date.getMinutes(), $0.length);
  82. case 's': return _this.padding(date.getSeconds(), $0.length);
  83. }
  84. });
  85. },
  86. padding(s, len) {
  87. var len = len - (s + '').length;
  88. for (var i = 0; i < len; i++) { s = '0' + s; }
  89. return s;
  90. },
  91. // 改变时间
  92. changeTime(time) {
  93. this.nowTime = this.format(new Date(time),"yyyy-MM-dd");
  94. this.currentDate = time;
  95. this.showPicker = false;
  96. this.getReport();
  97. },
  98. // 获取日报
  99. getReport() {
  100. this.hasWaiting = false;
  101. const toast = this.$toast.loading({
  102. forbidClick: true,
  103. duration: 0
  104. });
  105. this.$axios.post("/report/getReportFillStatus", {startDate: this.format(this.minDate), endDate:this.format(this.maxDate), userId: this.user.id})
  106. .then(res => {
  107. if(res.code == "ok") {
  108. toast.clear();
  109. this.report = res.data;
  110. } else {
  111. toast.clear();
  112. this.$toast.fail('获取失败');
  113. }
  114. }).catch(err=> {toast.clear();});
  115. },
  116. },
  117. mounted() {
  118. this.getReport();
  119. }
  120. };
  121. </script>
  122. <style lang="less" scoped>
  123. // 日历备注
  124. .van-calendar__top-info {
  125. background: linear-gradient(86deg, rgba(212, 165, 116, 0.98), rgba(238, 202, 163, 0.98));
  126. }
  127. .login_form {
  128. margin-top: 46px;
  129. }
  130. .one_report {
  131. margin-bottom: 15px;
  132. font-size:14px;
  133. }
  134. .form_text {
  135. margin: 15px 0 15px;
  136. padding: 0 12px;
  137. }
  138. .form_btn {
  139. text-align: right;
  140. }
  141. .form_btn button {
  142. margin-left: 10px;
  143. }
  144. .one_report_data {
  145. margin-bottom: 10px;
  146. padding: 0 22px;
  147. div {
  148. line-height: 30px;
  149. }
  150. }
  151. </style>
  152. <style >
  153. .waiting {
  154. color:orange;
  155. }
  156. .filledReportStyle {
  157. color:#32CD32;
  158. }
  159. .RejectStyle {
  160. color:red;
  161. }
  162. .van-calendar__bottom-info {
  163. -webkit-transform: scale(0.8);
  164. }
  165. </style>
  166. <style lang="less">
  167. .van-nav-bar .van-icon , .van-nav-bar__text {
  168. color: #20a0ff;
  169. }
  170. .button {
  171. float: right;
  172. width: 50px;
  173. height: 25px;
  174. line-height: 25px;
  175. text-align: center;
  176. border: 1px solid red;
  177. color: red;
  178. box-sizing: border-box;
  179. border-radius: 10px;
  180. font-size: 14px;
  181. display: flex;
  182. justify-content: center;
  183. align-items: center;
  184. }
  185. </style>