yyb
2026-05-19 9d89dedf542a7b9f8e2549c44723771133f79ef2
src/pages/oa/ApproveManage/approve-template/edit.vue
@@ -28,19 +28,18 @@
                      maxlength="50"
                      clearable />
          </up-form-item>
          <up-form-item label="模板类型"
                        prop="templateType"
          <up-form-item label="审批类型"
                        prop="businessType"
                        required
                        class="form-item-type">
            <up-radio-group v-model="form.templateType"
                            class="type-radio-group"
                            placement="row"
                            @change="onTemplateTypeChange">
              <up-radio v-for="opt in TEMPLATE_TYPE_OPTIONS"
                        :key="opt.value"
                        :name="opt.value"
                        :label="opt.name" />
            </up-radio-group>
                        class="form-item-select"
                        @click="openBusinessTypeSheet">
            <up-input :model-value="businessTypeText"
                      placeholder="请选择审批类型"
                      readonly />
            <template #right>
              <up-icon name="arrow-right"
                       @click.stop="openBusinessTypeSheet" />
            </template>
          </up-form-item>
          <up-form-item label="启用状态"
                        class="form-item-switch">
@@ -311,6 +310,12 @@
        </scroll-view>
      </view>
    </up-popup>
    <up-action-sheet :show="showBusinessTypeSheet"
                     title="选择审批类型"
                     :actions="businessTypeActions"
                     @select="onSelectBusinessType"
                     @close="showBusinessTypeSheet = false" />
  </view>
</template>
@@ -325,6 +330,7 @@
  } from "@/api/oa/approvalTemplate.js";
  import { userListNoPageByTenantId } from "@/api/system/user";
  import { formatDateToYMD } from "@/utils/ruoyi";
  import { fetchApprovalTemplateTypes } from "../../_utils/approvalTemplateType.js";
  const EDIT_STORAGE_KEY = "oa_approve_template_edit_row";
@@ -384,6 +390,7 @@
  const form = reactive({
    templateName: "",
    businessType: null,
    templateType: 1,
    enabled: "1",
    description: "",
@@ -413,11 +420,11 @@
  const rules = {
    templateName: [{ required: true, message: "请输入模板名称", trigger: "blur" }],
    templateType: [
    businessType: [
      {
        validator: (_rule, value, callback) => {
          if (value === "" || value === null || value === undefined) {
            callback(new Error("请选择模板类型"));
            callback(new Error("请选择审批类型"));
            return;
          }
          callback();
@@ -427,10 +434,22 @@
    ],
  };
  const TEMPLATE_TYPE_OPTIONS = [
    { name: "系统内置", value: 0 },
    { name: "自定义", value: 1 },
  ];
  const businessTypeOptions = ref([]);
  const showBusinessTypeSheet = ref(false);
  const businessTypeActions = computed(() =>
    businessTypeOptions.value.map(opt => ({
      name: opt.name,
      value: opt.value,
    }))
  );
  const businessTypeText = computed(() => {
    const matched = businessTypeOptions.value.find(
      opt => String(opt.value) === String(form.businessType)
    );
    return matched?.name || "";
  });
  const presetActions = FORM_PRESETS.map(item => ({
    name: item.name,
@@ -487,10 +506,12 @@
    if (!row) return;
    templateId.value = row.id;
    form.templateName = row.templateName || "";
    form.templateType =
      row.templateType === 0 || row.templateType === 1
        ? row.templateType
        : Number(row.templateType) || 1;
    const parsedBusiness = Number(row.businessType);
    form.businessType = Number.isNaN(parsedBusiness)
      ? row.businessType
      : parsedBusiness;
    const parsedTemplateType = Number(row.templateType);
    form.templateType = Number.isNaN(parsedTemplateType) ? 1 : parsedTemplateType;
    form.enabled = String(row.enabled ?? "1");
    form.description = row.description || "";
@@ -526,8 +547,18 @@
    uni.navigateBack();
  };
  const onTemplateTypeChange = () => {
    formRef.value?.validateField?.("templateType");
  const openBusinessTypeSheet = () => {
    if (!businessTypeOptions.value.length) {
      uni.showToast({ title: "审批类型加载中", icon: "none" });
      return;
    }
    showBusinessTypeSheet.value = true;
  };
  const onSelectBusinessType = action => {
    form.businessType = action.value;
    showBusinessTypeSheet.value = false;
    formRef.value?.validateField?.("businessType");
  };
  const onSelectPreset = action => {
@@ -710,6 +741,7 @@
      templateName: form.templateName.trim(),
      enabled: form.enabled,
      description: form.description?.trim() || "",
      businessType: form.businessType,
      templateType: form.templateType,
      formConfig: JSON.stringify({
        prompt: formConfig.prompt?.trim() || "",
@@ -792,7 +824,25 @@
    }
  });
  const loadTemplateTypes = () =>
    fetchApprovalTemplateTypes()
      .then(opts => {
        businessTypeOptions.value = opts;
        if (!templateId.value && opts.length) {
          const matched = opts.some(
            opt => String(opt.value) === String(form.businessType)
          );
          if (!matched) {
            form.businessType = opts[0].value;
          }
        }
      })
      .catch(() => {
        uni.showToast({ title: "获取审批类型失败", icon: "none" });
      });
  onMounted(() => {
    loadTemplateTypes();
    userListNoPageByTenantId()
      .then(res => {
        userList.value = res?.data || [];
@@ -926,18 +976,18 @@
    font-size: 15px !important;
  }
  :deep(.form-item-type .u-form-item__body) {
  :deep(.form-item-select .u-form-item__body) {
    align-items: center !important;
  }
  .type-radio-group {
    display: flex;
    justify-content: flex-end;
    flex-wrap: nowrap;
  :deep(.form-item-select .u-form-item__content) {
    flex: 1 !important;
    min-width: 0 !important;
    justify-content: flex-end !important;
  }
  :deep(.type-radio-group .u-radio) {
    margin-left: 20px;
  :deep(.form-item-select .u-input__content__field-wrapper__field) {
    text-align: right !important;
  }
  :deep(.form-item-switch .u-form-item__body) {