王震
2023-11-01 729fa0955c4d2176ae78f13ad2fc008dd7cc6518
src/views/quality/finishedProductInspection/finishedProductInspectionAdd.vue
@@ -4,10 +4,10 @@
    <div class="page-header">
        <div class="header-left">
            <a @click="$router.go(-1)"><i class="icon-btn-back"></i></a>
            <h2>编辑-产品检验</h2>
            <h2>编辑-产品检验单</h2>
        </div>
        <div class="btn-group header-right">
            <el-button @click="addTestProject">生成检验项目</el-button>
            <el-button @click="addTestProject" v-if="processInspectVo.id==null">生成检验项目</el-button>
        </div>
    </div>
    <div class="page-main">
@@ -18,7 +18,8 @@
                    <el-row>
                        <el-col :span="6">
                            <el-form-item label="订单号:">
                                <el-input @blur="selectInfoByOrderId" v-model="processInspectVo.orderNumber" placeholder="请输入订单号" autocomplete="off" />
                                <el-input @blur="selectInfoByOrderId" :disabled="processInspectVo.id != null"
                                v-model="processInspectVo.orderNumber" placeholder="请输入订单号" autocomplete="off" />
                            </el-form-item>
                        </el-col>
                        <el-col :span="6">
@@ -43,7 +44,7 @@
                    <el-row>
                        <el-col :span="6">
                            <el-form-item label="产品名称:">
                                <el-select style="width: 100%" @change="changeOptionsSamplename"
                                <el-select style="width: 100%" @change="changeOptionsSamplename" :disabled="processInspectVo.id != null"
                                    v-model="processInspectVo.material" size="small" placeholder="请选择产品名称">
                                    <el-option v-for="(item,index) in optionsSamplename" :key="index" :label="item.material"
                                        :value="item.materialCode">
@@ -74,7 +75,7 @@
                        <el-col :span="6">
                            <el-form-item label="数量:">
                                <el-input v-model="processInspectVo.quantity" placeholder="请输入数量"
                                    autocomplete="off" />
                                    autocomplete="off" :disabled="processInspectVo.id != null" />
                            </el-form-item>
                        </el-col>
                    </el-row>
