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
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
<template>
  <div class="container">
    <div class="title">
      {{ topHeader }}
      <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" size="small"> -->
      <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"
            @change="preDateChange"
            :disabled="true"
          />
        </el-form-item>
 
        <el-form-item label="日志类型">
          <el-select
            v-model="daily_type"
            placeholder="日志类型"
            style="width: 120px"
            clearable
            filterable
            :disabled="confirm_flag"
            @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
            :disabled="confirm_flag"
            @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
            :disabled="confirm_flag"
            @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"
            :disabled="confirm_flag"
          />
        </el-form-item>
 
        <el-form-item>
          <el-button @click="addRow" class="add-button" type="primary" v-if="!confirm_flag">增加</el-button>
          <el-button @click="submitForm" class="add-button" type="primary" v-if="!confirm_flag">保存</el-button>
          <el-button @click="submitConfirmForm" class="add-button" type="primary" v-else>工时确认</el-button>
        </el-form-item>
      </el-form>
 
      <div v-for="(daily, index) in dailys" :key="index" class="log-item">
        <!-- <el-form :inline="true" :rules="rules"  :ref="refHandler" :key="index" :model="daily"  size="small"> -->
        <el-form :inline="true" :rules="rules" :ref="refHandler" :key="index" :model="daily">
          <div class="log-item-content">
            <el-form-item>
              <el-text class="log-index">{{ index + 1 }}</el-text>
            </el-form-item>
 
            <el-form-item label="日志日期" prop="daily_date" :label-width="labelWidth">
              <el-date-picker
                v-model="daily.daily_date"
                type="date"
                placeholder="日志日期"
                size="default"
                value-format="YYYY-MM-DD"
                style="width: 120px"
                :disabled="true"
                :key="index"
              />
            </el-form-item>
 
            <el-form-item label="日志类型" prop="daily_type" :label-width="labelWidth">
              <el-select
                v-model="daily.daily_type"
                placeholder="日志类型"
                style="width: 100px"
                clearable
                filterable
                :disabled="confirm_flag"
                :key="index"
              >
                <!-- 其他类型选项 -->
                <el-option
                  v-for="item in daily.dailyTypeArr"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"
                />
              </el-select>
            </el-form-item>
 
            <el-form-item label="所属项目" prop="project_id" :label-width="labelWidth">
              <el-select
                v-model="daily.project_id"
                placeholder="所属项目"
                style="width: 140px"
                clearable
                filterable
                :disabled="confirm_flag"
                :key="index"
                @change="updateTasks(index)"
              >
                <el-option
                  v-for="item in daily.projectInfoArr"
                  :key="item.id"
                  :label="item.project_name"
                  :value="item.id"
                />
              </el-select>
            </el-form-item>
 
            <!-- <el-tooltip effect="dark" content="任务">
              <el-form-item label="任务"  prop="task_id" :label-width="labelWidth">
                <el-select v-model="daily.task_id" placeholder="任务" style="width: 120px;" clearable filterable :disabled="confirm_flag" >
                  <el-option
                    v-for="item in daily.projectTaskArr"
                    :key="item.id"
                    :label="item.task_name"
                    :value="item.id"
                  />
 
                </el-select>
              </el-form-item>
            </el-tooltip> -->
 
            <el-form-item label="状态" prop="daily_status" :label-width="labelWidth">
              <el-select
                v-model="daily.daily_status"
                placeholder="状态"
                style="width: 100px"
                clearable
                filterable
                :key="index"
              >
                <el-option
                  v-for="item in daily.dailyStatusArr"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"
                />
              </el-select>
            </el-form-item>
 
            <el-form-item label="日志内容" prop="daily_content" :label-width="labelWidth">
              <el-input
                v-model="daily.daily_content"
                placeholder="日志内容"
                style="width: 300px"
                :disabled="confirm_flag"
                :key="index"
              />
            </el-form-item>
 
            <el-form-item label="计划用时" prop="estimated_hours" :label-width="labelWidth">
              <el-input-number
                v-model="daily.estimated_hours"
                :step="0.5"
                label="计划用时"
                placeholder="计划用时"
                style="width: 120px"
                :disabled="confirm_flag"
                :key="index"
              />
            </el-form-item>
 
            <el-form-item label="实际用时" prop="actual_hours" :label-width="labelWidth" v-if="confirm_flag">
              <el-input-number
                v-model="daily.actual_hours"
                :step="0.5"
                :min="0"
                label="实际用时"
                placeholder="实际用时"
                style="width: 120px"
                :key="index"
              />
            </el-form-item>
 
            <el-form-item
              label="备注"
              prop="remark"
              :label-width="labelWidth"
              :rules="
                daily.daily_status != '2' && confirm_flag
                  ? { required: true, message: '请输入备注', trigger: ['blur', 'change'] }
                  : { required: false }
              "
            >
              <el-input v-model="daily.remark" placeholder="备注" style="width: 120px" :key="index" />
            </el-form-item>
 
            <el-form-item>
              <span @click="deleteRow(index)" class="delete-button" v-if="!confirm_flag" :key="index">删除</span>
            </el-form-item>
          </div>
        </el-form>
 
        <!-- <div class="log-item-action">
 
          <span @click="deleteRow(index)" class="delete-button" v-if="!confirm_flag" >删除</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'
 
