jjgzzhys.vue 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. <template>
  2. <div style="border: 1px black solid; width: 30%; height: 33%; position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%);">
  3. <div style="margin-top: 30px">
  4. <el-form-item label="考勤年月:" class="mab" prop="keyOrder" label-width="100">
  5. <el-input v-model="jjgzzhysformData.date" @keyup.enter="jgzzhysProductValue" style="width: 130px;"/>
  6. </el-form-item>
  7. <el-form-item label="从:" class="mab" prop="keyOrder" label-width="100">
  8. <el-date-picker v-model="jjgzzhysformData.start_date" type="date" placeholder="选择日期" style="width: 130px;">
  9. </el-date-picker>
  10. &nbsp;到:&nbsp;&nbsp;
  11. <el-date-picker v-model="jjgzzhysformData.end_date" type="date" placeholder="选择日期" style="width: 130px;">
  12. </el-date-picker>
  13. </el-form-item>
  14. <el-form-item label="法定假日1从:" class="mab" prop="keyOrder" label-width="100">
  15. <el-date-picker v-model="jjgzzhysformData.vacation_one_start" type="date" placeholder="选择日期" style="width: 130px;">
  16. </el-date-picker>
  17. &nbsp;&nbsp;~:&nbsp;&nbsp;
  18. <el-date-picker v-model="jjgzzhysformData.vacation_one_end" type="date" placeholder="选择日期" style="width: 130px;">
  19. </el-date-picker>
  20. </el-form-item>
  21. <el-form-item label="法定假日2从:" class="mab" prop="keyOrder" label-width="100">
  22. <el-date-picker v-model="jjgzzhysformData.vacation_two_start" type="date" placeholder="选择日期" style="width: 130px;">
  23. </el-date-picker>
  24. &nbsp;&nbsp;~:&nbsp;&nbsp;
  25. <el-date-picker v-model="jjgzzhysformData.vacation_two_end" type="date" placeholder="选择日期" style="width: 130px;">
  26. </el-date-picker>
  27. </el-form-item>
  28. <div class="dialog-footer" style="text-align: right; margin-top: auto; margin-right: 30px;">
  29. <el-button type="primary" @click="jjgzzhysclick">继 续</el-button>
  30. </div>
  31. </div>
  32. </div>
  33. </template>
  34. <script setup>
  35. import {ref, reactive} from 'vue'
  36. import {
  37. staffSalaryCount,
  38. } from '@/api/yunyin/yunying'
  39. import { ElMessage } from 'element-plus'
  40. const form = reactive({})
  41. const visible = ref(true)
  42. const jjgzzhysformData = reactive({
  43. date: '',
  44. start_date: null,
  45. end_date: null,
  46. vacation_one_start: null,
  47. vacation_one_end: null,
  48. vacation_two_start: null,
  49. vacation_two_end: null,
  50. });
  51. //=============页面默认加载获取=========
  52. // 获取当前日期
  53. const currentDate = new Date();
  54. // 获取当前年份和月份
  55. const year = currentDate.getFullYear();
  56. const month = currentDate.getMonth() + 1;
  57. // 如果月份小于 10,补零
  58. const formattedMonth = month < 10 ? '0' + month : month;
  59. // 组合年月
  60. jjgzzhysformData.date = year.toString() + formattedMonth.toString();
  61. // 封装日期格式化和处理月份范围的逻辑为一个函数
  62. const formatAndSetDates = (yearMonth) => {
  63. // 提取年份和月份
  64. const yearPart = yearMonth.slice(0, 4);
  65. const monthPart = yearMonth.slice(4);
  66. // 构建开始日期和结束日期的字符串
  67. const startDateString = `${yearPart}-${monthPart}-01`;
  68. const endDateString = `${yearPart}-${monthPart}-${new Date(yearPart, monthPart, 0).getDate()}`;
  69. // 设置开始日期和结束日期
  70. jjgzzhysformData.start_date = startDateString;
  71. jjgzzhysformData.end_date = endDateString;
  72. };
  73. // 初始化时调用一次
  74. formatAndSetDates(jjgzzhysformData.date);
  75. // 考勤年月回车时调用
  76. const jgzzhysProductValue = () => {
  77. formatAndSetDates(jjgzzhysformData.date);
  78. };
  79. //考勤年月按钮 继续
  80. const jjgzzhysclick = async () => {
  81. function formatDate(dateString) {
  82. const date = new Date(dateString);
  83. return date.getFullYear() + '-' +
  84. (date.getMonth() + 1).toString().padStart(2, '0') + '-' +
  85. date.getDate().toString().padStart(2, '0') + ' ';
  86. }
  87. const currentYear = new Date().getFullYear(); // 获取当前年份
  88. const isCurrentYearOrNull = (dateString) => {
  89. if (dateString === null) {
  90. return true; // 如果日期为null,也视为空
  91. }
  92. const year = parseInt(dateString.substring(0, 4)); // 提取日期的年份并转换为整数
  93. return year === currentYear || year === 1970; // 比较年份是否等于当前年份或者为1970
  94. };
  95. const start_date_formatted = isCurrentYearOrNull(jjgzzhysformData.start_date) ? formatDate(jjgzzhysformData.start_date) : "";
  96. const end_date_formatted = isCurrentYearOrNull(jjgzzhysformData.end_date) ? formatDate(jjgzzhysformData.end_date) : "";
  97. const vacation_one_start_formatted = isCurrentYearOrNull(jjgzzhysformData.vacation_one_start) ? formatDate(jjgzzhysformData.vacation_one_start) : "";
  98. const vacation_one_end_formatted = isCurrentYearOrNull(jjgzzhysformData.vacation_one_end) ? formatDate(jjgzzhysformData.vacation_one_end) : "";
  99. const vacation_two_start_formatted = isCurrentYearOrNull(jjgzzhysformData.vacation_two_start) ? formatDate(jjgzzhysformData.vacation_two_start) : "";
  100. const vacation_two_end_formatted = isCurrentYearOrNull(jjgzzhysformData.vacation_two_end) ? formatDate(jjgzzhysformData.vacation_two_end) : "";
  101. const formattedData = {
  102. start_date: start_date_formatted,
  103. end_date: end_date_formatted,
  104. vacation_one_start: vacation_one_start_formatted,
  105. vacation_one_end: vacation_one_end_formatted,
  106. vacation_two_start: vacation_two_start_formatted,
  107. vacation_two_end: vacation_two_end_formatted
  108. };
  109. console.log(formattedData)
  110. //目前没有接口,先不用调用
  111. // const staffSalaryCount_add = await staffSalaryCount(formattedData);
  112. // if (staffSalaryCount_add.code === 0) {
  113. // ElMessage({type: 'success',message: '更新成功'})
  114. // } else {
  115. // ElMessage({type: 'error',message: '更新失败'})
  116. // }
  117. };
  118. </script>
  119. <style scoped>
  120. :deep(.el-table td .cell) {
  121. line-height: 20px !important;
  122. }
  123. :deep(.el-tabs__header){
  124. margin-bottom: 0;
  125. }
  126. .search{
  127. margin-left: 0px !important;
  128. margin-right: 10px !important;
  129. }
  130. .bt{
  131. margin-left: 2px !important;
  132. padding: 3px !important;
  133. font-size: 12px;
  134. }
  135. .el-tabs__header{
  136. margin: 0px !important;
  137. }
  138. .gva-table-box{
  139. padding: 0px !important;
  140. }
  141. .el-pagination{
  142. margin-top: 0px !important;
  143. }
  144. .mab{
  145. margin-bottom: 5px;
  146. }
  147. </style>