index.vue 36.8 KB
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 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143

<template>
    <div>
      <!-- 添加类似于标签页的年份筛选 -->
      <div class="year-tabs">
        <a-radio-group v-model:value="selectedYear" button-style="solid" @change="handleYearChange">
          <a-radio-button v-for="year in yearOptions" :key="year.value" :value="year.value">
            {{ year.label }}
          </a-radio-button>
        </a-radio-group>
      </div>
      
      <!-- 配置卡片区域 - 改为标签页形式 -->
      <div class="config-section">
        <a-tabs v-model:activeKey="activeTabKey" @change="handleTabChange">
          <a-tab-pane key="calendar" tab="人事考勤日历配置">
        <div class="config-card">
          <div class="table-header">
            <div class="title">人事考勤日历配置</div>
            <a-button type="primary" @click="handleCreate(60)">新建</a-button>
          </div>
          
          <a-table
            :columns="calendarColumns"
            :data-source="calendarData"
            :pagination="false"
            bordered
            class="mt-4"
          >
            <template #bodyCell="{ column, record }">
              <template v-if="column.key === 'action'">
                <a-space>
                  <a-button type="link" @click="handleEdit(record)">
                    <template #icon><Icon icon="clarity:note-edit-line" /></template>
                    编辑
                  </a-button>
                  <a-popconfirm
                    title="是否确认删除?"
                    placement="left"
                    @confirm="handleDelete(record)"
                  >
                    <a-button type="link" danger>
                      <template #icon><Icon icon="ant-design:delete-outlined" /></template>
                      删除
                    </a-button>
                  </a-popconfirm>
                </a-space>
              </template>
            </template>
          </a-table>
        </div>
          </a-tab-pane>
        
          <a-tab-pane key="attendance" tab="考勤配置">
        <div class="config-card">
          <div class="table-header">
            <div class="title">考勤配置</div>
            <a-button type="primary" @click="handleAddAttendance">新建</a-button>
          </div>
          
          <a-table
            :columns="attendanceColumns"
                :data-source="attendanceTypes"
            :pagination="false"
            bordered
            class="mt-4"
                :scroll="{ x: 1500 }"
          >
            <template #bodyCell="{ column, record }">
                  <template v-if="column.dataIndex === 'typeName'">
                    <span class="attendance-type-name">{{ record.typeName }}</span>
                    <span class="year-indicator">({{ selectedYear }})</span>
                  </template>
                  <template v-else-if="column.key === 'action'">
                <a-space>
                      <a-button type="link" size="small" @click="handleEditAttendanceType(record)">
                    <template #icon><Icon icon="clarity:note-edit-line" /></template>
                    编辑
                  </a-button>
                </a-space>
              </template>
              <!-- 处理月份单元格,使其可点击编辑 -->
              <template v-else-if="column.key && column.key.startsWith('month') && column.key.includes('WorkDays')">
                <div class="editable-cell" @click="handleEditMonthCell(record, column.key)">
                  {{ record[column.dataIndex] }}
                </div>
              </template>
              <template v-else-if="column.key && column.key.startsWith('month') && column.key.includes('SalaryDays')">
                <div class="editable-cell" @click="handleEditMonthCell(record, column.key)">
                  {{ record[column.dataIndex] }}
                </div>
              </template>
            </template>
          </a-table>
        </div>
          </a-tab-pane>
          
          <a-tab-pane key="fiveInsurances" tab="五险一金配置">
            <div class="config-card">
              <div class="table-header">
                <div class="title">五险一金配置</div>
                <a-button type="primary" @click="handleAddInsurance">新建</a-button>
              </div>
              
              <a-table
                :columns="insuranceColumns"
                :data-source="insuranceData"
                :pagination="false"
                bordered
                class="mt-4"
                :scroll="{ x: 1500 }"
              >
                <template #bodyCell="{ column, record }">
                  <template v-if="column.dataIndex === 'relationName'">
                    <span class="insurance-type-name">{{ record.relationName }}({{ selectedYear }})</span>
                  </template>
                  <template v-else-if="column.key === 'action'">
                    <a-space>
                      <a-button type="link" size="small" @click="handleEditInsurance(record)">
                        <template #icon><Icon icon="clarity:note-edit-line" /></template>
                        编辑
                      </a-button>
                    </a-space>
                  </template>
                  <template v-else-if="column.dataIndex === 'personalTotal'">
                    <span class="total-cell">¥{{ calculatePersonalTotal(record) }}</span>
                  </template>
                  <template v-else-if="column.dataIndex === 'companyTotal'">
                    <span class="total-cell">¥{{ calculateCompanyTotal(record) }}</span>
                  </template>
                  <!-- 格式化所有金额显示 -->
                  <template v-else-if="isInsuranceAmountColumn(column.dataIndex)">
                    <span>¥{{ formatAmount(record[column.dataIndex]) }}</span>
                  </template>
                </template>
              </a-table>
            </div>
          </a-tab-pane>
        </a-tabs>
      </div>
      
      <PersonnelConfigModal @register="registerModal" @success="handleSuccess" />
      <AttendanceConfigModal @register="registerAttendanceModal" @success="handleSuccess" />
      <AttendanceEditModal @register="registerAttendanceEditModal" @success="handleSuccess" />
      <InsuranceConfigModal @register="registerInsuranceModal" @success="handleSuccess" />
    </div>
  </template>
  <script lang="ts">
    import { defineComponent, ref, onMounted } from 'vue';
    import Icon from '/@/components/Icon/Icon.vue';
    import { useModal } from '/@/components/Modal';
    import { useMessage } from '/@/hooks/web/useMessage';
    import PersonnelConfigModal from './PersonnelConfigModal.vue';
    import AttendanceConfigModal from './AttendanceConfigModal.vue';
    import AttendanceEditModal from './AttendanceEditModal.vue';
    import InsuranceConfigModal from './InsuranceConfigModal.vue';
    import { columns } from './personnelConfig.data';
    import { getPersonnelConfigList, deletePersonnelConfig } from '/@/api/project/account';
    import { defHttp } from '/@/utils/http/axios';
    
    // 生成年份选项
    const generateYearOptions = () => {
      const currentYear = new Date().getFullYear();
      const years: { label: string; value: string }[] = [];
      
      for (let i = -2; i <= 5; i++) {
        const year = currentYear + i;
        years.push({
          label: `${year}年`,
          value: year.toString(),
        });
      }
      
      return years;
    };
    
    // 定义后端返回的人事配置数据接口
    interface ApiPersonnelConfig {
      id: number;
      relationCode: string;
      relationName: string; // 月份
      relationValue: string; // JSON字符串,包含工作日和计薪日
      settingType: number; // 61-64对应不同的考勤类型
      settingValue: string; // 年份
    }
    
    // 定义前端使用的人事配置数据接口
    interface PersonnelConfig {
      id: number;
      year: string;
      month: string;
      calendarDays: number;
      workDays: number;
      salaryDays: number;
      legalHolidays: number;
      settingType?: string | number;
    }
    // 定义考勤类型接口
    interface AttendanceType {
      key: string;
      typeName: string; // 类型名称
      typeDisplayName: string; // 显示名称(包含年份)
      workHours: number;
      formula: string;
      data: Record<string, any>;
    }
    export default defineComponent({
      name: 'PersonnelConfigManagement',
      components: { Icon, PersonnelConfigModal, AttendanceConfigModal, AttendanceEditModal, InsuranceConfigModal },
      setup() {
        const { createMessage } = useMessage();
        const yearOptions = generateYearOptions();
        const selectedYear = ref(new Date().getFullYear().toString());
        
        // 增加标签页激活键的状态
        const activeTabKey = ref<string>('calendar');
        
        // 创建数据
        const calendarData = ref<PersonnelConfig[]>([]);
        const attendanceData = ref<ApiPersonnelConfig[]>([]);
        const insuranceData = ref<any[]>([]);
        
        // 固定的考勤类型
        const attendanceTypes = ref<AttendanceType[]>([
          {
            key: 'type-1',
            typeName: '9小时双休',
            typeDisplayName: '9小时双休',
            workHours: 9,
            formula: '计薪日*每日工时',
            data: {},
          },
          {
            key: 'type-2',
            typeName: '9大小周双休(生产科)',
            typeDisplayName: '9大小周双休(生产科)',
            workHours: 9,
            formula: '计薪日*每日工时+18',
            data: {},
          },
          {
            key: 'type-3',
            typeName: '8双休',
            typeDisplayName: '8双休',
            workHours: 8,
            formula: '计薪日*每日工时',
            data: {},
          },
          {
            key: 'type-4',
            typeName: '8.5大小周',
            typeDisplayName: '8.5大小周',
            workHours: 8.5,
            formula: '计薪日*每日工时+17',
            data: {},
          },
        ]);
        
        // 添加操作列到日历配置表格
        const calendarColumns = ref([
          ...columns,
          {
            title: '操作',
            key: 'action',
            width: 120,
            align: 'center',
          }
        ]);
        
        // 重新定义考勤配置表格列
        const attendanceColumns = ref([
          {
            title: '考勤项目',
            dataIndex: 'typeName',
            key: 'typeName',
            width: 160,
            fixed: 'left',
            align: 'left',
          },
          {
            title: '工时',
            dataIndex: 'workHours',
            key: 'workHours',
            width: 80,
            align: 'center',
          },
          {
            title: '每月工时计算',
            dataIndex: 'formula',
            key: 'formula',
            width: 160,
            align: 'center',
          },
          {
            title: '1月',
            children: [
              {
                title: '工作日',
                dataIndex: 'month1WorkDays',
                key: 'month1WorkDays',
                width: 70,
                align: 'center',
              },
              {
                title: '计薪日',
                dataIndex: 'month1SalaryDays',
                key: 'month1SalaryDays',
                width: 70,
                align: 'center',
              },
            ],
          },
          {
            title: '2月',
            children: [
              {
                title: '工作日',
                dataIndex: 'month2WorkDays',
                key: 'month2WorkDays',
                width: 70,
                align: 'center',
              },
              {
                title: '计薪日',
                dataIndex: 'month2SalaryDays',
                key: 'month2SalaryDays',
                width: 70,
                align: 'center',
              },
            ],
          },
          {
            title: '3月',
            children: [
              {
                title: '工作日',
                dataIndex: 'month3WorkDays',
                key: 'month3WorkDays',
                width: 70,
                align: 'center',
              },
              {
                title: '计薪日',
                dataIndex: 'month3SalaryDays',
                key: 'month3SalaryDays',
                width: 70,
                align: 'center',
              },
            ],
          },
          {
            title: '4月',
            children: [
              {
                title: '工作日',
                dataIndex: 'month4WorkDays',
                key: 'month4WorkDays',
                width: 70,
                align: 'center',
              },
              {
                title: '计薪日',
                dataIndex: 'month4SalaryDays',
                key: 'month4SalaryDays',
                width: 70,
                align: 'center',
              },
            ],
          },
          {
            title: '5月',
            children: [
              {
                title: '工作日',
                dataIndex: 'month5WorkDays',
                key: 'month5WorkDays',
                width: 70,
                align: 'center',
              },
              {
                title: '计薪日',
                dataIndex: 'month5SalaryDays',
                key: 'month5SalaryDays',
                width: 70,
                align: 'center',
              },
            ],
          },
          {
            title: '6月',
            children: [
              {
                title: '工作日',
                dataIndex: 'month6WorkDays',
                key: 'month6WorkDays',
                width: 70,
                align: 'center',
              },
              {
                title: '计薪日',
                dataIndex: 'month6SalaryDays',
                key: 'month6SalaryDays',
                width: 70,
                align: 'center',
              },
            ],
          },
          {
            title: '7月',
            children: [
              {
                title: '工作日',
                dataIndex: 'month7WorkDays',
                key: 'month7WorkDays',
                width: 70,
                align: 'center',
              },
              {
                title: '计薪日',
                dataIndex: 'month7SalaryDays',
                key: 'month7SalaryDays',
                width: 70,
                align: 'center',
              },
            ],
          },
          {
            title: '8月',
            children: [
              {
                title: '工作日',
                dataIndex: 'month8WorkDays',
                key: 'month8WorkDays',
                width: 70,
                align: 'center',
              },
              {
                title: '计薪日',
                dataIndex: 'month8SalaryDays',
                key: 'month8SalaryDays',
                width: 70,
                align: 'center',
              },
            ],
          },
          {
            title: '9月',
            children: [
              {
                title: '工作日',
                dataIndex: 'month9WorkDays',
                key: 'month9WorkDays',
                width: 70,
                align: 'center',
              },
              {
                title: '计薪日',
                dataIndex: 'month9SalaryDays',
                key: 'month9SalaryDays',
                width: 70,
                align: 'center',
              },
            ],
          },
          {
            title: '10月',
            children: [
              {
                title: '工作日',
                dataIndex: 'month10WorkDays',
                key: 'month10WorkDays',
                width: 70,
                align: 'center',
              },
              {
                title: '计薪日',
                dataIndex: 'month10SalaryDays',
                key: 'month10SalaryDays',
                width: 70,
                align: 'center',
              },
            ],
          },
          {
            title: '11月',
            children: [
              {
                title: '工作日',
                dataIndex: 'month11WorkDays',
                key: 'month11WorkDays',
                width: 70,
                align: 'center',
              },
              {
                title: '计薪日',
                dataIndex: 'month11SalaryDays',
                key: 'month11SalaryDays',
                width: 70,
                align: 'center',
              },
            ],
          },
          {
            title: '12月',
            children: [
              {
                title: '工作日',
                dataIndex: 'month12WorkDays',
                key: 'month12WorkDays',
                width: 70,
                align: 'center',
              },
              {
                title: '计薪日',
                dataIndex: 'month12SalaryDays',
                key: 'month12SalaryDays',
                width: 70,
                align: 'center',
              },
            ],
          },
          {
            title: '操作',
            key: 'action',
            width: 70,
            fixed: 'right',
            align: 'center',
          }
        ]);
        
        // 五险一金配置表格列
        const insuranceColumns = ref([
          {
            title: '社保待遇',
            dataIndex: 'relationName',
            key: 'relationName',
            width: 110,
            fixed: 'left',
            align: 'left',
          },
          {
            title: '个人承担社保公积金',
            children: [
              {
                title: '养老保险',
                dataIndex: 'personalPensionInsurance',
                key: 'personalPensionInsurance',
                width: 90,
                align: 'center',
              },
              {
                title: '医疗保险',
                dataIndex: 'personalPensionMedicalInsurance',
                key: 'personalPensionMedicalInsurance',
                width: 90,
                align: 'center',
              },
              {
                title: '失业保险',
                dataIndex: 'personalPensionUnemploymentInsurance',
                key: 'personalPensionUnemploymentInsurance',
                width: 90,
                align: 'center',
              },
              {
                title: '大额医疗',
                dataIndex: 'personalPensionLargeScaleMedicalInsurance',
                key: 'personalPensionLargeScaleMedicalInsurance',
                width: 90,
                align: 'center',
              },
              {
                title: '住房公积金',
                dataIndex: 'personalPensionProvidentFundInsurance',
                key: 'personalPensionProvidentFundInsurance',
                width: 90,
                align: 'center',
              },
              {
                title: '合计',
                dataIndex: 'personalTotal',
                key: 'personalTotal',
                width: 100,
                align: 'center',
              },
            ]
          },
          {
            title: '公司承担社保公积金',
            children: [
              {
                title: '养老保险',
                dataIndex: 'companyInsurance',
                key: 'companyInsurance',
                width: 90,
                align: 'center',
              },
              {
                title: '医疗保险',
                dataIndex: 'companyMedicalInsurance',
                key: 'companyMedicalInsurance',
                width: 90,
                align: 'center',
              },
              {
                title: '失业保险',
                dataIndex: 'companyUnemploymentInsurance',
                key: 'companyUnemploymentInsurance',
                width: 90,
                align: 'center',
              },
              {
                title: '工伤保险',
                dataIndex: 'companyEmploymentInjuryInsurance',
                key: 'companyEmploymentInjuryInsurance',
                width: 90,
                align: 'center',
              },
              {
                title: '生育保险',
                dataIndex: 'companyMaternityInsurance',
                key: 'companyMaternityInsurance',
                width: 90,
                align: 'center',
              },
              {
                title: '大额医疗',
                dataIndex: 'companyLargeScaleMedicalInsurance',
                key: 'companyLargeScaleMedicalInsurance',
                width: 90,
                align: 'center',
              },
              {
                title: '住房公积金',
                dataIndex: 'companyProvidentFundInsurance',
                key: 'companyProvidentFundInsurance',
                width: 90,
                align: 'center',
              },
              {
                title: '合计',
                dataIndex: 'companyTotal',
                key: 'companyTotal',
                width: 100,
                align: 'center',
              },
            ]
          },
          {
            title: '操作',
            key: 'action',
            width: 80,
            fixed: 'right',
            align: 'center',
          }
        ]);
        
        const [registerModal, { openModal }] = useModal();
        const [registerAttendanceModal, { openModal: openAttendanceModal }] = useModal();
        const [registerAttendanceEditModal, { openModal: openAttendanceEditModal }] = useModal();
        const [registerInsuranceModal, { openModal: openInsuranceModal }] = useModal();
        
        // 加载日历配置数据
        async function loadCalendarData() {
          try {
            const res = await getPersonnelConfigList({
              settingType: [60],
              settingValue: selectedYear.value
            });
            if (res && res.items) {
              calendarData.value = res.items.sort((a,b) =>{
                return a.month - b.month;
              });
            }
          } catch (error) {
            console.error('加载日历配置数据失败:', error);
          }
        }
        
        // 加载考勤配置数据
        async function loadAttendanceData() {
          try {
            const res = await getPersonnelConfigList({
              settingType: [61, 62, 63, 64],
              settingValue: selectedYear.value
            });
            console.log('API返回原始考勤数据:', res);
            if (res && res.items) {
              attendanceData.value = res.items;
              console.log('处理后的考勤数据:', attendanceData.value);
              // 检查每条记录的关键字段
              attendanceData.value.forEach((item, index) => {
                console.log(`考勤数据项 ${index}:`, {
                  id: item.id,
                  month: item.month,
                  settingType: item.settingType,
                  workDays: item.workDays,
                  salaryDays: item.salaryDays
                });
              });
              // 更新固定考勤类型数据
              processAttendanceTypeData();
            }
          } catch (error) {
            console.error('加载考勤配置数据失败:', error);
          }
        }
        
        // 处理考勤数据,按类型整理
        function processAttendanceTypeData() {
          const data = attendanceData.value;
          console.log('考勤数据5:', data);
          // 更新考勤类型的显示名称,添加年份
          attendanceTypes.value.forEach(type => {
            type.typeDisplayName = `${type.typeName}(${selectedYear.value})`;
            
            // 重置月份数据 - 不设置初始值,让未配置的月份保持为空
            for (let i = 1; i <= 12; i++) {
              type[`month${i}WorkDays`] = undefined;
              type[`month${i}SalaryDays`] = undefined;
              // 存储原始数据记录,用于编辑
              type[`month${i}Record`] = undefined;
            }
          });
          
          // 将数据分配到不同考勤类型
          data.forEach(item => {
            try {
              // 确保relationName存在且可转换为数字
              if (!item.month) return;
              
              const month = parseInt(item.month);
              const settingType = item.settingType;
              
              // 检查并使用workDays和salaryDays字段
              const workDays = item.workDays !== undefined ? item.workDays : undefined;
              const salaryDays = item.salaryDays !== undefined ? item.salaryDays : undefined;
              
              if (month >= 1 && month <= 12) {
                let targetType;
                
                // 根据settingType确定目标考勤类型
                if (settingType === 61) {
                  targetType = attendanceTypes.value[0]; // 9小时双休
                } else if (settingType === 62) {
                  targetType = attendanceTypes.value[1]; // 9大小周双休(生产科)
                } else if (settingType === 63) {
                  targetType = attendanceTypes.value[2]; // 8双休
                } else if (settingType === 64) {
                  targetType = attendanceTypes.value[3]; // 8.5大小周
                }
                
                if (targetType) {
                  // 只设置有效值
                  if (workDays !== undefined && workDays !== null) {
                    targetType[`month${month}WorkDays`] = workDays;
                  }
                  
                  if (salaryDays !== undefined && salaryDays !== null) {
                    targetType[`month${month}SalaryDays`] = salaryDays;
                  }
                  
                  // 存储原始记录,用于编辑操作
                  targetType[`month${month}Record`] = {
                    id: item.id,
                    month: month,
                    settingType: settingType,
                    workDays: workDays,
                    salaryDays: salaryDays
                  };
                }
              }
            } catch (e) {
              console.error('处理考勤数据出错:', e, item);
            }
          });
          
          // 调试日志
          console.log('处理后的考勤类型数据:', attendanceTypes.value);
        }
        
        // 加载五险一金配置数据
        async function loadInsuranceData() {
          try {
            const res = await defHttp.post({
              url: '/order/erp/system_setting/query_list',
              params: {
                settingType: [70, 71, 72,73],
                settingValue: selectedYear.value
              }
            });
            
            console.log('五险一金原始数据:', res);
            
            if (res && Array.isArray(res)) {
              console.log('是否执行:', res);
              // 处理返回的数据
              insuranceData.value = res.map(item => {
                console.log('是否执行2', item);
                // 解析relationValue JSON字符串
                let insuranceValues = {};
                
                try {
                  if (item.relationValue) {
                   
                    if (typeof item.relationValue === 'string') {
                      
                      insuranceValues = JSON.parse(item.relationValue);
                    } else if (typeof item.relationValue === 'object') {
                     
                      insuranceValues = item.relationValue;
                    }
                  }
                } catch (e) {
                  console.error('解析五险一金数据失败:', e);
                }
                
                // 合并原始数据和解析后的数据
                return {
                  ...item,
                  ...insuranceValues,
                };
              });
              
              console.log('处理后的五险一金数据:', insuranceData.value);
            }
          } catch (error) {
            console.error('加载五险一金配置数据失败:', error);
          }
        }
        
        // 计算个人承担社保公积金合计
        function calculatePersonalTotal(record) {
          const fields = [
            'personalPensionInsurance',
            'personalPensionMedicalInsurance',
            'personalPensionUnemploymentInsurance',
            'personalPensionLargeScaleMedicalInsurance',
            'personalPensionProvidentFundInsurance'
          ];
          
          let total = 0;
          for (const field of fields) {
            const value = Number(record[field] || 0);
            if (!isNaN(value)) {
              total += value;
            }
          }
          
          return total.toFixed(2);
        }
        
        // 计算公司承担社保公积金合计
        function calculateCompanyTotal(record) {
          const fields = [
            'companyInsurance',
            'companyMedicalInsurance',
            'companyUnemploymentInsurance',
            'companyEmploymentInjuryInsurance',
            'companyMaternityInsurance',
            'companyLargeScaleMedicalInsurance',
            'companyProvidentFundInsurance'
          ];
          
          let total = 0;
          for (const field of fields) {
            const value = Number(record[field] || 0);
            if (!isNaN(value)) {
              total += value;
            }
          }
          
          return total.toFixed(2);
        }
        
        // 加载所有数据
        function loadAllData() {
          console.log('开始加载所有数据...');
          loadCalendarData();
          loadAttendanceData();
          console.log('开始加载五险一金数据...');
          loadInsuranceData();
        }
        
        // 组件挂载后加载数据
        onMounted(() => {
          console.log('组件挂载,开始加载数据...');
          loadAllData();
        });
        // 处理年份变更
        function handleYearChange() {
          loadAllData();
        }
        
        // 处理标签页切换
        function handleTabChange(key: string) {
          console.log('标签页切换到:', key);
          
          // 如果切换到五险一金标签页,确保数据已加载
          if (key === 'fiveInsurances') {
            loadInsuranceData();
          }
        }
        function handleCreate(settingType: number) {
          openModal(true, {
            isUpdate: false,
            year: selectedYear.value,
            settingType: settingType,
          });
        }
        function handleEdit(record: PersonnelConfig) {
          openModal(true, {
            record,
            isUpdate: true,
          });
        }
        async function handleDelete(record: PersonnelConfig) {
          try {
            await deletePersonnelConfig({ids:[record.id]});
            createMessage.success('删除成功');
            // 重新加载数据
            loadAllData();
          } catch (error) {
            console.error('删除失败:', error);
          }
        }
        function handleSuccess() {
          // 重新加载数据
          loadAllData();
        }
        // 编辑考勤类型数据
        function handleEditAttendanceType(record: AttendanceType) {
          const settingTypeMap = {
            'type-1': 61, // 9小时双休
            'type-2': 62, // 9大小周双休(生产科)
            'type-3': 63, // 8双休
            'type-4': 64, // 8.5大小周
          };
          
          const settingType = settingTypeMap[record.key as keyof typeof settingTypeMap];
          
          if (settingType) {
            // 打开编辑模态框
            openAttendanceEditModal(true, {
              isUpdate: true,
              year: selectedYear.value,
              settingType: settingType,
              attendanceTypeName: record.typeName,
            });
          }
        }
        
        // 编辑考勤类型的月份数据
        function handleEditMonth(record: AttendanceType, month: number) {
          const settingTypeMap = {
            'type-1': 61, // 9小时双休
            'type-2': 62, // 9大小周双休(生产科)
            'type-3': 63, // 8双休
            'type-4': 64, // 8.5大小周
          };
          
          const settingType = settingTypeMap[record.key as keyof typeof settingTypeMap];
          const monthRecord = record[`month${month}Record`];
          
          if (settingType) {
            openAttendanceEditModal(true, {
              isUpdate: true,
              year: selectedYear.value,
              settingType: settingType,
              attendanceTypeName: record.typeName,
              record: monthRecord || {
                month: month,
                workDays: record[`month${month}WorkDays`],
                salaryDays: record[`month${month}SalaryDays`]
              }
            });
          }
        }
        function handleAddAttendance() {
          openAttendanceModal(true, {
            year: selectedYear.value,
          });
        }
        // 处理点击月份单元格
        function handleEditMonthCell(record: AttendanceType, key: string) {
          // 解析月份
          const monthMatch = key.match(/month(\d+)/);
          if (monthMatch && monthMatch[1]) {
            const month = parseInt(monthMatch[1]);
            handleEditMonth(record, month);
          }
        }
        // 处理新增五险一金配置
        function handleAddInsurance() {
          openInsuranceModal(true, {
            isUpdate: false,
            year: selectedYear.value,
          });
        }
        
        // 处理编辑五险一金配置
        function handleEditInsurance(record) {
          openInsuranceModal(true, {
            isUpdate: true,
            year: selectedYear.value,
            record,
          });
        }
        // 检查是否为五险一金金额列
        function isInsuranceAmountColumn(dataIndex: string) {
          const amountColumns = [
            'personalPensionInsurance',
            'personalPensionMedicalInsurance',
            'personalPensionUnemploymentInsurance',
            'personalPensionLargeScaleMedicalInsurance',
            'personalPensionProvidentFundInsurance',
            'companyInsurance',
            'companyMedicalInsurance',
            'companyUnemploymentInsurance',
            'companyEmploymentInjuryInsurance',
            'companyMaternityInsurance',
            'companyLargeScaleMedicalInsurance',
            'companyProvidentFundInsurance'
          ];
          return amountColumns.includes(dataIndex);
        }
        
        // 格式化金额,保留两位小数
        function formatAmount(amount) {
          if (amount === undefined || amount === null) return '0.00';
          return Number(amount).toFixed(2);
        }
        return {
          calendarColumns,
          attendanceColumns,
          insuranceColumns,
          calendarData,
          attendanceData,
          insuranceData,
          attendanceTypes,
          registerModal,
          registerAttendanceModal,
          registerAttendanceEditModal,
          registerInsuranceModal,
          yearOptions,
          selectedYear,
          activeTabKey,
          handleYearChange,
          handleTabChange,
          handleCreate,
          handleEdit,
          handleEditAttendanceType,
          handleEditMonth,
          handleEditMonthCell,
          handleDelete,
          handleSuccess,
          handleAddAttendance,
          handleAddInsurance,
          handleEditInsurance,
          calculatePersonalTotal,
          calculateCompanyTotal,
          isInsuranceAmountColumn,
          formatAmount,
        };
      },
    });
  </script>
  <style lang="less" scoped>
  .year-tabs {
    margin-bottom: 16px;
    border-bottom: 1px solid #f0f0f0;
    padding-bottom: 12px;
    
    .ant-radio-button-wrapper {
      min-width: 90px;
      text-align: center;
    }
  }
  .config-section {
    background-color: #fff;
    padding: 16px;
    border-radius: 2px;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.05);
  }
  .config-card {
    width: 100%;
  }
  .table-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
    
    .title {
      font-size: 16px;
      font-weight: bold;
    }
  }
  .ant-table-wrapper {
    margin-bottom: 20px;
  }
  .mb-4 {
    margin-bottom: 16px;
  }
  .mt-4 {
    margin-top: 16px;
  }
  .ant-table {
    .ant-table-thead > tr > th {
      text-align: center;
      padding: 8px 4px;
    }
    
    .ant-table-tbody > tr > td {
      text-align: center;
      padding: 8px 4px;
    }
  }
  .attendance-type-name {
    color: #ff4d4f;
    font-weight: 500;
  }
  .insurance-type-name {
    color: #1890ff;
    font-weight: 500;
  }
  .total-cell {
    color: #ff4d4f;
    font-weight: bold;
  }
  .editable-cell {
    cursor: pointer;
    padding: 4px;
    border-radius: 2px;
    
    &:hover {
      background-color: #f5f5f5;
      color: #1890ff;
      text-decoration: underline;
    }
  }
  </style>