$(document).ready(function () { Daterangeini(); //QueryddlStatus(); //1.初始化Table $('#wodaterange').tooltip(); }) /*显示daterangepicker*/ function Daterangeini() { $('#rangetime').val(moment().subtract('hours', 0).format('YYYY-MM-DD') + ' - ' + moment().format('YYYY-MM-DD')); $('#rangetime').daterangepicker( { //autoUpdateInput: false, timePicker: true, timePicker24Hour: true, 'center': true, 'locale': { "format": 'YYYY-MM-DD', "separator": " - ", "applyLabel": "确定", "cancelLabel": "取消", "fromLabel": "起始时间", "toLabel": "结束时间'", "customRangeLabel": "自定义", "weekLabel": "W", "daysOfWeek": ["日", "一", "二", "三", "四", "五", "六"], "monthNames": ["一月", "二月", "三月", "四月", "五月", "六月", "七月", "八月", "九月", "十月", "十一月", "十二月"], "firstDay": 1, //"cancelLabel": '清除' } }); //$('#rangetime').val(''); $('#rangetime').on('cancel.daterangepicker', function (ev, picker) { $(this).val(''); }); } let productsinfo = new Vue({ el: '#OnceMoldingRate', components: { 'BootstrapTable': BootstrapTable }, data: { columns: [], beforecolumn: [{ checkbox: true, rowspan: 2, align: 'center', valign: 'middle' }, { field: "机台", title: '机台号', rowspan: 2, align: 'center', valign: 'middle', }, { field: 'shift_type', title: '班次', rowspan: 2, align: 'center', valign: 'middle' } ], childcolumn: [ ], data:[], options: { pagination: true, //是否显示分页(*) pageSize: 12, //每页的记录行数(*) search: true, //是否显示表格搜索,此搜索是客户端搜索,不会进服务端, strictSearch: true, //showColumns: true, //是否显示所有的列 showRefresh: true, } }, methods: { //查询表格数据 inquireinfo: function (){ var self = this; self.columns = []; self.data = []; //console.log($('#ddlWorkshop').val()); if ($('#ddlMachine').val() == null && $('#ddlWorkshop').val() == null && $('#rangetime').val() =='') { toastr.warning('请输入查询参数', '', { progressBar: true }); return; } self.requestApi({ modulename: "OnceMoldingRate", funname: "OnceMoldingRate", //BatchRate para:{ machine: $('#ddlMachine').val(), workshop: $('#ddlWorkshop').val(), bt: $('#rangetime').val().substr(0, 10), et: $('#rangetime').val().split(' - ')[1]}, success:(ress) => { console.log(ress); self.beforecolumn = [{ checkbox: true, rowspan: 2, align: 'center', valign: 'middle' }, { field: "机台", title: '机台号', rowspan: 2, align: 'center', valign: 'middle', }, { field: 'shift_type', title: '班次', rowspan: 2, align: 'center', valign: 'middle' } ]; self.childcolumn = []; console.log(self.data) //console.log(ress[1].res)//直接使用ress有问题 console.log(ress[1].res[0].Time.length) for (var i = 0; i < ress[1].res[0].Time.length; i++) { self.beforecolumn.push( { title: ress[1].res[0].Time[i].wks_visit_date, colspan:3, align: 'center', valign: 'middle' } ); self.childcolumn.push( { field: ress[1].res[0].Time[i].wks_visit_date + "过站数", title: "过站数(块)", align: 'center', valign: 'middle' }, { field: ress[1].res[0].Time[i].wks_visit_date + "良品数", title: "良品数", align: 'center', valign: 'middle' }, { field: ress[1].res[0].Time[i].wks_visit_date + "良品率", title: "良品率", align: 'center', valign: 'middle' }, ) } self.data =ress[0].res; console.log(self.data) self.columns.push( self.beforecolumn ) self.columns.push( self.childcolumn ) console.log(ress[0].res) console.log(self .beforecolumn) }, fail: (ex) =>{ console.log(ex); } }) }, requestApi: function (config) {//modulename, funname, para, success, fail) { fetch("/api/" + config.modulename + "/" + config.funname + "", { method: "post", headers: { "Accept": "application/json, text/plain, */*", "Content-Type": "application/json" }, body: JSON.stringify(config.para) }).then( (res) => { return res.json() } ).then( (res) => { config.success(res) } ).catch( (ex) => { config.fail(ex) } ) }, form: function (config) { fetch("/" + config.modulename + "/" + config.funname + "", { method: "post", headers: { "Accept": "application/json, text/plain, */*", "Content-Type": "application/json" }, body: JSON.stringify(config.para) }).then( (res) => { return res.json() } ).then( (res) => { config.success(res) } ).catch( (ex) => { config.fail(ex) } ) }, } }); function QueryStorageMachineByWorkshop(areacode) { var promise = $.ajax({ url: '/api/Orders/QueryMachine', type: 'post', cache: true, async: true, contentType: "application/json", data: JSON.stringify({ areacode: areacode }) }); promise.done(function (r) { console.log(r) var options = ''; $.each(r.info, function (index, v) { options += ""; }); $('#ddlMachine').html(options); $('#ddlMachine').val(''); $('#ddlMachine').select2({ placeholder: "选择机台号", allowClear: true }); }); promise.fail(function (error) { console.log(error) alert(error); }); } //查询车间 function QueryddlWorkshop() { var promiseweld = $.ajax({ url: '/api/Orders/QueryWorkshop', //'/api/QC/QueryStatus' type: 'post', cache: true, async: true, }); promiseweld.done(function (r) { console.log(r); $.each(r.info, function (index, value) { console.log(index); $("#ddlWorkshop").append(""); }) $('#ddlWorkshop').val(''); $('#ddlWorkshop').select2({ placeholder: "车间", allowClear: true }); $('#ddlWorkshop').on('select2:select', function (e) { console.log($(this).val()); var selectvalue = $(this).val(); QueryStorageMachineByWorkshop(selectvalue); }); }); promiseweld.fail(function (error) { console.log(error) alert(error); }); } QueryddlWorkshop(); //导出EXCEl $('#btnExportExcel').click(function () { if ($('#ddlMachine').val() == null && $('#ddlWorkshop').val() == null && $('#rangetime').val()==''){ toastr.warning('请输入查询参数', '', { progressBar: true }); return; } var bt = $('#rangetime').val().substr(0, 10); var et = $('#rangetime').val().split(' - ')[1]; if (bt == '') { et = ''; } else { et = $('#rangetime').val().split(' - ')[1]; } doPost('/Report/MoldingExcel', [ machine = $('#ddlMachine').val(), workshop= $('#ddlWorkshop').val(), bt=$('#rangetime').val().substr(0, 10), endtime=et, ]) }) function doPost(to, p) { // to:提交动作(action),p:参数 var myForm = document.createElement("form"); myForm.method = "post"; myForm.action = to; for (var i in p) { var myInput = document.createElement("input"); myInput.setAttribute("name", "para"); // 为input对象设置name myInput.setAttribute("value", p[i]); // 为input对象设置value myForm.appendChild(myInput); } document.body.appendChild(myForm); myForm.submit(); document.body.removeChild(myForm); // 提交后移除创建的form } //var columns = []; //for (var i = 0; i < self.data.length; i++) { // for(let key in self.data[i]){ // columns.push( // { // field: key, // title:key, // valign: "middle", // align: "center", // } // ); // } //}