yhj
2024-06-05 b22000f1e0034376f408d236f4425e1dc98e51d8
pages/inspection/inspectionInfo.vue
@@ -2,62 +2,98 @@
   <view>
      <view>
         <uni-card>
            <u-row customStyle="margin-bottom: 10px">
               <u-col span="2">
                  <label>检验单号:</label>
               </u-col>
               <u-col span="4">
                  <label>{{item.TASK_NO}}</label>
               </u-col>
            </u-row>
            <u-row customStyle="margin-bottom: 10px">
               <u-col span="2">
                  <label>机台号:</label>
               </u-col>
               <u-col span="4">
                  <label>{{item.MACHINE_NO}}</label>
               </u-col>
            </u-row>
            <u-row customStyle="margin-bottom: 10px">
               <u-col span="2">
                  <label>工序名称:</label>
               </u-col>
               <u-col span="4">
                  <label>{{item.PROC_NAME}}</label>
               </u-col>
            </u-row>
            <u-row customStyle="margin-bottom: 10px">
               <u-col span="2">
                  <label>产品名称:</label>
               </u-col>
               <u-col span="4">
                  <label>{{item.ITEM_NAME}}</label>
               </u-col>
            </u-row>
            <u-row customStyle="margin-bottom: 10px">
               <u-col span="2">
                  <label>产品编号:</label>
               </u-col>
               <u-col span="4">
                  <label>{{item.ITEM_NO}}</label>
               </u-col>
            </u-row>
            <u-row customStyle="margin-bottom: 10px">
               <u-col span="2">
                  <label>检验员:</label>
               </u-col>
               <u-col span="4">
                  <label>{{name}}</label>
               </u-col>
            </u-row>
            <u-row customStyle="margin-bottom: 10px">
               <u-col span="2">
                  <label>检验类型</label>
               </u-col>
               <u-col span="4">
                  <label>{{item.REMEKE}}</label>
               </u-col>
            </u-row>
            <view :class="new Date().getTime()-new Date(item.BEGIN_TIME).getTime()>7200000?'red':''">
               <u-row customStyle="margin-bottom: 10px">
                  <u-col span="2">
                     <label>检验单号:</label>
                  </u-col>
                  <u-col span="4">
                     <label>{{item.TASK_NO}}</label>
                  </u-col>
               </u-row>
               <u-row customStyle="margin-bottom: 10px" v-if="item.LOT_NO">
                  <u-col span="2">
                     <label>销售单号:</label>
                  </u-col>
                  <u-col span="4">
                     <label>{{item.LOT_NO}}</label>
                  </u-col>
               </u-row>
               <u-row customStyle="margin-bottom: 10px">
                  <u-col span="2">
                     <label>工单数量:</label>
                  </u-col>
                  <u-col span="4">
                     <label>{{item.DAA008}}</label>
                  </u-col>
               </u-row>
               <u-row customStyle="margin-bottom: 10px">
                  <u-col span="2">
                     <label>机台 / 产线:</label>
                  </u-col>
                  <u-col span="4">
                     <label>{{item.MACHINE_NO}}</label>
                  </u-col>
               </u-row>
               <u-row customStyle="margin-bottom: 10px" v-if="item.PROC_NAME">
                  <u-col span="2">
                     <label>工序名称:</label>
                  </u-col>
                  <u-col span="4">
                     <label>{{item.PROC_NAME}}</label>
                  </u-col>
               </u-row>
               <u-row customStyle="margin-bottom: 10px">
                  <u-col span="2">
                     <label>产品名称:</label>
                  </u-col>
                  <u-col span="4">
                     <label>{{item.ITEM_NO}} | {{item.ITEM_NAME}}</label>
                  </u-col>
               </u-row>
               <u-row customStyle="margin-bottom: 10px">
                  <u-col span="2">
                     <label>图号颜色:</label>
                  </u-col>
                  <u-col>
                     <label>{{item.ENGINEERING_NO}} / {{item.COLOR_NAME}}</label>
                  </u-col>
               </u-row>
               <u-row customStyle="margin-bottom: 10px">
                  <u-col span="2">
                     <label>规格材质:</label>
                  </u-col>
                  <u-col>
                     <label>{{item.MODEL}} / {{item.MATERIAL}}</label>
                  </u-col>
               </u-row>
               <u-row customStyle="margin-bottom: 10px">
                  <u-col span="2">
                     <label>检验员/检验类型:</label>
                  </u-col>
                  <u-col span="4">
                     <label>{{item.OPERATE_MAN}} / {{item.FTYPE}}</label>
                  </u-col>
               </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>
