zouyu
2023-10-31 b5d7cad27e6d6382cc375a7bbfb91aad0c31195c
src/views/quality/finishedProductInspection/finishedProductInspectionAdd.vue
@@ -7,7 +7,7 @@
            <h2>编辑-产品检验</h2>
        </div>
        <div class="btn-group header-right">
            <el-button @click="addTestProjevt">生成检验项目</el-button>
            <el-button @click="addTestProject">生成检验项目</el-button>
        </div>
    </div>
    <div class="page-main">
@@ -34,21 +34,21 @@
                            </el-form-item>
                        </el-col>
                        <el-col :span="6">
                            <el-form-item label="产品名称:">
                                <el-select style="width: 100%" @change="changeOptionsSamplename"
                                    v-model="processInspectVo.material" size="small" placeholder="请选择产品名称">
                                    <el-option v-for="item in optionsSamplename" :key="item.id" :label="item.name"
                                        :value="item.id + '-' + item.name">
                                    </el-option>
                                </el-select>
                            <el-form-item label="质量追溯号:">
                                <el-input disabled v-model="processInspectVo.qualityTraceability"
                                    placeholder="请输入质量追溯号" autocomplete="off" />
                            </el-form-item>
                        </el-col>
                    </el-row>
                    <el-row>
                        <el-col :span="6">
                            <el-form-item label="质量追溯号:">
                                <el-input disabled v-model="processInspectVo.qualityTraceability"
                                    placeholder="请输入追溯号" autocomplete="off" />
                            <el-form-item label="产品名称:">
                                <el-select style="width: 100%" @change="changeOptionsSamplename"
                                    v-model="processInspectVo.material" size="small" placeholder="请选择产品名称">
                                    <el-option v-for="(item,index) in optionsSamplename" :key="index" :label="item.material"
                                        :value="item.materialCode">
                                    </el-option>
                                </el-select>
                            </el-form-item>
                        </el-col>
                        <el-col :span="6">
@@ -60,13 +60,13 @@
                        <el-col :span="6">
                            <el-form-item label="规格型号:">
                                <el-input disabled v-model="processInspectVo.specificationsModel"
                                    placeholder="请输入产品编码" autocomplete="off" />
                                    placeholder="请输入规格型号" autocomplete="off" />
                            </el-form-item>
                        </el-col>
                        <el-col :span="6">
                            <el-form-item label="单位:">
                                <el-input disabled v-model="processInspectVo.unit"
                                    placeholder="请输入产品编码" autocomplete="off" />
                                    placeholder="请输入单位" autocomplete="off" />
                            </el-form-item>
                        </el-col>
                    </el-row>
@@ -91,21 +91,22 @@
            </el-row>
            <el-row style="width:100%;">
                <el-col :span="24">
                    <el-table border :data="inspectionItems" max-height="400" :span-method="handleSpanMethod" height="calc(100vh - 550px)"
                        style="width: 100%">
                    <el-table border :data="inspectionItems" max-height="400" height="calc(100vh - 550px)"
                        :header-cell-style="{textAlign:'center',color:'black',backgroundColor:'#fafafa'}"
                        :cell-style="{textAlign:'center'}" row-key="iid"
                        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="name" label="指标"></el-table-column>
                        <el-table-column prop="unit" label="单位"></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 prop="internal" label="内测值"></el-table-column>
                        <el-table-column prop="inspectionValue" v-for="(item, index) in empiricalValueAdd" :key="index" label="检测值"
                            min-width="100" style="text-align: center;">
                            <template slot-scope="scope">
                                <el-tooltip :disabled="scope.row.dname != 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.dname === null" v-model="scope.row.empiricalValueAddss[index]"
                                        @blur="changeState(scope.row, index)" placeholder="请输入检测值"></el-input> -->
                                </el-tooltip>
                            </template>
                        </el-table-column>
@@ -120,7 +121,15 @@
                                </el-select>
                            </template>
                        </el-table-column>
                        <el-table-column label="结论">
                        <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>
@@ -137,7 +146,9 @@
            </el-row>
            <el-row style="width:100%;margin-top:-180px">
                <el-col :span="24">
                    <el-table border max-height="400" :data="inspectionResultForm">
                    <el-table border max-height="400" :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>
