usersign.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465
  1. <template>
  2. <div>
  3. <cu-custom bgColor="bg-gradual-pink" :isBack="true">
  4. <block slot="backText">返回</block>
  5. <block slot="content">考勤查询</block>
  6. </cu-custom>
  7. <div id='calendar'>
  8. <!-- 年份 月份 -->
  9. <div class='month'>
  10. <ul>
  11. <!--点击会触发pickpre函数,重新刷新当前日期 @click(vue v-on:click缩写) -->
  12. <li class='arrow' @click='pickPre(currentYear,currentMonth)'>上个月</li>
  13. <li class='year-month'>
  14. <span class='choose-year'>{{ currentYear }}年</span>
  15. <span class='choose-month'>{{ currentMonth }}月</span>
  16. </li>
  17. <li class='arrow' @click='pickNext(currentYear,currentMonth)'>下个月</li>
  18. </ul>
  19. <br>
  20. </div>
  21. <hr>
  22. <!-- 星期 -->
  23. <ul class='weekdays'>
  24. <li>日</li>
  25. <li>一</li>
  26. <li>二</li>
  27. <li>三</li>
  28. <li>四</li>
  29. <li>五</li>
  30. <li>六</li>
  31. </ul>
  32. <!-- 日期 -->
  33. <ul class='days'>
  34. <!-- 核心 v-for循环 每一次循环用<li>标签创建一天 -->
  35. <li v-for='(dayobject,i) in days' :key='i'>
  36. <!--本月-->
  37. <!--如果不是本月 改变类名加灰色-->
  38. <span v-if='dayobject.day.getMonth()+1 != currentMonth' class='other-month'>{{ dayobject.day.getDate() }}</span>
  39. <!--如果是本月 还需要判断是不是这一天-->
  40. <span v-else>
  41. <!--今天 同年同月同日-->
  42. <!-- <span v-for='(s,i) in rows' v-if='s=='></span> -->
  43. <span v-if='dayobject.day.getFullYear() == new Date().getFullYear() && dayobject.day.getMonth() == new Date().getMonth() && dayobject.day.getDate() == new Date().getDate()'
  44. class='active' @click="getDayTime(dayobject.day)">今
  45. </span>
  46. <span v-else @click="getDayTime(dayobject.day)">
  47. <span class="act" >{{ dayobject.day.getDate() }}</span>
  48. <div style="margin-top: -10px;" v-if='SetDays!=[] &&SetDays.length>0 &&SetDays!=undefined ' v-for='(dayobj,i) in SetDays'>
  49. <strong v-if='dayobj.iss == dayobject.day.getDate() && dayobj.is=="2" &&dayobject.day<=ToDay' style="color: #4E6FE2;font-size: 20px;">.</strong>
  50. <strong v-if='dayobj.iss == dayobject.day.getDate() && dayobj.is=="1" &&dayobject.day<=ToDay' style="color: red;font-size: 20px;">.</strong>
  51. </div>
  52. <!-- <div style="margin-top: -10px;" v-if='SetDays==[] ||SetDays.length<1'>
  53. <strong style="color: red;font-size: 20px;">.</strong>
  54. </div> -->
  55. </span>
  56. </span>
  57. </li>
  58. </ul>
  59. <div class='ts' v-if='count=="2"'>
  60. <span style="width: 10px;height: 30px;background-color: #96A8F3;border-radius:2px 0 0 2px;">
  61. </span>
  62. <span style="display: flex; width: 250px; height: 30px; align-items: center;background-color: #F1F3F6;">
  63. <span style="flex: 1; display: flex; justify-content: center;"> <strong>{{SetMdays}}考勤正常 </strong></span>
  64. </span>
  65. </div>
  66. <div class='ts' v-if='count=="1"'>
  67. <span style="width: 10px;height: 30px;background-color: #DA402B;border-radius:2px 0 0 2px;">
  68. </span>
  69. <span style="display: flex; width: 250px; height: 30px; align-items: center;background-color: #F1F3F6;">
  70. <span style="flex: 1; display: flex; justify-content: center;"> <strong>{{SetMdays}}考勤异常 </strong></span>
  71. </span>
  72. </div>
  73. <div style="background: #ffffff;padding: 20px;">
  74. <span style="color: #9599A5;font-size: 15px;">
  75. 打卡记录: <span v-if='SetData.length<1'>无</span>
  76. <ul class="steps">
  77. <li v-for="(item,index) in SetData" :key="item+index" :class="{'active':Steps===index}" >
  78. {{item.userDate}} <span style="margin-left: 20px;">{{item.checkinType}}</span>
  79. <span style="margin-left: 20px;">{{item.exceptionType}}</span>
  80. </li>
  81. </ul>
  82. </span>
  83. </div>
  84. <div class='ts'>
  85. <span style="height: 2px;width: 100%;background-color: #B4C3E0;"></span>
  86. <br>
  87. <span style="color: #9599A5;font-size: 15px;">
  88. 请假/外出记录:<span v-if='Setdds==""&&Setdds==null'>无</span>
  89. <br>
  90. <br>
  91. <span v-if='Setdds!=""&&Setdds!=null'>
  92. {{Setdds.holidayType}}&nbsp;&nbsp;({{Setdds.holidayCount}}小时)&nbsp;&nbsp;开始时间&nbsp;{{Setdds.startDates}}&nbsp;至&nbsp;{{Setdds.endDates}}
  93. </span>
  94. <span v-if='work!=""&&work!=null'>
  95. 加班&nbsp;&nbsp;({{work.duration}}小时)&nbsp;&nbsp;开始时间&nbsp;{{work.begin_date}}&nbsp;至&nbsp;{{work.end_date}}
  96. </span>
  97. </span>
  98. </div>
  99. </div>
  100. </div>
  101. </template>
  102. <script>
  103. export default {
  104. data() {
  105. return {
  106. userUrl:'/attendance/attendance/list2',
  107. currentDay: 1,
  108. currentMonth: 1,
  109. currentYear: 1970,
  110. currentWeek: 1,
  111. days: [],
  112. rows: ["2021-1-8"],
  113. SetData:[],
  114. SetDays:[],
  115. SetBeginDay:null,
  116. SetEndDay:null,
  117. SetMdays:null,
  118. Setdds:null,
  119. count:'',
  120. ToDay:new Date(),
  121. state:'',
  122. work:{}
  123. }
  124. },
  125. created: function() {
  126. // 在vue初始化时调用
  127. var da=null;
  128. var date=null;
  129. this.state=uni.getStorageSync('status');
  130. if(this.state==2||this.state=="2"){
  131. da=uni.getStorageSync('date');
  132. date=this.formatDate(this.currentYear,this.currentMonth,1);
  133. }
  134. this.initData(da)
  135. this.querys(da)
  136. },
  137. methods: {
  138. initData: function(cur) {
  139. // var leftcount = 0 // 存放剩余数量
  140. var date
  141. if (cur) {
  142. date = new Date(cur)
  143. } else {
  144. var now = new Date()
  145. var d = new Date(this.formatDate(now.getFullYear(), now.getMonth(), 1))
  146. d.setDate(35)
  147. date = new Date(this.formatDate(d.getFullYear(), d.getMonth() + 1, 1))
  148. }
  149. this.currentDay = date.getDate()
  150. this.currentYear = date.getFullYear()
  151. this.currentMonth = date.getMonth() + 1
  152. this.currentWeek = date.getDay() // 1...6,0
  153. if (this.currentWeek === 0) {
  154. this.currentWeek = 7
  155. }
  156. var str = this.formatDate(
  157. this.currentYear,
  158. this.currentMonth,
  159. this.currentDay
  160. )
  161. this.days.length = 0
  162. // 今天是周日,放在第一行第7个位置,前面6个
  163. // 初始化本周
  164. for (var i = this.currentWeek; i >= 0; i--) {
  165. var d2 = new Date(str)
  166. d2.setDate(d2.getDate() - i)
  167. var dayobjectSelf = {} // 用一个对象包装Date对象 以便为以后预定功能添加属性
  168. dayobjectSelf.day = d2
  169. this.days.push(dayobjectSelf) // 将日期放入data 中的days数组 供页面渲染使用
  170. }
  171. // 其他周
  172. for (var j = 1; j <= 37 - this.currentWeek; j++) {
  173. var d3 = new Date(str)
  174. d3.setDate(d3.getDate() + j)
  175. var dayobjectOther = {}
  176. dayobjectOther.day = d3
  177. this.days.push(dayobjectOther)
  178. }
  179. var s=this.days
  180. console.log(s)
  181. },
  182. getDayTime(el) {
  183. var date=new Date()
  184. var date2 =new Date(el)
  185. if(date2<=date){
  186. this.querys(el);
  187. }
  188. },
  189. querys:function(s){
  190. var userid=this.$store.getters.userid;
  191. if(s!=null &&s!=""){
  192. var date=this.formats(s);
  193. }else{
  194. var t=new Date()
  195. var date=this.formats(t);
  196. }
  197. this.SetMdays=this.formatt(date);
  198. var ts=this.state;
  199. if(this.state==2||this.state=="2"){
  200. //userid=this.$store.getters.id;
  201. userid=uni.getStorageSync('id');
  202. }
  203. console.log(this.state)
  204. this.$http.get(this.userUrl,{params:{userid:userid,date:date}}).then(res=>{
  205. this.SetData=res.data.date;
  206. if(res.data.day.length>0&&res.data.day!=[]&&res.data.day!=undefined){
  207. this.SetDays=res.data.day;
  208. }
  209. if(res.data.data!=null){
  210. this.Setdds=res.data.data;
  211. }if(res.data.data==null){
  212. this.Setdds="";
  213. }
  214. this.count=res.data.count;
  215. this.work=res.data.work;
  216. console.log(res)
  217. }).catch(err => {
  218. console.log(err);
  219. });
  220. },
  221. formats:function(e){
  222. var date = new Date(e);
  223. var seperator1 = "-";
  224. var year = date.getFullYear();
  225. var month = date.getMonth() + 1;
  226. var strDate = date.getDate();
  227. if (month >= 1 && month <= 9) {
  228. month = "0" + month;
  229. }
  230. if (strDate >= 0 && strDate <= 9) {
  231. strDate = "0" + strDate;
  232. }
  233. var currentdate = year + seperator1 + month + seperator1 + strDate;
  234. return currentdate;
  235. },
  236. formatt:function(e){
  237. var date = new Date(e);
  238. var seperator1 = "月";
  239. var day="日";
  240. var month = date.getMonth() + 1;
  241. var strDate = date.getDate();
  242. var currentdate = month + seperator1 + strDate+day;
  243. return currentdate;
  244. },
  245. pickPre: function(year, month) {
  246. // setDate(0); 上月最后一天
  247. // setDate(-1); 上月倒数第二天
  248. // setDate(dx) 参数dx为 上月最后一天的前后dx天
  249. var d = new Date(this.formatDate(year, month, 1))
  250. d.setDate(0)
  251. this.initData(this.formatDate(d.getFullYear(), d.getMonth() + 1, 1))
  252. this.querys(d);
  253. },
  254. pickNext: function(year, month) {
  255. var d = new Date(this.formatDate(year, month+1, 1))
  256. var ds=this.formatDate(year, month, 0);
  257. var nowDate = new Date();
  258. var dt=this.formatDate(nowDate.getFullYear(),nowDate.getMonth(),0);
  259. var ts=nowDate.getDate();
  260. if(ds<=dt){
  261. //d.setDate(35)
  262. this.initData(this.formatDate(d.getFullYear(), d.getMonth() + 1, 1))
  263. this.querys(d);
  264. }
  265. },
  266. // 返回 类似 2016-01-02 格式的字符串
  267. formatDate: function(year, month, day) {
  268. var y = year
  269. if(month>12){
  270. month=1;
  271. y=year+1;
  272. }
  273. var m = month
  274. if (m < 10) m = '0' + m
  275. var d = day
  276. if (d < 10) d = '0' + d
  277. return y + '-' + m + '-' + d
  278. },
  279. ret(){
  280. this.$Router.push({name:'index'})
  281. }
  282. }
  283. }
  284. </script>
  285. <style>
  286. .steps {
  287. counter-reset: step; /*创建步骤数字计数器*/
  288. width: 360px;
  289. margin: 0 auto;
  290. margin-left: -30px;
  291. margin-top: 10px;
  292. }
  293. /*步骤描述*/
  294. .steps li {
  295. position: relative;
  296. padding: 0 20px 20px;
  297. list-style: none;
  298. line-height: 22px;
  299. border-left: 2px solid #ccc;
  300. }
  301. /*步骤数字*/
  302. .steps li:before {
  303. content: counter(step); /*设定计数器内容*/
  304. counter-increment: step; /*计数器值递增*/
  305. display: block;
  306. position: absolute;
  307. margin-left: -6px;
  308. top: 0;
  309. left: -5px;
  310. width: 22px;
  311. height: 22px;
  312. line-height: 23px;
  313. text-align: center;
  314. background: #B4C3E0;
  315. color: #EDF1F7;
  316. font-size: 14px;
  317. border-radius: 50%;
  318. }
  319. li {
  320. list-style-type: none;
  321. }
  322. #calendar {
  323. font-size: 12px;
  324. width: 100%;
  325. margin: 0 auto;
  326. box-shadow: 0 2px 2px 0 rgba(0, 0, 0, 0.14), 0 3px 1px -2px rgba(0, 0, 0, 0.1),
  327. 0 1px 5px 0 rgba(0, 0, 0, 0.12);
  328. }
  329. .month {
  330. width: 100%;
  331. color: #333333;
  332. background: #ffffff;
  333. }
  334. .month ul {
  335. margin: 0;
  336. padding: 0;
  337. display: flex;
  338. justify-content: space-between;
  339. height: 35px;
  340. }
  341. .year-month {
  342. display: flex;
  343. align-items: center;
  344. justify-content: space-around;
  345. margin-top: 10px;
  346. }
  347. .choose-month {
  348. text-align: center;
  349. font-size: 12px;
  350. }
  351. .arrow {
  352. padding: 15px;
  353. color: #999999;
  354. }
  355. .month ul li {
  356. font-size: 12px;
  357. text-transform: uppercase;
  358. letter-spacing: 3px;
  359. }
  360. .weekdays {
  361. margin: 0;
  362. padding: 10px;
  363. display: flex;
  364. flex-wrap: wrap;
  365. color: #999;
  366. justify-content: space-around;
  367. background: #ffffff;
  368. }
  369. .weekdays li {
  370. display: inline-block;
  371. width: 13.6%;
  372. text-align: center;
  373. }
  374. .days {
  375. padding: 10px;
  376. background: #ffffff;
  377. margin: 0;
  378. display: flex;
  379. flex-wrap: wrap;
  380. }
  381. .ts {
  382. padding: 20px;
  383. background: #ffffff;
  384. margin: 0;
  385. display: flex;
  386. flex-wrap: wrap;
  387. }
  388. .days li {
  389. list-style-type: none;
  390. display: inline-block;
  391. width: 14.2%;
  392. text-align: center;
  393. padding-bottom: 4px;
  394. padding-top: 5px;
  395. font-size: 13px;
  396. color: #000;
  397. height: 40px;
  398. }
  399. .days li .active {
  400. padding: 8px 10px;
  401. border-radius: 5%;
  402. background: #00b8ec;
  403. color: #fff;
  404. }
  405. .days li .other-month {
  406. padding: 5px;
  407. color: gainsboro;
  408. }
  409. .days li:hover .act{
  410. padding: 6px 10px;
  411. border-radius: 50%;
  412. background: #e1e1e1;
  413. color: #fff;
  414. }
  415. .top{
  416. background-color: #5677AC;
  417. width: 100%;
  418. height: 40px;
  419. }
  420. </style>