123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424 |
- <template>
- <div class="WorkHoursSelect">
- <div class="select-title">
- <span>工作量分配</span>
- </div>
- <div class="select-list">
- <div class="title">
- <div class="left">
- {{ '工作项目' + (defaultTotalTime ? `(总耗时${defaultTotalTime}小时)` : '') }}
- </div>
- <div class="right">
- <el-input
- ref="searchInputRef"
- placeholder="搜索项目"
- v-model="searchValue"
- @input="searchOnchange"
- clearable
- />
- </div>
- </div>
- <ul class="list-ul">
- <li v-for="(item, index) in dataList" :key="index" @click="handleClick(item)">
- <div class="project-write">
- <el-popover
- ref="popperRef"
- popper-class="popover-panel"
- placement="top-end"
- :width="400"
- trigger="click"
- :visible="item.visible"
- >
- <template #reference>
- <div class="time-select">
- <span>{{ item.count ? `(${item.count}小时)` : '' }}</span>
- {{ item['name'] }}
- </div>
- </template>
- <template #default>
- <div class="work-hours-select-panel">
- <p class="title">{{ item['name'] }} 工时 (小时)</p>
- <div class="panel-input-number">
- 输入时间:
- <el-input-number
- v-model="item.count"
- class="input-number"
- :min="0"
- :max="80"
- controls-position="right"
- @change="(val) => changeCount(val, index)"
- />
- </div>
- <div class="panel-numeric-key">
- <ul>
- <li
- v-for="(num, i) in 40"
- :style="{
- background: i + 1 === item.count ? '#1b80eb' : '#f7f8fa',
- color: i + 1 === item.count ? '#fff' : '#000000'
- }"
- :key="i"
- @click="changeCount(num, index, true)"
- >
- <span>{{ num }}</span>
- </li>
- </ul>
- </div>
- <div class="panel-submit">
- <el-button type="primary" @click="panelSubmit(index)">确定</el-button>
- <el-button type="danger" @click="changeCount(0, index)">清零</el-button>
- <el-button type="info" @click="panelCancel(index)"> 取消 </el-button>
- </div>
- </div>
- </template>
- </el-popover>
- </div>
- </li>
- </ul>
- </div>
- </div>
- </template>
- <script setup lang="ts">
- /** 周日报相同文件 */
- import request from '@/config/axios'
- import { getUserInfo } from '@/utils/tool'
- // 获取用户信息
- const userInfo = getUserInfo()
- defineOptions({ name: 'WorkHoursSelect' })
- interface IProp {
- onChange: (any) => any
- initialData?: any[] // 初始数据
- nowDate: string
- }
- const props = defineProps<IProp>()
- const { onChange } = props
- const { initialData, nowDate } = toRefs(props)
- // 默认工作项目总时长
- const defaultTotalTime = ref(0)
- // 工时填写弹框的ref
- const popperRef = ref<any>(null)
- // 初始化数据
- const dataList = ref<any[]>([])
- const setInitData = () => {
- // 如果不是切换天数,则不重置
- if (defaultTotalTime.value > 0) return
- if (initialData?.value?.length == 0) {
- dataList.value = dataList.value.map((item) => {
- return {
- ...item,
- count: 0
- }
- })
- return
- }
- if (initialData.value && initialData.value.length > 0) {
- const initialObj = {}
- initialData.value.forEach((item) => {
- initialObj[item.projectId] = item.workTime
- })
- const timer = setTimeout(() => {
- dataList.value = dataList.value.map((item) => {
- let count = 0
- if (initialObj[item.id]) {
- count = initialObj[item.id]
- }
- return {
- ...item,
- count
- }
- })
- dataList.value.sort((x, y) => y['count'] - x['count'])
- clearTimeout(timer)
- }, 0)
- } else {
- getAllProject()
- }
- getTotalTime()
- }
- watch(
- () => initialData.value,
- () => {
- setInitData()
- }
- )
- watch(
- () => nowDate.value,
- () => {
- // 切换日期,重置数据
- defaultTotalTime.value = 0
- setInitData()
- }
- )
- onMounted(async () => {
- await getAllProject()
- await setInitData()
- })
- // 获取任务列表
- const getAllProject = async () => {
- const { records } = await request.get(
- {
- url: `/project/page`,
- params: {
- pageSize: -1,
- userId: userInfo.id ?? '',
- xmzList: [1, 4] // 仅可对进行中和已验收的项目进行填报
- }
- },
- '/business'
- )
- dataList.value = records.map((item) => {
- return {
- visible: false,
- count: 0,
- name: item.xmmc,
- id: item.id
- }
- })
- }
- // 临时存储数量
- const tempCount = ref(0)
- // 工时数量
- const changeCount = (val, index, submit?) => {
- // 获取临时数量
- tempCount.value = dataList.value[index].count
- dataList.value[index].count = val
- if (submit) {
- panelSubmit(index)
- }
- }
- // 计算总工时
- const getTotalTime = () => {
- defaultTotalTime.value = dataList.value.reduce((total, item) => {
- return total + item.count
- }, 0)
- }
- // 提交工时
- const panelSubmit = (index: number) => {
- dataList.value[index].visible = false
- getTotalTime()
- tempCount.value = 0
- // 提交工时后清空搜索框
- if (tempSearchList.value.length > 0) {
- searchInputRef.value?.clear()
- } else {
- // 提交后进行一下数据排序
- dataList.value.sort((x, y) => y['count'] - x['count'])
- // 提交工时后将已填数据传出去
- const countList = dataList.value
- .filter((item) => item.count > 0)
- .map((item) => ({
- workTime: item.count,
- projectId: item.id
- }))
- onChange(countList)
- }
- }
- // 取消选择
- const panelCancel = (index: number) => {
- dataList.value[index] = {
- ...dataList.value[index],
- visible: false,
- count: tempCount.value
- }
- getTotalTime()
- }
- // 搜索内容的临时存储
- const searchInputRef = ref<any>(null)
- const tempSearchList = ref<any[]>([])
- const searchValue = ref('')
- // 搜索内容改变时触发
- const searchOnchange = (val: string) => {
- // 搜索框第一次搜索时触发
- if (tempSearchList.value.length < dataList.value.length) {
- tempSearchList.value = dataList.value
- }
- // 搜索内容为空时,清空搜索列表,并显示全部数据
- if (val.length == 0) {
- clearSearch()
- return
- }
- // 使用 filter() 方法进行模糊查询
- const filteredArray = tempSearchList.value.filter((item) => {
- // 创建正则表达式,忽略大小写,并且匹配关键词
- const regex = new RegExp(val, 'i')
- // 使用正则表达式测试数组中的每个元素
- return regex.test(item.name)
- })
- dataList.value = filteredArray
- }
- // 清除内容时触发
- const clearSearch = () => {
- const countObj = {}
- dataList.value.forEach((item) => {
- countObj[item.id] = item.count
- })
- tempSearchList.value.forEach((item) => {
- if (countObj[item.id]) {
- // 如果有值,则赋值
- item.count = countObj[item.id]
- }
- })
- // 顺便进行一下数据排序
- tempSearchList.value.sort((x, y) => y['count'] - x['count'])
- // 还原全部数据
- dataList.value = tempSearchList.value
- // 提交工时后将已填数据传出去
- const countList = dataList.value
- .filter((item) => item.count > 0)
- .map((item) => ({
- workTime: item.count,
- projectId: item.id
- }))
- onChange(countList)
- tempSearchList.value = []
- getTotalTime()
- }
- interface IProject {
- name: string
- id: string
- }
- const emit = defineEmits<{
- (e: 'select', val: IProject): void
- }>()
- const handleClick = (val: IProject): void => {
- emit('select', val)
- openDialog(val.id)
- }
- // 打开弹窗
- const openDialog = (id) => {
- // 并且关闭所有其他弹窗
- dataList.value.forEach((item) => {
- item.visible = item.id == id
- })
- }
- </script>
- <style lang="scss" scoped>
- .WorkHoursSelect {
- width: 100%;
- height: calc(100% - 140px);
- display: flex;
- .select-title {
- font-family:
- Microsoft YaHei,
- Microsoft YaHei;
- width: 100px;
- font-size: 14px;
- font-weight: 400;
- height: 36px;
- line-height: 36px;
- text-align: right;
- padding-right: 12px;
- :before {
- content: '*';
- color: var(--el-color-danger);
- margin-right: 4px;
- }
- }
- .select-list {
- flex: 1;
- height: 100%;
- border: 1px solid #dee0e3;
- .title {
- padding: 8px 20px;
- background-color: #f7f8fa;
- color: #121518;
- display: flex;
- justify-content: space-between;
- align-items: center;
- }
- .list-ul {
- width: 100%;
- height: calc(100% - 50px);
- overflow-y: scroll;
- text-align: center;
- background-color: #fff;
- width: 100%;
- li {
- text-align: left;
- color: #000000;
- padding: 6px 10px;
- cursor: pointer;
- justify-content: space-between;
- &:hover {
- background-color: #d3e5ff;
- }
- .project-write {
- width: 100%;
- padding-left: 10px;
- }
- }
- .time-select {
- span {
- color: #1b80eb;
- }
- }
- }
- }
- }
- .work-hours-select-panel {
- .title {
- padding: 10px;
- text-align: center;
- background-color: #f7f8fa;
- color: #121518;
- font-size: 16px;
- font-weight: 400;
- }
- .popover-panel {
- padding: 0 !important;
- }
- .panel-input-number {
- height: 21px;
- margin: 10px 0;
- font-size: 16px;
- font-weight: 400;
- color: #404956;
- .input-number {
- width: calc(100% - 86px);
- }
- }
- .panel-numeric-key {
- text-align: center;
- overflow-y: auto;
- height: calc(100% - 42px);
- ul {
- padding: 20px 0;
- display: grid;
- grid-template-columns: repeat(8, 36px);
- gap: 10px;
- justify-content: space-between; /* 水平居中 */
- align-items: center; /* 垂直居中 */
- li {
- text-align: center;
- height: 35px;
- line-height: 35px;
- border-radius: 2px;
- color: #000000;
- cursor: pointer;
- }
- li:hover {
- border: 2px solid #1b80eb;
- }
- }
- }
- }
- </style>
|