فهرست منبع

小程序合同流程修改

ouyj 1 روز پیش
والد
کامیت
a4623b70dc
3فایلهای تغییر یافته به همراه82 افزوده شده و 8 حذف شده
  1. 22 0
      api/contract.js
  2. 31 4
      components/processForms/contract-form.vue
  3. 29 4
      pages/work/contract/start.vue

+ 22 - 0
api/contract.js

@@ -266,3 +266,25 @@ export function getPurchaseDetailList(useId, contractPurchaseFormId = '', page =
 		}
 	})
 }
+
+/**
+ * 验证合同编号是否已存在
+ * @param {String} useId - 用户 ID
+ * @param {string} contractNumber - 合同编号
+ * @param {string} universalid - 合同ID(可选,用于审批流程中排除自己)
+ */
+export function checkContractNumber(useId, contractNumber, universalid = '') {
+	return request({
+		url: preUrl,
+		method: 'post',
+		data: {
+			serviceId: 'miniapp_contractFlowCustom',
+			params: {
+				task: 'checkContractNumber',
+				useId: useId,
+				contractNumber: contractNumber,
+				universalid: universalid
+			}
+		}
+	})
+}

+ 31 - 4
components/processForms/contract-form.vue

@@ -6,7 +6,12 @@
       <uni-section titleFontSize="1.3rem" title="基本信息" type="line"></uni-section>
       <uni-forms ref="baseFormRef" :modelValue="baseForm" :rules="baseFormRules" label-position="left" :label-width="100" :border="true">
         <uni-forms-item name="contract_number" label="合同编号">
-          <uni-easyinput v-model="baseForm.contract_number" disabled placeholder="自动生成"></uni-easyinput>
+          <!-- 发起环节或字段可编辑时显示输入框 -->
+          <uni-easyinput v-if="isInitiateOrFieldEditable('contract_number')" 
+                         v-model="baseForm.contract_number"
+                         placeholder="请输入合同编号"></uni-easyinput>
+          <!-- 否则显示只读文本 -->
+          <uni-easyinput v-else v-model="baseForm.contract_number" disabled></uni-easyinput>
         </uni-forms-item>
         <uni-forms-item name="contract_name" label="合同名称" required>
           <uni-easyinput v-model="baseForm.contract_name"
@@ -594,7 +599,7 @@ import { ref, watch, computed, nextTick, onMounted } from 'vue'
 import { useUserStore } from '@/store/user.js'
 import config from '@/config.js'
 import { uploadSignatureBoardImg, getSeal } from '@/api/process.js'
-import { getContractTypeList, getPaymentTypeList, getMaterialList, getSupplierList, getClientList, getPurchaseApplyList, getPurchaseDetailList } from '@/api/contract.js'
+import { getContractTypeList, getPaymentTypeList, getMaterialList, getSupplierList, getClientList, getPurchaseApplyList, getPurchaseDetailList, checkContractNumber } from '@/api/contract.js'
 import $modal from '@/plugins/modal.js'
 
 const userStore = useUserStore()
