let productsinfo = new Vue({ el: '#yieldForm', components: { 'BootstrapTable': BootstrapTable }, data: { columns: [], data: [], leftheader: [ { title: '部门', field: 'workshop', align: 'center' }, { title: '内容/目标', field: 'content', align: 'center' }, { title: '', field: 'month', align: 'center' }, { title: '', field: 'week', align: 'center' }], rightheader:[], 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 + "周");//周日做为下周的开始计算 }, methods: { //立即执行方法 immediate: function () { var self = this; self.rightheader = [];//将右侧表头初始化为空 //获取今天是今年第几周(以周六为一周第一天) 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; var s1 = Math.ceil(rq / (24 * 60 * 60 * 1000))+1; //今天是本年第几天 var residueDay = s1 - oneDay; var s2 = Math.ceil(residueDay / 7) + 1; //当天是今年第几周 //console.log("今天是本年第" + s1 + "天,第" + s2 + "周");//周日做为下周的开始计算 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' }) } console.log(self.rightheader); //获取当前月份第一天是周几 var oneday = new Date(year + '/' + month + '/01').getDay(); console.log(oneday); //如果是周六则不需要上个月的数据,否则需要加入上个月部分数据 if (oneday != 6) { //获取上个月天数 var olddays if (month == '01') { olddays = self.mGetDate(year - 1, 12); } else { olddays = self.mGetDate(year, month - 1); } console.log(olddays); //获取上个月月份的英文简写 var olddate = new Date(year + '/' + eval(month - 1)); console.log(olddate.toDateString()); var oldmonthEnglish = olddate.toDateString().split(" ")[1]; //上个月份英文 //查上个月需要几天 var borrow; switch (oneday) { case 0: borrow = 1; break; case 1: borrow = 2; break; case 2: borrow = 3; break; case 3: borrow = 4; break; case 4: borrow = 5; break; case 5: borrow = 6; break; } console.log(borrow); //获取需要天数的日期 var datetime = olddays + 1 - borrow; for (var i = olddays; i > datetime - 1; i--) { if (month == '01') { self.rightheader.unshift({ title: eval(year - 1) + '/' + '12/' + i, field: 'oldmonth' + i, align: 'center' }); } else { self.rightheader.unshift({ title: eval(month - 1) + '/' + i, field: 'oldmonth' + i, align: 'center' }); } } } console.log(self.rightheader); if (month.substr(0, 1) == 0) { month = month.substr(1) + '月'; } else { month = month + '月'; } self.leftheader[2].title = month; self.leftheader[3].title = s2 + 'W'; console.log(self.leftheader); //将两段数组合并、显示 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 = [];//将右侧表头初始化为空 //获取今天是今年第几周(以周六为一周第一天) 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; var s1 = Math.ceil(rq / (24 * 60 * 60 * 1000))+1; //今天是本年第几天 var residueDay = s1 - oneDay; var s2 = Math.ceil(residueDay / 7) + 1; //当天是今年第几周 //console.log("今天是本年第" + s1 + "天,第" + s2 + "周");//周日做为下周的开始计算 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: monthEnglish + i, align: 'center' }) } console.log(self.rightheader); //获取当前月份第一天是周几 var oneday = new Date(year + '/' + month + '/01').getDay(); console.log(oneday); //如果是周六则不需要上个月的数据,否则需要加入上个月部分数据 if (oneday != 6) { //获取上个月天数 var olddays if (month == '01') { olddays = self.mGetDate(year-1, 12); } else { olddays = self.mGetDate(year, month - 1); } console.log(olddays); //获取上个月月份的英文简写 var olddate = new Date(year + '/' + eval(month-1)); console.log(olddate.toDateString()); var oldmonthEnglish = olddate.toDateString().split(" ")[1]; //上个月份英文 //查上个月需要几天 var borrow; switch (oneday) { case 0: borrow = 1; break; case 1: borrow = 2; break; case 2: borrow = 3; break; case 3: borrow = 4; break; case 4: borrow = 5; break; case 5: borrow = 6; break; } console.log(borrow); //获取需要天数的日期 var datetime = olddays + 1 - borrow; for (var i = olddays; i > datetime - 1; i--) { if (month == '01') { self.rightheader.unshift({ title: eval(year - 1) + '/' + '12/' + i, field: oldmonthEnglish + i, align: 'center' }); } else { self.rightheader.unshift({ title: eval(month - 1) + '/' + i, field: oldmonthEnglish + i, align: 'center' }); } } } console.log(self.rightheader); if (month.substr(0, 1) == 0) { month = month.substr(1) + '月'; } else { month = month + '月'; } self.leftheader[2].title = month; self.leftheader[3].title = s2 + 'W'; console.log(self.leftheader); //将两段数组合并、显示 self.columns = [...self.leftheader, ...self.rightheader] //月份查询条件 var monthCondition = { year: $('#jedatetime').val().substr(0, $('#jedatetime').val().lastIndexOf("-")), month: self.monthCondition() }; console.log(monthCondition); //周查询条件(先获取当天年月日) var weekCondition = {};//存储周条件 var sameDay = new Date(); console.log(sameDay); var sameyear = sameDay.getFullYear(); //当天的年份 var samemonth = sameDay.getMonth() + 1; //当天的月份 var sameoneday1 = self.getFirstDayOfWeek(sameDay); //获取本周第一天日期 console.log(sameoneday1); var sameoneday = self.timeFormat(sameoneday1); console.log(sameoneday); var sameDay2 = new Date(); var samenineday1 = self.getFirstDayOfWeek(sameDay2); //获取本周最后一天的后一天日期 samenineday1.setDate(samenineday1.getDate() + 7); var samenineday = self.timeFormat(samenineday1); console.log(samenineday); console.log(); weekCondition.bt = sameoneday; weekCondition.et = samenineday; var weekeveryday = []; //存储周每一天 for (var i = 0; i < 7; i++) { var sameDay3 = new Date(); console.log(sameDay2); var samefistday = self.getFirstDayOfWeek(sameDay3); //获取本周第一天日期 console.log(samefistday); samefistday.setDate(samefistday.getDate() + i); var weekinday = self.dateFormat(samefistday); weekeveryday.push(weekinday); } weekCondition.weekDay = weekeveryday; console.log(weekCondition); //天的条件 var dayCondition = [];//存储天条件 console.log(year); console.log(month); console.log(days); console.log(self.columns.length); if (self.columns.length > days+4) { var number = self.columns.length - days - 4; for (var i = 4; i < 4 + number;i++) { if (self.columns[i].title.split("/").length == 3) { dayCondition.push({ year: self.columns[i].title.split("/")[0], month: self.columns[i].title.split("/")[1], day: self.columns[i].title.split("/")[2], }); } else { dayCondition.push({ year: year, month: self.columns[i].title.split("/")[0], day: self.columns[i].title.split("/")[1], }); } } } console.log(monthCondition); //对象 console.log(weekCondition); //对象 console.log(dayCondition); //数组 //进行数据查询 self.requestApi({ modulename: "YieldForm", funname: "YieldFormInfo", //BatchRate para: { workshop: $('#ddlWorkshop').val(),monthCondition: monthCondition, weekCondition: weekCondition, dayCondition: dayCondition}, success: (res) => { console.log(res.info); }, fail: (ex) => { console.log(ex); } }) }, //获取这周的周六(第一天) 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) } ) } } });