zouyu
2023-11-02 13f3799fc43eae5f670c72a675b1fb9326f5a102
src/views/quality/rawMaterial/rawMaterial-form.vue
@@ -3,7 +3,8 @@
    <div class="page-header">
      <div class="header-left">
        <a @click="$router.go(-1)"><i class="icon-btn-back"></i></a>
        <h2>编辑-原材料检验</h2>
        <h2 v-if="resultVal!=null && dataForm.id!=null">查看-原材料检验</h2>
        <h2 v-else>编辑-原材料检验</h2>
      </div>
      <div class="btn-group header-right">
        <el-button @click="save()" v-if="this.dataForm.id==null">保存</el-button>
@@ -21,10 +22,11 @@
            <el-row>
              <el-col :span="6">
                <el-form-item label="零件号" prop="code">
                <el-input v-model="dataForm.code">
                <el-input v-model="dataForm.code" :disabled="resultVal!=null && dataForm.id!=null">
                  <el-button
                    slot="append"
                    icon="el-icon-search"
                    :disabled="resultVal!=null && dataForm.id!=null"
                    @click="queryCode()"></el-button>
                </el-input>
                </el-form-item>
@@ -38,6 +40,7 @@
            <el-col :span="6">
                <el-form-item prop="formTime" label="来料日期">
                <el-date-picker 
                    style="width:100%"
                    v-model="dataForm.formTime"
                    type="datetime"
                    value-format="yyyy-MM-dd HH:mm:ss"
@@ -68,19 +71,19 @@
                </el-col>
                <el-col :span="6">
                  <el-form-item label="数量" prop="number">
                      <el-input v-model="dataForm.number" />
                      <el-input v-model="dataForm.number" :disabled="resultVal!=null" />
                  </el-form-item>
                </el-col>
                <el-col :span="6">
                  <el-form-item label="报检日期" prop="createTime" v-if="dataForm.id!=null">
                      <el-input v-model="dataForm.createTime" />
                      <el-input v-model="dataForm.createTime" disabled />
                  </el-form-item>
                </el-col>
            </el-row>
            <el-row>
              <el-col :span="6">
                <el-form-item label="报检人" prop="createUser" v-if="dataForm.id!=null">
                      <el-input v-model="dataForm.createUser" />
                      <el-input v-model="dataForm.createUser" disabled />
                </el-form-item>
              </el-col>
            </el-row>
@@ -91,9 +94,9 @@
            <el-col :span="19">检验项目</el-col>
            <el-col :span="5">
                <div style="width:100%;text-align: right;">
                    <el-button v-show="dataForm.id==null" size="small" @click="clickAddLine">添加检验行</el-button>
                    <el-button size="small" @click="addTeatValueColumn()">添加检验值列</el-button>
                    <el-button size="small" @click="delTeatValueColumn()">删除检验值列</el-button>
                    <el-button v-if="dataForm.id==null" size="small" @click="clickAddLine">添加检验行</el-button>
                    <el-button v-if="resultVal==null || dataForm.id==null" size="small" @click="addTeatValueColumn()">添加检测值列</el-button>
                    <el-button v-if="resultVal==null || dataForm.id==null" size="small" @click="delTeatValueColumn()">删除检测值列</el-button>
                </div>
            </el-col>
        </el-row>
@@ -101,7 +104,7 @@
            <el-col :span="24">
                <el-table :header-cell-style="{textAlign:'center',color:'black',backgroundColor:'#fafafa'}" 
                :cell-style="{textAlign:'center'}" ref="table"
                :data="list" border style="width: 100%;" height="320">
                :data="list" border style="width: 100%;" height="400">
                  <el-table-column type="index" label="序号" width="60">
                  </el-table-column>
                  <el-table-column prop="name" label="项目" width="260">