@@ -82,91 +83,85 @@
            </el-form>
        </div>
        <div class="finishedProduct-detail">
            <el-row style="width:100%;z-index: 10;height:50px;">
            <el-row style="width:100%;z-index: 10;height:30px;">
                <el-col :span="12" class="inspectionProject_span">检验项目</el-col>
                <el-col :span="12" class="inspectionProject_span" style="text-align: right;">
                    <el-button size="mini" @click="clickAddInspectionColumn()">添加检验值列</el-button>
                    <el-button size="mini" @click="clickDeleteInspectionColumn()">删除检验值列</el-button>
                    <el-button size="mini" @click="clickAddInspectionColumn()">添加检测值列</el-button>
                    <el-button size="mini" @click="clickDeleteInspectionColumn()">删除检测值列</el-button>
                </el-col>
            </el-row>
            <el-row style="width:100%;">
                <el-col :span="24">
                    <el-table border :data="inspectionItems" max-height="400" height="calc(100vh - 550px)"
                    <el-table border :data="inspectionItems" height="400"
                        :header-cell-style="{textAlign:'center',color:'black',backgroundColor:'#fafafa'}" 
                        :cell-style="{textAlign:'center'}" row-key="iid"
                        :cell-style="{textAlign:'center'}" row-key="iid" default-expand-all
                        style="width: 100%" ref="table" :tree-props="{children: 'children', hasChildren: 'hasChildren'}">
                        <el-table-column type="index" label="序号" width="60"></el-table-column>
                        <el-table-column label="项目" prop="father"></el-table-column>
                        <el-table-column prop="iname" label="指标"></el-table-column>
                        <el-table-column prop="iunit" label="单位"></el-table-column>
                        <el-table-column prop="required" label="标准值"></el-table-column>
                        <el-table-column label="项目" prop="father" width="240" ></el-table-column>
                        <el-table-column prop="iname" label="指标" width="240" ></el-table-column>
                        <el-table-column prop="iunit" label="单位" width="240" ></el-table-column>
                        <el-table-column prop="required" label="标准值" width="240" ></el-table-column>
                        <el-table-column prop="inspectionValue" v-for="(item, index) in empiricalValueAdd" :key="index" label="检测值"
                            min-width="100" style="text-align: center;">
                            width="240" style="text-align: center;">
                            <template slot-scope="scope">
                                <el-tooltip :disabled="scope.row.dname != null" class="item" effect="dark" content="请先选择设备!"
                                <el-tooltip v-if="scope.row.iname!=null" :disabled="scope.row.eId != null"
                                class="item" effect="dark" content="请先选择设备!"
                                    placement="top-start">
                                    <!-- <el-input :disabled="scope.row.dname === null" v-model="scope.row.empiricalValueAddss[index]"
                                        @blur="changeState(scope.row, index)" placeholder="请输入检测值"></el-input> -->
                                    <el-input :disabled="scope.row.eId == null" v-model="scope.row.empiricalValueAddss[index]"
                                        @blur="changeState(scope.row, index)" placeholder="请输入检测值"></el-input>
                                </el-tooltip>
                            </template>
                        </el-table-column>
                        <el-table-column prop="dname" label="试验设备" min-width="100">
                        <el-table-column prop="deviceName" label="试验设备" min-width="250">
                            <template slot-scope="scope">
                                <el-button v-if="!scope.row.isSelectDevice" type="text" @click="clickTableSelect(scope)">{{
                                    scope.row.dname == null ? "请选择" : scope.row.dname
                                }}</el-button>
                                <el-select  v-if="scope.row.isSelectDevice" style="width: 100%;" @change="clickNodeSure(scope.row)" v-model="filterText" placeholder="请选择">
                                    <el-option v-for="item in materialOptions" :key="item.id" :label="item.device" :value="item.id">
                                    </el-option>
                                <el-select style="width:100%" v-model="scope.row.eId"
                                v-if="scope.row.iname != null" 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 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 label="结论" fixed="right" min-width="100">
                            <template slot-scope="scope">
                                <span style="color: #34BD66;" v-if="scope.row.result === 1">合格</span>
                                <span style="color: #E84738;" v-else-if="scope.row.result === 0">不合格</span>
                                <span v-show="scope.row.result === null">暂未结论</span>
                                <div v-if="scope.row.iname!=null">
                                    <span style="color: #34BD66;" v-if="scope.row.iresult == 1">合格</span>
                                    <span style="color: #E84738;" v-else-if="scope.row.iresult == 0">不合格</span>
                                    <span v-else>暂无结论</span>
                                </div>
                            </template>
                        </el-table-column>
                    </el-table>
                </el-col>
            </el-row>
        </div>
        <div class="finishedProduct-detail">
        <div class="finishedProduct-result">
            <el-row style="width:100%">
                <el-col :span="24">检测结果</el-col>
            </el-row>
            <el-row style="width:100%;margin-top:-180px">
            <el-row style="width:100%;">
                <el-col :span="24">
                    <el-table border max-height="400" :data="inspectionResultForm"
                    <el-table border height="90" :data="inspectionResultForm"
                    :header-cell-style="{textAlign:'center',color:'black',backgroundColor:'#fafafa'}" 
                    :cell-style="{textAlign:'center'}">
                        <el-table-column prop="id" label="物料编号"></el-table-column>
                        <el-table-column prop="name" label="物料名称"></el-table-column>
                        <el-table-column prop="inspecter" label="检验员"></el-table-column>
                        <el-table-column prop="conclusion" label="检验结论"></el-table-column>
                        <el-table-column prop="operation" label="上报"></el-table-column>
                        <el-table-column prop="materialCode" label="物料编号"></el-table-column>
                        <el-table-column prop="material" label="物料名称"></el-table-column>
                        <el-table-column prop="userName" label="检验员"></el-table-column>
                        <el-table-column prop="result" label="检验结论">
                            <template slot-scope="scope">
                                <el-tag type="success" v-if="scope.row.result == 1">合格</el-tag>
                                <el-tag type="danger" v-else-if="scope.row.result == 0">不合格</el-tag>
                            </template>
                        </el-table-column>
                        <el-table-column  label="操作">
                            <template>
                                <el-button type="text"  @click="submitSave()" size="small">上报</el-button>
                            </template>
                        </el-table-column>
                    </el-table>
                </el-col>
            </el-row>
        </div>
    </div>
    <el-dialog title="请选择设备" :visible.sync="centerDialogVisible" width="20%">
        <div class="div_device_dialog">
            <el-select style="width: 100%;" @change="clickNodeSure()" v-model="filterText" placeholder="请选择">
                <el-option v-for="item in materialOptions" :key="item.id" :label="item.device" :value="item.id">
                </el-option>
            </el-select>
        </div>
    </el-dialog>
