yhj
2024-06-05 b22000f1e0034376f408d236f4425e1dc98e51d8
pages/inspection/inspectionInfo.vue
@@ -77,6 +77,23 @@
               </u-row>
               <u-button text="生成检验资料" type="primary" :plain="true" style="width: 200px;height: 100px;position: absolute;top: 30%;right: 10%;" @click="generate()"></u-button>
            </view>
             <view class="container">
                 <button @click="fetchDrawingNumber">查看图号</button>
                 <!-- 弹出窗口 -->
                 <view v-if="pdfVisible" class="modal">
                   <view class="modal-content">
                     <view class="modal-header">
                       <text>PDF预览</text>
                       <button @click="closeModal">关闭</button>
                     </view>
                     <web-view v-if="pdfLink" :src="pdfLink" class="pdf-view"></web-view>
                   </view>
                 </view>
               </view>
         </uni-card>
      </view>
@@ -304,6 +321,7 @@
            })
         },
         getBadReason() {
            getBadReason().then(res => {
               console.log(res)
               if(!res.result) {
@@ -323,7 +341,70 @@
               }
            }
            return true
         }
      },
      getMaterialInfo(checkNo) {
           return uni.request({
             url: '/check/getMaterialInfo?checkNo=' + checkNo,
             method: 'POST',
             header: {
               'Content-Type': 'application/json',
               'dataType': 'json',
               'Accept': 'application/json'
             }
           });
         },
          closeModal() {
                 this.pdfVisible = false;
               },
      fetchDrawingNumber() {
                        // 获取当前页面的检验单号
                        const checkNo = this.item.CHECK_NO;
                        // 第一次请求:获取物料信息
                        this.getMaterialInfo(checkNo).then(res => {
                          const data = res[1].data; // uni.request 返回的是一个数组,res[1] 才是 response
                          if (data.result) {
                            const { materialId, drawingNumber } = data.data;
                             const url = `http://192.168.0.98:808/deviceMessage.ashx?lb=${materialId}&id=${drawingNumber}`;
                            // 第二次请求:获取PDF链接
                            uni.request({
                              url: url,
                              method: 'POST',
                              success: (response) => {
                                const respData = response.data;
                                if (respData.result) {
                                  this.pdfLink = respData.link; // 设置PDF链接
                                  this.pdfVisible = true; // 打开弹出窗口
                                } else {
                                  uni.showToast({
                                    title: respData.msg,
                                    icon: 'none'
                                  });
                                }
                              },
                              fail: (error) => {
                                uni.showToast({
                                  title: '请求图号链接失败',
                                  icon: 'none'
                                });
                              }
                            });
                          } else {
                            uni.showToast({
                              title: data.msg,
                              icon: 'none'
                            });
                          }
                        }).catch(error => {
                          uni.showToast({
                            title: '获取物料信息失败',
                            icon: 'none'
                          });
                        });
      }
   }
</script>