@@ -686,7 +691,9 @@ const baseForm = ref<any>({
 	contract_entrying_operator: '',
 	contract_entrying_operator_name: '',
 	// 组织 ID
-	unit_id: ''
+	unit_id: '',
+	// 合同ID(用于审批流程中排除自己)
+	universalid: ''
 })
 
 const baseFormRules = ref({
@@ -823,7 +830,9 @@ watch(() => props.formData, (newVal) => {
 			// 组织 ID
 			unit_id: newVal.unit_id || '',
 			// 保存公司名称,用于销售合同时对调需方供方(从后端获取)
-			companyName: newVal.companyName || ''
+			companyName: newVal.companyName || '',
+			// 合同ID(用于审批流程中排除自己)
+			universalid: newVal.universalid || ''
 		}
 		
 		// 从 contractMaterialList 中获取物料列表
@@ -1688,6 +1697,24 @@ function closeSignature() {
 // 暴露验证方法给父组件
 defineExpose({
 	validate: async () => {
+		// 合同编号验证(发起环节或字段可编辑时需要验证)
+		if (isSeModel.value || getFieldEditable('contract_number')) {
+			if (!baseForm.value.contract_number || !baseForm.value.contract_number.trim()) {
+				return Promise.reject(new Error('合同编号不能为空!'))
+			}
+					
+			// 验证合同编号唯一性(异步调用后端接口)
+			try {
+				const res = await checkContractNumber(userStore.user.useId, baseForm.value.contract_number, baseForm.value.universalid || '')
+				if (res.returnCode !== '1') {
+					return Promise.reject(new Error(res.returnMsg || '合同编号验证失败'))
+				}
+			} catch (error) {
+				console.error('合同编号验证失败', error)
+				return Promise.reject(new Error('合同编号验证失败,请重试'))
+			}
+		}
+		
 		// 基本信息验证
 		if (!baseForm.value.contract_name || !baseForm.value.contract_name.trim()) {
 			return Promise.reject(new Error('合同名称不能为空!'))

+ 29 - 4
pages/work/contract/start.vue

@@ -3,8 +3,8 @@
     <!-- 基本信息 -->
     <uni-card title="基本信息" spacing="0">
       <uni-forms ref="baseFormRef" :modelValue="baseForm" :rules="baseFormRules" label-position="left" :label-width="100" :border="true">
-        <uni-forms-item name="contract_number" label="合同编号">
-          <uni-easyinput v-model="baseForm.contract_number" disabled placeholder="自动生成"></uni-easyinput>
+        <uni-forms-item name="contract_number" label="合同编号" required>
+          <uni-easyinput v-model="baseForm.contract_number" placeholder="请输入合同编号"></uni-easyinput>
         </uni-forms-item>
         <uni-forms-item name="contract_name" label="合同名称" required>
           <uni-easyinput v-model="baseForm.contract_name" placeholder="请输入合同名称"></uni-easyinput>
@@ -369,7 +369,7 @@ import { onLoad } from '@dcloudio/uni-app'
 import { useUserStore } from '@/store/user.js'
 import $modal from '@/plugins/modal.js'
 import $tab from '@/plugins/tab.js'
-import { getContractInitData, startContractProcess, getMaterialList, getSupplierList, getClientList, getPurchaseApplyList, getPurchaseDetailList } from '@/api/contract.js'
+import { getContractInitData, startContractProcess, getMaterialList, getSupplierList, getClientList, getPurchaseApplyList, getPurchaseDetailList, checkContractNumber } from '@/api/contract.js'
 import { uploadFile, getProcessInfo } from '@/api/work.js'
 import config from '@/config.js'
 
@@ -436,7 +436,9 @@ function initBaseForm() {
     if (res.returnCode === '1') {
       const params = res.returnParams
       
-      baseForm.contract_number = params.contract_number || ''
+      // 合同编号改为手动输入,不再生成
+      // baseForm.contract_number = params.contract_number || ''
+      baseForm.contract_number = '' // 清空,由用户手动输入
       baseForm.initiator = params.initiator || userStore.user.name
       baseForm.department = params.department || ''
       baseForm.depid = params.depid || null
@@ -512,6 +514,10 @@ const fileSeqs = ref<any[]>([])
 const baseFormRef = ref(null)
 const baseFormRules = computed(() => {
   return {
+    contract_number: {
+      rules: [{ required: true, message: '请输入合同编号' }],
+      label: '合同编号'
+    },
     contract_name: {
       rules: [{ required: true, message: '请输入合同名称' }],
       label: '合同名称'
@@ -1274,6 +1280,25 @@ async function submitForm() {
   }
 
   // 1. 校验基本信息
+  // 1. 校验必填字段
+  if (!baseForm.contract_number || baseForm.contract_number.trim() === '') {
+    $modal.msgError('合同编号不能为空')
+    return
+  }
+  
+  // 验证合同编号唯一性
+  try {
+    const checkRes = await checkContractNumber(userStore.user.useId, baseForm.contract_number)
+    if (checkRes.returnCode !== '1') {
+      $modal.msgError(checkRes.returnMsg || '合同编号验证失败')
+      return
+    }
+  } catch (error) {
+    console.error('合同编号验证失败', error)
+    $modal.msgError('合同编号验证失败,请重试')
+    return
+  }
+  
   if (!baseForm.contract_name || baseForm.contract_name.trim() === '') {
     $modal.msgError('合同名称不能为空')
     return