</div>
</template>
@@ -174,39 +169,22 @@
import { 
    chooseMater,
    addFinish,
    queryById, } from '@/api/quality/finishedProduct'
import { updateDeviceById,selectDevice } from '@/api/quality/rawMaterial'
    queryById,
    updateDeviceById,
    updateFinishedInsProduct,
    updateFinishedInspectById,
 } from '@/api/quality/finishedProduct'
import { selectDevice } from '@/api/quality/rawMaterial'
export default {
    data() {
        return {
            deviceList: [],
            hasChildren: true,
            showUp: false,
            isAddProject: false,
            showLook: false,
            detailId: 0,
            rowInfp: {},
            search: {
                countSize: 10,
                pageSize: 1,
                result: "", // 检测状态
                name: "", // 产品名称
                techfather: "" // 工序
            },
            optionsSamplename: [],
            inspectionTable: [],
            tableColumn: [],
            optionSoptionSprocesses: [],
            optionTechnology: [],
            inspectionTableTotal: 0,
            pageSize: 10,
            currentPage: 1,
            treeProject: [],
            // 添加列
            empiricalValueAdd: 1,
            // 编辑时存储最长的列数字,做删除判断
            empiricalValueAddMaxNumber: 0,
            showAddPage: false,
            processInspectVo: {
                id: null,
                material: null,
@@ -220,56 +198,9 @@
                unit: null,
                technologyId: null
            },
            InspectioniD: null,
            addInspectionform: [
                {
                    number: "",
                    username: "",
                    projectname: "",
                    tracenumber: "",
                    code: "",
                    class: "",
                    specificationmodel: "",
                    unit: "",
                    quantity: "",
                    group: "",
                    worker: "",
                    machine: ""
                }]
            ,
            inspectionItems: [], // 新增检验项目表格
            inspectionResultForm: [
                {
                    id: "",
                    name: "",
                    inspecter: "",
                    conclusion: "",
                    operation: ""
                }
            ],
            options: [],
            value: "",
            rowList: [],
            spanArr: [],
            position: 0,
            // 设备选择树显示
            centerDialogVisible: false,
            filterText: "",
            materialOptions: [],
            defaultProps: {
                // 设备树数据设置
                children: "children",
                label: "name"
            },
            nodeData: {
                id: 0,
                name: null
            }, // node点击保存当前点击数据
            clickSelectDevice: {
                index: null, // 点击选择存储当前行索引
                rpId: null // 点击选择存储当前行项目Id
            }
        };
            inspectionResultForm: [],
        }
    },
    watch: {
    },