@@ -65,20 +101,24 @@
         <uni-table border stripe emptyText="暂无更多数据" style="margin-left: 5px;margin-right: 5px;">
            <!-- 表头行 -->
            <uni-tr>
               <uni-th align="center" width="80">检验项目</uni-th>
               <uni-th align="left" width="100">检验工具</uni-th>
               <uni-th align="left" width="180">备注</uni-th>
               <uni-th align="left" width="30">检验数量</uni-th>
               <uni-th align="left" width="80">上限值</uni-th>
               <uni-th align="left" width="80">下限值</uni-th>
               <uni-th align="left" width="100">检验值</uni-th>
               <uni-th align="left" width="80">检验结果</uni-th>
               <uni-th align="center" width="60">检验项目</uni-th>
               <uni-th align="center" width="60">检验工具</uni-th>
               <uni-th align="center" width="140">规格</uni-th>
               <uni-th align="center" width="80" v-if="item.DEPARTMENT_NO=='HS0202'">组件名称</uni-th>
               <uni-th align="center" width="40">数量</uni-th>
               <uni-th align="center" width="60">上限值</uni-th>
               <uni-th align="center" width="60">下限值</uni-th>
               <uni-th align="center" width="70">检验值</uni-th>
               <uni-th align="center" width="78">结果</uni-th>
               <uni-th align="center" width="80">不良原因</uni-th>
               <uni-th align="center" width="80">备注</uni-th>
            </uni-tr>
            <!-- 表格数据行 -->
            <uni-tr v-for="item in table">
            <uni-tr v-for="(item,index) in table">
               <uni-td>{{item.CHECK_ITEM}}</uni-td>
               <uni-td>{{item.CHECK_TOOL}}</uni-td>
               <uni-td>{{item.SPECIFICATION}}</uni-td>
               <uni-td v-if="item.FTEXT_TYPE">{{item.FTEXT_TYPE}}</uni-td>
               <uni-td>{{item.CHECK_NUM}}</uni-td>
               <uni-td>{{item.UP_ALLOW}}</uni-td>
               <uni-td>{{item.DOWN_ALLOW}}</uni-td>
@@ -89,29 +129,61 @@
               </uni-td>
               <uni-td>
                  <u-tag
                     v-if="item.UP_ALLOW && item.VALUE <= item.UP_ALLOW && item.VALUE >= item.DOWN_ALLOW || !item.UP_ALLOW && item.VALUE == '合格'"
                     v-if="item.UP_ALLOW && (parseFloat(item.VALUE) <= parseFloat(item.UP_ALLOW) && parseFloat(item.VALUE) >= parseFloat(item.DOWN_ALLOW)) || (!item.UP_ALLOW && item.VALUE == '合格')"
                     text="合格" type="success"></u-tag>
                  <u-tag
                     v-if="item.UP_ALLOW && (item.VALUE > item.UP_ALLOW || item.VALUE < item.DOWN_ALLOW) || !item.UP_ALLOW && item.VALUE == '不合格'"
                     v-else
                     text="不合格" type="error"></u-tag>
               </uni-td>
               <uni-td>
<!--                   <view class="content" @click="useOutClickSide">
                     <easy-select ref="easySelect" size="medium" :value="item.BAD_REASON" @selectOne="selectOne($event,index)"></easy-select>
                  </view> -->
                  <view class="login">
                     <w-select style="margin-left: 20rpx;" v-model='chooseValue' defaultValue="请选择"
                     :list='list' valueName='CONTENT' keyName="ID" @change='change(index)'>
                     </w-select>
                  </view>
               </uni-td>
               <uni-td>
                  <u--textarea height="40px" v-model="item.MEMO" placeholder="请输入内容"></u--textarea>
               </uni-td>
            </uni-tr>
         </uni-table>
      </view>
      <u-button text="提交"  type="primary" style="position: absolute;bottom:0;" @click="submit()"></u-button>
      <view style="margin-top: 10px;">
         <u-row style="margin-bottom: 5px;">
            <u--text type="info" text="备注"></u--text>
         </u-row>
         <u-row>
            <u--textarea v-model="remeke" placeholder="请输入内容"></u--textarea>
         </u-row>
      </view>
      <u-button text="提交" type="primary" style="margin-top: 10px;" @click="submit()"></u-button>
      <u-toast ref="uToast" />
   </view>
