WeekCalendar.vue 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260
  1. <template>
  2. <div class="log-list">
  3. <div class="title">
  4. <div class="show-month">{{ moment(thisMonth).format('YYYY 年 M 月') }}</div>
  5. </div>
  6. <div class="content" v-loading="isLoading">
  7. <div
  8. v-for="(item, index) in thisMonthLogs"
  9. :key="item.week"
  10. class="week-item"
  11. :style="{
  12. backgroundColor: item.bgColor,
  13. border: item.endDate == checkItem ? `1.5px solid ${item.color}` : 'none'
  14. }"
  15. @click="goToWeeklyPage(item)"
  16. >
  17. <div class="left">
  18. <div class="week-title">{{ weekTitleList[index] }}</div>
  19. <div class="week-date">{{
  20. `${moment(item.startDate).format('M月D日')} ~ ${moment(item.endDate).format('M月D日')}`
  21. }}</div>
  22. </div>
  23. <div class="right">
  24. <div class="icon-box" :style="{ backgroundColor: item.color }">
  25. <el-icon>
  26. <Check v-if="item.icon == 'Check'" />
  27. <Close v-if="item.icon == 'Close'" />
  28. <EditPen v-if="item.icon == 'EditPen'" />
  29. <More v-if="item.icon == 'More'" />
  30. </el-icon>
  31. </div>
  32. <span>{{ item.type }}</span>
  33. </div>
  34. </div>
  35. </div>
  36. </div>
  37. </template>
  38. <script lang="ts" setup>
  39. /**
  40. * @description 首页周报列表
  41. * 先获取到最近三个月的工作日列表详情,对工作日进行周数划分
  42. * 再获取近三个月的周报列表,对周报填报情况进行判断
  43. */
  44. import moment from 'moment'
  45. import { service, http } from './service'
  46. interface IProp {
  47. detailTime: any[]
  48. userId: string
  49. onChange: any
  50. }
  51. const { detailTime, userId, onChange } = defineProps<IProp>()
  52. const isLoading = ref<boolean>(false)
  53. // 所有的周日报和周划分
  54. // const allWorkDayListAndLogs = ref<any>([])
  55. // 本月日期
  56. const thisMonth = ref<any>(moment(detailTime[1]))
  57. // 本月的周日报和周划分
  58. const thisMonthLogs = ref<any>([])
  59. // 获取工作日列表
  60. onMounted(async () => {
  61. await initPageList()
  62. // 初始化的时候进行一些选择
  63. let nowLog: any = thisMonthLogs.value[0]
  64. if (detailTime[0] != detailTime[1]) {
  65. nowLog =
  66. thisMonthLogs.value.find(
  67. (item: any) => item.startDate == detailTime[0] && item.endDate == detailTime[1]
  68. ) ?? thisMonthLogs.value[0]
  69. } else {
  70. nowLog =
  71. thisMonthLogs.value.find((item: any) => moment().isBetween(item.startDate, item.endDate)) ??
  72. thisMonthLogs.value[0]
  73. }
  74. goToWeeklyPage(nowLog)
  75. })
  76. const message = useMessage()
  77. // 获取当月工作日列表详情
  78. const workDayList = async () => {
  79. const detailTime = [
  80. thisMonth.value.startOf('month').format('YYYY-MM-DD HH:mm:ss'),
  81. thisMonth.value.endOf('month').format('YYYY-MM-DD HH:mm:ss')
  82. ]
  83. const workDays = await http.getWorkDayList(detailTime[0], detailTime[1])
  84. const workDayObj = service.setWorkDayListToWeek(workDays)
  85. return workDayObj
  86. }
  87. // 合并工作日和周报列表并初始化页面
  88. const initPageList = async () => {
  89. isLoading.value = true
  90. const workObj = await workDayList()
  91. const logList = await http.getMonthLogList(thisMonth.value, userId)
  92. const allWorkDayListAndLogs = service.mergeWorkDayAndLogs(workObj, logList)
  93. const pointer = moment(thisMonth.value).format('YYYY-M')
  94. const thisMonthLog = allWorkDayListAndLogs[pointer].map((item: any) => {
  95. // 默认未填
  96. item.type = statusObj[1].type
  97. item.icon = statusObj[1].icon
  98. item.color = statusObj[1].color
  99. item.bgColor = statusObj[1].bgColor
  100. // 如果本周
  101. const startOfWeek = moment().startOf('week')
  102. const endOfWeek = moment().endOf('week').add(1, 'day')
  103. if (moment(item.startDate).isBetween(startOfWeek, endOfWeek)) {
  104. item.icon = statusObj[2].icon
  105. item.color = statusObj[2].color
  106. item.bgColor = statusObj[2].bgColor
  107. item.type = statusObj[2].type
  108. }
  109. // 如果已填,且不是暂存
  110. if (item.isLog.length > 0 && !item.isLog[0].isTemp) {
  111. const isLog = item.isLog[0]
  112. item.id = isLog.id
  113. item.icon = statusObj[0].icon
  114. item.color = statusObj[0].color
  115. item.bgColor = statusObj[0].bgColor
  116. item.type = statusObj[0].type
  117. }
  118. // 如果已填但是是暂存
  119. if (item.isLog.length > 0 && item.isLog[0].isTemp) {
  120. // 啥也不做
  121. item.type = '暂存'
  122. }
  123. // 如果未到
  124. if (moment(item.startDate).isAfter(moment())) {
  125. item.icon = statusObj[3].icon
  126. item.color = statusObj[3].color
  127. item.bgColor = statusObj[3].bgColor
  128. item.type = statusObj[3].type
  129. }
  130. return item
  131. })
  132. isLoading.value = false
  133. thisMonthLogs.value = thisMonthLog
  134. const nowLog = thisMonthLog.find((item: any) =>
  135. moment(checkItem.value).isBetween(
  136. item.startDate,
  137. moment(item.endDate).add(1, 'day'),
  138. item.endDate
  139. )
  140. )
  141. if (nowLog) {
  142. itemOnChange(nowLog)
  143. }
  144. }
  145. // 颜色列表
  146. const weekTitleList = ['第一周', '第二周', '第三周', '第四周', '第五周']
  147. const statusObj = [
  148. { type: '已填', icon: 'Check', color: '#0ACE9D', bgColor: '#EAF8F4' },
  149. { type: '未填', icon: 'Close', color: '#F85638', bgColor: '#F8EAEA' },
  150. { type: '待填', icon: 'EditPen', color: '#1B80EB', bgColor: '#DDEDFD' },
  151. { type: '未到', icon: 'More', color: '#BDC7CE', bgColor: '#F2F6FA' }
  152. ]
  153. // 跳转到周报填写或详情页面
  154. // const { push } = useRouter()
  155. const checkItem = ref(moment())
  156. const goToWeeklyPage = (item: any) => {
  157. if (item.type == '未到') {
  158. message.info('还未到这周!')
  159. return
  160. }
  161. // 修改点击的item
  162. checkItem.value = item.endDate
  163. itemOnChange(item)
  164. }
  165. const itemOnChange = (item: any) => {
  166. const logDetail = item.isLog[0] ?? {}
  167. const changeData: any = {
  168. ...logDetail,
  169. reportStartDate: item.startDate,
  170. reportEndDate: item.endDate,
  171. weekDate: [item.startDate, item.endDate],
  172. isLog: logDetail,
  173. userId
  174. }
  175. onChange(changeData)
  176. }
  177. </script>
  178. <style scoped lang="scss">
  179. .log-list {
  180. padding: 10px 10px;
  181. height: calc(100% - 100px);
  182. .title {
  183. display: flex;
  184. .check-btn {
  185. font-size: 18px;
  186. font-weight: bold;
  187. color: #626b70;
  188. cursor: pointer;
  189. }
  190. .show-month {
  191. margin: 0 10px;
  192. font-weight: bold;
  193. font-size: 16px;
  194. color: #2d333c;
  195. }
  196. }
  197. .content {
  198. margin-top: 20px;
  199. height: 100%;
  200. overflow-y: scroll;
  201. .week-item {
  202. height: 90px;
  203. margin-bottom: 15px;
  204. border-radius: 4px 4px 4px 4px;
  205. display: flex;
  206. justify-content: space-between;
  207. align-items: center;
  208. padding: 10px 20px;
  209. cursor: pointer;
  210. .week-title {
  211. font-weight: bold;
  212. font-size: 17px;
  213. color: #121518;
  214. }
  215. .week-date {
  216. font-weight: 400;
  217. font-size: 16px;
  218. color: #2b333c;
  219. margin-top: 8px;
  220. }
  221. .right {
  222. display: flex;
  223. height: 50px;
  224. justify-content: space-between;
  225. align-items: center;
  226. padding-right: 5px;
  227. }
  228. .icon-box {
  229. width: 20px;
  230. height: 20px;
  231. border-radius: 50%;
  232. line-height: 20px;
  233. text-align: center;
  234. font-size: 12px;
  235. margin: 0 10px;
  236. color: #fff;
  237. }
  238. }
  239. }
  240. ::-webkit-scrollbar {
  241. width: 0 !important;
  242. }
  243. }
  244. </style>