Parcourir la source

refactor(订单表单): 重构物料明细组件为只读模式并优化代码

yz il y a 3 semaines
Parent
commit
90745bfdcd

+ 101 - 33
src/components/order-form/material-detail-option.js

@@ -4,40 +4,59 @@
  */
 
 /**
+ * 物料明细状态枚举
+ * @readonly
+ * @enum {string}
+ */
+export const MATERIAL_DETAIL_STATUS = {
+  /** 待确认 */
+  PENDING: '0',
+  /** 已确认 */
+  CONFIRMED: '1',
+  /** 已取消 */
+  CANCELLED: '2'
+}
+
+/**
+ * @typedef {keyof typeof MATERIAL_DETAIL_STATUS} MaterialDetailStatusKey
+ * @typedef {typeof MATERIAL_DETAIL_STATUS[MaterialDetailStatusKey]} MaterialDetailStatus
+ */
+
+/**
  * @typedef {Object} MaterialDetailQueryParams
  * @description 物料明细查询参数类型定义
- * @property {string} itemName - 物料名称
- * @property {string} itemCode - 物料编码
- * @property {string} specification - 规格型号
- * @property {string} warehouseName - 仓库名称
- * @property {number} current - 当前页码
- * @property {number} size - 每页条数
+ * @property {string} itemName - 物料名称,支持模糊查询
+ * @property {string} itemCode - 物料编码,支持模糊查询
+ * @property {string} specification - 规格型号,支持模糊查询
+ * @property {string} warehouseName - 仓库名称,支持模糊查询
+ * @property {number} current - 当前页码,从1开始
+ * @property {number} size - 每页条数,范围1-100
  */
 
 /**
  * @typedef {Object} MaterialDetailFormData
  * @description 物料明细表单数据类型定义
- * @property {string} itemCode - 物料编码
- * @property {string} itemName - 物料名称
- * @property {string} specification - 规格型号
- * @property {string} mainCategoryName - 主物料分类
- * @property {string} warehouseName - 仓库名称
- * @property {number} availableQuantity - 可用数量
- * @property {number} orderQuantity - 订单数量
- * @property {number} confirmQuantity - 确认数量
- * @property {number} unitPrice - 单价
- * @property {number} taxRate - 税率
- * @property {number} taxAmount - 税额
- * @property {number} totalAmount - 总金额
- * @property {string} detailStatus - 明细状态
+ * @property {string} itemCode - 物料编码,必填,最大长度50
+ * @property {string} itemName - 物料名称,必填,最大长度100
+ * @property {string} specification - 规格型号,可选,最大长度100
+ * @property {string} mainCategoryName - 主物料分类名称,只读
+ * @property {string} warehouseName - 仓库名称,只读
+ * @property {number} availableQuantity - 可用数量,非负数,精度2位小数
+ * @property {number} orderQuantity - 订单数量,非负数,精度2位小数
+ * @property {number} confirmQuantity - 确认数量,非负数,精度2位小数
+ * @property {number} unitPrice - 单价,非负数,精度2位小数
+ * @property {number} taxRate - 税率,范围0-100,精度2位小数
+ * @property {number} taxAmount - 税额,自动计算,精度2位小数
+ * @property {number} totalAmount - 总金额,自动计算,精度2位小数
+ * @property {MaterialDetailStatus} detailStatus - 明细状态
  */
 
 /**
  * @typedef {Object} MaterialDetailItem
  * @description 物料明细列表项类型定义
- * @property {string|number} id - 明细ID
- * @property {string} itemId - 物料ID
- * @property {string} itemCode - 物料编码
+ * @property {string} id - 明细ID,唯一标识符
+ * @property {string} itemId - 物料ID,关联物料表
+ * @property {string} itemCode - 物料编码,业务唯一标识
  * @property {string} itemName - 物料名称
  * @property {string} specification - 规格型号
  * @property {string} mainCategoryId - 主物料分类ID
@@ -51,9 +70,9 @@
  * @property {number} taxRate - 税率
  * @property {number} taxAmount - 税额
  * @property {number} totalAmount - 总金额
- * @property {string} detailStatus - 明细状态
- * @property {string} createTime - 创建时间
- * @property {string} updateTime - 更新时间
+ * @property {MaterialDetailStatus} detailStatus - 明细状态
+ * @property {string} createTime - 创建时间,ISO 8601格式
+ * @property {string} updateTime - 更新时间,ISO 8601格式
  */
 
 /**
@@ -62,12 +81,61 @@
  */
 
 /**
- * 获取物料明细表格配置
- * @description 生成物料明细表格的AvueJS配置选项
- * @param {boolean} [readonly=false] - 是否为只读模式
- * @returns {AvueCrudOption} AvueJS表格配置对象
+ * AvueJS表格配置选项类型定义
+ * @typedef {Object} AvueTableOption
+ * @description 物料明细表格的AvueJS配置对象
+ * @property {boolean} border - 是否显示边框
+ * @property {boolean} index - 是否显示序号列
+ * @property {boolean} indexLabel - 序号列标题
+ * @property {boolean} stripe - 是否显示斑马纹
+ * @property {boolean} menuAlign - 操作列对齐方式
+ * @property {boolean} align - 表格内容对齐方式
+ * @property {boolean} refreshBtn - 是否显示刷新按钮
+ * @property {boolean} columnBtn - 是否显示列设置按钮
+ * @property {boolean} searchBtn - 是否显示搜索按钮
+ * @property {boolean} addBtn - 是否显示新增按钮
+ * @property {boolean} editBtn - 是否显示编辑按钮
+ * @property {boolean} delBtn - 是否显示删除按钮
+ * @property {boolean} viewBtn - 是否显示查看按钮
+ * @property {boolean} selection - 是否显示多选框
+ * @property {boolean} reserveSelection - 是否保留选择状态
+ * @property {string} height - 表格高度
+ * @property {string} calcHeight - 计算高度的偏移量
+ * @property {Array<AvueColumnOption>} column - 列配置数组
  */
