tj
2025-06-05 bba272999cc546f65781bf3d20245a3f819af67f
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
<template>
  <div class="container">
    <div class="title">
      批量日志补录
      <span class="back" @click="back"> <i class="iconfont icon-fanhui"></i> 返回 </span>
    </div>
 
    <div class="log-list">
      <el-divider content-position="left" direction="vertical" class="top-class"></el-divider>
      <el-text type="primary">可以根据下面预设值进行初始化</el-text>
 
      <el-form model="form" ref="form" :inline="true" class="pre-form-class" label-width="auto">
        <el-form-item label="日志日期">
          <el-date-picker
            v-model="daily_date"
            type="date"
            placeholder="日志日期"
            size="default"
            value-format="YYYY-MM-DD"
            style="width: 120px"
            disabled
          />
 
          <!-- <el-date-picker
              v-model="daily_date"
              type="date"
              placeholder="日志日期"
              size="default"
              value-format="YYYY-MM-DD"
              style="width: 120px;"
              @change="preDateChange"
            /> -->
        </el-form-item>
 
        <el-form-item label="日志类型">
          <el-select
            v-model="daily_type"
            placeholder="日志类型"
            style="width: 120px"
            clearable
            filterable
            @change="preDailyTypeChange"
          >
            <el-option v-for="item in dailyTypeArr" :key="item.value" :label="item.label" :value="item.value" />
          </el-select>
        </el-form-item>
 
        <el-form-item label="所属项目">
          <el-select
            v-model="project_id"
            placeholder="所属项目"
            style="width: 150px"
            clearable
            filterable
            @change="preProjectInfoChange"
          >
            <el-option v-for="item in projectInfoArr" :key="item.id" :label="item.project_name" :value="item.id" />
          </el-select>
        </el-form-item>
 
        <el-form-item label="状态">
          <el-select
            v-model="daily_status"
            placeholder="状态"
            style="width: 150px"
            clearable
            filterable
            @change="preProjectStatusChange"
          >
            <el-option v-for="item in dailyStatusArr" :key="item.value" :label="item.label" :value="item.value" />
          </el-select>
        </el-form-item>
 
        <el-form-item label="初始化条数">
          <el-input
            type="number"
            v-model="itemSize"
            placeholder="初始化条数"
            style="width: 80px"
            @change="preItemSizeChange"
          />
        </el-form-item>
 
        <el-form-item>
          <el-button @click="addRow" class="add-button" type="primary">增加</el-button>
          <el-button @click="submitForm" class="add-button" type="primary">保存</el-button>
        </el-form-item>
      </el-form>
 
      <div v-for="(daily, index) in dailys" :key="index" class="log-item">
        <div class="log-item-content">
          <el-text class="log-index">{{ index + 1 }}</el-text>
          <el-tooltip effect="dark" content="日志日期">
            <el-date-picker
              v-model="daily.daily_date"
              type="date"
              placeholder="日志日期"
              size="default"
              value-format="YYYY-MM-DD"
              style="width: 120px"
              disabled
            />
          </el-tooltip>
          <el-tooltip effect="dark" content="日志类型">
            <el-select v-model="daily.daily_type" placeholder="日志类型" style="width: 100px" clearable filterable>
              <!-- 其他类型选项 -->
              <el-option v-for="item in daily.dailyTypeArr" :key="item.value" :label="item.label" :value="item.value" />
            </el-select>
          </el-tooltip>
          <el-tooltip effect="dark" content="所属项目">
            <el-select
              v-model="daily.project_id"
              placeholder="所属项目"
              style="width: 140px"
              clearable
              filterable
              @change="updateTasks(index)"
            >
              <el-option
                v-for="item in daily.projectInfoArr"
                :key="item.id"
                :label="item.project_name"
                :value="item.id"
              />
            </el-select>
          </el-tooltip>
          <el-tooltip effect="dark" content="任务">
            <el-select v-model="daily.task_id" placeholder="任务" style="width: 120px" clearable filterable>
              <el-option v-for="item in daily.projectTaskArr" :key="item.id" :label="item.task_name" :value="item.id" />
            </el-select>
          </el-tooltip>
          <el-tooltip effect="dark" content="状态">
            <el-select v-model="daily.daily_status" placeholder="状态" style="width: 100px" clearable filterable>
              <el-option
                v-for="item in daily.dailyStatusArr"
                :key="item.value"
                :label="item.label"
                :value="item.value"
              />
            </el-select>
          </el-tooltip>
          <el-tooltip effect="dark" content="日志内容">
            <el-input v-model="daily.daily_content" placeholder="日志内容" style="width: 400px" />
          </el-tooltip>
          <el-tooltip effect="dark" content="计划用时">
            <el-input-number
              v-model="daily.estimated_hours"
              :step="0.5"
              label="计划用时"
              placeholder="计划用时"
              style="width: 100px"
            />
          </el-tooltip>
          <el-tooltip effect="dark" content="实际用时">
            <el-input-number
              v-model="daily.actual_hours"
              :step="0.5"
              :min="0"
              label="实际用时"
              placeholder="实际用时"
              style="width: 100px"
            />
          </el-tooltip>
          <el-tooltip effect="dark" content="备注">
            <el-input v-model="daily.remark" placeholder="备注" style="width: 120px" />
          </el-tooltip>
        </div>
 
        <div class="log-item-action">
          <span @click="deleteRow(index)" class="delete-button">删除</span>
        </div>
      </div>
    </div>
  </div>
