<template>
  <!-- 添加或修改菜单对话框 -->
  <el-dialog
    title="工资信息"
    v-model="visible"
    width="800px"
    append-to-body
    draggable
    :close-on-click-modal = "false"
  >
    <div style="padding: 8px 24px 16px 24px">
      <el-form size="small" label-width="50px">
        <el-row :gutter="30">
          <el-col :span="24">
            <el-table
              ref="dbTable"
              :data="detailList"
              size="small"
              border
              max-height="400"
              header-row-class-name="list-header-row"
              row-class-name="list-row"
              show-summary
              :summary-method="getSummaries"
            >
              <el-table-column
                type="index"
                label="序号"
                width="50"
                align="center"
              />
              <el-table-column label="员工姓名" width="80" align="center">
                <template #default="scope">
                  <span>{{ scope.row.employeeName }}</span>
                </template>
              </el-table-column>

              <el-table-column label="身份证号" width="150" align="center">
                <template #default="scope">
                  <span>{{ scope.row.idCode }}</span>
                </template>
              </el-table-column>
              <!-- <el-table-column label="发放日期" width="80" align="center">
                <template>
                  <span>{{}}</span>
                </template>
              </el-table-column> -->
              <el-table-column
                label="应发工资"
                width="80"
                header-align="center"
                align="right"
                prop="planSalary"
              >
                <template #default="scope">
                  <span>{{ rowNum(scope.row.planSalary) }}</span>
                </template>
              </el-table-column>
              <el-table-column
                label="实发工资"
                width="80"
                header-align="center"
                align="right"
                prop="actuallySalary"
              >
                <template #default="scope">
                  <span>{{ rowNum(scope.row.actuallySalary) }}</span>
                </template>
              </el-table-column>

              <el-table-column
                label="奖金及其他"
                width="100"
                header-align="center"
                align="right"
                prop="bonusAmount"
              >
                <template #default="scope">
                  <span>{{ rowNum(scope.row.bonusAmount) }}</span>
                </template>
              </el-table-column>
              <el-table-column label="社保" align="center">
                <el-table-column
                  label="养老保险"
                  width="80"
                  header-align="center"
                  align="right"
                  prop="endowmentInsurance"
                >
                  <template #default="scope">
                    <span>{{ rowNum(scope.row.endowmentInsurance) }}</span>
                  </template>
                </el-table-column>
                <el-table-column
                  label="医疗保险"
                  width="80"
                  header-align="center"
                  align="right"
                  prop="medicalInsurance"
                >
                  <template #default="scope">
                    <span>{{ rowNum(scope.row.medicalInsurance) }}</span>
                  </template>
                </el-table-column>
                <el-table-column
                  label="失业险"
                  width="80"
                  header-align="center"
                  align="right"
                  prop="unemploymentBenefit"
                >
                  <template #default="scope">
                    <span>{{ rowNum(scope.row.unemploymentBenefit) }}</span>
                  </template>
                </el-table-column>
                <el-table-column
                  label="大病险"
                  width="80"
                  header-align="center"
                  align="right"
                  prop="seriousIllnessInsurance"
                >
                  <template #default="scope">
                    <span>{{ rowNum(scope.row.seriousIllnessInsurance) }}</span>
                  </template>
                </el-table-column>
              </el-table-column>
              <el-table-column
                label="公积金"
                width="80"
                header-align="center"
                align="right"
                prop="housingFund"
              >
                <template #default="scope">
                  <span>{{ rowNum(scope.row.housingFund) }}</span>
                </template>
              </el-table-column>
              <el-table-column
                label="个税"
                width="60"
                header-align="center"
                align="right"
                prop="currentIndividualIncomeTax"
              >
                <template #default="scope">
                  <span>{{
                    rowNum(scope.row.currentIndividualIncomeTax)
                  }}</span>
                </template>
              </el-table-column>
              <el-table-column
                label="其它扣款"
                width="80"
                header-align="center"
                align="right"
                prop="otherCut"
              >
                <template #default="scope">
                  <span>{{ rowNum(scope.row.otherCut) }}</span>
                </template>
              </el-table-column>
              <el-table-column
                label="备注"
                width="60"
                align="center"
                prop="accidentInsurance"
              >
                <template #default="scope">
                  <span>{{ scope.row.accidentInsurance }}</span>
                </template>
              </el-table-column>
            </el-table>
          </el-col>
          <el-col :span="24">
            <el-form-item label="备注">{{ content }} </el-form-item>
          </el-col>
        </el-row>
      </el-form>
    </div>
  </el-dialog>
</template>


<script setup>
const { proxy } = getCurrentInstance();
import { getSalaryDetail } from "@/api/business/production/detail";
import { rowNum, numberToCurrencyNo } from "@/utils/index";

/** 父组件传参 */
const props = defineProps({
  getList: {
    type: Function,
    default: () => {},
  },
});
const { getList } = toRefs(props);
/** 字典数组区 */
const { develop_type } = proxy.useDict("develop_type");
/** 表单抽屉 页变量 */
const detailList = ref([]);
const title = ref("");
const loading = ref(false);
const multiple = ref(true);
const visible = ref(false);
const editStatus = ref(false);
const content = ref("");
const isFullscreen = ref(false);
const addDetailNum = ref(1);
const currentMember = {};
const provinces = ref(proxy.region.getProvinces());
provinces.value.unshift({ code: "", name: "全部" });
const cities = ref([]);
const districts = ref([]);

const sourceCategories = ref([]);

const addType = ref(1);

watch(addType, (value) => {
  switch (value) {
    case "1":
      break;
    case "2":
      break;
    default:
      break;
  }
});

const webHost = import.meta.env.VITE_APP_BASE_API;

const followQuery = ref({});

/***********************  表单页方法 ****************************/

/** 抽屉打开 */
function open(data) {
  console.log("工资open");
  getSalaryDetail(data).then((response) => {
    if (response.data) {
      detailList.value = response.data.details;
      content.value = response.data.content;
    }
    visible.value = true;
  });
}

function getSummaries(param) {
  const { columns, data } = param;
  const sums = [];
  columns.forEach((column, index) => {
    if (index === 0) {
      sums[index] = "合计";
      return;
    } else if (index === 1) {
      sums[index] = "";
      return;
    }
    const values = data.map((item) => Number(item[column.property]));

    if (!values.every((value) => isNaN(value))) {
      sums[index] = values.reduce((prev, curr) => {
        const value = Number(curr);
        if (!isNaN(value)) {
          return (Number(prev) + Number(curr)).toFixed(2);
        } else {
          return Number(prev).toFixed(2);
        }
      }, 0);
      sums[index] = numberToCurrencyNo(sums[index]);
    } else {
      sums[index] = "";
    }
  });
  return sums;
}

function init() {}

// 暴露给父组件的方法
defineExpose({
  open,
});
init();
</script>

<style></style>