yuan
6 天以前 9ea5ff67655241271bdf04bb50ca3a8d60c4e22a
src/views/personnelManagement/socialSecuritySet/components/formDia.vue
@@ -1,31 +1,34 @@
<template>
  <div>
    <FormDialog v-model="dialogFormVisible"
    <FormDialog
      v-model="dialogFormVisible"
                :operation-type="operationType"
                :title="dialogTitle"
                width="80%"
                @close="closeDia"
                @confirm="submitForm"
                @cancel="closeDia">
      <el-form ref="formRef"
               :model="form"
               :rules="rules"
               label-position="top">
      @cancel="closeDia"
    >
      <el-form ref="formRef" :model="form" :rules="rules" label-position="top">
        <el-row :gutter="24">
          <!-- 左侧:适用人员 -->
          <el-col :span="8">
            <el-form-item label="适用人员:"
                          prop="deptIds">
            <el-form-item label="适用人员:" prop="deptIds">
              <div class="dept-checkbox-wrap">
                <el-checkbox-group v-model="form.deptIds"
                                   :disabled="isDetail">
                  <div v-for="dept in deptList"
                <el-checkbox-group
                  v-model="form.deptIds"
                  :disabled="isDetail"
                >
                  <div
                    v-for="dept in deptList"
                       :key="dept.deptId"
                       class="dept-checkbox-item">
                    class="dept-checkbox-item"
                  >
                    <el-checkbox :value="dept.deptId">
                      {{ dept.deptName }}
                      <span v-if="dept.personCount != null"
                            class="dept-count">{{ dept.personCount }}人</span>
                      <span v-if="dept.personCount != null" class="dept-count"
                        >{{ dept.personCount }}人</span
                      >
                    </el-checkbox>
                  </div>
                </el-checkbox-group>
