usersign.vue 13 KB

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