tech-general-managers.vue 30.9 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
<template>
  <div class="app-container">
    <!-- 页面头部 -->
    <div class="page-header">
      <div class="header-left">
        <h2>科技部总经理工资</h2>
        <p class="page-desc">管理科技部总经理工资数据,包括溯源金额、Cell金额、提成、补贴、扣款等信息</p>
      </div>
      <div class="header-right">
        <el-button 
          type="success" 
          icon="el-icon-download"
          @click="handleExport"
          :loading="exportLoading"
        >
          导出
        </el-button>
        <el-button 
          type="primary" 
          icon="el-icon-cpu"
          @click="showCalculateDialog"
          :loading="calculateLoading"
        >
          计算工资
        </el-button>
        <el-button 
          icon="el-icon-refresh" 
          @click="getList"
          :loading="loading"
        >
          刷新
        </el-button>
      </div>
    </div>

    <!-- 搜索区域 -->
    <div class="search-container">
      <el-form :model="queryParams" ref="queryForm" :inline="true" label-width="50px">
        <el-form-item label="月份" prop="month">
          <el-date-picker
            v-model="queryParams.month"
            type="month"
            placeholder="选择月份"
            format="yyyyMM"
            value-format="yyyyMM"
            style="width: 200px"
          />
        </el-form-item>
        <el-form-item label="岗位" prop="position">
          <el-select 
            v-model="queryParams.position" 
            placeholder="请选择岗位"
            clearable
            filterable
            style="width: 200px"
          >
            <el-option label="全部" :value="''" />
            <el-option label="科技一部" value="科技一部" />
            <el-option label="科技二部" value="科技二部" />
          </el-select>
        </el-form-item>
        <!-- <el-form-item label="关键词" prop="keyword">
          <el-input
            v-model="queryParams.keyword"
            placeholder="员工姓名/账号"
            clearable
            style="width: 200px"
          />
        </el-form-item> -->
        <el-form-item>
          <el-button type="primary" icon="el-icon-search" @click="handleQuery">搜索</el-button>
          <el-button icon="el-icon-refresh" @click="resetQuery">重置</el-button>
        </el-form-item>
      </el-form>
    </div>

    <!-- 数据表格 -->
    <div class="table-container">
      <NCC-table 
        v-loading="loading" 
        :data="list" 
        border 
        stripe
        height="calc(100vh - 420px)"
        :header-cell-style="{ background: '#f5f7fa', color: '#606266' }"
      >
        <!-- 基本信息 -->
        <el-table-column prop="EmployeeName" label="员工姓名" width="120" align="center" fixed="left">
          <template slot-scope="scope">
            <div class="employee-name">
              <i class="el-icon-user employee-icon"></i>
              <span>{{ scope.row.EmployeeName || '无' }}</span>
            </div>
          </template>
        </el-table-column>
        <el-table-column prop="Position" label="岗位" width="120" align="center" fixed="left">
          <template slot-scope="scope">
            <span>{{ scope.row.Position || '无' }}</span>
          </template>
        </el-table-column>
        <el-table-column prop="EmployeeAccount" label="员工账号" width="120" align="center" fixed="left">
          <template slot-scope="scope">
            <span>{{ scope.row.EmployeeAccount || '无' }}</span>
          </template>
        </el-table-column>

        <!-- 业绩信息 -->
        <el-table-column label="业绩信息" align="center">
          <el-table-column prop="TraceabilityAmount" label="溯源金额" width="120" align="center">
            <template slot-scope="scope">
              <span>{{ formatMoney(scope.row.TraceabilityAmount) }}</span>
            </template>
          </el-table-column>
          <el-table-column prop="CellAmount" label="Cell金额" width="120" align="center">
            <template slot-scope="scope">
              <span>{{ formatMoney(scope.row.CellAmount) }}</span>
            </template>
          </el-table-column>
        </el-table-column>

        <!-- 提成信息 -->
        <el-table-column label="提成信息" align="center">
          <el-table-column prop="TraceabilityCommissionRate" label="溯源金额提成比例" width="160" align="center">
            <template slot-scope="scope">
              <span>{{ formatPercent(scope.row.TraceabilityCommissionRate) }}</span>
            </template>
          </el-table-column>
          <el-table-column prop="TraceabilityCommissionAmount" label="溯源金额提成金额" width="160" align="center">
            <template slot-scope="scope">
              <span>{{ formatMoney(scope.row.TraceabilityCommissionAmount) }}</span>
            </template>
          </el-table-column>
          <el-table-column prop="CellCommissionRate" label="Cell金额提成比例" width="160" align="center">
            <template slot-scope="scope">
              <span>{{ formatPercent(scope.row.CellCommissionRate) }}</span>
            </template>
          </el-table-column>
          <el-table-column prop="CellCommissionAmount" label="Cell金额提成金额" width="160" align="center">
            <template slot-scope="scope">
              <span>{{ formatMoney(scope.row.CellCommissionAmount) }}</span>
            </template>
          </el-table-column>
          <el-table-column prop="TotalCommission" label="提成合计" width="120" align="center">
            <template slot-scope="scope">
              <span>{{ formatMoney(scope.row.TotalCommission) }}</span>
            </template>
          </el-table-column>
        </el-table-column>

        <!-- 工资信息 -->
        <el-table-column label="工资信息" align="center">
          <el-table-column prop="BaseSalary" label="底薪" width="120" align="center">
            <template slot-scope="scope">
              <span>{{ formatMoney(scope.row.BaseSalary) }}</span>
            </template>
          </el-table-column>
          <el-table-column prop="WorkingDays" label="在店天数" width="100" align="center">
            <template slot-scope="scope">
              <span>{{ scope.row.WorkingDays || '0' }}</span>
            </template>
          </el-table-column>
          <el-table-column prop="LeaveDays" label="请假天数" width="100" align="center">
            <template slot-scope="scope">
              <span>{{ scope.row.LeaveDays || '0' }}</span>
            </template>
          </el-table-column>
          <el-table-column prop="CalculatedGrossSalary" label="核算应发工资" width="140" align="center">
            <template slot-scope="scope">
              <span>{{ formatMoney(scope.row.CalculatedGrossSalary) }}</span>
            </template>
          </el-table-column>
          <el-table-column prop="FinalGrossSalary" label="最终应发工资" width="140" align="center">
            <template slot-scope="scope">
              <span>{{ formatMoney(scope.row.FinalGrossSalary) }}</span>
            </template>
          </el-table-column>
        </el-table-column>

        <!-- 补贴信息 -->
        <el-table-column label="补贴信息" align="center">
          <el-table-column prop="MonthlyTrainingSubsidy" label="当月培训补贴" width="140" align="center">
            <template slot-scope="scope">
              <span>{{ formatMoney(scope.row.MonthlyTrainingSubsidy) }}</span>
            </template>
          </el-table-column>
          <el-table-column prop="MonthlyTransportSubsidy" label="当月交通补贴" width="140" align="center">
            <template slot-scope="scope">
              <span>{{ formatMoney(scope.row.MonthlyTransportSubsidy) }}</span>
            </template>
          </el-table-column>
          <el-table-column prop="LastMonthTrainingSubsidy" label="上月培训补贴" width="140" align="center">
            <template slot-scope="scope">
              <span>{{ formatMoney(scope.row.LastMonthTrainingSubsidy) }}</span>
            </template>
          </el-table-column>
          <el-table-column prop="LastMonthTransportSubsidy" label="上月交通补贴" width="140" align="center">
            <template slot-scope="scope">
              <span>{{ formatMoney(scope.row.LastMonthTransportSubsidy) }}</span>
            </template>
          </el-table-column>
          <el-table-column prop="TotalSubsidy" label="补贴合计" width="120" align="center">
            <template slot-scope="scope">
              <span>{{ formatMoney(scope.row.TotalSubsidy) }}</span>
            </template>
          </el-table-column>
        </el-table-column>

        <!-- 扣款信息 -->
        <el-table-column label="扣款信息" align="center">
          <el-table-column prop="MissingCard" label="缺卡扣款" width="120" align="center">
            <template slot-scope="scope">
              <span>{{ formatMoney(scope.row.MissingCard) }}</span>
            </template>
          </el-table-column>
          <el-table-column prop="LateArrival" label="迟到扣款" width="120" align="center">
            <template slot-scope="scope">
              <span>{{ formatMoney(scope.row.LateArrival) }}</span>
            </template>
          </el-table-column>
          <el-table-column prop="LeaveDeduction" label="请假扣款" width="120" align="center">
            <template slot-scope="scope">
              <span>{{ formatMoney(scope.row.LeaveDeduction) }}</span>
            </template>
          </el-table-column>
          <el-table-column prop="SocialInsuranceDeduction" label="扣社保" width="120" align="center">
            <template slot-scope="scope">
              <span>{{ formatMoney(scope.row.SocialInsuranceDeduction) }}</span>
            </template>
          </el-table-column>
          <el-table-column prop="RewardDeduction" label="扣除奖励" width="120" align="center">
            <template slot-scope="scope">
              <span>{{ formatMoney(scope.row.RewardDeduction) }}</span>
            </template>
          </el-table-column>
          <el-table-column prop="AccommodationDeduction" label="扣住宿费" width="120" align="center">
            <template slot-scope="scope">
              <span>{{ formatMoney(scope.row.AccommodationDeduction) }}</span>
            </template>
          </el-table-column>
          <el-table-column prop="StudyPeriodDeduction" label="扣学习期费用" width="140" align="center">
            <template slot-scope="scope">
              <span>{{ formatMoney(scope.row.StudyPeriodDeduction) }}</span>
            </template>
          </el-table-column>
          <el-table-column prop="WorkClothesDeduction" label="扣工作服费用" width="140" align="center">
            <template slot-scope="scope">
              <span>{{ formatMoney(scope.row.WorkClothesDeduction) }}</span>
            </template>
          </el-table-column>
          <el-table-column prop="TotalDeduction" label="扣款合计" width="120" align="center">
            <template slot-scope="scope">
              <span>{{ formatMoney(scope.row.TotalDeduction) }}</span>
            </template>
          </el-table-column>
        </el-table-column>

        <!-- 其他信息 -->
        <el-table-column label="其他信息" align="center">
          <el-table-column prop="Bonus" label="发奖金" width="100" align="center">
            <template slot-scope="scope">
              <span>{{ formatMoney(scope.row.Bonus) }}</span>
            </template>
          </el-table-column>
          <el-table-column prop="ReturnPhoneDeposit" label="退手机押金" width="120" align="center">
            <template slot-scope="scope">
              <span>{{ formatMoney(scope.row.ReturnPhoneDeposit) }}</span>
            </template>
          </el-table-column>
          <el-table-column prop="ReturnAccommodationDeposit" label="退住宿押金" width="120" align="center">
            <template slot-scope="scope">
              <span>{{ formatMoney(scope.row.ReturnAccommodationDeposit) }}</span>
            </template>
          </el-table-column>
          <el-table-column prop="LastMonthSupplement" label="补发上月" width="120" align="center">
            <template slot-scope="scope">
              <span>{{ formatMoney(scope.row.LastMonthSupplement) }}</span>
            </template>
          </el-table-column>
        </el-table-column>

        <!-- 支付信息 -->
        <el-table-column label="支付信息" align="center">
          <el-table-column prop="ActualSalary" label="实发工资" width="120" align="center">
            <template slot-scope="scope">
              <span>{{ formatMoney(scope.row.ActualSalary) }}</span>
            </template>
          </el-table-column>
          <el-table-column prop="MonthlyPaymentStatus" label="当月是否发放" width="140" align="center">
            <template slot-scope="scope">
              <span>{{ scope.row.MonthlyPaymentStatus || '无' }}</span>
            </template>
          </el-table-column>
          <el-table-column prop="PaidAmount" label="支付金额" width="120" align="center">
            <template slot-scope="scope">
              <span>{{ formatMoney(scope.row.PaidAmount) }}</span>
            </template>
          </el-table-column>
          <el-table-column prop="PendingAmount" label="待支付金额" width="120" align="center">
            <template slot-scope="scope">
              <span>{{ formatMoney(scope.row.PendingAmount) }}</span>
            </template>
          </el-table-column>
          <el-table-column prop="MonthlyTotalPayment" label="当月支付总额" width="140" align="center">
            <template slot-scope="scope">
              <span>{{ formatMoney(scope.row.MonthlyTotalPayment) }}</span>
            </template>
          </el-table-column>
        </el-table-column>

        <!-- 操作列 -->
        <el-table-column label="操作" width="200" align="center" fixed="right">
          <template slot-scope="scope">
            <el-button 
              type="text" 
              size="mini"
              icon="el-icon-view"
              @click="showDetail(scope.row)"
            >
              查看详情
            </el-button>
            <el-button 
              type="text" 
              size="mini"
              icon="el-icon-document"
              @click="showStoreDetail(scope.row)"
              v-if="scope.row.StoreDetail"
              style="margin-left: 8px;"
            >
              门店明细
            </el-button>
          </template>
        </el-table-column>
      </NCC-table>
    </div>

    <!-- 计算工资弹窗 -->
    <el-dialog
      title="计算科技部总经理工资"
      :visible="calculateDialogVisible"
      width="500px"
      :close-on-click-modal="false"
      @close="handleCalculateDialogClose"
    >
      <el-form label-width="100px" label-position="right">
        <el-form-item label="选择年份" required>
          <el-date-picker
            v-model="calculateYear"
            type="year"
            placeholder="请选择年份"
            format="yyyy"
            value-format="yyyy"
            style="width: 100%"
          />
        </el-form-item>
        <el-form-item label="选择月份" required>
          <el-date-picker
            v-model="calculateMonth"
            type="month"
            placeholder="请选择月份"
            format="yyyyMM"
            value-format="yyyyMM"
            style="width: 100%"
          />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="handleCalculateDialogClose">取消</el-button>
        <el-button 
          type="primary" 
          @click="handleCalculateConfirm"
          :loading="calculateLoading"
        >
          确定
        </el-button>
      </div>
    </el-dialog>

    <!-- 详情弹窗 -->
    <tech-general-manager-detail-dialog
      :visible="detailVisible"
      :detail-data="currentDetailData"
      @close="handleDetailClose"
    />

    <!-- 门店明细弹窗 -->
    <el-dialog
      title="门店明细"
      :visible="storeDetailVisible"
      width="1400px"
      @close="handleStoreDetailClose"
    >
      <el-table :data="storeDetailList" border stripe max-height="500">
        <el-table-column prop="StoreName" label="门店名称" width="150" align="center" fixed="left" />
        <el-table-column label="溯源金额信息" align="center">
            <el-table-column prop="TraceabilityBillingAmount" label="溯源开单金额"  align="center">
                <template slot-scope="scope">
                    <span>{{ formatMoney(scope.row.TraceabilityBillingAmount) }}</span>
                </template>
            </el-table-column>
            <el-table-column prop="TraceabilityRefundAmount" label="溯源退卡金额" align="center">
                <template slot-scope="scope">
                    <span>{{ formatMoney(scope.row.TraceabilityRefundAmount) }}</span>
                </template>
            </el-table-column>
            <el-table-column prop="TraceabilityAmount" label="溯源金额"  align="center">
                <template slot-scope="scope">
                <span>{{ formatMoney(scope.row.TraceabilityAmount) }}</span>
                </template>
            </el-table-column>
        </el-table-column>
        <el-table-column label="Cell金额信息" align="center">
          <el-table-column prop="CellBillingAmount" label="Cell开单金额"  align="center">
            <template slot-scope="scope">
              <span>{{ formatMoney(scope.row.CellBillingAmount) }}</span>
            </template>
          </el-table-column>
          <el-table-column prop="CellRefundAmount" label="Cell退卡金额" align="center">
            <template slot-scope="scope">
              <span>{{ formatMoney(scope.row.CellRefundAmount) }}</span>
            </template>
          </el-table-column>
          <el-table-column prop="CellAmount" label="Cell金额" align="center">
            <template slot-scope="scope">
              <span>{{ formatMoney(scope.row.CellAmount) }}</span>
            </template>
          </el-table-column>
        </el-table-column>
      </el-table>
      <div slot="footer" class="dialog-footer">
        <el-button @click="handleStoreDetailClose">关闭</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { getTechGeneralManagerSalaryList, calculateTechGeneralManagerSalary } from '@/api/extend/techGeneralManagerSalary'