@@ -35,117 +38,124 @@
          <!-- 右侧:基础信息 + 保险类型 -->
          <el-col :span="16">
            <!-- 基础信息 -->
            <el-card class="form-card"
                     shadow="never">
            <el-card class="form-card" shadow="never">
              <template #header>
                <span class="card-title"><span class="card-title-line">|</span> 基础信息</span>
                <el-icon class="card-collapse">
                  <ArrowUp />
                </el-icon>
                <el-icon class="card-collapse"><ArrowUp /></el-icon>
              </template>
              <el-form-item label="方案标题:"
                            prop="title">
                <el-input v-model="form.title"
              <el-form-item label="方案标题:" prop="title">
                <el-input
                  v-model="form.title"
                          placeholder="请输入"
                          clearable
                          :disabled="isDetail" />
                  :disabled="isDetail"
                />
              </el-form-item>
              <el-form-item label="备注:"
                            prop="remark">
                <el-input v-model="form.remark"
              <el-form-item label="备注:" prop="remark">
                <el-input
                  v-model="form.remark"
                          type="textarea"
                          :rows="2"
                          placeholder="请输入"
                          clearable
                          :disabled="isDetail" />
                  :disabled="isDetail"
                />
              </el-form-item>
            </el-card>
            <!-- 保险类型 -->
            <el-card class="form-card"
                     shadow="never">
            <el-card class="form-card" shadow="never">
              <template #header>
                <span class="card-title"><span class="card-title-line">|</span> 保险类型</span>
                <el-button v-if="!isDetail"
                <el-button
                  v-if="!isDetail"
                           type="primary"
                           size="small"
                           @click="addInsuranceBenefit">
                  @click="addInsuranceBenefit"
                >
                  添加保险福利
                </el-button>
              </template>
              <el-row :gutter="16">
                <el-col v-for="(item, index) in form.insuranceBenefits"
                <el-col
                  v-for="(item, index) in form.insuranceBenefits"
                        :key="item._key"
                        :span="12">
                  :span="12"
                >
                  <div class="insurance-benefit-card">
                    <div class="insurance-benefit-title">
                      保险福利{{ index + 1 }}
                      <el-button v-if="!isDetail && form.insuranceBenefits.length > 1"
                      <el-button
                        v-if="!isDetail && form.insuranceBenefits.length > 1"
                                 type="danger"
                                 link
                                 size="small"
                                 class="card-delete-btn"
                                 @click="removeInsuranceBenefit(index)">
                        @click="removeInsuranceBenefit(index)"
                      >
                        删除
                      </el-button>
                    </div>
                    <el-form-item :prop="'insuranceBenefits.' + index + '.insuranceType'"
                    <el-form-item
                      :prop="'insuranceBenefits.' + index + '.insuranceType'"
                                  label="保险类型:"
                                  label-width="100px"
                                  :rules="[{ required: true, message: '请选择保险类型', trigger: 'blur' }]"
                    >
                      <el-select v-model="item.insuranceType"
                      <el-select
                        v-model="item.insuranceType"
                                 placeholder="请选择"
                                 clearable
                                 style="width: 100%"
                                 :disabled="isDetail">
                        <el-option v-for="opt in insuranceTypeOptions"
                        :disabled="isDetail"
                      >
                        <el-option
                          v-for="opt in insuranceTypeOptions"
                                   :key="opt.value"
                                   :label="opt.label"
                                   :value="opt.value" />
                          :value="opt.value"
                        />
                      </el-select>
                    </el-form-item>
                    <el-form-item label="缴费基数:"
                                  label-width="100px"
                                  :prop="'insuranceBenefits.' + index + '.paymentBase'"
                                  :rules="[{ validator: validatePaymentBase, trigger: 'blur' }]">
                    <el-form-item label="缴费基数:" label-width="100px">
                      <div class="base-salary-wrap">
                        <el-input v-model="item.paymentBase"
                        <el-input
                          v-model="item.paymentBase"
                                  placeholder="根据基本工资缴纳"
                                  clearable
                                  style="width: 120px"
                                  type="number"
                                  :disabled="isDetail || item.useBasicSalary"
                                  @input="handlePaymentBaseInput(item)" />
                        <el-checkbox v-model="item.useBasicSalary"
                                     @change="(val) => handleUseBasicSalaryChange(item, index)"
                                     :disabled="isDetail">
                          @input="handlePaymentBaseInput(item)"
                        />
                        <el-checkbox
                          v-model="item.useBasicSalary"
                          @change="handleUseBasicSalaryChange(item)"
                          :disabled="isDetail"
                        >
                          调用基本工资
                        </el-checkbox>
                      </div>
                    </el-form-item>
                    <el-form-item label="个人缴费比例:"
                                  label-width="100px"
                                  :prop="'insuranceBenefits.' + index + '.personalRatio'"
                                  :rules="[{ required: true, message: '请输入个人缴费比例', trigger: 'blur' }]">
                    <el-form-item label="个人缴费比例:" label-width="100px">
                      <div class="personal-ratio-wrap">
                        <el-input v-model="item.personalRatio"
                        <el-input
                          v-model="item.personalRatio"
                                  placeholder="请输入"
                                  clearable
                                  style="width: 100px"
                                  type="number"
                                  :disabled="isDetail"
                                  :min="0"
                                  @input="handlePersonalRatioInput(item)" />
                        />
                        <span class="ratio-unit">(%)</span>
                        <span class="ratio-plus">+</span>
                        <el-input v-model="item.personalFixed"
                        <el-input
                          v-model="item.personalFixed"
                                  placeholder="请输入"
                                  clearable
                                  style="width: 100px"
                                  type="number"
                                  :disabled="isDetail"
                                  :min="0"
                                  @input="handlePersonalFixedInput(item)" />
                        />
                      </div>
                    </el-form-item>
                  </div>
@@ -160,21 +170,11 @@
</template>
<script setup>
  import {
    ref,
    reactive,
    toRefs,
    getCurrentInstance,
    nextTick,
    computed,
  } from "vue";
import { ref, reactive, toRefs, getCurrentInstance, nextTick, computed } from "vue";
  import FormDialog from "@/components/Dialog/FormDialog.vue";
  import { ArrowUp } from "@element-plus/icons-vue";
  import { listDept } from "@/api/system/dept.js";
  import {
    socialSecurityAdd,
    socialSecurityUpdate,
  } from "@/api/personnelManagement/socialSecuritySet.js";