</template>
 
<script>
import { reactive, ref, onMounted } from 'vue'
import { ElMessageBox, ElMessage } from 'element-plus'
import projectInfo from '@/model/projectInfo'
import sysDictItemModel from '@/model/sysDictItem'
import projectDaily from '@/model/projectDaily'
import { getDefaultDate, getYesterdayDate, getStartAndEndOfWeek, getPreviousWeekDates } from '@/utils/dateUtils'
 
export default {
  props: {
    editId: {
      type: String,
      default: null,
    },
    editDailyDate: {
      type: String,
      default: null,
    },
  },
  setup(props, context) {
    const loading = ref(false)
 
    const dailyTypeArr = ref([])
    const dailyStatusArr = ref([])
    const projectInfoArr = ref([])
    const projectTaskArr = ref([])
 
    const daily_date = ref(getDefaultDate())
    const daily_type = ref('1')
    const project_id = ref('')
    const daily_status = ref('0')
 
    const itemSize = ref(3)
 
    const dailys = ref([])
 
    const form = ref({})
 
    const listAssign = (a, b) => Object.keys(a).forEach(key => {
      a[key] = b[key] || a[key]
    })
 
    /**
     * 表单规则验证
     */
    const { rules } = getRules()
 
    onMounted(() => {
      // if (props.editId) {
      //   getdaily()
      // }
      if (props.editDailyDate) {
        // 设定当天的日志只能是传过来的值
 
        daily_date.value = props.editDailyDate
      }
 
      loadDictDitems()
 
      loadBatchRows()
    })
 
    // 根据字典类型查询字典
    const loadDictDitems = async () => {
      dailyTypeArr.value = await sysDictItemModel.getSysDictItemListByType('daily_type')
      dailyStatusArr.value = await sysDictItemModel.getSysDictItemListByType('daily_status')
 
      const params = { status: '1,2,3,4' }
      projectInfoArr.value = await projectInfo.getProjectInfoList(params)
      // projectInfoArr.value= await projectInfo.getProjectInfoList("")
    }
 
    // 根据字典类型查询字典
    const loadBatchRows = () => {
      // 循环10次
      for (let i = 0; i < itemSize.value; i++) {
        addRow()
      }
    }
 
    const getdaily = async () => {
      loading.value = true
      const res = await projectDaily.getProjectDaily(props.editId)
      listAssign(daily, res)
      loading.value = false
    }
 
    const preDateChange = () => {
      for (let i = 0; i < dailys.value.length; i++) {
        dailys.value[i].daily_date = daily_date.value
      }
    }
 
    const preDailyTypeChange = () => {
      for (let i = 0; i < dailys.value.length; i++) {
        dailys.value[i].daily_type = daily_type.value
      }
    }
 
    const preProjectInfoChange = () => {
      for (let i = 0; i < dailys.value.length; i++) {
        dailys.value[i].project_id = project_id.value
      }
    }
 
    const preProjectStatusChange = () => {
      for (let i = 0; i < dailys.value.length; i++) {
        dailys.value[i].daily_status = daily_status.value
      }
    }
 
    const preItemSizeChange = () => {
      dailys.value = []
      loadBatchRows()
    }
 
    // 重置表单
    const resetForm = () => {
      dailys.value = []
      loadBatchRows()
    }
 
    const submitForm = async formName => {
      for (let i = 0; i < dailys.value.length; i++) {
        const index = i + 1
        const tmpDaily = dailys.value[i]
        const yesterday = getYesterdayDate()
        const today = getDefaultDate()
 
        if (!tmpDaily.daily_date) {
          ElMessage.error(`条目(${index})的日志日期不能为空!`)
          return
        }
        if (!tmpDaily.project_id) {
          ElMessage.error(`条目(${index})的所属项目不能为空!`)
          return
        }
        if (!tmpDaily.daily_type) {
          ElMessage.error(`条目(${index})的日志类型不能为空!`)
          return
        }
        if (!tmpDaily.daily_status) {
          ElMessage.error(`条目(${index})的状态不能为空!`)
          return
        }
 
        if (!tmpDaily.daily_content) {
          ElMessage.error(`条目(${index})的日志内容不能为空!`)
          return
        }
        if (!tmpDaily.estimated_hours) {
          ElMessage.error(`条目(${index})的计划用时不能为空!`)
          return
        }
        if (!tmpDaily.actual_hours) {
          ElMessage.error(`条目(${index})的实际用时不能为空!`)
          return
        }
      }
 
      // 删除操作
      // ElMessageBox.confirm('请检查完成状态与实际用时,如无问题则将确认补录,补录的数据无需再次提交, 是否继续?', '提示', {
      ElMessageBox.confirm('请检查完成状态与实际用时,如无问题则将确认补录, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning',
      })
        .then(async () => {
          loading.value = true
          const newData = camel(dailys.value)
 
          const tempForm = { daily_list: JSON.stringify(newData) }
 
          const res = await projectDaily.supplementaryProjectDailyBatch(tempForm)
 
          if (res.code < window.MAX_SUCCESS_CODE) {
            // 重新初始化
            resetForm()
            ElMessage.success(`${res.message}`)
            loading.value = false
          } else {
            ElMessage.success(`${res.message}`)
            loading.value = false
          }
        })
        .catch(() => {
          // 用户点击取消按钮时执行的操作
          // 可以选择不做任何事情,也可以显示取消消息
          // ElMessage.info('操作已取消'); // 如果需要显示取消消息,可以取消注释
        })
    }
 
    const addRow = () => {
      dailys.value.push({
        id: '',
        project_id: project_id.value,
        task_id: '',
        task_desc: '',
        daily_date: daily_date.value,
        daily_type: daily_type.value,
        daily_content: '',
        daily_status: daily_status.value,
        estimated_hours: 2,
        actual_hours: 0,
        remark: '',
        dailyTypeArr,
        dailyStatusArr,
        projectInfoArr,
        projectTaskArr,
      })
    }
 
    const deleteRow = index => {
      dailys.value.splice(index, 1)
    }
 
    const updateTasks = index => {
      dailys.value[index].projectTaskArr = [
        { task_name: '子选项1', id: 'suboption1' },
        { task_name: '子选项2', id: 'suboption2' },
      ]
    }
 
    const back = () => {
      context.emit('editClose')
    }
 
    return {
      back,
      rules,
      resetForm,
      submitForm,
 
      dailys,
      addRow,
      deleteRow,
 
      dailyTypeArr,
      dailyStatusArr,
      projectInfoArr,
      updateTasks,
 
      form,
      daily_date,
      daily_type,
      project_id,
      daily_status,
      itemSize,
 
      preDateChange,
      preDailyTypeChange,
      preProjectInfoChange,
      preItemSizeChange,
      preProjectStatusChange,
    }
  },
}
 
