usersign.vue 13 KB

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