let productsinfo = new Vue({ el: '#yieldForm', components: { 'BootstrapTable': BootstrapTable }, data: { columns: [], data: [], leftheader: [ { title: '车间', field: 'workshop', align: 'center', width: 70 }, { title: '站点', field: 'Processes', align: 'center', width: 51 }, { title: '机台', field: 'wks_desc', align: 'center', width: 100 }, { title: '班次', field: 'dailyShift', align: 'center', width: 51 }], rightheader: [], saturday: [], options: { //pagination: true, //是否显示分页(*) //pageSize: 12, //每页的记录行数(*) search: true, //是否显示表格搜索,此搜索是客户端搜索,不会进服务端, strictSearch: true, //showColumns: true, //是否显示所有的列 showRefresh: true, //height: 580, //onClickRow: function (row, $element, field) { // console.log(row); // var flow = row.flow; // console.log(flow); // productsinfo.requestApi({ // modulename: "Orders", // funname: "QueryWorkshop", //BatchRate // para: { flow: flow }, // success: (res) => { // console.log(res); // productsinfo.stations = res; // //显示工艺流程 // //clearTimeout(produstsinfo.hide); // $("#flow").slideDown('slow'); // console.log(productsinfo.hide); // productsinfo.hide = setTimeout(function () { $("#flow").slideUp('slow'); }, 6000); // $("#flow").mouseover(function () { // clearTimeout(productsinfo.hide); // console.log(productsinfo.hide); // $("#flow").stop(false, true); // }); // $("#flow").mouseleave(function () { // $("#flow").slideUp('slow'); // }); // }, // fail: (ex) => { // console.log(ex); // } // }) //} } }, created() { }, mounted() { var self = this; self.QueryddlWorkshop(); self.Daterangeini(); self.immediate(); //获取今天是今年第几周 var d1 = new Date(); var d2 = new Date(); d2.setMonth(0); console.log(d2); d2.setDate(1); console.log(d2); var oneWeek = d2.getDay();//获取本年第一天是周几 var oneDay = 6 - oneWeek;//本年第一周的天数 var rq = d1 - d2 + 1; var s1 = Math.ceil(rq / (24 * 60 * 60 * 1000)); //今天是本年第几天 var residueDay = s1 - oneDay; var s2 = Math.ceil(residueDay / 7) + 1; //当天是今年第几周 console.log("今天是本年第" + s1 + "天,第" + s2 + "周");//周日做为下周的开始计算 //站点 var station = [ { process_code: 'M10', descriptions: '焊接' }, { process_code: 'M15', descriptions: '叠层' }, { process_code: 'N30', descriptions: '层压' }, { process_code: 'N40', descriptions: '层压后检验' }, { process_code: 'M45', descriptions: '装框' }, { process_code: 'N50', descriptions: '清洗' }, { process_code: 'N60', descriptions: '全检' } ]; $.each(station, function (index, value) { console.log(index); $("#ddlStation").append(""); }) $('#ddlStation').val(''); $('#ddlStation').select2({ placeholder: "站点", allowClear: true }); }, methods: { //立即执行方法 immediate: function () { var self = this; self.rightheader = [];//将右侧表头初始化为空 var month = $('#jedatetime').val().substr($('#jedatetime').val().lastIndexOf("-")).substr(1); console.log(month); var year = $('#jedatetime').val().substr(0, $('#jedatetime').val().lastIndexOf("-")); //获取当前月份英文作为表头field var date = new Date(year + '/' + month); console.log(date.toDateString()); var monthEnglish = date.toDateString().split(" ")[1]; //当前月份英文 console.log(date.toDateString().split(" ")[1]); //获取月份天数 var days = self.mGetDate(year, month); console.log(days); //将本月的天数先加入数组中,存储起来 for (var i = 1; i < days + 1; i++) { self.rightheader.push({ title: month + '/' + i, field: 'month' + i, align: 'center', width: 60 }) } self.getSixDay(year, month) console.log(self.saturday); ////获取今天是今年第几周(以周六为一周第一天) //var d1 = new Date(year + '/' + month + '/' + self.saturday[0]); //var d2 = new Date(); //d2.setMonth(0); //console.log(d2); //d2.setDate(1); //console.log(d2); //var oneWeek = d2.getDay();//获取本年第一天是周几 //var oneDay = 6 - oneWeek;//本年第一周的天数 //console.log(oneDay); //var rq = d1 - d2; //var s1 = Math.ceil(rq / (24 * 60 * 60 * 1000)) + 1; //今天是本年第几天 //console.log(s1); //var residueDay = s1 - oneDay; //var s2 = Math.ceil(residueDay / 7) + 1; //当天是今年第几周 //console.log(s2); //console.log(self.rightheader); //for (var i = 0; i < self.saturday.length; i++) { // self.rightheader.splice(self.saturday[i] - 1 + i, 0, { // title: eval(s2 + i) + '周', // field: 'week' + i, // align: 'center', // width: 51 // }); //} //将两段数组合并、显示 self.columns = [...self.leftheader, ...self.rightheader] }, //查询表格数据 inquireinfo: function () { if ($('#ddlWorkshop').val() == null) { toastr.warning('请选择车间', '', { progressBar: true }); return; } if ($('#jedatetime').val() == null) { toastr.warning('请选择时间', '', { progressBar: true }); return; } var self = this; self.rightheader = [];//将右侧表头初始化为空 self.saturday = []; var month = $('#jedatetime').val().substr($('#jedatetime').val().lastIndexOf("-")).substr(1); console.log(month); var year = $('#jedatetime').val().substr(0, $('#jedatetime').val().lastIndexOf("-")); //获取当前月份英文作为表头field var date = new Date(year + '/' + month); console.log(date.toDateString()); var monthEnglish = date.toDateString().split(" ")[1]; //当前月份英文 console.log(date.toDateString().split(" ")[1]); //获取月份天数 var days = self.mGetDate(year, month); console.log(days); //将本月的天数先加入数组中,存储起来 for (var i = 1; i < days + 1; i++) { if (i < 10) { self.rightheader.push({ title: month + '-' + i, field: month + '-0' + i, align: 'center', width: 51 }) } else { self.rightheader.push({ title: month + '-' + i, field: month + '-' + i, align: 'center', width: 60 }) } } self.getSixDay(year, month) console.log(self.saturday); ////获取今天是今年第几周(以周六为一周第一天) //var d1 = new Date(year + '/' + month + '/' + self.saturday[0]); //var d2 = new Date(year + '/01/01'); //d2.setMonth(0); //console.log(d2); //d2.setDate(1); //console.log(d2); //var oneWeek = d2.getDay();//获取本年第一天是周几 //var oneDay = 6 - oneWeek;//本年第一周的天数 //console.log(oneDay); //var rq = d1 - d2; //var s1 = Math.ceil(rq / (24 * 60 * 60 * 1000)) + 1; //今天是本年第几天 //console.log(s1); //var residueDay = s1 - oneDay; //var s2 = Math.ceil(residueDay / 7) + 1; //当天是今年第几周 //console.log(s2); //console.log(self.rightheader); //for (var i = 0; i < self.saturday.length; i++) { // self.rightheader.splice(self.saturday[i] - 1 + i, 0, { // title: eval(s2 + i) + '周', // field: '第' + eval(s2 + i) + '周', // align: 'center', // width: 51 // }); //} console.log(self.leftheader); console.log(self.rightheader); //将两段数组合并、显示 self.columns = [...self.leftheader, ...self.rightheader] //月份查询条件 var monthCondition = { year: $('#jedatetime').val().substr(0, $('#jedatetime').val().lastIndexOf("-")), month: self.monthCondition() }; console.log(monthCondition); var cmonth; if (monthCondition.month.length == 2) { cmonth = '0' + monthCondition.month.substr(0, 1); } else { cmonth = monthCondition.month.substr(0, 2); } //进行数据查询 self.requestApi({ modulename: "CurEverydayStationCapacity", funname: "CurEverydayStationCapacity", para: { workshop: $('#ddlWorkshop').val(), year: monthCondition.year, month: cmonth, station: $('#ddlStation option:selected').text()}, success: (res) => { console.log(res); self.data = res; }, fail: (ex) => { console.log(ex); } }) }, //获取一个月中哪些天是周六 getSixDay: function (year, month) { var self = this; var tempTime = new Date(year, month, 0); var time = new Date(); var sunday = new Array(); for (var i = 1; i <= tempTime.getDate(); i++) { time.setFullYear(year, month - 1, i); var day = time.getDay(); if (day == 6) { self.saturday.push(i); } } }, //获取这周的周六(第一天) getFirstDayOfWeek: function (date) { var self = this; var weekday = date.getDay() || 0; //获取星期几,getDay()返回值是 0(周日) 到 6(周六) 之间的一个整数。0||7为7,即weekday的值为1-7 date.setDate(date.getDate() - weekday - 1);//往前算(weekday-1)天,年份、月份会自动变化 //return self.timeFormat(date); return date; }, zero: function (s) { return s < 10 ? '0' + s : s }, timeFormat: function (date) { if (!date || typeof (date) === "string") { this.error("参数异常,请检查..."); } var self = this; var y = date.getFullYear(); //年 var m = self.zero(date.getMonth() + 1); //月 var d = self.zero(date.getDate()); //日 return y + '-' + m + '-' + d + ' ' + '00:00:00' }, dateFormat: function (date) { if (!date || typeof (date) === "string") { this.error("参数异常,请检查..."); } var self = this; var y = date.getFullYear(); //年 var m = self.zero(date.getMonth() + 1); //月 var d = self.zero(date.getDate()); //日 return { year: y, month: m, day: d } }, monthCondition: function () { if ($('#jedatetime').val().substr($('#jedatetime').val().lastIndexOf("-")).substr(1, 1) == 0) { return $('#jedatetime').val().substr($('#jedatetime').val().lastIndexOf("-")).substr(2) + '月'; } else { return $('#jedatetime').val().substr($('#jedatetime').val().lastIndexOf("-")).substr(1) + '月'; } }, QueryddlWorkshop: function () { 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 }); }); promiseweld.fail(function (error) { console.log(error) alert(error); }); }, Daterangeini: function () { jeDate("#jedatetime", { onClose: false, theme: { bgcolor: "#00A1CB", color: "#ffffff", pnColor: "#00CCFF" }, format: "YYYY-MM", isinitVal: true, }) }, //获取月份天数 mGetDate: function (year, month) { var d = new Date(year, month, 0); return d.getDate(); }, 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) } ) } } }); $('#btnExportExcel').click(function () { if ($('#ddlWorkshop').val() == null && $('#ddlStation').val() == null && $('#jedatetime').val() == '') { toastr.warning('请输入查询参数', '', { progressBar: true }); return; } if ($('#ddlWorkshop').val() == null) { toastr.warning('请选择车间', '', { progressBar: true }); return; } if ($('#jedatetime').val() == '') { toastr.warning('请选择时间', '', { progressBar: true }); return; } doPost('/Report/CurEverydayStationCapacityExcel', [ workshop = $('#ddlWorkshop').val(), year = $('#jedatetime').val().substr(0, $('#jedatetime').val().lastIndexOf("-")), month = $('#jedatetime').val().substr(5,2), station = $('#ddlStation option:selected').text() ]) }) 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 }