/**
 * 表单验证规则
 */
function getRules() {
  /**
   * 验证回调函数
   */
  const checkInfo = (rule, value, callback) => {
    if (!value) {
      callback(new Error('信息不能为空'))
    }
    callback()
  }
  const rules = {
    daily_date: [{ validator: checkInfo, trigger: 'blur', required: true }],
    daily_type: [{ validator: checkInfo, trigger: 'blur', required: true }],
    daily_content: [{ validator: checkInfo, trigger: 'blur', required: true }],
    estimated_hours: [{ validator: checkInfo, trigger: 'blur', required: true }],
  }
  return { rules }
}
 
/**
 * 下划线转驼峰
 */
function camel(data) {
  if (typeof data !== 'object' || !data) return data
  if (Array.isArray(data)) {
    return data.map(item => camel(item))
  }
 
  const newData = {}
  for (const key in data) {
    const newKey = key.replace(/_([a-z])/g, (p, m) => m.toUpperCase())
    newData[newKey] = camel(data[key])
  }
  return newData
}
 
/**
 * 驼峰转下划线
 */
function underline(data) {
  if (typeof data !== 'object' || !data) return data
  if (Array.isArray(data)) {
    return data.map(item => underline(item))
  }
 
  const newData = {}
  for (const key in data) {
    const newKey = key.replace(/([A-Z])/g, (p, m) => `_${m.toLowerCase()}`)
    newData[newKey] = underline(data[key])
  }
  return newData
}
</script>
 
<style lang="scss" scoped>
.container {
  .title {
    height: 59px;
    line-height: 59px;
    color: $parent-title-color;
    font-size: 16px;
    font-weight: 500;
    text-indent: 40px;
    border-bottom: 1px solid #dae1ec;
 
    .back {
      float: right;
      margin-right: 40px;
      cursor: pointer;
    }
  }
 
  .wrap {
    padding: 20px;
  }
 
  .submit {
    float: left;
  }
}
</style>
 
<style scoped>
.top-class {
  margin: 10 5 5 5;
}
.pre-form-class {
  margin: 5px;
}
.log-list {
  margin-top: 10px;
  max-height: 90%; /* 设置最大高度,出现滚动条 */
  overflow-y: auto; /* 垂直滚动条 */
  width: 99%;
  overflow-x: auto;
  scrollbar-width: thin;
  scrollbar-color: #ccc #f2f2f2;
}
 
.log-index {
  padding-left: 5px;
  padding-right: 5px;
  width: 20px;
}
.log-item {
  display: flex;
  align-items: center;
  justify-content: left;
  margin-bottom: 2px;
  /* padding: 10px; */
  /* background-color: #f2f2f2; */
}
 
.log-item-content {
  /* flex: 1; */
  /* display: flex; */
  /* align-items: center; */
  width: auto;
  display: flex;
}
 
.log-item-action {
  flex-shrink: 0;
  margin-left: 5px;
}
 
.delete-button {
  cursor: pointer;
  font-size: 14px;
}
 
.add-button {
  margin: 5px;
}
</style>