@@ -130,17 +133,18 @@
                    <template slot-scope="scope">
                      <el-tooltip :disabled="scope.row.equipmentId != null" class="item" effect="dark" content="请先选择设备!"
                        placement="top-start">
                        <el-input :disabled="scope.row.equipmentId == null" v-model="scope.row.testValueList[index]"
                          @blur="updateTestValue(scope.row)" placeholder="请输入检测值"></el-input>
                        <el-input :disabled="scope.row.equipmentId == null ||  (dataForm.id!=null&&resultVal!=null)" v-model="scope.row.testValueList[index]"
                          @blur="updateTestValue(scope.row,index)" placeholder="请输入检测值"></el-input>
                      </el-tooltip>
                    </template>
                  </el-table-column>
                  <el-table-column prop="deviceName" label="试验设备" min-width="260">
                    <template slot-scope="scope">
                      <el-select style="width:100%" v-model="scope.row.equipmentId" filterable @change="updateDevice(scope.row)">
                          <el-option v-for="(item,index) in deviceList"
                          :key="index" :value="item.id" :label="item.number +'-'+ item.name"></el-option>
                      </el-select>
                        <el-select :disabled="resultVal!=null && dataForm.id!=null" style="width:100%"
                        v-model="scope.row.equipmentId" filterable @change="updateDevice(scope.row,scope.$index)">
                            <el-option v-for="(item,index) in deviceList"
                            :key="index" :value="item.id" :label="item.number +'-'+ item.name"></el-option>
                        </el-select>
                    </template>
                  </el-table-column>
                  <el-table-column fixed="right" v-if="dataForm.id != null" prop="testState" label="结论" min-width="150">
@@ -159,43 +163,64 @@
            </el-col>
        </el-row>
      </div>
      <div class="rawMaterial-detail">
      <div class="rawMaterial-result">
        <el-row>
          <el-col :span="24">检验结论</el-col>
        </el-row>
        <el-row style="width:100%">
          <el-col :span="24">
            <avue-crud
              ref="conclusion"
              :option="option"
              :data="conclusionTable"
              v-model="conclusion">
                <template slot="judgeState" slot-scope="scope">
                  <el-tag type="success" v-if="scope.row.judgeState == 1">合格</el-tag>
                  <el-tag type="danger" v-else-if="scope.row.judgeState == 0">不合格</el-tag>
                </template>
                <template #menu>
                  <el-button type="text" @click="submitSave()" size="small">上报</el-button>
                </template>
              </avue-crud>
            <el-table border height="90" :data="conclusionTable" ref="conclusion" v-model="conclusion"
            :header-cell-style="{textAlign:'center',color:'black',backgroundColor:'#fafafa'}"
            :cell-style="{textAlign:'center'}">
                <el-table-column prop="code" label="物料编号"></el-table-column>
                <el-table-column prop="name" label="物料名称"></el-table-column>
                <el-table-column prop="userName" label="检验员"></el-table-column>
                <el-table-column prop="judgeState" label="检验结论">
                  <template slot-scope="scope">
                    <el-tag type="success" v-if="scope.row.judgeState == 1">合格</el-tag>
                    <el-tag type="danger" v-else-if="scope.row.judgeState == 0">不合格</el-tag>
                  </template>
                </el-table-column>
                <el-table-column  label="操作">
                    <template>
                        <el-button type="text" :disabled="resultVal!=null && dataForm.id!=null" @click="showDialog()" size="small">上报</el-button>
                    </template>
                </el-table-column>
            </el-table>
          </el-col>
        </el-row>
      </div>
    </div>
    <rawMaterialPartDialog :paramObj="paramObj" :currshowlist.sync="showPart"  @listenToPartEvent="selectPart" />
    <el-dialog
      title="上报"
      :visible.sync="dialogVisible"
      width="30%" class="l-mes">
      <el-row>
        <el-col>
          <span>不合格数量:</span>
          <el-input type="number" v-model="unqualifiedNum" placeholder="请输入不合格数量"/>
        </el-col>
        <el-col>
          <span>实检数量:</span>
          <el-input type="number" placeholder="请输入实检数量" v-model="fiedNum"/>
        </el-col>
      </el-row>
      <span slot="footer" class="dialog-footer">
        <el-button @click="dialogVisible = false">取 消</el-button>
        <el-button type="primary" @click="submitSave()">确 定</el-button>
      </span>
    </el-dialog>
  </div>
</template>
<script>
import { object,conclusion } from '@/const/crud/quality/rawMaterial'
import { 
  selectDevice,
  addRawInspects,
  getObj,
  updateRawInsProduct,
  updateRawInspectsById,
  chooseIFS,
  selectHisByCode,
  updateDeviceById, } from '@/api/quality/rawMaterial'
  import rawMaterialPartDialog from '@/views/common/rawMaterial-part'
export default {
@@ -205,6 +230,10 @@
    },
    data(){
        return{
            fiedNum: null,
            unqualifiedNum: null,
            dialogVisible:false,
            resultVal: null,
            projectList: [],
            paramObj: {},
            IFSData: [],
@@ -243,8 +272,6 @@
              userName: '',
              testState: ''
            }],
            tableOption: object,
            option: conclusion,
            dataRule: {},
            deviceList: [],
        }