import TechGeneralManagerDetailDialog from './tech-general-manager-detail-dialog.vue'

export default {
  name: 'TechGeneralManagerSalary',
  components: {
    TechGeneralManagerDetailDialog
  },
  data() {
    // 获取当前年月
    const getCurrentYear = () => {
      return new Date().getFullYear().toString()
    }
    const getCurrentMonth = () => {
      const now = new Date()
      const year = now.getFullYear()
      const month = String(now.getMonth() + 1).padStart(2, '0')
      return `${year}${month}`
    }

    return {
      loading: false,
      calculateLoading: false,
      exportLoading: false,
      list: [],
      total: 0,
      calculateDialogVisible: false,
      calculateYear: getCurrentYear(),
      calculateMonth: getCurrentMonth(),
      detailVisible: false,
      currentDetailData: null,
      storeDetailVisible: false,
      storeDetailList: [],
      queryParams: {
        currentPage: 1,
        pageSize: 300, // 写死为300
        year: getCurrentYear(),
        month: getCurrentMonth(), // yyyyMM 格式
        position: '',
        keyword: ''
      }
    }
  },
  created() {
    this.getList()
  },
  methods: {
    // 获取列表数据
    async getList() {
      this.loading = true
      try {
        // 处理年月:从month选择器中提取年份和月份
        let year = ''
        let month = ''
        
        if (this.queryParams.month && this.queryParams.month.length === 6) {
          // yyyyMM 格式,如 202512
          year = this.queryParams.month.substring(0, 4)
          month = this.queryParams.month.substring(4, 6)
        } else if (this.queryParams.year && this.queryParams.month) {
          // 分别选择年份和月份
          year = this.queryParams.year
          month = this.queryParams.month.length === 6 
            ? this.queryParams.month.substring(4, 6) 
            : this.queryParams.month
        } else {
          // 使用默认值(当前年月)
          const now = new Date()
          year = now.getFullYear().toString()
          month = String(now.getMonth() + 1).padStart(2, '0')
        }

        const params = {
          currentPage: this.queryParams.currentPage,
          pageSize: this.queryParams.pageSize,
          Year: parseInt(year),
          Month: parseInt(month),
          Position: this.queryParams.position || undefined,
          Keyword: this.queryParams.keyword || ''
        }

        const response = await getTechGeneralManagerSalaryList(params)

        if (response.code === 200) {
          this.list = response.data.list || []
          this.total = (response.data.pagination && response.data.pagination.total) || 0
        } else {
          this.$message.error(response.msg || '获取数据失败')
        }
      } catch (error) {
        console.error('获取科技部总经理工资列表失败:', error)
        this.$message.error('获取数据失败' + error)
      } finally {
        this.loading = false
      }
    },

    // 搜索
    handleQuery() {
      this.queryParams.currentPage = 1
      this.getList()
    },

    // 重置搜索
    resetQuery() {
      const getCurrentYear = () => {
        return new Date().getFullYear().toString()
      }
      const getCurrentMonth = () => {
        const now = new Date()
        const year = now.getFullYear()
        const month = String(now.getMonth() + 1).padStart(2, '0')
        return `${year}${month}`
      }

      this.queryParams = {
        currentPage: 1,
        pageSize: 300, // 写死为300
        year: getCurrentYear(),
        month: getCurrentMonth(),
        position: '',
        keyword: ''
      }
      this.getList()
    },

    // 显示计算工资弹窗
    showCalculateDialog() {
      const getCurrentYear = () => {
        return new Date().getFullYear().toString()
      }
      const getCurrentMonth = () => {
        const now = new Date()
        const year = now.getFullYear()
        const month = String(now.getMonth() + 1).padStart(2, '0')
        return `${year}${month}`
      }
      this.calculateYear = getCurrentYear()
      this.calculateMonth = getCurrentMonth()
      this.calculateDialogVisible = true
    },

    // 关闭计算工资弹窗
    handleCalculateDialogClose() {
      this.calculateDialogVisible = false
    },

    // 确认计算工资
    async handleCalculateConfirm() {
      if (!this.calculateYear || !this.calculateMonth) {
        this.$message.warning('请选择年份和月份')
        return
      }

      // 从calculateMonth中提取月份(yyyyMM格式,如202512)
      const year = parseInt(this.calculateYear)
      const month = this.calculateMonth.length === 6 
        ? parseInt(this.calculateMonth.substring(4, 6)) 
        : parseInt(this.calculateMonth)

      this.calculateLoading = true
      try {
        const response = await calculateTechGeneralManagerSalary(year, month)
        if (response.code === 200) {
          this.$message.success('计算工资成功')
          this.calculateDialogVisible = false
          this.getList()
        } else {
          this.$message.error(response.msg || '计算工资失败')
        }
      } catch (error) {
        console.error('计算工资失败:', error)
        this.$message.error(error.message || '计算工资失败')
      } finally {
        this.calculateLoading = false
      }
    },

    // 显示门店明细
    showStoreDetail(row) {
      try {
        if (row.StoreDetail) {
          const detail = JSON.parse(row.StoreDetail)
          // 确保是数组格式
          this.storeDetailList = Array.isArray(detail) ? detail : []
          this.storeDetailVisible = true
        } else {
          this.$message.info('暂无门店明细')
        }
      } catch (error) {
        console.error('解析门店明细失败:', error)
        this.$message.error('门店明细格式错误')
      }
    },

    // 关闭门店明细弹窗
    handleStoreDetailClose() {
      this.storeDetailVisible = false
      this.storeDetailList = []
    },

    // 显示详情
    showDetail(row) {
      this.currentDetailData = row
      this.detailVisible = true
    },

    // 关闭详情弹窗
    handleDetailClose() {
      this.detailVisible = false
      this.currentDetailData = null
    },

    // 导出功能
    async handleExport() {
      if (!this.list || this.list.length === 0) {
        this.$message.warning('暂无数据可导出')
        return
      }

      this.exportLoading = true
      try {
        // 动态导入 xlsx 库
        const XLSX = await import('xlsx')

        // 构建表头(根据后端DTO字段的中文映射)
        const headers = [
          '员工姓名',
          '员工账号',
          '核算岗位',
          '统计月份',
          '是否离职',
          '溯源金额',
          'Cell金额',
          '底薪',
          '溯源金额提成比例',
          '溯源金额提成金额',
          'Cell金额提成比例',
          'Cell金额提成金额',
          '提成合计',
          '在店天数',
          '请假天数',
          '核算应发工资',
          '最终应发工资',
          '当月培训补贴',
          '当月交通补贴',
          '上月培训补贴',
          '上月交通补贴',
          '补贴合计',
          '缺卡扣款',
          '迟到扣款',
          '请假扣款',
          '扣社保',
          '扣除奖励',
          '扣住宿费',
          '扣学习期费用',
          '扣工作服费用',
          '扣款合计',
          '发奖金',
          '退手机押金',
          '退住宿押金',
          '补发上月',
          '实发工资',
          '当月是否发放',
          '支付金额',
          '待支付金额',
          '当月支付总额',
          '是否锁定'
        ]

        // 构建数据行
        const dataRows = this.list.map(item => [
          item.EmployeeName || '无',
          item.EmployeeAccount || '无',
          item.Position || '无',
          item.StatisticsMonth || '无',
          item.IsTerminated === 1 ? '已离职' : '在职',
          this.formatMoney(item.TraceabilityAmount),
          this.formatMoney(item.CellAmount),
          this.formatMoney(item.BaseSalary),
          this.formatPercent(item.TraceabilityCommissionRate),
          this.formatMoney(item.TraceabilityCommissionAmount),
          this.formatPercent(item.CellCommissionRate),
          this.formatMoney(item.CellCommissionAmount),
          this.formatMoney(item.TotalCommission),
          item.WorkingDays || '0',
          item.LeaveDays || '0',
          this.formatMoney(item.CalculatedGrossSalary),
          this.formatMoney(item.FinalGrossSalary),
          this.formatMoney(item.MonthlyTrainingSubsidy),
          this.formatMoney(item.MonthlyTransportSubsidy),
          this.formatMoney(item.LastMonthTrainingSubsidy),
          this.formatMoney(item.LastMonthTransportSubsidy),
          this.formatMoney(item.TotalSubsidy),
          this.formatMoney(item.MissingCard),
          this.formatMoney(item.LateArrival),
          this.formatMoney(item.LeaveDeduction),
          this.formatMoney(item.SocialInsuranceDeduction),
          this.formatMoney(item.RewardDeduction),
          this.formatMoney(item.AccommodationDeduction),
          this.formatMoney(item.StudyPeriodDeduction),
          this.formatMoney(item.WorkClothesDeduction),
          this.formatMoney(item.TotalDeduction),
          this.formatMoney(item.Bonus),
          this.formatMoney(item.ReturnPhoneDeposit),
          this.formatMoney(item.ReturnAccommodationDeposit),
          this.formatMoney(item.LastMonthSupplement),
          this.formatMoney(item.ActualSalary),
          item.MonthlyPaymentStatus || '无',
          this.formatMoney(item.PaidAmount),
          this.formatMoney(item.PendingAmount),
          this.formatMoney(item.MonthlyTotalPayment),
          item.IsLocked === 1 ? '已锁定' : '未锁定'
        ])

        // 合并表头和数据
        const excelData = [headers, ...dataRows]

        // 创建工作表
        const ws = XLSX.utils.aoa_to_sheet(excelData)

        // 设置列宽
        const colWidths = headers.map(() => ({ wch: 15 }))
        ws['!cols'] = colWidths

        // 创建工作簿
        const wb = XLSX.utils.book_new()
        XLSX.utils.book_append_sheet(wb, ws, '科技部总经理工资')

        // 生成文件名
        const now = new Date()
        const timestamp = now.getFullYear() + 
          String(now.getMonth() + 1).padStart(2, '0') + 
          String(now.getDate()).padStart(2, '0') + 
          String(now.getHours()).padStart(2, '0') + 
          String(now.getMinutes()).padStart(2, '0') + 
          String(now.getSeconds()).padStart(2, '0')
        const fileName = `科技部总经理工资_${timestamp}.xlsx`

        // 导出文件
        XLSX.writeFile(wb, fileName)

        this.$message.success('导出成功')
      } catch (error) {
        console.error('导出失败:', error)
        this.$message.error('导出失败,请重试')
      } finally {
        this.exportLoading = false
      }
    },

    // 格式化金额
    formatMoney(value) {
      if (value === null || value === undefined || value === '') {
        return '0.00'
      }
      return Number(value).toFixed(2)
    },

    // 格式化百分比
    formatPercent(value) {
      if (value === null || value === undefined || value === '') {
        return '0.00%'
      }
      return (Number(value) * 100).toFixed(2) + '%'
    }
  }
}
</script>

<style lang="scss" scoped>
.app-container {
  padding: 20px;
  background: #f5f5f5;
}

.page-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 20px;
  padding: 20px;
  background: #fff;
  border-radius: 8px;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);

  .header-left {
    h2 {
      margin: 0 0 8px 0;
      color: #303133;
      font-size: 20px;
      font-weight: 600;
    }

    .page-desc {
      margin: 0;
      color: #909399;
      font-size: 14px;
    }
  }

  .header-right {
    display: flex;
    gap: 12px;
  }
}

.search-container {
  margin-bottom: 20px;
  padding: 20px;
  background: #fff;
  border-radius: 8px;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.table-container {
  margin-bottom: 20px;
  padding: 20px;
  background: #fff;
  border-radius: 8px;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.employee-name {
  display: flex;
  align-items: center;
  gap: 6px;

  .employee-icon {
    color: #409EFF;
    font-size: 16px;
  }
}

// 表格样式优化
::v-deep .el-table {
  .el-table__header-wrapper {
    th {
      background-color: #f5f7fa;
      color: #606266;
      font-weight: 600;
    }
  }

  .el-table__body-wrapper {
    .el-table__row {
      &:hover {
        background-color: #f5f7fa;
      }
    }
  }
}
</style>