</template>
<script>
   import {
      getInspectionInfo, saveInspectionInfo
      getInspectionInfo,
      saveInspectionInfo,
      getBadReason,
      generateInfo
   } from '../../api/inspection';
   import {
      baseUrl
   } from '../../config.js'
   export default {
      data() {
         return {
            item: {},
            table: [],
            name:''
            name: '',
            remeke: '',
            //show: false
            chooseValue: "",
            list: []
         }
      },
      onLoad(option) {
@@ -119,27 +191,70 @@
         this.item = item
         this.getInspection(item.CHECK_NO)
         this.name = uni.getStorageSync('userInfo').username
         this.getBadReason()
      },
      onNavigationBarButtonTap(e) {
         let that = this
         uni.chooseImage({
            count: 1,
            sizeType: ['original', 'compressed'],
            sourceType: ['camera'],
            success: chooseImage => {
               const tempFilePaths = chooseImage.tempFilePaths;
               uni.uploadFile({
                  url: 'http://183.249.77.50:8008' + '/hkFile/upload?mid=' + that.item.CHECK_NO +
                     '&username=' + uni.getStorageSync('userInfo').code,
                  filePath: tempFilePaths[0],
                  name: 'file',
                  success: (uploadFileRes) => {
                     console.log(uploadFileRes.data);
                  },
                  fail: (res) => {
                     console.log(res)
                  }
               });
            }
         })
      },
      methods: {
         getInspection(chenkNo) {
            getInspectionInfo(chenkNo).then(res => {
               // this.table = res.data
               for (let item of res.data) {
                  for (let i = 0; i < parseInt(item.CHECK_NUM); i++) {
                     let insert = JSON.parse(JSON.stringify(item))
                     insert.CHECK_ITEM = insert.CHECK_ITEM + '-' + i
                     if (!insert.UP_ALLOW) {
                        insert.VALUE = '合格'
                     } else {
                        insert.VALUE = 0
                     }
                     this.table.push(insert)
                  // for (let i = 0; i < parseInt(item.CHECK_NUM); i++) {
                  //    let insert = JSON.parse(JSON.stringify(item))
                  //    insert.CHECK_ITEM = insert.CHECK_ITEM + '-' + i
                  //    if (!insert.UP_ALLOW) {
                  //       insert.VALUE = '合格'
                  //    } else {
                  //       insert.VALUE = null
                  //    }
                  //    this.table.push(insert)
                  // }
                  if (!item.UP_ALLOW) {
                     item.VALUE = '合格'
                  } else {
                     item.VALUE = null
                  }
                  this.table.push(item)
               }
               console.log(this.table)
            })
         },
         // selectOne(options,index) {
         //    this.table[index].BAD_REASON = options.label
         //    console.log(options.label);
         // },
         // useOutClickSide() {
         //    this.$refs.easySelect.hideOptions && this.$refs.easySelect.hideOptions()
         // },
         change(index) {
            this.table[index].BAD_REASON=this.chooseValue;
         },
         changeSwitch(item) {
            console.log(item)
            if (item.VALUE == '合格') {
               item.VALUE = '不合格'
            } else {
@@ -147,11 +262,150 @@
            }
         },
         submit() {
            saveInspectionInfo(this.item.CHECK_NO,this.table).then(res => {
               console.log(res)
            if(this.table.length==0){
               this.$refs.uToast.show({
                  message: "提交失败,请维护检验项目",
                  type: 'error'
               })
               return
            }else{
               if(this.check()) {
                  saveInspectionInfo(this.item.CHECK_NO, this.table, this.remeke).then(res => {
                     if(!res.result) {
                        this.$refs.uToast.show({
                           message: res.msg,
                           type: 'error'
                        })
                        return
                     }else{
                        // this.$refs.uToast.show({
                        //    message: "提交成功",
                        //    type: 'success'
                        // })
                        let pages=getCurrentPages();
                        let beforePage=pages[pages.length-2];
                        uni.navigateBack({
                           delta: 1,  //返回的页面数,如果为1表示返回上一页
                           success: (event)=> {
                              console.log('提交成功');
                              beforePage.$vm.reload()
                           }
                        });
                     }
                  })
                  return
               }
               this.$refs.uToast.show({
                  message: '有检验项目未录入完整测试结果!',
                  type: 'error'
               })
               return
            }
         },
         generate(){
            generateInfo(this.item.CHECK_NO).then(res=>{
               if(!res.result){
                  this.$refs.uToast.show({
                     message:res.msg,
                     type:'error'
                  })
                  return
               }else{
                  this.$refs.uToast.show({
                     message: "更新成功",
                     type: 'success'
                  })
                  this.table.splice(0,this.table.length)
                  this.getInspection(this.item.CHECK_NO)
               }
            })
         },
         getBadReason() {
            getBadReason().then(res => {
               console.log(res)
               if(!res.result) {
                  this.$refs.uToast.show({
                     message: res.msg,
                     type: 'error'
                  })
                  return
               }
               this.list = res.data
            })
         },
         check() {
            for(let item of this.table) {
               if(item.VALUE === null) {
                  return false
               }
            }
            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>
@@ -180,4 +434,7 @@
   .text {
      font-size: x-large;
   }
   .red{
      color: red;
   }
</style>