@@ -282,20 +213,101 @@
    },
    mounted() {
        this.getDeviceList()
        this.processInspectVo.id = this.$route.query.id
        this.init()
    },
    methods: {
        submitSave(){
            let pro = 0
            this.inspectionItems.forEach(item => {
                if(item.children){
                    let arr = item.children.filter(obj=>{
                            return obj.iresult == 0;
                    })
                    console.log("aaa--",arr,arr.length)
                    pro+=arr.length
                }
            })
            if (pro > 0) {
                this.$prompt('请输入不合格数量', '不合格数量', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    inputPattern: /^\d+$/,
                    inputErrorMessage: '请输入正确数字格式'
                }).then(({ value }) => {
                    let data = {
                    id: this.processInspectVo.id,
                    number: value
                    }
                    updateFinishedInspectById(data).then(res => {
                        this.$message.success("上报成功");
                    });
                }).catch(() => {});
            }else{
                updateFinishedInspectById({id:this.processInspectVo.id,number:0}).then(res => {
                    this.$message.success("上报成功");
                });
            }
            this.init()
        },
        init(){
            let id = this.processInspectVo.id
            if(id != null){
                queryById(id).then(res=>{
                    let result = res.data.data
                    this.processInspectVo.orderNumber = result.orderNumber
                    this.processInspectVo.mcode = result.materialCode
                    this.processInspectVo.prname = result.customerName
                    this.processInspectVo.sname = result.projectName
                    this.processInspectVo.material = result.material
                    this.processInspectVo.specificationsModel = result.specs
                    this.processInspectVo.unit = result.punit
                    this.processInspectVo.quantity = result.quantity
                    let resultVal = 1
                    let userList = []
                    result.children.forEach(item=>{
                        item.iid = Math.random()
                        if(item.children != undefined){
                            item.children.forEach(obj=>{
                                let arr = []
                                if(obj.userName){
                                    userList.push(obj.userName)
                                }
                                if(obj.inspectionValue){
                                    arr = obj.inspectionValue.split(",")
                                }
                                if(obj.iresult && obj.iresult == 0){
                                    resultVal = 0
                                }
                                obj.empiricalValueAddss = arr
                                if(arr.length > this.empiricalValueAdd){
                                    this.empiricalValueAdd = arr.length
                                }
                            })
                        }
                    })
                    this.inspectionItems = result.children
                    this.inspectionResultForm = [{
                        materialCode: result.materialCode,
                        material: result.material,
                        userName: Array.from(new Set(userList)).join(","),
                        result: resultVal,
                    }]
                }).catch(error=>{
                    console.log(error)
                })
            }
        },
        getDeviceList(){
            selectDevice(null).then(res=>{
            this.deviceList = res.data.data
                this.deviceList = res.data.data
            })
        },
        updateDevice(row){
            if(this.dataForm.id != null){
            updateDeviceById({equiomentId:row.equipmentId,rpId:row.rpId}).then(res=>{
            updateDeviceById({equiomentId:row.eId,fpid:row.iId}).then(res=>{
            }).catch(error=>{
                console.log(error)
            })
            }
        },
        changeOptionsSamplename(val) {
            let sample = this.optionsSamplename.filter(o => {
@@ -307,65 +319,29 @@
            this.processInspectVo.specificationsModel = sample.specs
            this.processInspectVo.unit = sample.unit
        },
        handleClick(row) {
            this.rowInfp = row
            this.showLook = true
        },
        updateInsInfo(row) {
            this.rowInfp = row
            this.showUp = true
        },
        searchPro() {
            this.search.countSize = this.pageSize
            this.search.pageSize = this.currentPage
            this.defaultInitializationTable()
        },
        // 点击表格选择触发
        clickTableSelect(scope) {
            if(this.clickSelectDevice.index!=null){
                this.$set(this.inspectionItems[this.clickSelectDevice.index],'isSelectDevice',false)
            }
            this.clickSelectDevice.index = scope.$index;
            this.clickSelectDevice.rpId = scope.row.id;
            this.getOptions(scope.row);
        },
        changeState(row, index) {
            if (row.did != null && row.did != '') {
                // let val = row.empiricalValueAddss.filter(item => {
                //     return item != '' && item != null
                // })
                // let eq = val.filter(item => {
                //     return /^[^><=]/.test(item)
                // })
                // if (eq.length > 0) {
                //     this.$message({
                //         message: "检测值[" + eq + "]格式首位应包含>,<或者=",
                //         type: 'warning'
                //     });
                //     return
                // }
            if (row.iid != null && row.iid != '') {
                let str = ""
                row.empiricalValueAddss.forEach(e => {
                    str += e + ","
                })
                if (str.slice(0, -1) === '' || str.slice(0, -1) === null || str.slice(0, -1) === undefined) {
                str = str.slice(0,-1);
                if (str === undefined || str === '' || str === null ) {
                    return
                }
                this.$axios.post(this.$api.url.inspectionItemlose_focus_update, {
                    deviceId: row.did,
                    inspectionItemId: row.id,
                    inspectionValue: str.slice(0, -1)
                }, {
                    headers: { "Content-Type": "application/json" }
                }).then(res => {
                    row.result = res.data.result
                    row.username = res.data.username
                let obj = {
                    equiomentId: row.eId,
                    fpid: row.iid,
                    inspectionValue: str
                }
                updateFinishedInsProduct(obj).then(res=>{
                    if(res.data.code == 0){
                        this.$message.success("更新成功")
                    }else{
                        this.$message.error("更新失败")
                    }
                    this.init()
                })
            } else {
                this.$message({
                    message: '请选择择设备!',
                    type: 'warning'
                });
            }
        },
        addTestProject() {
@@ -388,6 +364,11 @@
                        let proList = response.data.data.children
                        proList.forEach(item=>{
                            item.iid = Math.random();
                            if(item.children != undefined){
                                item.children.forEach(obj=>{
                                    obj.empiricalValueAddss = []
                                })
                            }
                        })
                        this.inspectionItems = proList
                    }).catch(error=>{
@@ -421,34 +402,6 @@
                }
            })
        },
        // 表格初始化接口
        defaultInitializationTable() {
            // this.$axios
            //     .post(this.$api.url.selectProcessInspectsList, this.search)
            //     .then(res => {
            //         this.inspectionTableTotal = res.data.total;
            //         this.inspectionTable = res.data.row;
            //     });
        },
        // 添加行
        clickAddLine() {
            let obj = {
                material: "",
                materialCode: "",
                orderNumber: "",
                quantity: 0,
                specificationsModel: "",
                techfather: "",
                techname: "",
                technologyId: 0,
                unit: ""
            };
            this.inspectionItems.push(obj);
        },
        // 删除行
        clickDeleteline(scope) {
            this.inspectionItems.splice(scope.$index, 1);
        },
        // 删除检验值列
        clickDeleteInspectionColumn() {
            if (this.empiricalValueAdd - 1 === 0) {
@@ -456,7 +409,7 @@
                if (this.empiricalValueAddMaxNumber != this.empiricalValueAdd - 1) {
                    this.empiricalValueAdd = this.empiricalValueAdd - 1;
                    this.inspectionItems.forEach(i => {
                        i.testValueList.splice(this.empiricalValueAdd, 1);
                        i.empiricalValueAddss.splice(this.empiricalValueAdd, 1);
                    });
                }
            }
@@ -472,7 +425,19 @@
<style scoped>
.finishedProduct-detail {
  width: 100%;
  height: 460px;
  height: 470px;
  padding: 10px 20px;
  display: flex;
  border: 1px solid #ddd;
  background-color: #fff;
  margin-top: 10px;
  box-sizing: border-box;
  flex-wrap: wrap;
}
.finishedProduct-result {
  width: 100%;
  height: 150px;
  padding: 10px 20px;
  display: flex;
  border: 1px solid #ddd;