Browse Source

优化表单数据处理,确保后端返回的数字类型正确转换为数字;调整操作列宽度,新增导出功能

liqianyi 2 days ago
parent
commit
6e3c962759

+ 11 - 0
src/views/modules/production/plan-submit.vue

@@ -212,6 +212,17 @@ export default {
             }
           })
 
+          // 后端有时把数字类型返回为字符串,导致 el-radio 的严格相等比较失败(无法显示已选中)。
+          // 在这里把相关字段转换为 Number,确保和模板中 :label 使用的类型一致。
+          this.dataForm.proProductList.forEach(p => {
+            if (p.disposal != null && p.disposal !== '') {
+              p.disposal = Number(p.disposal)
+            }
+            if (p.isTechnology != null && p.isTechnology !== '') {
+              p.isTechnology = Number(p.isTechnology)
+            }
+          })
+
           // console.log(this.dataForm)
         } else {
           this.$message.error(data.msg)

+ 5 - 3
src/views/modules/production/plan.vue

@@ -35,7 +35,7 @@
         <el-table-column prop="state" header-align="center" align="center" min-width="160"
           :show-tooltip-when-overflow="true" :formatter="formatState" label="状态">
         </el-table-column>
-        <el-table-column fixed="right" header-align="center" align="center" width="220" label="操作">
+        <el-table-column fixed="right" header-align="center" align="center" width="130" label="操作">
           <template slot-scope="scope">
             <el-button type="text" size="small" @click="submitHandle(scope.row, true)">查看</el-button>
             <el-button v-if="scope.row.state == 1" type="text" size="small"
@@ -51,8 +51,10 @@
       </el-pagination>
     </template>
     <!-- 弹窗 -->
-    <assign v-if="assignVisible" ref="assign" @onChose="onChose" @refreshDataList="getDataList"/>
-    <notice-change v-if="noticeChangeVisible" ref="noticeChange" @onChose="onChose" @refreshDataList="getDataList"/>
+    <assign v-if="assignVisible" ref="assign" @onChose="onChose" @refreshDataList="getDataList" />
+    <!-- 通知变更设置弹窗 -->
+    <notice-change v-if="noticeChangeVisible" ref="noticeChange" @onChose="onChose" @refreshDataList="getDataList" />
+    <!-- 处理弹窗 -->
     <submit-plan v-if="submitVisible" ref="submit" @onChose="onChose" @refreshDataList="getDataList" />
   </div>
 </template>

+ 42 - 4
src/views/modules/tech/project-tech-submit.vue

@@ -97,13 +97,13 @@
         <el-table-column fixed="right" prop="cntAll" header-align="center" align="center" min-width="80"
           :show-tooltip-when-overflow="true" label="计划数量">
         </el-table-column>
-        <el-table-column fixed="right" prop="isTechnology" header-align="center" align="center" min-width="140"
+        <el-table-column fixed="right" prop="isTechnology" header-align="center" align="center" min-width="110"
           :show-tooltip-when-overflow="true" label="是否编制工艺">
           <template slot-scope="scope">
             {{ scope.row.isTechnology == 2 ? '否' : '是' }}
           </template>
         </el-table-column>
-        <el-table-column fixed="right" prop="techId" header-align="center" align="center" min-width="140"
+        <el-table-column fixed="right" prop="techId" header-align="center" align="center" min-width="100"
           :show-tooltip-when-overflow="true" label="是否有工艺">
           <template slot-scope="scope">
             {{ scope.row.techId == null || scope.row.techId == 0 ? '否' : '是' }}
@@ -112,12 +112,15 @@
         <el-table-column prop="notes" header-align="center" align="center" min-width="140"
           :show-tooltip-when-overflow="true" label="备注">
         </el-table-column>
-        <el-table-column v-if="!disabled" fixed="right" prop="disposal" header-align="center" align="center" width="120"
+        <el-table-column v-if="!disabled" fixed="right" prop="disposal" header-align="center" align="center" width="150"
           :show-tooltip-when-overflow="true" label="操作">
           <template slot-scope="scope">
             <el-button type="text" v-if="scope.row.techId == null || scope.row.techId == 0"
               @click="handleCrafts(0, scope.row.productId)">新建工艺</el-button>
-            <el-button type="text" v-else @click="handleCrafts(scope.row.techId, scope.row.productId)">修改工艺</el-button>
+            <template v-else>
+              <el-button type="text" @click="handleCrafts(scope.row.techId, scope.row.productId)">修改工艺</el-button>
+              <el-button type="text" @click="exportCraft(scope.row)">导出</el-button>
+            </template>
           </template>
         </el-table-column>
       </el-table>
@@ -259,6 +262,41 @@ export default {
       console.log('productId:' + productId)
       this.$emit('showCraftsAddOrDetail', techId, this.orderId, productId)
     }
+    ,
+    // 导出某一行的工艺为 Excel
+    exportCraft(row) {
+      // 按需求构造传入的部分数据
+      const payload = {
+        batchNumber: row.batchNumber || '',
+        cntAll: row.cntAll || 0,
+        orderCode: this.dataForm.orderCode || '',
+        productName: row.productName || '',
+        // 后端字段要求的是 techI(按用户说明),这里传入当前行的 techId
+        techI: row.techId || 0
+      }
+
+      this.$http({
+        url: this.$http.adornUrl('/biz-service/projTechnology/exportExcel'),
+        method: 'post',
+        data: this.$http.adornData(payload),
+        responseType: 'blob'
+      }).then(response => {
+        const blob = new Blob([response.data], { type: 'application/vnd.ms-excel' })
+        const url = window.URL.createObjectURL(blob)
+        const link = document.createElement('a')
+        link.href = url
+        // 使用产品名作为文件名的一部分,回退到通用名
+        const name = (row.productName ? row.productName + '-' : '') + '工艺导出.xlsx'
+        link.setAttribute('download', name)
+        document.body.appendChild(link)
+        link.click()
+        document.body.removeChild(link)
+        window.URL.revokeObjectURL(url)
+      }).catch(err => {
+        console.error('导出失败', err)
+        this.$message.error('导出失败')
+      })
+    }
   }
 }
 </script>

+ 4 - 1
src/views/modules/tech/project-tech.vue

@@ -52,11 +52,14 @@
         layout="total, sizes, prev, pager, next, jumper">
       </el-pagination>
     </template>
-    <!-- 弹窗 -->
+    <!-- 指派弹窗 -->
     <assign v-if="assignVisible" ref="assign" @onChose="onChose" @refreshDataList="getDataList" />
+    <!-- 通知变更设置弹窗 -->
     <notice-change v-if="noticeChangeVisible" ref="noticeChange" @onChose="onChose" />
+    <!-- 处理弹窗 -->
     <submit-plan v-if="submitVisible" ref="submit" @onChose="onChose" @showCraftsAddOrDetail="showCraftsAddOrDetail"
       @refreshDataList="getDataList" />
+    <!-- 工艺详情弹窗 -->
     <crafts-add-or-detail ref="craftsAddOrDetail" @onChose="onCloseCraftsAddOrDetail" v-if="craftsAddOrDetailVisible"
       @refreshDataList="getDataList" />
   </div>