jjgzzhys.vue 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  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: 55px">
  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: 20px;">
  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. import { useUserStore } from '@/pinia/modules/user'
  41. const userStore = useUserStore()
  42. const _username = ref('')
  43. _username.value = userStore.userInfo.userName + '/' + userStore.userInfo.nickName
  44. const form = reactive({})
  45. const visible = ref(true)
  46. const jjgzzhysformData = reactive({
  47. date: '',
  48. start_date: '',
  49. end_date: '',
  50. vacation_one_start: '',
  51. vacation_one_end: '',
  52. vacation_two_start: '',
  53. vacation_two_end: '',
  54. });
  55. //=============页面默认加载获取=========
  56. // 获取当前日期
  57. const currentDate = new Date();
  58. // 获取当前年份和月份
  59. const year = currentDate.getFullYear();
  60. const month = currentDate.getMonth() + 1;
  61. // 如果月份小于 10,补零
  62. const formattedMonth = month < 10 ? '0' + month : month;
  63. // 组合年月
  64. jjgzzhysformData.date = year.toString() + formattedMonth.toString();
  65. // 封装日期格式化和处理月份范围的逻辑为一个函数
  66. const formatAndSetDates = (yearMonth) => {
  67. // 提取年份和月份
  68. const yearPart = yearMonth.slice(0, 4);
  69. const monthPart = yearMonth.slice(4);
  70. // 构建开始日期和结束日期的字符串
  71. const startDateString = `${yearPart}-${monthPart}-01`;
  72. const endDateString = `${yearPart}-${monthPart}-${new Date(yearPart, monthPart, 0).getDate()}`;
  73. // 设置开始日期和结束日期
  74. jjgzzhysformData.start_date = startDateString;
  75. jjgzzhysformData.end_date = endDateString;
  76. };
  77. // 初始化时调用一次
  78. formatAndSetDates(jjgzzhysformData.date);
  79. // 考勤年月回车时调用
  80. const jgzzhysProductValue = () => {
  81. formatAndSetDates(jjgzzhysformData.date);
  82. };
  83. //考勤年月按钮 继续
  84. const kqny = ref('')
  85. const jjgzzhysclick = async () => {
  86. var date = jjgzzhysformData.date;//202403
  87. var year = date.slice(0, 4);//2024
  88. var month = date.slice(4);//03
  89. if (month < 1 || month > 12) {
  90. ElMessage({type: 'warning',message: '月份必须在1到12月之间'})
  91. return false;
  92. } else {
  93. if (month.length === 1) {
  94. month = '0' + month;
  95. }
  96. kqny.value = year+month;
  97. }
  98. function formatDate(dateString) {
  99. if (dateString === null || dateString === '') {
  100. return '';
  101. }
  102. const formattedDate = new Date(dateString);
  103. const year = formattedDate.getFullYear();
  104. const month = String(formattedDate.getMonth() + 1).padStart(2, '0');
  105. const day = String(formattedDate.getDate()).padStart(2, '0');
  106. return `${year}-${month}-${day}`;
  107. }
  108. var dateMonth = kqny.value.slice(-2);//获取date后两位月份
  109. //开始日期结束日期
  110. if (formatDate(jjgzzhysformData.start_date).slice(5, 7) !== dateMonth && formatDate(jjgzzhysformData.end_date).slice(5, 7) !== dateMonth) {
  111. ElMessage({type: 'warning',message: '考勤月份和开始日期和结束日期的月份不一致'})
  112. return false;
  113. }
  114. //法定假日1开始日期结束日期
  115. if (jjgzzhysformData.vacation_one_start && formatDate(jjgzzhysformData.vacation_one_start).slice(5, 7) !== dateMonth && jjgzzhysformData.vacation_one_end && formatDate(jjgzzhysformData.vacation_one_end).slice(5, 7) !== dateMonth) {
  116. ElMessage({ type: 'warning', message: '考勤月份和法定假日1的月份不一致' });
  117. return false;
  118. }
  119. //法定假日2开始日期结束日期
  120. if (jjgzzhysformData.vacation_two_start && formatDate(jjgzzhysformData.vacation_two_start).slice(5, 7) !== dateMonth && jjgzzhysformData.vacation_two_end && formatDate(jjgzzhysformData.vacation_two_end).slice(5, 7) !== dateMonth) {
  121. ElMessage({ type: 'warning', message: '考勤月份和开法定假日2的月份不一致' });
  122. return false;
  123. }
  124. //返回接口数据
  125. const formattedData = {
  126. sys_id: _username.value,
  127. date: kqny.value,
  128. start_date: formatDate(jjgzzhysformData.start_date),
  129. end_date: formatDate(jjgzzhysformData.end_date),
  130. days: '',
  131. vacation_one_start: formatDate(jjgzzhysformData.vacation_one_start),
  132. vacation_one_end: formatDate(jjgzzhysformData.vacation_one_end),
  133. vacation_two_start: formatDate(jjgzzhysformData.vacation_two_start),
  134. vacation_two_end: formatDate(jjgzzhysformData.vacation_two_end)
  135. };
  136. console.log(formattedData);
  137. const staffSalaryCount_add = await staffSalaryCount(formattedData);//调用接口
  138. console.log(staffSalaryCount_add)
  139. // if (staffSalaryCount_add.code === 0) {
  140. // ElMessage({type: 'success',message: msg})
  141. // }else{
  142. // ElMessage({type: 'error',message: '更新失败'})
  143. // }
  144. };
  145. </script>
  146. <style scoped>
  147. :deep(.el-table td .cell) {
  148. line-height: 20px !important;
  149. }
  150. :deep(.el-tabs__header){
  151. margin-bottom: 0;
  152. }
  153. .search{
  154. margin-left: 0px !important;
  155. margin-right: 10px !important;
  156. }
  157. .bt{
  158. margin-left: 2px !important;
  159. padding: 3px !important;
  160. font-size: 12px;
  161. }
  162. .el-tabs__header{
  163. margin: 0px !important;
  164. }
  165. .gva-table-box{
  166. padding: 0px !important;
  167. }
  168. .el-pagination{
  169. margin-top: 0px !important;
  170. }
  171. .mab{
  172. margin-bottom: 5px;
  173. }
  174. </style>