@@ -160,9 +171,16 @@
</template>
<script>
import {
    chooseMater,
    addFinish,
    queryById, } from '@/api/quality/finishedProduct'
import { updateDeviceById,selectDevice } from '@/api/quality/rawMaterial'
export default {
    data() {
        return {
            deviceList: [],
            hasChildren: true,
            showUp: false,
            isAddProject: false,
            showLook: false,
@@ -195,7 +213,7 @@
                mcode: null,
                prname: null,
                sname: null,
                orderNumber: "",
                orderNumber: "ZTTIC20230001",
                qualityTraceability: null,
                quantity: null,
                specificationsModel: null,
@@ -254,27 +272,40 @@
        };
    },
    watch: {
        // filterText(val) {
        //     this.$refs.tree.filter(val);
        // }
    },
    beforeUpdate(){
      this.$nextTick(()=>{
        this.$refs.table.doLayout();
      })
    },
    created() {
    },
    mounted() {
        this.getTableData()
        // this.getOptions();
        this.getDeviceList()
    },
    methods: {
        changeOptionsSamplename() {
            let id = this.processInspectVo.material.split("-")[0]
            let sample = this.optionsSamplename.filter(o => {
                return o.id == id
            })[0]
            this.processInspectVo.qualityTraceability = sample.qualityTraceability
            this.processInspectVo.mcode = sample.mcode
            this.processInspectVo.specificationsModel = sample.specifications
            this.processInspectVo.unit = sample.unit
        getDeviceList(){
            selectDevice(null).then(res=>{
            this.deviceList = res.data.data
            })
        },
        comBack() {
            this.$parent.comBackMain()
        updateDevice(row){
            if(this.dataForm.id != null){
            updateDeviceById({equiomentId:row.equipmentId,rpId:row.rpId}).then(res=>{
            }).catch(error=>{
                console.log(error)
            })
            }
        },
        changeOptionsSamplename(val) {
            let sample = this.optionsSamplename.filter(o => {
                return o.materialCode == val
            })[0]
            // this.processInspectVo.qualityTraceability = sample.qualityTraceability
            this.processInspectVo.mcode = sample.materialCode
            this.processInspectVo.material = sample.material
            this.processInspectVo.specificationsModel = sample.specs
            this.processInspectVo.unit = sample.unit
        },
        handleClick(row) {
            this.rowInfp = row
@@ -284,44 +315,10 @@
            this.rowInfp = row
            this.showUp = true
        },
        combackMain() {
            this.showUp = false
            this.showLook = false
        },
        searchPro() {
            this.search.countSize = this.pageSize
            this.search.pageSize = this.currentPage
            this.defaultInitializationTable()
        },
        // 点击设备树保存点击记录
        nodeClick(data) {
            if (data.id != undefined) this.nodeData = data;
        },
        // 设备树过滤搜索
        filterNode(value, data) {
            if (!value) return true;
            return data.name.indexOf(value) !== -1;
        },
        // 获取设备树内容
        getOptions(row) {
            this.$axios.get(this.$api.url.inspectionItemChooseDev, {
                params: {
                    father: row.father,
                    name: row.name,
                    technologyId: this.processInspectVo.technologyId
                }
            }).then(res => {
                this.materialOptions = res.data;
                this.filterText = row.did
                if(this.materialOptions.length===1){
                    this.$message({
                    message: '该项目下只有一个试验设备,无需选择!',
                    type: 'warning'
                });
                    return
                }
                row.isSelectDevice = true
            });
        },
        // 点击表格选择触发
        clickTableSelect(scope) {
@@ -331,35 +328,6 @@
            this.clickSelectDevice.index = scope.$index;
            this.clickSelectDevice.rpId = scope.row.id;
            this.getOptions(scope.row);
        },
        // 点击树里面的确定
        clickNodeSure(row) {
            let select = this.materialOptions.filter(item => {
                return item.id === this.filterText
            })[0]
            this.nodeData.id = select.id
            this.nodeData.name = select.device
            if (this.detailId == null) {
                this.inspectionItems[
                    this.clickSelectDevice.index
                ].did = this.nodeData.id;
                this.inspectionItems[
                    this.clickSelectDevice.index
                ].dname = this.nodeData.name;
                this.centerDialogVisible = false;
            } else {
                this.$axios
                    .post(this.$api.url.inspectionItemUpdateDevByInsId, {
                        id: this.clickSelectDevice.rpId,
                        type: 2,
                        devId: this.nodeData.id
                    })
                    .then(res => {
                        this.getTableData()
                        this.centerDialogVisible = false;
                        row.isSelectDevice=false
                    });
            }
        },
        changeState(row, index) {
            if (row.did != null && row.did != '') {
@@ -400,187 +368,67 @@
                });
            }
        },
        // 每页条数改变时触发 选择一页显示多少行
        handleSizeChange(val) {
            this.search.countSize = val;
            this.defaultInitializationTable();
        },
        handleSpanMethod({ row, column, rowIndex, columnIndex }) {
            if (columnIndex === 0) {
                const _row = this.spanArr[rowIndex];
                const _col = _row > 0 ? 1 : 0;
                return {
                    rowspan: _row,
                    colspan: _col
                }
        addTestProject() {
            let val = this.processInspectVo
            let data = {
                customerName: val.prname,
                material: val.material,
                materialCode: val.mcode,
                orderNumber: val.orderNumber,
                projectName: val.sname,
                quantity: val.quantity,
                specs: val.specificationsModel,
                unit: val.unit,
            }
            if (columnIndex === 1) {
                const _row = this.spanArr[rowIndex];
                const _col = _row > 0 ? 1 : 0;
                return {
                    rowspan: _row,
                    colspan: _col
                }
            }
        },
        // 合并表格
        mergeTable() {
            this.rowList = []
            this.spanArr = []
            this.position = 0
            this.inspectionItems.forEach((item, index) => {
                if (index === 0) {
                    this.spanArr.push(1);
                    this.position = 0;
                } else {
                    if (this.inspectionItems[index].father === this.inspectionItems[index - 1].father) {
                        this.spanArr[this.position] += 1;
                        this.spanArr.push(0);
                    } else {
                        this.spanArr.push(1);
                        this.position = index;
                    }
                }
            })
        },
        changeOptionSoptionSprocesses() {
            this.optionTechnology = []
            let working = this.optionSoptionSprocesses.filter(item => {
                return item.name === this.processInspectVo.techfather
            })[0]
            this.optionTechnology = working.children
        },
        addTestProjevt() {
            // this.isAddProject = true
            let val = JSON.parse(JSON.stringify(this.processInspectVo))
            val.material = this.processInspectVo.material.split("-")[1]
            val.id = this.processInspectVo.material.split("-")[0]
            this.$axios.post(this.$api.url.finishedInspectAddFinish, val, {
                headers: { "Content-Type": "application/json" }
            }).then(res => {
                if (res.code == 201) {
                    this.$message({
                        message: res.message,
                        type: 'warning'
                    });
                    return
                }
                this.detailId = res.data
                this.inspectionResultForm[0].id = val.mcode
                this.inspectionResultForm[0].name = val.material
                this.getTableData()
            })
        },
        getTableData() {
            this.$axios.get(this.$api.url.finishedInspectSelectFinishInspectsListById, {
                params: {
                    id: this.detailId
                }
            }).then(res => {
                this.processInspectVo.technologyId = res.data[0].techId
            })
            this.$axios.get(this.$api.url.inspectionItemListUser, {
                params: {
                    id: this.detailId,
                    type: 2
                }
            }).then(res => {
                if (res.data.length < 1) {
                    return
                }
                this.inspectionItems = res.data
                let arr = []
                let val = JSON.parse(JSON.stringify(this.inspectionItems))
                const uName = []
                //转成一维数组
                val.forEach(l => {
                    let father = l.father
                    l.children.forEach(c => {
                        c.father = father
                        c.empiricalValueAddss = []
                        if (c.inspectionValue != '' && c.inspectionValue != null) {
                            c.empiricalValueAddss = c.inspectionValue.split(",");
                        } else {
                            c.empiricalValueAddss.push("")
                        }
                        uName.push(c['username'])
                        c.isSelectDevice = false
                        arr.push(c)
            addFinish(data).then(res=>{
                let id = res.data.data
                if(id != null){
                    queryById(id).then(response=>{
                        console.log(response.data.data.children)
                        let proList = response.data.data.children
                        proList.forEach(item=>{
                            item.iid = Math.random();
                        })
                        this.inspectionItems = proList
                    }).catch(error=>{
                        console.log(error);
                    })
                })
                this.inspectionItems = arr
                let arrSort = JSON.parse(JSON.stringify(arr))
                //根据集合对象数组长度排序
                arrSort.sort((a, b) => {
                    if (a.empiricalValueAddss.length < b.empiricalValueAddss.length) {
                        return -1; // a排在b前面
                    } else if (a.empiricalValueAddss.length > b.empiricalValueAddss.length) {
                        return 1; // a排在b后面
                    } else {
                        return 0; // 保持相对顺序不变
                    }
                });
                // console.log(arrSort);
                console.log(uName);
                let name = [...new Set(uName)].filter(item => item !== null);
                let rname = ''
                name.forEach(m => {
                    rname += m + ","
                })
                this.inspectionResultForm[0].inspecter = rname.slice(0, -1)
                this.empiricalValueAdd = arrSort[arrSort.length - 1].empiricalValueAddss.length
                this.mergeTable(arr)
                }
            }).catch(error=>{
                console.log(error)
            })
        },
        selectSample() {
            let sample = this.optionsSamplename.filter(item => {
                return item.name === this.processInspectVo.material
            })[0]
            this.processInspectVo.techfather = null
            this.processInspectVo.techname = null
            this.processInspectVo.materialCode = sample.code
            this.processInspectVo.specificationsModel = sample.specifications
            this.processInspectVo.unit = sample.unit
            this.optionSoptionSprocesses = []
            this.optionSoptionSprocesses = sample.children
        },
        selectInfoByOrderId() {
            this.$axios.get(this.$api.url.finishedInspectChooseMater, {
                params: {
            chooseMater({
                    orderNumber: this.processInspectVo.orderNumber
                }
            }).then(res => {
                if (res.data.length > 0) {
                    console.log(res.data);
                    this.processInspectVo.sname = res.data[0].sname
                    this.processInspectVo.prname = res.data[0].prname
                    this.optionsSamplename = res.data[0].children
                }).then(res => {
                if (res.data.data != null) {
                    this.processInspectVo.sname = res.data.data.projectName
                    this.processInspectVo.prname = res.data.data.customerName
                    this.optionsSamplename = res.data.data.children
                } else {
                    this.$message({
                        message: '没有该订单号!',
                        type: 'warning'
                    });
                    this.processInspectVo.sname = null
                    this.processInspectVo.prname = null
                    this.optionsSamplename = []
                    this.processInspectVo.mcode = null
                    this.processInspectVo.material = null
                    this.processInspectVo.specificationsModel = null
                    this.processInspectVo.unit = null
                }
            })
        },
        // 当前页改变时触发 跳转其他页
        handleCurrentChange(val) {
            this.search.pageSize = val;
            this.defaultInitializationTable();
        },
        // 显示新增页面
        handleAddNew() {
            this.showAddPage = true;
            // this.getTableData()
        },
        // 表格初始化接口
        defaultInitializationTable() {
            this.$axios
                .post(this.$api.url.selectProcessInspectsList, this.search)
                .then(res => {
                    this.inspectionTableTotal = res.data.total;
                    this.inspectionTable = res.data.row;
                });
            // this.$axios
            //     .post(this.$api.url.selectProcessInspectsList, this.search)
            //     .then(res => {
            //         this.inspectionTableTotal = res.data.total;
            //         this.inspectionTable = res.data.row;
            //     });
        },
        // 添加行
        clickAddLine() {
@@ -618,9 +466,6 @@
            this.empiricalValueAdd = this.empiricalValueAdd + 1;
        }
    },
    created() {
        this.defaultInitializationTable(); // 初始化表格数据
    }
}
</script>
@@ -639,7 +484,7 @@
.finishedProduct-basic {
  background-color: #fff;
  height: 150px;
  height: 155px;
  display: flex;
  flex-wrap: wrap;
  padding: 10px 20px;