calendar.vue 7.3 KB

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