zss
2024-04-02 60cde7048175902baa66fd81ddfd174aeda3292a
src/views/quality/rawMaterial/index.vue
@@ -17,7 +17,7 @@
<template>
    <div class="mod-config">
        <basic-container>
            <ttable
            <ttable
            :table="table"
            :resultData="resultData"
            @handleSelectionChange="handleSelectionChange"
@@ -27,7 +27,7 @@
            @queryParam="getQueryParam($event)"
            ref="rawMaterialTable">
            <template #toolbar>
                <el-button @click="exportRawMaterial" type="primary" >导出</el-button>
                <!-- <el-button @click="exportRawMaterial" type="primary" >导出</el-button> -->
            </template>
            </ttable>
        </basic-container>
@@ -38,11 +38,11 @@
            @refreshDataList="getData"
        ></RawMaterialForm>
        <el-dialog
        top="10vh"
        top="7vh"
        title="打印预览"
        :visible.sync="printDialogVisible"
        width="60%">
        <div style="width:100%;height: 60vh;overflow-y: scroll;">
        width="70%">
        <div style="width:90%;margin-left:5%;height: 60vh;overflow-y: scroll;">
            <printTemplate id="printRaw" :formData="printFormData"></printTemplate>
        </div>
        <span slot="footer" class="dialog-footer">
@@ -54,12 +54,13 @@
</template>
<script>
import ttable from '@/views/common/ztt-table.vue'
import { getRawInspectList,delObj,exportRawMaterial,getObj } from '@/api/quality/rawMaterial'
import { getRawInspectList,delObj,exportRawMaterial,getObj,downloadReport,checkPutIFS } from '@/api/quality/rawMaterial'
import RawMaterialForm from './rawMaterial-form'
import * as fecha from 'element-ui/lib/utils/date'
import { mapGetters } from 'vuex'
import PrintJS from 'print-js'
import printTemplate from './rawMaterial-print.vue'
import { transformZip } from '@/util/fileTransform'
import printTemplate from './rawMaterial-print'
  export default {
    data() {
        return {
@@ -69,6 +70,7 @@
            resultData:[],
            addOrUpdateVisible: false,
            type: [1],
            multipleSelection: [],
            prelang: 'rawMaterial',
            ajaxFun: getRawInspectList,
            options: {
@@ -94,12 +96,43 @@
                column: [
                    {
                        minWidth: '120',
                        prop: 'code',
                        label: '原材料编码',
                        prop: 'rawInsNo',
                        label: '原材料检验编号',
                        isTrue: true,
                        isSearch: true,
                        searchInfoType: 'text',
                        render: { fun: this.addOrUpdateHandle }
                    },
                    {
                        minWidth: '120',
                        prop: 'type',
                        label: '检验类型',
                        isTrue: true,
                        isSearch: true,
                        searchInfoType: 'select',
                        optList: () => {
                            return this.typeList
                        }
                    },
                    {
                        minWidth: '120',
                        prop: 'checkState',
                        label: '审核状态',
                        isTrue: true,
                        isSearch: true,
                        searchInfoType: 'select',
                        formatter: this.checkStateFormat,
                        optList: () => {
                            return this.checkStateList
                        }
                    },
                    {
                        minWidth: '120',
                        prop: 'code',
                        label: '原材料编码',
                        isTrue: true,
                        isSearch: true,
                        searchInfoType: 'text'
                    },
                    {
                        minWidth: '120',
@@ -154,12 +187,13 @@
                    },
                    {
                        minWidth: '120',
                        prop: 'createTime',
                        prop: 'startTime',
                        label: '报检日期',
                        isTrue: true,
                        sort: true,
                        isSearch: true,
                        searchInfoType: 'text',
                        searchInfoType: 'datetimerange',
                        formatter: this.formatDateTime,
                    },
                    {
@@ -177,6 +211,7 @@
                        isTrue: true,
                        isSearch: true,
                        searchInfoType: 'text',
                        searchInfoType: 'datetimerange',
                        formatter: this.formatDateTime,
                    },
                    {
@@ -203,32 +238,17 @@
                                return this.StateList
                            }
                    },
                    {
                        minWidth: '120',
                        prop: 'remark',
                        label: '备注',
                        isTrue: true,
                        isSearch: true,
                        searchInfoType: 'text',
                    },
                ],
                toolbar: [
                {
                    text: '新增',
                    type: 'primary',
                    fun: this.addOrUpdateHandle
                }],
                operator: [{
                    text: '打印',
                    type: 'text',
                    size: 'small',
                    fun: this.previewFun,
                    show: {
                        val: [
                            '1',
                            '0'
                        ],
                        key: 'judgeState'
                    }
                },
                {
                    text: '作废',
                    type: 'text',
                    size: 'small',
                    fun: this.deleteHandle
                }],
                toolbar: [],
                operator: null,
                operatorConfig: {
                fixed: 'right',
                label: '操作',
@@ -238,6 +258,8 @@
            },
            insStateList: [{label:'全部',value:''},{label:'已检测',value:'1'},{label:'未检测',value:'0'}],
            StateList: [{label:'全部',value:''},{label:'已合格',value:'1'},{label:'不合格',value:'0'}],
            typeList: [{label:'全部',value:''},{label:'首检',value:'首检'},{label:'返检',value:'返检'}],
            checkStateList: [{label:'未审核',value:'0'},{label:'审核通过',value:'1'},{label:'审核不通过',value:'2'}],
        }
    },
    components: {
@@ -246,8 +268,49 @@
        printTemplate,
    },
    created() {
        if(this.permissions.quality_rawMaterial_add){
            this.table.toolbar.push({
                text: '新增',
                type: 'primary',
                fun: this.addOrUpdateHandle
            })
        }
        if(this.permissions.quality_rawMaterial_download){
            this.table.toolbar.push({
                text: '下载检验报告',
                type: 'primary',
                loading: false,
                disabled: false,
                fun: this.downloadReport,
    },
            })
        }
        if(this.permissions.quality_rawMaterial_check){
            this.table.operator = [{
                text: '审核',
                type: 'text',
                size: 'small',
                fun: this.examineHandle,
                showFun: (row)=>{return row.type==='首检'&& row.insState==='1'},
                show: {
                    key: 'checkState',
                    val: ['0','2']
                    }
            }]
        }
        if(this.permissions.quality_rawMaterial_del){
            this.table.operator.push({
                    text: '作废',
                    type: 'text',
                    size: 'small',
                    fun: this.deleteHandle,
                    show: {
                        key: 'judgeState',
                        val: ['',null]
                    }
                })
        }
     },
    computed: {
        ...mapGetters(['permissions'])
    },