-export function getMaterialDetailOption(readonly = false) {
+
+/**
+ * AvueJS列配置选项类型定义
+ * @typedef {Object} AvueColumnOption
+ * @description 表格列的配置对象
+ * @property {string} label - 列标题
+ * @property {string} prop - 列属性名
+ * @property {string} [type] - 列类型
+ * @property {number} [minWidth] - 最小宽度
+ * @property {number} [width] - 固定宽度
+ * @property {boolean} [sortable] - 是否可排序
+ * @property {boolean} [search] - 是否可搜索
+ * @property {string} [align] - 对齐方式
+ * @property {boolean} [overHidden] - 是否隐藏溢出内容
+ * @property {string} [searchPlaceholder] - 搜索框占位符
+ * @property {Array<{label: string, value: string}>} [dicData] - 字典数据
+ * @property {Object} [props] - 字典属性配置
+ * @property {string} [formatter] - 格式化函数名
+ */
+
+/**
+ * 获取物料明细表格配置选项
+ * @description 返回AvueJS表格组件的配置对象,表格始终为只读模式,不支持编辑、新增、删除操作
+ * @returns {AvueTableOption} AvueJS表格配置对象
+ * @since 2.0.0
+ * @example
+ * // 使用示例
+ * const tableOption = getMaterialDetailOption()
+ * // tableOption.addBtn === false
+ * // tableOption.editBtn === false
+ * // tableOption.delBtn === false
+ */
+export function getMaterialDetailOption() {
   return {
     border: true,
     index: true,
@@ -75,9 +143,9 @@ export function getMaterialDetailOption(readonly = false) {
     stripe: true,
     menuAlign: 'center',
     align: 'center',
-    addBtn: !readonly,
-    editBtn: !readonly,
-    delBtn: !readonly,
+    addBtn: false,
+    editBtn: false,
+    delBtn: false,
     viewBtn: true,
     searchShow: true,
     searchMenuSpan: 6,

+ 105 - 378
src/components/order-form/material-detail-table.vue

@@ -23,15 +23,6 @@
         >
           导入物料
         </el-button>
-        <el-button
-          v-if="selectedRows.length > 0"
-          type="danger"
-          icon="el-icon-delete"
-          size="small"
-          @click="handleBatchDelete"
-        >
-          批量删除 ({{ selectedRows.length }})
-        </el-button>
       </div>
     </div>
 
@@ -43,32 +34,8 @@
         :data="materialDetails"
         :option="tableOption"
         :page.sync="page"
-        @row-save="handleRowSave"
-        @row-update="handleRowUpdate"
-        @row-del="handleRowDelete"
-        @selection-change="handleSelectionChange"
         @refresh-change="handleRefresh"
       >
-        <!-- 自定义操作列 -->
-        <template slot="menuLeft" slot-scope="{ row, index }">
-          <el-button
-            type="text"
-            size="small"
-            icon="el-icon-edit"
-            @click="handleEditDetail(row, index)"
-          >
-            编辑
-          </el-button>
-          <el-button
-            type="text"
-            size="small"
-            icon="el-icon-delete"
-            class="delete-btn"
-            @click="handleDeleteDetail(row, index)"
-          >
-            删除
-          </el-button>
-        </template>
 
         <!-- 总金额列自定义渲染 -->
         <template slot="totalAmount" slot-scope="{ row }">
@@ -95,50 +62,60 @@
       @cancel="handleImportCancel"
     />
 
-    <!-- 编辑明细弹窗 -->
-    <el-dialog
-      title="编辑物料明细"
-      :visible.sync="editDialogVisible"
-      width="600px"
-      :close-on-click-modal="false"
-      @close="handleEditDialogClose"
-    >
-      <avue-form
-        ref="editForm"
-        v-model="editFormData"
-        :option="editFormOption"
-        @submit="handleEditSubmit"
-        @reset-change="handleEditReset"
-      />
-      <div slot="footer" class="dialog-footer">
-        <el-button @click="editDialogVisible = false">取消</el-button>
-        <el-button
-          type="primary"
-          :loading="editLoading"
-          @click="handleEditSubmit"
-        >
-          确定
-        </el-button>
-      </div>
-    </el-dialog>
+
   </div>
 </template>
 
 <script>
-import { getMaterialDetailOption } from './material-detail-option'
+import { getMaterialDetailOption, MATERIAL_DETAIL_STATUS } from './material-detail-option'
 import MaterialImportDialog from './material-import-dialog.vue'
 
 /**
+ * 状态标签类型映射常量
+ * @type {Record<MaterialDetailStatus, TagType>}
+ */
+const STATUS_TAG_TYPE_MAP = {
+  [MATERIAL_DETAIL_STATUS.PENDING]: 'warning',   // 待确认
+  [MATERIAL_DETAIL_STATUS.CONFIRMED]: 'success', // 已确认
+  [MATERIAL_DETAIL_STATUS.CANCELLED]: 'danger'   // 已取消
+}
+
+/**
+ * 状态文本映射常量
+ * @type {Record<MaterialDetailStatus, string>}
+ */
+const STATUS_TEXT_MAP = {
+  [MATERIAL_DETAIL_STATUS.PENDING]: '待确认',
+  [MATERIAL_DETAIL_STATUS.CONFIRMED]: '已确认',
+  [MATERIAL_DETAIL_STATUS.CANCELLED]: '已取消'
+}
+
+/**
  * @typedef {import('./material-detail-option').MaterialDetailItem} MaterialDetailItem
  * @typedef {import('./material-detail-option').MaterialDetailFormData} MaterialDetailFormData
+ * @typedef {import('./material-detail-option').AvueTableOption} AvueTableOption
+ * @typedef {import('./material-detail-option').MaterialDetailStatus} MaterialDetailStatus
+ */
+
+/**
+ * 分页配置类型定义
+ * @typedef {Object} PaginationConfig
+ * @property {number} currentPage - 当前页码,从1开始
+ * @property {number} pageSize - 每页显示条数
+ * @property {number} total - 总记录数
+ */
+
+/**
+ * 状态标签类型映射
+ * @typedef {'warning'|'success'|'danger'|'info'} TagType
  */
 
 /**
  * 物料明细表格组件
- * @description 用于管理订单的物料明细信息,支持导入、编辑、删除等操作
- * @author 系统开发团队
- * @version 1.0.0
- * @since 2024-01-15
+ * @description 用于展示订单的物料明细信息,支持物料导入功能(只读模式)
+ * 该组件已移除所有编辑、新增、删除功能,仅支持数据展示和物料导入
+ * @emits {Array<MaterialDetailItem>} material-import - 物料导入事件
+ * @emits {void} refresh - 刷新事件
  */
 export default {
   name: 'MaterialDetailTable',
@@ -151,47 +128,43 @@ export default {
    */
   props: {
     /**
-     * 订单ID
+     * 订单ID - 关联的订单唯一标识符
      * @type {string|number|null}
      */
     orderId: {
       type: [String, Number],
-      default: null
+      default: null,
+      validator: (value) => value === null || value === undefined || (typeof value === 'string' && value.length > 0) || (typeof value === 'number' && value > 0)
     },
 
-    /**
-     * 是否为编辑模式
-     * @type {boolean}
-     */
-    isEdit: {
-      type: Boolean,
-      default: false
-    },
+
 
     /**
-     * 物料明细列表
+     * 物料明细列表 - 要展示的物料明细数据
      * @type {Array<MaterialDetailItem>}
      */
     materialDetails: {
       type: Array,
-      default: () => []
+      default: () => [],
+      validator: (value) => Array.isArray(value)
     }
   },
 
   /**
    * 组件数据
+   * @returns {Object} 组件响应式数据对象
    */
   data() {
     return {
       /**
-       * 表单数据
+       * 表单数据 - AvueJS组件的表单数据绑定
        * @type {MaterialDetailFormData}
        */
       formData: {},
 
       /**
-       * 分页配置
-       * @type {Object}
+       * 分页配置 - 表格分页相关配置
+       * @type {PaginationConfig}
        */
       page: {
         currentPage: 1,
@@ -200,40 +173,10 @@ export default {
       },
 
       /**
-       * 选中的行数据
-       * @type {Array<MaterialDetailItem>}
-       */
-      selectedRows: [],
-
-      /**
-       * 导入弹窗显示状态
-       * @type {boolean}
-       */
-      importDialogVisible: false,
-
-      /**
-       * 编辑弹窗显示状态
-       * @type {boolean}
-       */
-      editDialogVisible: false,
-
-      /**
-       * 编辑表单数据
-       * @type {MaterialDetailFormData}
-       */
-      editFormData: {},
-
-      /**
-       * 编辑加载状态
+       * 导入弹窗显示状态 - 控制物料导入弹窗的显示/隐藏
        * @type {boolean}
        */
-      editLoading: false,
-
-      /**
-       * 当前编辑的行索引
-       * @type {number|null}
-       */
-      editRowIndex: null
+      importDialogVisible: false
     }
   },
 
@@ -242,23 +185,11 @@ export default {
    */
   computed: {
     /**
-     * 表格配置选项
-     * @returns {Object} AvueJS表格配置
+     * 表格配置选项 - 获取AvueJS表格的配置对象
+     * @returns {AvueTableOption} AvueJS表格配置对象,已配置为只读模式
      */
     tableOption() {
-      return getMaterialDetailOption(!this.isEdit)
-    },
-
-    /**
-     * 编辑表单配置选项
-     * @returns {Object} AvueJS表单配置
-     */
-    editFormOption() {
-      return {
-        submitBtn: false,
-        emptyBtn: false,
-        column: this.tableOption.column.filter(col => !col.hide)
-      }
+      return getMaterialDetailOption()
     }
   },
 
@@ -283,296 +214,92 @@ export default {
    */
   methods: {
     /**
-     * 处理导入物料按钮点击
-     * @description 打开物料导入弹窗
+     * 处理导入物料按钮点击事件
+     * @description 打开物料导入弹窗,允许用户选择和导入物料
+     * @returns {void}
      */
     handleImportMaterial() {
       this.importDialogVisible = true
     },
 
     /**
-     * 处理批量删除
-     * @description 删除选中的物料明细
-     */
-    async handleBatchDelete() {
-      try {
-        await this.$confirm(
-          `确定要删除选中的 ${this.selectedRows.length} 条物料明细吗?`,
-          '批量删除确认',
-          {
-            confirmButtonText: '确定',
-            cancelButtonText: '取消',
-            type: 'warning'
-          }
-        )
-
-        // 过滤掉选中的行
-        const updatedDetails = this.materialDetails.filter(
-          item => !this.selectedRows.some(selected => selected.id === item.id)
-        )
-
-        this.$emit('material-change', updatedDetails)
-        this.$message.success(`成功删除 ${this.selectedRows.length} 条物料明细`)
-        this.selectedRows = []
-      } catch (error) {
-        // 用户取消删除
-      }
-    },
-
-    /**
-     * 处理行保存
-     * @param {MaterialDetailFormData} row - 行数据
-     * @param {Function} done - 完成回调
-     * @param {Function} loading - 加载状态回调
-     */
-    async handleRowSave(row, done, loading) {
-      try {
-        loading(true)
-        
-        // 计算总金额
-        const calculatedRow = this.calculateRowAmounts(row)
-        
-        // 生成新的ID
-        const newRow = {
-          ...calculatedRow,
-          id: Date.now().toString(),
-          createTime: new Date().toISOString(),
-          updateTime: new Date().toISOString()
-        }
-
-        const updatedDetails = [...this.materialDetails, newRow]
-        this.$emit('material-change', updatedDetails)
-        
-        this.$message.success('添加物料明细成功')
-        done()
-      } catch (error) {
-        this.$message.error('添加物料明细失败')
-      } finally {
-        loading(false)
-      }
-    },
-
-    /**
-     * 处理行更新
-     * @param {MaterialDetailFormData} row - 行数据
-     * @param {number} index - 行索引
-     * @param {Function} done - 完成回调
-     * @param {Function} loading - 加载状态回调
-     */
-    async handleRowUpdate(row, index, done, loading) {
-      try {
-        loading(true)
-        
-        // 计算总金额
-        const calculatedRow = this.calculateRowAmounts(row)
-        calculatedRow.updateTime = new Date().toISOString()
-
-        const updatedDetails = [...this.materialDetails]
-        updatedDetails[index] = calculatedRow
-        
-        this.$emit('material-change', updatedDetails)
-        this.$message.success('更新物料明细成功')
-        done()
-      } catch (error) {
-        this.$message.error('更新物料明细失败')
-      } finally {
-        loading(false)
-      }
-    },
-
-    /**
-     * 处理行删除
-     * @param {MaterialDetailItem} row - 行数据
-     * @param {number} index - 行索引
-     */
-    async handleRowDelete(row, index) {
-      try {
-        await this.$confirm(
-          '确定要删除这条物料明细吗?',
-          '删除确认',
-          {
-            confirmButtonText: '确定',
-            cancelButtonText: '取消',
-            type: 'warning'
-          }
-        )
-
-        const updatedDetails = this.materialDetails.filter((_, i) => i !== index)
-        this.$emit('material-change', updatedDetails)
-        this.$message.success('删除物料明细成功')
-      } catch (error) {
-        // 用户取消删除
-      }
-    },
-
-    /**
-     * 处理选择变化
-     * @param {Array<MaterialDetailItem>} selection - 选中的行数据
-     */
-    handleSelectionChange(selection) {
-      this.selectedRows = selection
-    },
-
-    /**
-     * 处理刷新
+     * 处理表格刷新事件
+     * @description 触发刷新事件,通知父组件重新加载数据
+     * @returns {void}
+     * @emits refresh
      */
     handleRefresh() {
-      // 刷新逻辑,如果需要的话
-    },
-
-    /**
-     * 处理编辑明细
-     * @param {MaterialDetailItem} row - 行数据
-     * @param {number} index - 行索引
-     */
-    handleEditDetail(row, index) {
-      this.editFormData = { ...row }
-      this.editRowIndex = index
-      this.editDialogVisible = true
-    },
-
-    /**
-     * 处理删除明细
-     * @param {MaterialDetailItem} row - 行数据
-     * @param {number} index - 行索引
-     */
-    handleDeleteDetail(row, index) {
-      this.handleRowDelete(row, index)
-    },
-
-    /**
-     * 处理编辑提交
-     */
-    async handleEditSubmit() {
-      try {
-        this.editLoading = true
-        
-        // 表单验证
-        const valid = await this.validateEditForm()
-        if (!valid) {
-          return
-        }
-
-        // 计算总金额
-        const calculatedData = this.calculateRowAmounts(this.editFormData)
-        calculatedData.updateTime = new Date().toISOString()
-
-        const updatedDetails = [...this.materialDetails]
-        updatedDetails[this.editRowIndex] = calculatedData
-        
-        this.$emit('material-change', updatedDetails)
-        this.$message.success('更新物料明细成功')
-        this.editDialogVisible = false
-      } catch (error) {
-        this.$message.error('更新物料明细失败')
-      } finally {
-        this.editLoading = false
-      }
-    },
-
-    /**
-     * 处理编辑重置
-     */
-    handleEditReset() {
-      this.editFormData = {}
-    },
-
-    /**
-     * 处理编辑弹窗关闭
-     */
-    handleEditDialogClose() {
-      this.editFormData = {}
-      this.editRowIndex = null
+      this.$emit('refresh')
     },
 
     /**
-     * 处理导入确认
-     * @param {Array<MaterialDetailItem>} importedMaterials - 导入的物料列表
+     * 处理物料导入确认事件
+     * @description 处理物料导入确认,将导入的物料数据传递给父组件并关闭弹窗
+     * @param {Array<MaterialDetailItem>} importedMaterials - 导入的物料列表,必须为有效的物料明细数组
+     * @returns {void}
+     * @emits material-import
      */
     handleImportConfirm(importedMaterials) {
+      if (!Array.isArray(importedMaterials)) {
+        console.warn('导入的物料数据必须为数组格式')
+        return
+      }
       this.$emit('material-import', importedMaterials)
       this.importDialogVisible = false
     },
 
     /**
-     * 处理导入取消
+     * 处理物料导入取消事件
+     * @description 取消物料导入操作,关闭导入弹窗
+     * @returns {void}
      */
     handleImportCancel() {
       this.importDialogVisible = false
     },
 
     /**
-     * 验证编辑表单
-     * @returns {Promise<boolean>} 验证结果
-     */
-    async validateEditForm() {
-      return new Promise((resolve) => {
-        this.$refs.editForm.validate((valid) => {
-          resolve(valid)
-        })
-      })
-    },
-
-    /**
-     * 计算行金额
-     * @param {MaterialDetailFormData} row - 行数据
-     * @returns {MaterialDetailFormData} 计算后的行数据
-     */
-    calculateRowAmounts(row) {
-      const orderQuantity = Number(row.orderQuantity) || 0
-      const unitPrice = Number(row.unitPrice) || 0
-      const taxRate = Number(row.taxRate) || 0
-
-      // 计算税额和总金额
-      const subtotal = orderQuantity * unitPrice
-      const taxAmount = subtotal * (taxRate / 100)
-      const totalAmount = subtotal + taxAmount
-
-      return {
-        ...row,
-        orderQuantity,
-        unitPrice,
-        taxRate,
-        taxAmount: Number(taxAmount.toFixed(2)),
-        totalAmount: Number(totalAmount.toFixed(2))
-      }
-    },
-
-    /**
      * 格式化金额显示
-     * @param {number} amount - 金额
-     * @returns {string} 格式化后的金额字符串
+     * @description 将数字金额格式化为带货币符号的字符串,保留2位小数
+     * @param {number|string|null|undefined} amount - 金额数值,支持数字、字符串或空值
+     * @returns {string} 格式化后的金额字符串,格式为 ¥XX.XX
+     * @example
+     * formatAmount(123.456) // 返回 "¥123.46"
+     * formatAmount(null) // 返回 "¥0.00"
+     * formatAmount('100') // 返回 "¥100.00"
      */
     formatAmount(amount) {
-      return `¥${Number(amount || 0).toFixed(2)}`
+      const numAmount = Number(amount || 0)
+      if (isNaN(numAmount)) {
+        console.warn(`无效的金额值: ${amount}`)
+        return '¥0.00'
+      }
+      return `¥${numAmount.toFixed(2)}`
     },
 
     /**
      * 获取状态标签类型
-     * @param {string} status - 状态值
-     * @returns {string} 标签类型
+     * @description 根据物料明细状态值返回对应的Element UI标签类型
+     * @param {MaterialDetailStatus} status - 物料明细状态值
+     * @returns {TagType} Element UI标签类型
+     * @example
+     * getStatusTagType('0') // 返回 'warning'
+     * getStatusTagType('1') // 返回 'success'
      */
     getStatusTagType(status) {
-      const typeMap = {
-        '0': 'warning', // 待确认
-        '1': 'success', // 已确认
-        '2': 'danger'   // 已取消
-      }
-      return typeMap[status] || 'info'
+      return STATUS_TAG_TYPE_MAP[status] || 'info'
     },
 
     /**
      * 获取状态文本
-     * @param {string} status - 状态值
-     * @returns {string} 状态文本
+     * @description 根据物料明细状态值返回对应的中文描述
+     * @param {MaterialDetailStatus} status - 物料明细状态值
+     * @returns {string} 状态的中文描述文本
+     * @example
+     * getStatusText('0') // 返回 '待确认'
+     * getStatusText('1') // 返回 '已确认'
      */
     getStatusText(status) {
-      const textMap = {
-        '0': '待确认',
-        '1': '已确认',
-        '2': '已取消'
-      }
-      return textMap[status] || '未知'
+      return STATUS_TEXT_MAP[status] || '未知'
     }
   }
 }
@@ -652,4 +379,4 @@ export default {
     justify-content: flex-end;
   }
 }
-</style>
+</style>

+ 12 - 10
src/components/order-form/order-form-mixin.js

@@ -320,7 +320,7 @@ export default {
 
         // 等待DOM更新后清除表单验证
         await this.$nextTick()
-        
+
         if (this.$refs.orderForm && typeof this.$refs.orderForm.clearValidate === 'function') {
           this.$refs.orderForm.clearValidate()
         }
@@ -344,16 +344,16 @@ export default {
 
       try {
         const response = await getDetail(orderId)
-        
+
         if (!response || !response.data || !response.data.data) {
           throw new Error('服务器返回数据格式错误')
         }
 
         const orderData = response.data.data
-        
+
         // 安全地映射订单数据到表单,确保数据类型正确
         this.formData = this.mapOrderDataToForm(orderData)
-        
+
       } catch (error) {
         const errorMessage = error.message || '加载订单详情失败'
         console.error('加载订单详情失败:', error)
@@ -485,15 +485,17 @@ export default {
       }
 
       try {
-        // AvueJS 表单验证方法,使用 Promise 包装
-        return new Promise((resolve) => {
+        const isValid = await new Promise((resolve) => {
           this.$refs.orderForm.validate((valid) => {
-            if (!valid) {
-              this.$message.warning('请检查表单填写是否正确')
-            }
             resolve(Boolean(valid))
           })
         })
+
+        if (!isValid) {
+          this.$message.warning('请检查表单填写是否正确')
+        }
+
+        return isValid
       } catch (error) {
         console.warn('表单验证失败:', error)
         this.$message.warning('请检查表单填写是否正确')
@@ -526,7 +528,7 @@ export default {
 
       Object.keys(data).forEach(key => {
         const value = data[key]
-        
+
         // 跳过null、undefined和空字符串,但保留备注字段
         if (value === null || value === undefined || (value === '' && key !== 'remark')) {
           return