Преглед изворни кода

购买链接增加小程序码

张田田 пре 5 месеци
родитељ
комит
64323092d6
2 измењених фајлова са 126 додато и 58 уклоњено
  1. 2 0
      src/model/care.model.ts
  2. 124 58
      src/service/AddItems.vue

+ 2 - 0
src/model/care.model.ts

@@ -60,6 +60,7 @@ export interface SystemItemModel {
   isForInfer?: string | null; // 是否为调理方案项目
   effect: string; // 功效
   itemImgFirst: string; // 操作图片
+  miniProgramCode: string; // 小程序码
   itemVideoFirst: string; // 操作视频
   attrFirst: string; // 特色
   isOffline?: string | null; // 是否线下
@@ -74,6 +75,7 @@ export interface SystemItemModel {
   types?: string[]; // 项目应用
   attrEighth: string; // 购买链接
   attrNinth: string; // 跳转类型
+  attrTen: string; // 小程序码
 }
 
 export type SystemIteQuery = Partial<SystemItemModel>;

+ 124 - 58
src/service/AddItems.vue

@@ -108,31 +108,56 @@ const isDerivationModalOpen = ref(false);
 const rules = {
   name: [{ required: true, message: '请输入项目名称', trigger: 'blur' }],
   conditioningProgramType: [{ required: true, message: '请选择方案类型', trigger: 'change' }],
-  institutionId: [{ 
-    required: true, 
-    message: '请选择机构名称', 
-    trigger: 'blur',
-    validator: (rule: any, value: any, callback: any) => {
-      // 如果推导逻辑弹窗打开,跳过验证
-      if (isDerivationModalOpen.value) {
-        callback();
-        return;
-      }
-      if (!value) {
-        callback(new Error('请选择机构名称'));
-      } else {
-        callback();
-      }
-    }
-  }],
+  institutionId: [
+    {
+      required: true,
+      message: '请选择机构名称',
+      trigger: 'blur',
+      validator: (rule: any, value: any, callback: any) => {
+        // 如果推导逻辑弹窗打开,跳过验证
+        if (isDerivationModalOpen.value) {
+          callback();
+          return;
+        }
+        if (!value) {
+          callback(new Error('请选择机构名称'));
+        } else {
+          callback();
+        }
+      },
+    },
+  ],
   isOffline: [{ required: true, message: '请选择线下项目', trigger: 'change' }],
   isDelivery: [{ required: true, message: '请选择是否配送', trigger: 'change' }],
 };
+const showMiniProgramCode = ref<boolean>(false);
+const showBuyLink = ref<boolean>(false);
+// 判断是否为小程序码类型
+const isMiniProgramCodeType = computed(() => {
+  return form.attrNinth === 'miniprogram';
+});
+watch(
+  () => form.attrNinth,
+  (newVal) => {
+    if (newVal && newVal === 'URL') {
+      // 购买链接显示不必填  小程序码隐藏
+      showMiniProgramCode.value = false;
+      showBuyLink.value = true;
+    } else if (newVal && newVal === 'miniprogram') {
+      // 跳转类型是小程序码 小程序码显示并且必上传  购买链接显示不必填
+      showMiniProgramCode.value = true;
+      showBuyLink.value = true;
+    } else {
+      // 跳转类型是其他类型 小程序码隐藏 购买链接隐藏 目前是这样处理  后期如果有其他类型再做处理
+      showMiniProgramCode.value = false;
+      showBuyLink.value = false;
+    }
+  }
+);
 const isShowOnline = ref<boolean>(false);
 const isShowDelivery = ref<boolean>(false);
 const supplierArr = ref<any[]>([]);
 
-
 // 获取所有的供应商
 async function getSupplier(params: any) {
   supplierOptions.value = [];
@@ -253,7 +278,7 @@ function doSubmit() {
     message.error('请选择方案类型');
     return;
   }
-  
+
   // 自定义验证:检查项目应用是否已选择
   if (!checkedList.value || checkedList.value.length === 0) {
     message.error('请选择项目应用');
@@ -271,7 +296,8 @@ function doSubmit() {
     // 计价规则相关字段校验
     if (form.pricingType === '0') {
       const { unitPrice, pricingUnit, convertDose, convertUnit } = form.cpFixedPricingRule || {};
-      const allFilled = (unitPrice !== '' && unitPrice !== null && unitPrice !== undefined) && pricingUnit && (convertDose !== '' && convertDose !== null && convertDose !== undefined) && convertUnit;
+      const allFilled =
+        unitPrice !== '' && unitPrice !== null && unitPrice !== undefined && pricingUnit && convertDose !== '' && convertDose !== null && convertDose !== undefined && convertUnit;
       if (!allFilled) {
         message.error('请将单价、计价单位、相当于、使用单位全部填写');
         return;
@@ -298,7 +324,7 @@ function doSubmit() {
     //   //   return;
     //   // }
     // } else
-     if (form.addType === 'system') {
+    if (form.addType === 'system') {
       form.isOffline = 'N';
       form.isDelivery = 'N';
     }
@@ -316,7 +342,8 @@ function doSubmit() {
     // 计价规则非必填时,做全填/全空校验
     if (form.pricingType === '0') {
       const { unitPrice, pricingUnit, convertDose, convertUnit } = form.cpFixedPricingRule || {};
-      const allFilled = (unitPrice !== '' && unitPrice !== null && unitPrice !== undefined) && pricingUnit && (convertDose !== '' && convertDose !== null && convertDose !== undefined) && convertUnit;
+      const allFilled =
+        unitPrice !== '' && unitPrice !== null && unitPrice !== undefined && pricingUnit && convertDose !== '' && convertDose !== null && convertDose !== undefined && convertUnit;
       const allEmpty = !unitPrice && !pricingUnit && !convertDose && !convertUnit;
       if (!(allFilled || allEmpty)) {
         message.error('单价、计价单位、相当于、使用单位要么全部填写,要么全部为空');
@@ -351,18 +378,26 @@ function doSubmit() {
     }
   }
 
-  // 购买链接与跳转类型联动校验:有购买链接则必须选择跳转类型
+  // 购买链接与跳转类型联动校验
   if (form.addType === 'itemsList') {
+   
+    // 有购买链接则必须选择跳转类型
     const hasBuyUrl = !!(form.attrEighth && String(form.attrEighth).trim());
     if (hasBuyUrl && !form.attrNinth) {
       message.error('请选择跳转类型');
       return;
     }
+     // 如果选择了小程序码类型,类型是小程序码  小程序码必填 链接可填
+     if (form.attrNinth === 'miniprogram' && miniProgramCodeList.value.length === 0) {
+      message.error('请上传小程序码');
+      return;
+    }
   }
 
   formRef.value?.validate().then(() => {
     form.photo = fileList.value[0]?.response?.url || fileList.value[0]?.url || '';
     form.itemImgFirst = optionsList.value[0]?.response?.url || optionsList.value[0]?.url || '';
+    form.attrTen = miniProgramCodeList.value[0]?.response?.url || miniProgramCodeList.value[0]?.url || '';
     // 合并推导逻辑数据到表单数据中
     if (hasDerivationLogic.value && derivationData.value.cpPatientMatchRule) {
       form.cpPatientMatchRule = { ...derivationData.value.cpPatientMatchRule };
@@ -392,16 +427,16 @@ const jumpTypeOptions = ref<{ label: string; value: string }[]>([]);
 // 获取跳转类型
 async function getJumpType() {
   jumpTypeOptionsLoading.value = true;
-  try { 
-  const res = await getDictionaryMethod('fdhb_cpbuy_type');
-  if (res?.length > 0) {
-    jumpTypeOptions.value = res;
+  try {
+    const res = await getDictionaryMethod('fdhb_cpbuy_type');
+    if (res?.length > 0) {
+      jumpTypeOptions.value = res;
+    }
+  } catch (error: any) {
+    message.error(error.message);
+  } finally {
+    jumpTypeOptionsLoading.value = false;
   }
-} catch (error: any) {
-  message.error(error.message);
-} finally {
-  jumpTypeOptionsLoading.value = false;
-}
 }
 
 // 处理下拉框点击事件
@@ -412,7 +447,6 @@ function handleSelectClick() {
   }
 }
 
-
 onMounted(async () => {
   const deptId = localStorage.getItem('deptId');
   if (props.data.addType === 'system' && deptId) {
@@ -463,7 +497,17 @@ onMounted(async () => {
           },
         ]
       : [];
-
+    miniProgramCodeList.value = res.attrTen
+      ? [
+          {
+            uid: '-1',
+            name: 'image.png',
+            status: 'done',
+            url: res.attrTen,
+            thumbUrl: res.attrTen,
+          },
+        ]
+      : [];
     // 处理视频数据
     if (res.itemVideoFirst) {
       videoFileList.value = [
@@ -486,7 +530,7 @@ onMounted(async () => {
   // 获取方案类型
   getConditioningProgramType();
   // 获取跳转类型
-  getJumpType();  
+  getJumpType();
 });
 const emits = defineEmits<{
   submit: [data?: SystemItemModel];
@@ -508,6 +552,8 @@ const uploadProps = reactive({ showRemoveIcon: true });
 const fileList = ref<UploadFile[]>([]);
 // 操作图片
 const optionsList = ref<UploadFile[]>([]);
+// 小程序码
+const miniProgramCodeList = ref<UploadFile[]>([]);
 // 安全挂载弹层,避免 document 不可用或被父层遮挡
 function getSafePopupContainer(triggerNode?: HTMLElement) {
   try {
@@ -550,23 +596,27 @@ const videoFileList = ref<UploadFile[]>([]);
 // 供应商校验规则:仅在"项目应用 勾选 服务包"且"新增项目(itemsList)"时必填
 const supplierRules = computed(() => {
   const need = checkedList.value.includes('1') && form.addType === 'itemsList';
-  return need ? [{ 
-    required: true, 
-    message: '请选择供应商', 
-    trigger: 'blur',
-    validator: (rule: any, value: any, callback: any) => {
-      // 如果推导逻辑弹窗打开,跳过验证
-      if (isDerivationModalOpen.value) {
-        callback();
-        return;
-      }
-      if (!value) {
-        callback(new Error('请选择供应商'));
-      } else {
-        callback();
-      }
-    }
-  }] : [];
+  return need
+    ? [
+        {
+          required: true,
+          message: '请选择供应商',
+          trigger: 'blur',
+          validator: (rule: any, value: any, callback: any) => {
+            // 如果推导逻辑弹窗打开,跳过验证
+            if (isDerivationModalOpen.value) {
+              callback();
+              return;
+            }
+            if (!value) {
+              callback(new Error('请选择供应商'));
+            } else {
+              callback();
+            }
+          },
+        },
+      ]
+    : [];
 });
 
 // 上传前校验
@@ -766,7 +816,7 @@ const isDerivationEmpty = computed(() => {
 function handleDerivation() {
   // 设置推导逻辑弹窗打开状态
   isDerivationModalOpen.value = true;
-  
+
   VxeUI.modal.open({
     title: `推导逻辑`,
     height: 750,
@@ -795,7 +845,7 @@ function handleDerivation() {
           onSubmit: (data: any) => {
             derivationData.value = data;
             hasDerivationLogic.value = true; // 设置推导逻辑已编辑
-            
+
             // 重置状态并清除验证状态
             isDerivationModalOpen.value = false;
             nextTick(() => {
@@ -1087,14 +1137,30 @@ function handleDerivation() {
           </div>
         </div>
       </a-form-item>
-      <!-- 购买链接 -->
-      <a-form-item label="购买链接:" v-if="form.addType === 'itemsList'">
-        <a-input v-model:value="form.attrEighth" placeholder="请输入" />
-      </a-form-item>
       <!-- 跳转类型 -->
       <a-form-item label="跳转类型:" v-if="form.addType === 'itemsList'" style="width: 100%">
         <Vxe-select v-model="form.attrNinth" :options="jumpTypeOptions" placeholder="请选择" clearable transfer style="width: 100%" />
       </a-form-item>
+      <!-- 购买链接 -->
+      <a-form-item label="购买链接:" v-if="form.addType === 'itemsList' && showBuyLink">
+        <a-input v-model:value="form.attrEighth" placeholder="请输入" />
+      </a-form-item>
+      <a-form-item label="小程序码:" class="image-form-item" 
+      v-if="form.addType === 'itemsList' && showMiniProgramCode" :required="isMiniProgramCodeType">
+        <a-upload
+          :showUploadList="uploadProps"
+          v-model:file-list="miniProgramCodeList"
+          list-type="picture-card"
+          @preview="handlePreview"
+          :maxCount="1"
+          :customRequest="customUpload"
+        >
+          <div v-if="miniProgramCodeList.length < 1">
+            <PlusOutlined />
+            <div style="margin-top: 8px">上传</div>
+          </div>
+        </a-upload>
+      </a-form-item>
       <!-- 机构名称 -->
       <a-form-item label="机构名称:" v-if="form?.addType === 'itemsList'" required name="institutionId">
         <a-tree-select