王震
2023-10-31 7a415908713af60d445412c17683886722ae8f44
src/views/quality/rawMaterial/rawMaterial-form.vue
@@ -6,7 +6,7 @@
        <h2>编辑-原材料检验</h2>
      </div>
      <div class="btn-group header-right">
        <el-button @click="save()">保存</el-button>
        <el-button @click="save()" v-if="this.dataForm.id==null">保存</el-button>
      </div>
    </div>
    <div class="page-main">
@@ -100,33 +100,59 @@
                </div>
            </el-col>
        </el-row>
        <el-row style="width:100%;margin-top:-30px">
        <el-row style="width:100%;">
            <el-col :span="24">
                <avue-crud
                ref="crud"
                :option="tableOption"
                @current-row-change="changeEquipment"
                :data="list"
                v-model="form">
                  <template slot="testValue" 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.testValue"
                         @blur="updateTestValue(scope.row)" placeholder="请输入检测值"></el-input>
                    </el-tooltip>
                  </template>
                  <template slot="deviceName" slot-scope="scope">
                    <el-select v-model="scope.row.equipmentId" filterable>
                        <el-option v-for="(item,index) in deviceList"
                        :key="index" :value="item.id" :label="item.number +'-'+ item.name"></el-option>
                    </el-select>
                  </template>
                  <template slot="testState" slot-scope="scope">
                    <span v-if="scope.row.testState == 0" style="color:#F56C6C">不合格</span>
                    <span v-else-if="scope.row.testState == 1" style="color:#67C23A">合格</span>
                    <span v-else>暂无结论</span>
                  </template>
                </avue-crud>
                <el-table :data="list" border style="width: 100%;" height="320">
                  <el-table-column type="index" label="序号" width="60">
                  </el-table-column>
                  <el-table-column prop="name" label="项目" width="260">
                    <template slot-scope="scope">
                      <el-input :disabled="dataForm.id != null" class="inline-input" v-model="scope.row.name"
                        placeholder="请输入项目名称"></el-input>
                    </template>
                  </el-table-column>
                  <el-table-column prop="unit" label="单位" width="260">
                    <template slot-scope="scope">
                      <el-input :disabled="dataForm.id != null" v-model="scope.row.unit" placeholder="请输入单位"></el-input>
                    </template>
                  </el-table-column>
                  <el-table-column prop="required" label="标准值" width="260">
                    <template slot-scope="scope">
                      <el-input :disabled="dataForm.id != null" v-model="scope.row.required"
                        placeholder="请输入标准值"></el-input>
                    </template>
                  </el-table-column>
                  <el-table-column prop="testValue" label="检测值" min-width="260" v-for="(item, index) in empiricalValueAdd"
                    :key="index">
                    <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-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>
                    </template>
                  </el-table-column>
                  <el-table-column fixed="right" v-if="dataForm.id != null" prop="testState" label="结论" min-width="150">
                    <template slot-scope="scope">
                      <span v-if="scope.row.testState == 0" style="color:#F56C6C">不合格</span>
                      <span v-else-if="scope.row.testState == 1" style="color:#67C23A">合格</span>
                      <span v-else>暂无结论</span>
                    </template>
                  </el-table-column>
                  <el-table-column fixed="right" style="background-color: white;" v-if="dataForm.id == null" label="操作" width="150">
                    <template slot-scope="scope">
                      <el-button type="text" @click="clickDeleteline(scope)">取消</el-button>
                    </template>
                  </el-table-column>
                </el-table>
            </el-col>
        </el-row>
      </div>
@@ -141,36 +167,57 @@
              :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" size="small">上报</el-button>
                  <el-button type="text" @click="submitSave()" size="small">上报</el-button>
                </template>
              </avue-crud>
          </el-col>
        </el-row>
      </div>
    </div>
  </div>
</template>
<script>
import { object,conclusion } from '@/const/crud/quality/rawMaterial'
import { selectDevice,addRawInspects,getObj,updateRawInsProduct } from '@/api/quality/rawMaterial'
import {
  selectDevice,
  addRawInspects,
  getObj,
  updateRawInsProduct,
  updateRawInspectsById,
  updateDeviceById, } from '@/api/quality/rawMaterial'