export default {
  props: {
    comfirmFlag: {
      type: Boolean,
      default: false,
    },
    editDailyDate: {
      type: String,
      default: null,
    },
  },
  setup(props, context) {
    const topHeader = ref('日志新增')
    const labelWidth = ref('90px')
    const loading = ref(false)
 
    const dailyTypeArr = ref([])
    const dailyStatusArr = ref([])
    const projectInfoArr = ref([])
    const projectTaskArr = ref([])
 
    const daily_date = ref(getDefaultDate())
    const confirm_flag = ref(false)
    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 ruleForm = ref([])
    const refHandler = el => {
      if (el) {
        ruleForm.value.push(el)
      }
    }
 
    const listAssign = (a, b) => Object.keys(a).forEach(key => {
      a[key] = b[key] || a[key]
    })
 
    /**
     * 表单规则验证
     */
    const rules = ref(getAddRules())
 
    onMounted(() => {
      loadDictDitems()
 
      if (props.editId) {
        // getdaily()
      }
 
      if (props.editDailyDate) {
        // 设定当天的日志只能是传过来的值
        daily_date.value = props.editDailyDate
      }
      confirm_flag.value = props.comfirmFlag
      if (confirm_flag.value == true) {
        topHeader.value = '日志工时确认'
        rules.value = getConfirmRules()
      } else {
        confirm_flag.value == false
        topHeader.value = '日志新增'
        rules.value = getAddRules()
      }
    })
 
    // 根据字典类型查询字典
    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("")
      // 获取该daily_date 日期下的所有日志信息
      await getdailyByDailyDate()
    }
 
    // 根据字典类型查询字典
    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 getdailyByDailyDate = async () => {
      loading.value = true
      const res = await projectDaily.getProjectDailyByDailyDate(daily_date.value)
      if (res && res.length > 0) {
        res.forEach(item => {
          item.daily_type = String(item.daily_type)
          item.project_id = String(item.project_id)
          item.task_id = String(item.task_id)
          item.daily_status = String(item.daily_status)
          item.dailyTypeArr = dailyTypeArr
          item.dailyStatusArr = dailyStatusArr
          item.projectInfoArr = projectInfoArr
          item.projectTaskArr = projectTaskArr
        })
        dailys.value = res
      } else {
        loadBatchRows()
      }
 
      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=[]
      getdailyByDailyDate()
      loadBatchRows()
      const forms = ruleForm.value
      forms.forEach(tmpForm => {
        if (tmpForm) {
          tmpForm.resetFields()
        }
      })
    }
 
    const validForm = () => {
      const forms = ruleForm.value
 
      const validateArray = forms.map(async (tmpForm, index, array) => await tmpForm.validate(valid => valid))
 
      const result = Promise.all(validateArray)
      return result
    }
 
    const submitForm = async formName => {
      const result = validForm()
      result.then(res => {
        let validateFlag = true
        res.forEach(validateRes => {
          validateFlag &= validateRes
        })
        if (validateFlag) {
          // 查看计划工时
          let planHours = 0
          for (let i = 0; i < dailys.value.length; i++) {
            const index = i + 1
            const tmpDaily = dailys.value[i]
            planHours += tmpDaily.estimated_hours
          }
          if (planHours < 6) {
            ElMessage.error(`计划用时小于6小时不能保存,${daily_date.value}的计划工时数为${planHours}小时!`)
            return
          }
 
          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.createProjectDailyBatch(tempForm)
 
              if (res.code < window.MAX_SUCCESS_CODE) {
                // 重新初始化
                resetForm()
                ElMessage.success(`${res.message}`)
                loading.value = false
              } else {
                ElMessage.error(`${res.message}`)
                loading.value = false
              }
            })
            .catch(() => {
              // 用户点击取消按钮时执行的操作
              // 可以选择不做任何事情,也可以显示取消消息
              // ElMessage.info('操作已取消'); // 如果需要显示取消消息,可以取消注释
            })
        }
      })
    }
 
    const submitForm2 = async formName => {
      let planHours = 0
      for (let i = 0; i < dailys.value.length; i++) {
        const index = i + 1
        const tmpDaily = dailys.value[i]
        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
        }
        planHours += tmpDaily.estimated_hours
      }
 
      // 工时不满6个小时的不可以保存,数据库加当前,区分新增和修改情况
      const existHours = await projectDaily.getExistsHours(daily_date.value, '')
 
      if (existHours) {
        planHours += existHours.estimated_hours
      }
      if (planHours < 6) {
        ElMessage.error(`计划用时小于6小时不能保存,${daily_date.value}的计划工时数为${planHours}小时!`)
        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.createProjectDailyBatch(tempForm)
 
          if (res.code < window.MAX_SUCCESS_CODE) {
            // 重新初始化
            resetForm()
            ElMessage.success(`${res.message}`)
            loading.value = false
          } else {
            ElMessage.error(`${res.message}`)
            loading.value = false
          }
        })
        .catch(() => {
          // 用户点击取消按钮时执行的操作
          // 可以选择不做任何事情,也可以显示取消消息
          // ElMessage.info('操作已取消'); // 如果需要显示取消消息,可以取消注释
        })
    }
 
    const submitConfirmForm = () => {
      const result = validForm()
      result.then(res => {
        let validateFlag = true
        res.forEach(validateRes => {
          validateFlag &= validateRes
        })
        if (validateFlag) {
          // 查看计划工时
          let actualHours = 0
          for (let i = 0; i < dailys.value.length; i++) {
            const index = i + 1
            const tmpDaily = dailys.value[i]
            actualHours += tmpDaily.actual_hours
            
            if (tmpDaily.daily_status != '2' && isBlank(tmpDaily.remark)) {
              ElMessage.error('日志状态是非完成的需要填写备注!')
              return
            }
          }
          if (actualHours < 6) {
            ElMessage.error(`实际用时小于6小时不能保存,${daily_date.value}的实际工时数为${actualHours}小时!`)
            return
          }
 
          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.createProjectDailyBatch(tempForm)
 
              if (res.code < window.MAX_SUCCESS_CODE) {
                // 重新初始化
                resetForm()
                ElMessage.success(`${res.message}`)
                loading.value = false
              } else {
                ElMessage.error(`${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_date: props.editDailyDate,
        daily_type: daily_type.value,
        daily_content: '',
        daily_status: daily_status.value,
        estimated_hours: 2,
        actual_hours: 0,
        remark: '',
        dailyTypeArr,
        dailyStatusArr,
        projectInfoArr,
        projectTaskArr,
      })
    }
 
    function isBlank(str) {
      return !str || str.replace(/\s/g, '').length === 0
    }
 
    const deleteRow = index => {
      dailys.value.splice(index, 1)
    }
 
    const updateTasks = index => {
      console.log(dailys.value[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,
 
      topHeader,
      labelWidth,
 
      dailys,
      addRow,
      deleteRow,
      submitConfirmForm,
 
      dailyTypeArr,
      dailyStatusArr,
      projectInfoArr,
      updateTasks,
 
      form,
      daily_date,
      confirm_flag,
      daily_type,
      project_id,
      daily_status,
      itemSize,
 
      preDateChange,
      preDailyTypeChange,
      preProjectInfoChange,
      preItemSizeChange,
      preProjectStatusChange,
 
      loading,
 
      getConfirmRules,
      getAddRules,
      ruleForm,
      refHandler,
    }
  },
}
function getDefaultDate() {
  const today = new Date()
  const year = today.getFullYear()
  const month = String(today.getMonth() + 1).padStart(2, '0')
  const day = String(today.getDate()).padStart(2, '0')
  const now = `${year}-${month}-${day}`
  return now
}
 
/**
 * 表单验证规则
 */
function getAddRules() {
  /**
   * 验证回调函数
   */
  const hourInfo = (rule, value, callback) => {
    if (value <= 0) {
      callback(new Error('工时至少为0.5小时'))
    }
    callback()
  }
  const rules = {
    daily_date: [{ message: '请输入日期', trigger: 'blur', required: true }],
    daily_type: [{ message: '请选择日志类型', trigger: 'blur', required: true }],
    project_id: [{ message: '请选择项目', trigger: 'blur', required: true }],
    daily_status: [{ message: '请选择日志状态', trigger: 'blur', required: true }],
    daily_content: [{ message: '请输入日志内容', trigger: 'change', required: true }],
    estimated_hours: [{ validator: hourInfo, trigger: 'change', required: true }],
  }
  return rules
}
 
function getConfirmRules() {
  /**
   * 验证回调函数
   */
  const checkHourInfo = (rule, value, callback) => {
    if (value <= 0) {
      callback(new Error('工时至少为0.5小时'))
    }
    callback()
  }
  const checkRemarkInfo = (rule, value, callback) => {
    if (!value) {
      callback(new Error('信息不能为空'))
    }
    callback()
  }
 
  const checkStatusInfo = (rule, value, callback) => {
    if (!value) {
      callback(new Error('请选择日志状态'))
    }
 
    callback()
  }
 
  const rules = {
    daily_date: [{ message: '请输入日期', trigger: 'blur', required: true }],
    daily_type: [{ message: '请选择日志类型', trigger: 'blur', required: true }],
    project_id: [{ message: '请选择项目', trigger: 'blur', required: true }],
    daily_status: [{ validator: checkStatusInfo, trigger: 'blur', required: true }],
    daily_content: [{ message: '请输入日志内容', trigger: 'blur', required: true }],
    estimated_hours: [{ validator: checkHourInfo, trigger: 'change', required: true }],
    actual_hours: [{ validator: checkHourInfo, trigger: 'change', required: true }],
    // remark: [{validator:checkRemarkInfo, trigger: 'change', required: true }],
  }
  return rules
}
 
/**
 * 表单验证规则
 */
function getHoursRules() {
  /**
   * 验证回调函数
   */
  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 }],
    project_id: [{ validator: checkInfo, trigger: 'blur', required: true }],
    daily_content: [{ message: '请输入日志内容', 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>