@@ -256,15 +283,21 @@
    },
    mounted(){
      this.dataForm.id = this.$route.query.id
      this.resultVal = this.$route.query.resultVal
      if(this.resultVal == null){
        let val = sessionStorage.getItem("raw-resultVal-"+this.dataForm.id)
        val == undefined ? null : this.resultVal=val
      }
      this.init()
      let isShow = this.dataForm.id == null ? true : false
      this.tableOption.menu = isShow
      let len = this.tableOption.column.length
      this.tableOption.column[len-1].hide = isShow
      this.getDeviceList()
    },
    watch:{
      dialogVisible(newVal){
        if(newVal){
          this.unqualifiedNum = null
          this.fiedNum = null
        }
      }
    },
    methods:{
      changeName(index,row){
@@ -286,7 +319,7 @@
          this.dataForm.supplier = param.supplier
          this.dataForm.number = param.number
          this.dataForm.message = param.message
          this.projectList = param.rawInsProducts
          this.projectList = param.rawInsProducts == null ? [] : param.rawInsProducts
        }
      },
      queryCode(){
@@ -295,38 +328,41 @@
        }
        this.showPart = true
      },
      updateDevice(row){
      updateDevice(row,index){
        if(this.dataForm.id != null){
          updateDeviceById({equiomentId:row.equipmentId,rpId:row.rpId}).then(res=>{
            this.list[index].testValue = ''
            this.list[index].testState = null
            this.list[index].testValueList = []
          }).catch(error=>{
            console.log(error)
          })
        }
      },
      submitSave(){
      showDialog(){
        let pro = this.list.filter(item => {
          return item.testState == 0;
        })
        if (pro.length > 0) {
          this.$prompt('请输入不合格数量', '不合格数量', {
            confirmButtonText: '确定',
            cancelButtonText: '取消',
            inputPattern: /^\d+$/,
            inputErrorMessage: '请输入正确数字格式'
          }).then(({ value }) => {
            let data = {
              id: this.dataForm.id,
              number: value
            }
            updateRawInspectsById(data).then(res => {
              this.$message.success("上报成功");
            });
          }).catch(() => {});
          this.dialogVisible = true
        }else{
          updateRawInspectsById({id:this.dataForm.id,number:0}).then(res => {
          this.$message.success("上报成功");
        });
          this.submitSave()
        }
      },
      //上报
      submitSave(){
        let data = {
          id: this.dataForm.id,
          number: this.unqualifiedNum,
          toLocationNo: this.fiedNum
        }
        updateRawInspectsById(data).then(res => {
          if(res.data.code == 0){
            sessionStorage.setItem("raw-resultVal-"+this.dataForm.id,res.data.data)
            this.$message.success("上报成功");
            this.dialogVisible = false
          }
        });
        this.init()
      },
      addTeatValueColumn(){
@@ -359,8 +395,9 @@
          }
        }
      },
      updateTestValue(row){
        if(row.rpId == null){
      updateTestValue(row,index){
        console.log(row,index)
        if(row.rpId == null || row.testValueList[index]==null){
          return
        }
        let obj = {
@@ -400,12 +437,13 @@
              let arr = []
              if(item.testValue != undefined ){
                arr = item.testValue.split(",")
                this.empiricalValueAdd = arr.length
              }else{
                this.empiricalValueAdd = 1
                if(arr.length > this.empiricalValueAdd){
                  this.empiricalValueAdd = arr.length
                }
              }
              this.list.push({
                equipmentId: item.equiomentId,
                deviceName: item.deviceName,
                name: item.rpName,
                required: item.required,
                testValue: item.testValue,
@@ -419,14 +457,13 @@
              code: data.code,
              name: data.name,
              userName: Array.from(new Set(userNameList)).join(','),
              judgeState: data.judgeState
              judgeState: this.resultVal==null?null:this.resultVal
            }]
          }).catch(error=>{
            this.$message.error("获取失败",error)
          })
        }else{
          this.conclusionTable = []
          this.tableOption.column = object.column
        }
      },
      save(){
@@ -438,6 +475,7 @@
        })
        addRawInspects(data).then(res=>{
            this.$message.success("保存成功")
            this.$router.go(-1)
        }).catch(error=>{
          this.$message.error(error)
        })
@@ -454,7 +492,19 @@
<style>
.rawMaterial-detail {
  width: 100%;
  height: 400px;
  height: 470px;
  padding: 10px 20px;
  display: flex;
  border: 1px solid #ddd;
  background-color: #fff;
  margin-top: 10px;
  box-sizing: border-box;
  flex-wrap: wrap;
}
.rawMaterial-result {
  width: 100%;
  height: 150px;
  padding: 10px 20px;
  display: flex;
  border: 1px solid #ddd;