export default {
    data(){
        return{
            columnIndex: 2,
            // 添加列
            empiricalValueAdd: 1,
            // 编辑时存储最长的列数字,做删除判断
            empiricalValueAddMaxNumber: 0,
            columnList: [],
            dataForm:{
                id: null,
                judgeState: null,
                formTime: '2023-10-28 00:00:00',
                message: '-2050314,1,1,*,1002',
                name: 'name',
                code: 'code4',
                specs: 'specs',
                unit: 'mm',
                number: '111',
                supplier: 'supplier',
                rawInsProducts: null,
                rawInsProducts: [{
                  equipmentId: 0,
                  name: '',
                  required: '',
                  testValue: '',
                  unit: '',
                  testValueList: []
                }]
            },
            form: null,
            list:[],
@@ -197,83 +244,59 @@
      this.getDeviceList()
    },
    watch:{
      'columnList.length':function(newVal){
        const column = [{
              label: '项目',
              width: 260,
              prop: 'name',
              span: 24,
              type: 'text',
              cell: true,
            }, {
              width: 260,
              label: '单位',
              prop: 'unit',
              span: 24,
              type: 'text',
              cell: true,
            }, {
              width: 260,
              label: '标准值',
              prop: 'required',
              type: 'text',
              span: 24,
              cell: true,
            }, {
              label: '检测值',
              prop: 'testValue',
              type: 'text',
              width: 260,
              slot: true,
              formSlot: true,
              cell: true,
            }, {
              label: '试验设备',
              prop: 'deviceName',
              type: 'select',
              cell: true,
              slot: true,
              formSlot: true,
              width: 260
            },{
              label: '结论',
              prop: 'testState',
              type: 'text',
              slot: true,
              formSlot: true,
              hide: true,
              fixed: 'right'
        }]
        if(newVal > 0){
          if(this.columnList.length > 0){
            this.tableOption.column = column
            this.columnList.forEach(item=>{
              this.tableOption.column.splice(4,0,item)
            })
          }
        }else{
          this.tableOption.column = column
        }
      },
    },
    methods:{
      changeEquipment(current,old){
        console.log(current,old)
      updateDevice(row){
        if(this.dataForm.id != null){
          updateDeviceById({equiomentId:row.equipmentId,rpId:row.rpId}).then(res=>{
          }).catch(error=>{
            console.log(error)
          })
        }
      },
      submitSave(){
        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(() => {});
        }else{
          updateRawInspectsById({id:this.dataForm.id,number:0}).then(res => {
          this.$message.success("上报成功");
        });
        }
        this.init()
      },
      addTeatValueColumn(){
        let propName = 'testValue' + this.columnIndex
        this.columnList.push({
          label: '检测值',
          prop: propName,
          type: 'text',
          width: 260,
          $cellEdit: true,
          disabled: this.list[0].equiomentId == null
        })
        this.columnIndex+=1
        this.empiricalValueAdd = this.empiricalValueAdd + 1;
      },
      // 删除行
      clickDeleteline(scope) {
        this.list.splice(scope.$index, 1);
      },
      delTeatValueColumn(){
        this.columnList.pop()
        if (this.empiricalValueAdd - 1 === 0) { } else {
          if (this.empiricalValueAddMaxNumber != this.empiricalValueAdd - 1) {
            this.empiricalValueAdd = this.empiricalValueAdd - 1;
            this.list.forEach(i => {
              i.testValueList.splice(this.empiricalValueAdd, 1);
            });
          }
        }
      },
      updateTestValue(row){
        if(row.rpId == null){
@@ -282,7 +305,7 @@
        let obj = {
          equiomentId: row.equipmentId,
          rpId: row.rpId,
          testValue: row.testValue
          testValue: row.testValueList.join(",")
        }
        updateRawInsProduct(obj).then(res=>{
          if(res.data.code === 0){
@@ -308,10 +331,18 @@
            this.dataForm.number = data.number
            this.dataForm.createTime = data.creatTime
            this.dataForm.createUser = data.createUser
            // this.dataForm.judgeState = data.judgeState
            let userNameList = []
            this.list = []
            data.children.forEach(item=>{
              userNameList.push(item.userName)
              let arr = []
              if(item.testValue != undefined ){
                arr = item.testValue.split(",")
                this.empiricalValueAdd = arr.length
              }else{
                this.empiricalValueAdd = 1
              }
              this.list.push({
                equipmentId: item.equiomentId,
                name: item.rpName,
@@ -319,14 +350,15 @@
                testValue: item.testValue,
                unit: item.rpUnit,
                testState: item.testState,
                rpId: item.rpId
                rpId: item.rpId,
                testValueList: arr
              })
            })
            this.conclusionTable = [{
              code: data.code,
              name: data.name,
              userName: Array.from(new Set(userNameList)).join(','),
              testState: ''
              judgeState: data.judgeState
            }]
          }).catch(error=>{
            this.$message.error("获取失败",error)
@@ -339,8 +371,10 @@
      save(){
        let data = this.dataForm
        data.rawInsProducts = this.list
        console.log(this.list)
        return
        data.rawInsProducts.forEach(item=>{
          let val = item.testValueList.join(",")
          item.testValue = val
        })
        addRawInspects(data).then(res=>{
            this.$message.success("保存成功")
        }).catch(error=>{
@@ -350,12 +384,13 @@
      // 添加行
      clickAddLine() {
        let obj = {
          $cellEdit: true,
          equipmentId: null,
          name: "",
          required: "",
          testValue: "",
          unit: ""
          unit: "",
          testState: null,
          testValueList: [],
        };
        this.list.push(obj);
      },