Browse Source

增加修改物料功能

wuhb 3 weeks ago
parent
commit
537dd32cfc
2 changed files with 74 additions and 16 deletions
  1. 15 1
      api/apply/index.uts
  2. 59 15
      pages/apply/applyNew.uvue

+ 15 - 1
api/apply/index.uts

@@ -138,7 +138,7 @@ export const getMeasureList = (): Promise<any> => {
 /**
  * 删除物料
  * @param itemId 物料ID
- * @returns 
+ * @returns
  */
 export const deleteMaterial = (itemId: string): Promise<any> => {
 	return request({
@@ -147,6 +147,20 @@ export const deleteMaterial = (itemId: string): Promise<any> => {
 	})
 }
 
+/**
+ * 修改物料(移动端使用)
+ * @param itemId 物料ID
+ * @param data 物料数据
+ * @returns
+ */
+export const updateMaterial = (itemId: string, data: UTSJSONObject | null): Promise<any> => {
+	return request({
+		url: `/mes/md/mditem/updateApply/${itemId}`,
+		method: 'PUT',
+		data: data
+	})
+}
+
 /**
  * 获取物料申请待领取数量
  * @param userId 用户ID

+ 59 - 15
pages/apply/applyNew.uvue

@@ -169,7 +169,7 @@
 		    <view class="modal-mask" @click="showAddMaterialModal = false"></view>
 		    <view class="modal-content">
 		        <view class="modal-header">
-		            <text class="modal-title">新增物料</text>
+		            <text class="modal-title">{{ materialModalTitle }}</text>
 		            <text class="modal-close" @click="showAddMaterialModal = false">取消</text>
 		        </view>
 				<view v-if="addMaterialError.length > 0" class="error-tip">
@@ -284,7 +284,7 @@
 
 <script setup lang="uts">
 import { ref, computed, onBeforeUnmount, onMounted } from 'vue'
-import { getItemTypeListByParentId, getItemList, savePurchaseApply, confirmPurchaseApply, addMaterial, getMeasureList, deleteMaterial } from '../../api/apply/index'
+import { getItemTypeListByParentId, getItemList, savePurchaseApply, confirmPurchaseApply, addMaterial, getMeasureList, deleteMaterial, updateMaterial } from '../../api/apply/index'
 import { getUserInfo } from '../../utils/storage'
 import UploadImage from '../../components/upload-image/upload-image.uvue'
 import type { UploadResponse } from '../../types/workbench'
@@ -343,6 +343,13 @@ const deleteImageIndex = ref<number>(0)
 const showImagePreview = ref<boolean>(false)
 const previewUrls = ref<string[]>([])
 const previewIndex = ref<number>(0)
+// 编辑物料相关
+const editingMaterialItem = ref<Item | null>(null)
+
+// 弹窗标题
+const materialModalTitle = computed<string>(() => {
+	return editingMaterialItem.value != null ? '修改物料' : '新增物料'
+})
 
 type NewMaterial = {
 	itemName: string
@@ -562,12 +569,41 @@ const selectMeasure = (item: UTSJSONObject): void => {
 	}
 	
 	const handleItemClick = (item: any | null, index: number): void => {
-	    if (item == null) return
-		const mdItem = item as Item
+    if (item == null) return
+	const mdItem = item as Item
+	// 判断是否满足编辑条件
+	if (getAuditStatus(mdItem) == 0 && !mdItem.isSelected && canDeleteMaterial(mdItem)) {
+		// 满足编辑条件,弹出编辑窗口
+		editingMaterialItem.value = mdItem
+		let imageUrls: UploadResponse[] = []
+		if (mdItem.imageUrls && mdItem.imageUrls.length > 0) {
+			const fileNames = mdItem.imageUrls.split(',')
+			imageUrls = fileNames.map((fileName: string) => {
+				return {
+					fileName: fileName,
+					url: fileName
+				} as UploadResponse
+			})
+		}
+		let itemName = mdItem.itemName
+		if (mdItem.specification && mdItem.itemName.endsWith('(' + mdItem.specification + ')')) {
+			itemName = mdItem.itemName.substring(0, mdItem.itemName.length - ('(' + mdItem.specification + ')').length)
+		}
+		newMaterial.value = {
+			itemName: itemName,
+			specification: mdItem.specification || '',
+			measureName: mdItem.measureName || '',
+			imageUrls: imageUrls,
+			productUrl: mdItem.productUrl || ''
+		} as NewMaterial
+		showAddMaterialModal.value = true
+	} else {
+		// 不满足编辑条件,跳转到详情页
 	    uni.navigateTo({
 	        url: `/pages/item/detail?id=${mdItem.itemId}`
 	    })
 	}
+}
 	const getItemName = (item: any | null): string => {
 	    if (item == null) return ''
 	    const mdItem = item as Item
@@ -792,7 +828,7 @@ const handlePreviewChange = (e: any): void => {
     previewIndex.value = e.detail.current
 }
 
-// 处理新增物料
+// 处理新增/编辑物料
 const handleAddMaterial = async (): Promise<void> => {
 	// 验证输入
 	if (newMaterial.value.itemName.length == 0) {
@@ -817,16 +853,22 @@ const handleAddMaterial = async (): Promise<void> => {
 			materialData['imageUrls'] = imageFileNames
 			materialData['productUrl'] = newMaterial.value.productUrl
 		
-		// 调用接口保存物料
-		await addMaterial(materialData)
-		
-		// 保存成功
-		uni.showToast({ title: '物料新增成功', icon: 'success'})
+		// 判断是新增还是编辑
+		if (editingMaterialItem.value != null) {
+			// 编辑模式
+			await updateMaterial(editingMaterialItem.value.itemId, materialData)
+			uni.showToast({ title: '物料修改成功', icon: 'success'})
+		} else {
+			// 新增模式
+			await addMaterial(materialData)
+			uni.showToast({ title: '物料新增成功', icon: 'success'})
+		}
 		
 		// 关闭弹窗
 		showAddMaterialModal.value = false
 		
 		// 清空表单
+		editingMaterialItem.value = null
 		newMaterial.value = {
 			itemName: '',
 			specification: '',
@@ -1043,17 +1085,19 @@ onMounted(() => {
 	    border-bottom: 1px solid #f9f9f9;
 	}
 	.item-header {
+    display: flex;
     flex-direction: row;
     align-items: center;
     justify-content: space-between;
     margin-bottom: 10rpx;
 }
 
-.item-actions {
-    display: flex;
-    align-items: center;
-    gap: 10rpx;
-}
+	.item-actions {
+		display: flex;
+		align-items: center;
+		gap: 10rpx;
+	}
+
 	.item-title {
 	        flex: 1;
 	    }