From c880739ec4cd5ede33b31eb98ad5f7628ea288e5 Mon Sep 17 00:00:00 2001 From: zss <zss@example.com> Date: 星期一, 11 十二月 2023 17:41:40 +0800 Subject: [PATCH] Merge remote-tracking branch 'origin/master' --- src/views/quality/rawMaterial/index.vue | 253 ++++++++++++++++++++++++++++++++++--------------- 1 files changed, 174 insertions(+), 79 deletions(-) diff --git a/src/views/quality/rawMaterial/index.vue b/src/views/quality/rawMaterial/index.vue index 3e33e70..0c11eb8 100644 --- a/src/views/quality/rawMaterial/index.vue +++ b/src/views/quality/rawMaterial/index.vue @@ -20,13 +20,15 @@ <ttable :table="table" :resultData="resultData" - @change ="costPlannedAmountChange" @handleSelectionChange="handleSelectionChange" :prelang="prelang" :options="options" :ajaxFun="ajaxFun" + @queryParam="getQueryParam($event)" ref="rawMaterialTable"> - <template #toolbar></template> + <template #toolbar> + <el-button @click="exportRawMaterial" type="primary" >瀵煎嚭</el-button> + </template> </ttable> </basic-container> <!-- 寮圭獥, 鏂板 / 淇敼 --> @@ -35,21 +37,40 @@ ref="addOrUpdate" @refreshDataList="getData" ></RawMaterialForm> + <el-dialog + top="7vh" + title="鎵撳嵃棰勮" + :visible.sync="printDialogVisible" + 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"> + <el-button @click="()=>{printDialogVisible = false;this.printFormData=null}">鍙� 娑�</el-button> + <el-button type="primary" @click="printFun()">鎵� 鍗�</el-button> + </span> + </el-dialog> </div> </template> <script> -import ExportMaterial from './ExportMaterial.vue' import ttable from '@/views/common/ztt-table.vue' -import { getRawInspectList,delObj } from '@/api/quality/rawMaterial' +import { getRawInspectList,delObj,exportRawMaterial,getObj,downloadReport } 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 { transformZip } from '@/util/fileTransform' +import printTemplate from './rawMaterial-print.vue' export default { data() { return { + printFormData: null, + printDialogVisible: false, + queryParam: {}, resultData:[], addOrUpdateVisible: false, type: [1], + multipleSelection: [], prelang: 'rawMaterial', ajaxFun: getRawInspectList, options: { @@ -64,24 +85,31 @@ isRefresh: true, // 鏄惁鏄剧ず鍒锋柊鎸夐挳 isShowHide: true, // 鏄惁鏄剧ず鏄惧奖鎸夐挳H isSearch: true, // 楂樼骇鏌ヨ鎸夐挳 - defaultOrderBy: { column: 'formTime', direction: 'desc' }, + defaultOrderBy: { column: 'createTime', direction: 'desc' }, }, table: { total: 0, currentPage: 1, pageSize: 20, data: [], - isExport:true, // 鏍囬 column: [ + { + minWidth: '120', + prop: 'rawInsNo', + label: '鍘熸潗鏂欐楠岀紪鍙�', + isTrue: true, + isSearch: true, + searchInfoType: 'text', + render: { fun: this.addOrUpdateHandle } + }, { minWidth: '120', prop: 'code', label: '鍘熸潗鏂欑紪鐮�', isTrue: true, isSearch: true, - searchInfoType: 'text', - render: { fun: this.addOrUpdateHandle } + searchInfoType: 'text' }, { minWidth: '120', @@ -139,6 +167,7 @@ prop: 'createTime', label: '鎶ユ鏃ユ湡', isTrue: true, + sort: true, isSearch: true, searchInfoType: 'text', formatter: this.formatDateTime, @@ -186,18 +215,32 @@ }, ], toolbar: [ - { - text: '鏂板', - type: 'primary', - fun: this.addOrUpdateHandle - }, - { - text: '瀵煎嚭', - type: 'primary', - fun: this.handleExcel - } + { + text: '鏂板', + type: 'primary', + fun: this.addOrUpdateHandle + }, + { + text: '涓嬭浇妫�楠屾姤鍛�', + type: 'primary', + fun: this.downloadReport + } ], - operator: [{ + operator: [ + // { + // text: '鎵撳嵃', + // type: 'text', + // size: 'small', + // fun: this.previewFun, + // show: { + // val: [ + // '1', + // '0' + // ], + // key: 'judgeState' + // } + // }, + { text: '浣滃簾', type: 'text', size: 'small', @@ -217,47 +260,100 @@ components: { ttable, RawMaterialForm, - ExportMaterial, + printTemplate, }, - created() { - - }, + created() { }, computed: { ...mapGetters(['permissions']) }, - methods:{ - async costPlannedAmountChange(value){ - this.resultData= value - }, - - handleExcel() { - console.log(this.resultData); - console.log(this.table.column); - // let arr = this.table.column.map(el = el.isTrue == true) - // console.log(arr); - let arr = this.table.column.filter(item => item.isTrue == true).map(item => { - return{ - prop:item.prop, - label:item.label - } - }) - let opt = { - title: '鏂囨。鏍囬', - column: [{ - label:'', - prop:'header', - children:arr - }], - data: this.resultData + watch:{ + printFormData(newVal){ + if(newVal){ + this.printFormData = newVal + } } - this.$Export.excel({ - title: opt.title, - columns: opt.column, - data: opt.data - }); - // console.log(this.table); - - }, + }, + methods:{ + 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) + }) + downloadReport({ids : ids}).then(res=>{ + transformZip(res) + }).catch(error=>{ + console.log(error) + }) + } + }, + //鏌ョ湅鎶ュ憡鎸夐挳 + previewFun(row){ + getObj(row.id).then(res=>{ + this.printFormData = res.data.data + this.printDialogVisible = true + }).catch(error=>{ + console.log(error); + }) + }, + //鎵撳嵃鎸夐挳 + printFun() { + this.printDialogVisible = false; + PrintJS({ + printable: "printRaw", + type: "html", + // header: "鍘熸潗鏂欐娴嬫姤鍛�", + targetStyles: ["*"], + style: `@page {margin: 0mm 5mm;size: A4;} + html {zoom:100%;} + @media print { + html,body{ + width:200mm; + height:297mm; + } + }`, + ignoreElements: ["no-ignore"], + orientation: 'portrait' + }); + }, + getQueryParam(data){ + this.queryParam = data + }, + exportRawMaterial(){ + exportRawMaterial(this.queryParam).then(res=>{ + this.downloadFun(res) + }).catch(error=>{ + console.log(error); + }) + }, + downloadFun(result){ + if(result == null || result == undefined){ + return; + } + var nameList = result.headers['content-disposition']; + nameList = decodeURI(nameList); + var fileName = nameList.split('=')[1]; + const blob = new Blob([result.data], { type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' }) + const downloadElement = document.createElement('a') // 鏂板缓涓�涓狣OM鑺傜偣 + const href = window.URL.createObjectURL(blob) // 鍒涘缓涓嬭浇鐨勯摼鎺� + downloadElement.href = href + downloadElement.download = fileName // 涓嬭浇鍚庢枃浠跺悕 + document.body.appendChild(downloadElement) // 灏嗘柊澧炵殑鑺傜偣鎸傝浇鍒伴〉闈笂 + downloadElement.click() // 鐐瑰嚮涓嬭浇 + document.body.removeChild(downloadElement) // 涓嬭浇瀹屾垚绉婚櫎鍏冪礌 + window.URL.revokeObjectURL(href) + }, // 鍒犻櫎 deleteHandle(row) { this.$confirm('鏄惁纭鍒犻櫎璇ユ暟鎹細' + row.code , '鎻愮ず', { @@ -308,37 +404,36 @@ }, 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]) + // } + // } // 寰幆鑷畾涔夋寜閽紝鍒ゆ柇姣忎釜鎸夐挳鐨刾ermitArr鏄惁瀹屽叏鍖呭惈閫変腑鐘舵�侊紝鑻ュ畬鍏ㄥ寘鍚紝鍒欐寜閽寒锛屽惁鍒欐寜閽伆 - 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 + // } + // } }, } } -- Gitblit v1.9.3