@@ -259,6 +322,60 @@
        }
    },
    methods:{
        examineHandle(val){
            this.$confirm('是否审核通过该检验项?', '提示', {
                distinguishCancelAndClose: true,
                confirmButtonText: '通过',
                cancelButtonText: '不通过',
                type: 'warning'
            }).then(() => {
                this.checkPutIFSFun(val.id,1);
            }).catch((action) => {
                if(action === 'cancel'){
                    this.checkPutIFSFun(val.id,2);
                }
            });
        },
        checkPutIFSFun(id,result){
            checkPutIFS(id, result).then(res=>{
                if(res.status===200){
                    this.getData()
                }
            }).catch(error=>{
                console.error(error)
            })
        },
        downloadReport(){
            let selection = this.multipleSelection
            if(!selection || selection.length < 1){
                this.$message.error("请先选择检验数据")
                return
            }else{
                let arr = selection.filter(s=>{
                    return s.judgeState==null || s.judgeState==''
                })
                if(arr.length > 0){
                    this.$message.error("只能选择已检测的数据")
                    return
                }
                let ids = []
                selection.forEach(ele=>{
                    ids.push(ele.id)
                })
                this.table.toolbar.find((e) => e.text === '下载检验报告').loading = true
                this.table.toolbar.find((e) => e.text === '下载检验报告').disabled = true
                try{
                    downloadReport({ids : ids}).then(res=>{
                        transformZip(res)
                    })
                }catch(error){
                    console.log(error)
                } finally{
                    this.table.toolbar.find((e) => e.text === '下载检验报告').loading = false
                    this.table.toolbar.find((e) => e.text === '下载检验报告').disabled = false
                }
            }
        },
        //查看报告按钮
        previewFun(row){
            getObj(row.id).then(res=>{
@@ -274,10 +391,16 @@
            PrintJS({
                printable: "printRaw",
                type: "html",
                maxWidth: 880,
                // header: "原材料检测报告",
                style: '@page {margin: 0 5mm;}',
                targetStyles: ["*"],
                style: `@page {margin: 0mm 5mm;size: A4 landscape;}
                    html {zoom:100%;}
                    @media print {
                 html,body{
                   width:200mm;
                   height:297mm;
                 }
               }`,
                ignoreElements: ["no-ignore"],
                orientation: 'portrait'
            });
@@ -287,7 +410,6 @@
        },
        exportRawMaterial(){
            exportRawMaterial(this.queryParam).then(res=>{
                console.log(res)
                this.downloadFun(res)
            }).catch(error=>{
                console.log(error);
@@ -331,11 +453,16 @@
        },
        // 新增 / 修改
        addOrUpdateHandle(row) {
            console.log(row);
            if(!this.permissions.quality_rawMaterial_edit && row.id!=null){
                this.$message.error("该角色没有操作权限")
                return
            }
            this.$router.push({
                name: 'rawMaterialForm',
                query: {
                    id: row == null ? null : row.id,
                query: {
                    id: row == null ? null : row.id
                 },
                 params: {
                    resultVal: row == null ? null : row.judgeState
                 }
            })
@@ -349,51 +476,57 @@
            }
        },
        formatJudgeState(row, column, cellValue){
            if(cellValue != undefined || cellValue != null){
            if(cellValue != undefined && cellValue != null && cellValue != ''){
                if(cellValue == 0){
                    return "<span style='color:#E84738;'>不合格</span>"
                }
                return "<span style='color:#34BD66;'>合格</span>"
            }
        },
        checkStateFormat(row, column, cellValue){
            this.checkStateList.forEach((obj) => {
                if (obj.value === cellValue) {
                    cellValue = obj.label
                }
            })
            return cellValue
        },
        formatDateTime(row, column, cellValue) {
            return cellValue ? fecha.format(new Date(cellValue), 'yyyy-MM-dd') : ''
        },
        getData() {
            this.$refs.rawMaterialTable.getDataList()
        },
        // table自带事件
        handleSelectionChange(val) {
            this.multipleSelection = val
            // 根据状态,禁用表头按钮
            // 筛选出选中记录的状态
            var stateArr = val.map(function(value, index) {
                return value.coState
            })
            // var stateArr = val.map(function(value, index) {
            //     return value.coState
            // })
            // 选中状态数组元素去重
            var uniqueStateArr = []
            for (var i = 0; i < stateArr.length; i++) {
                if (uniqueStateArr.indexOf(stateArr[i]) == -1) {
                uniqueStateArr.push(stateArr[i])
                }
            }
            // var uniqueStateArr = []
            // for (var i = 0; i < stateArr.length; i++) {
            //     if (uniqueStateArr.indexOf(stateArr[i]) == -1) {
            //     uniqueStateArr.push(stateArr[i])
            //     }
            // }
            // 循环自定义按钮,判断每个按钮的permitArr是否完全包含选中状态,若完全包含,则按钮亮,否则按钮灰
            for (var i = 0; i < this.stateTagArr.length; i++) {
                if (
                uniqueStateArr.every((val) =>
                    this.stateTagArr[i].permitArr.length <= 0
                    ? true
                    : this.stateTagArr[i].permitArr.includes(val)
                )
                ) {
                this.stateTagArr[i].disabled = false
                } else {
                this.stateTagArr[i].disabled = true
                }
            }
            this.multipleSelection = val
            // for (var i = 0; i < this.stateTagArr.length; i++) {
            //     if (
            //     uniqueStateArr.every((val) =>
            //         this.stateTagArr[i].permitArr.length <= 0
            //         ? true
            //         : this.stateTagArr[i].permitArr.includes(val)
            //     )
            //     ) {
            //     this.stateTagArr[i].disabled = false
            //     } else {
            //     this.stateTagArr[i].disabled = true
            //     }
            // }
        },
    }
  }
  </script>