import { socialSecurityAdd, socialSecurityUpdate } from "@/api/personnelManagement/socialSecuritySet.js";
  const emit = defineEmits(["close"]);
  const { proxy } = getCurrentInstance();
@@ -237,7 +237,7 @@
  function flattenDept(tree, list = []) {
    if (!tree || !tree.length) return list;
    tree.forEach(node => {
  tree.forEach((node) => {
      list.push({
        deptId: node.deptId,
        deptName: node.deptName,
@@ -251,7 +251,7 @@
  }
  const loadDeptList = () => {
    listDept().then(res => {
  listDept().then((res) => {
      const tree = res.data ?? [];
      deptList.value = flattenDept(tree);
    });
@@ -261,55 +261,19 @@
    form.value.insuranceBenefits.push(defaultBenefit());
  };
  const removeInsuranceBenefit = index => {
const removeInsuranceBenefit = (index) => {
    form.value.insuranceBenefits.splice(index, 1);
  };
  const handleUseBasicSalaryChange = (item, index) => {
const handleUseBasicSalaryChange = (item) => {
    if (item.useBasicSalary) {
      item.paymentBase = "";
    }
    nextTick(() => {
      formRef.value?.validateField(`insuranceBenefits.${index}.paymentBase`);
    });
  };
  const handlePaymentBaseInput = item => {
const handlePaymentBaseInput = (item) => {
    if (item.paymentBase !== "" && item.paymentBase != null) {
      item.useBasicSalary = false;
    }
  };
  const handlePersonalRatioInput = item => {
    if (item.personalRatio !== "" && item.personalRatio != null) {
      const value = Number(item.personalRatio);
      if (value < 0) {
        item.personalRatio = "";
      }
    }
  };
  const handlePersonalFixedInput = item => {
    if (item.personalFixed !== "" && item.personalFixed != null) {
      const value = Number(item.personalFixed);
      if (value < 0) {
        item.personalFixed = "";
      }
    }
  };
  const validatePaymentBase = (rule, value, callback) => {
    const match = rule.field.match(/insuranceBenefits\.(\d+)\.paymentBase/);
    if (match) {
      const index = parseInt(match[1], 10);
      const item = form.value.insuranceBenefits[index];
      if (item && !item.useBasicSalary && (!value || value === "")) {
        callback(new Error("请输入缴费基数"));
      } else {
        callback();
      }
    } else {
      callback();
    }
  };
@@ -337,8 +301,8 @@
      if (d.deptIds) {
        form.value.deptIds = String(d.deptIds)
          .split(",")
          .filter(v => v !== "")
          .map(v => {
        .filter((v) => v !== "")
        .map((v) => {
            const num = Number(v);
            return Number.isNaN(num) ? v : num;
          });
@@ -348,7 +312,7 @@
      const detailList = d.schemeInsuranceDetailList || [];
      form.value.insuranceBenefits =
        detailList.length > 0
          ? detailList.map(b => ({
        ? detailList.map((b) => ({
              _key: Math.random().toString(36).slice(2),
              insuranceType: b.insuranceType || "",
              paymentBase: b.paymentBase ?? "",
@@ -366,7 +330,7 @@
      closeDia();
      return;
    }
    formRef.value?.validate(valid => {
  formRef.value?.validate((valid) => {
      if (!valid) return;
      const deptIds =
        Array.isArray(form.value.deptIds) && form.value.deptIds.length
@@ -379,15 +343,17 @@
        })
      );
      const insuranceTypes = schemeInsuranceDetailList
        .map(item => item.insuranceType)
        .filter(v => v)
      .map((item) => item.insuranceType)
      .filter((v) => v)
        .join(",");
      // 部门名称,多个使用逗号隔开(根据选中的 deptIds 与 deptList 计算)
      const deptNames = (deptList.value || [])
        .filter(d =>
          (form.value.deptIds || []).some(id => String(id) === String(d.deptId))
      .filter((d) =>
        (form.value.deptIds || []).some(
          (id) => String(id) === String(d.deptId)
        )
        .map(d => d.deptName)
      )
      .map((d) => d.deptName)
        .join(",");
      const submitData = {
        id: form.value.id,