|
@@ -0,0 +1,289 @@
|
|
|
|
|
+define(['jquery', 'bootstrap', 'backend', 'table', 'form','jQuery.print'], function ($, undefined, Backend, Table, Form) {
|
|
|
|
|
+ var Controller = {
|
|
|
|
|
+ index: function () {
|
|
|
|
|
+ // 初始化表格参数配置
|
|
|
|
|
+ Table.api.init({
|
|
|
|
|
+ extend: {
|
|
|
|
|
+ index_url: 'feeding/index' + location.search,
|
|
|
|
|
+ add_url: 'feeding/add',
|
|
|
|
|
+ edit_url: 'feeding/edit',
|
|
|
|
|
+ del_url: 'feeding/del',
|
|
|
|
|
+ multi_url: 'feeding/multi',
|
|
|
|
|
+ import_url: 'feeding/import',
|
|
|
|
|
+ table: 'feeding',
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
|
|
+ var table = $("#table");
|
|
|
|
|
+ // 初始化表格
|
|
|
|
|
+ table.bootstrapTable({
|
|
|
|
|
+ url: $.fn.bootstrapTable.defaults.extend.index_url,
|
|
|
|
|
+ pk: 'id',
|
|
|
|
|
+ sortName: 'id',
|
|
|
|
|
+ fixedColumns: true,
|
|
|
|
|
+ fixedRightNumber: 1,
|
|
|
|
|
+ columns: [
|
|
|
|
|
+ [
|
|
|
|
|
+ {checkbox: true},
|
|
|
|
|
+ {field: 'id', title: __('Id')},
|
|
|
|
|
+ {field: 'bach', title: __('Bach'), operate: 'LIKE'},
|
|
|
|
|
+ {field: 'material', title: __('Material'), operate: 'LIKE'},
|
|
|
|
|
+ {field: 'nweight', title: __('Nweight'), operate: 'LIKE'},
|
|
|
|
|
+ {field: 'weight', title: __('Weight'), operate: 'LIKE'},
|
|
|
|
|
+ {field: 'gy_num', title: __('Gy_num')},
|
|
|
|
|
+ {field: 'date', title: __('Date'), operate: 'LIKE'},
|
|
|
|
|
+ {field: 'operator', title: __('Operator'), operate: 'LIKE'},
|
|
|
|
|
+ // {field: 'tid', title: __('Tid')},
|
|
|
|
|
+ {field: 'inspector', title: __('Inspector'), operate: 'LIKE'},
|
|
|
|
|
+ {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
|
|
|
|
|
+ ]
|
|
|
|
|
+ ]
|
|
|
|
|
+ });
|
|
|
|
|
+ table.on('post-body.bs.table',function(){
|
|
|
|
|
+ $(".btn-add").data("area",["100%","100%"]);
|
|
|
|
|
+ });
|
|
|
|
|
+ // 为表格绑定事件
|
|
|
|
|
+ Table.api.bindevent(table);
|
|
|
|
|
+ },
|
|
|
|
|
+ add: function () {
|
|
|
|
|
+ var num=0;
|
|
|
|
|
+ $('#c-bach').keydown((e)=>{
|
|
|
|
|
+ let key = e.which;
|
|
|
|
|
+ if(key == 13){
|
|
|
|
|
+ if(num === 0){
|
|
|
|
|
+ $.ajax({
|
|
|
|
|
+ method:"POST",
|
|
|
|
|
+ data:{bach:$("#c-bach").val()},//批次号
|
|
|
|
|
+ url:"feeding/get_task",
|
|
|
|
|
+ success(res){
|
|
|
|
|
+ //批次号重复/做下拉选择
|
|
|
|
|
+ if(res.data.length>1){
|
|
|
|
|
+ let str = '';
|
|
|
|
|
+ str+='<select class="selectpicker form-control" id="bach"><option>请选择对应的生产量</option>';
|
|
|
|
|
+ for(var i=0;i<res.data.length;i++){
|
|
|
|
|
+ str+='<option value="'+i+'">'+res.data[i].create+' 生产量:'+res.data[i].number+'</option>';
|
|
|
|
|
+ }
|
|
|
|
|
+ str+='</select><a href="javascript:;" id="btn" class="btn btn-success">确认</a>';
|
|
|
|
|
+ $('#c-bach').parent('#c_bach').append(str);
|
|
|
|
|
+ $("#bach").change(()=>{
|
|
|
|
|
+ $("#c-name").val(res.data[$("#bach").val()].name);
|
|
|
|
|
+ $("#c-specifications").val(res.data[$("#bach").val()].drawer_name);
|
|
|
|
|
+ $("#c-unit").val(res.data[$("#bach").val()].examine_name);
|
|
|
|
|
+ });
|
|
|
|
|
+ $("#btn").click(()=>{
|
|
|
|
|
+ if($("#c-bach").attr('readonly')==='readonly'){
|
|
|
|
|
+ return false;
|
|
|
|
|
+ }
|
|
|
|
|
+ $("#bach").css('cssText','display:none! important');
|
|
|
|
|
+ $("#btn").css('display','none');
|
|
|
|
|
+ $.ajax({
|
|
|
|
|
+ method:"POST",
|
|
|
|
|
+ url:"feeding/get_formula",
|
|
|
|
|
+ data:{
|
|
|
|
|
+ bach:$("#c-bach").val(),
|
|
|
|
|
+ num:res.data[$("#bach").val()].number
|
|
|
|
|
+ },
|
|
|
|
|
+ success(result){
|
|
|
|
|
+ var str = '';
|
|
|
|
|
+ var html = '';
|
|
|
|
|
+ for(var i=0;i<result.data.length;i++){
|
|
|
|
|
+ str += "<tr class='tablestr"+i+" tablestr'><td><input class='form-control material' type='text' name='row[material][]' readonly value='"+result.data[i].material+"'></td>";
|
|
|
|
|
+ str += "<td><input class='form-control' type='text' name='row[nweight][]' readonly value='"+result.data[i].nweight+"'></td>";
|
|
|
|
|
+ str += "<td><input class='form-control' type='number' name='row[weight][]' value='";
|
|
|
|
|
+ if (result.data[i].weight) {
|
|
|
|
|
+ str += parseFloat(result.data[i].weight) + "' readonly ";
|
|
|
|
|
+ }
|
|
|
|
|
+ str += "'></td>";
|
|
|
|
|
+ str += "<input class='form-control' type='hidden' name='row[gy_num][]' value='"+result.data[i].gy_num+"'>";
|
|
|
|
|
+ str += "<td><input class='form-control' type='text' name='row[gy_name][]' readonly value='"+result.data[i].gy_name+"'></td>";
|
|
|
|
|
+ str += "</tr>";
|
|
|
|
|
+ html += `<tr>
|
|
|
|
|
+ <td>${result.data[i].material}</td>
|
|
|
|
|
+ <td>${result.data[i].nweight}</td><td>`;
|
|
|
|
|
+ if (result.data[i].weight) {
|
|
|
|
|
+ html += parseFloat(result.data[i].weight);
|
|
|
|
|
+ }
|
|
|
|
|
+ html += `
|
|
|
|
|
+ </td><td>${result.data[i].gy_name}</td>
|
|
|
|
|
+ </tr>`;
|
|
|
|
|
+
|
|
|
|
|
+ }
|
|
|
|
|
+ html+= `<tr>
|
|
|
|
|
+ <td style="width: 100px;text-align: center">总计</td>
|
|
|
|
|
+ <td class="total" style="width: 100px;text-align: center">${result.total}</td>
|
|
|
|
|
+ <td id="total"></td>
|
|
|
|
|
+ <td></td>
|
|
|
|
|
+ </tr>`;
|
|
|
|
|
+ $("#print_gy").append(html);
|
|
|
|
|
+ $("#table").append(str);
|
|
|
|
|
+ $("#c-bach").attr('readonly','readonly');
|
|
|
|
|
+ $("#wuliao").keydown((e)=>{
|
|
|
|
|
+ let key = e.which;
|
|
|
|
|
+ var error = 0;
|
|
|
|
|
+ if(key === 13){
|
|
|
|
|
+ var wuliao = $("#wuliao").val();
|
|
|
|
|
+ for(var i=0;i<result.data.length;i++) {
|
|
|
|
|
+ if(result.data[i].material===wuliao){
|
|
|
|
|
+ $(".material")[i].setAttribute('style','color:red');
|
|
|
|
|
+ error++;
|
|
|
|
|
+ }
|
|
|
|
|
+ if(result.data[i].material.indexOf('/')!==-1){
|
|
|
|
|
+ var arr = result.data[i].material.split('/');
|
|
|
|
|
+ if(arr.indexOf($("#wuliao").val()) !== -1){
|
|
|
|
|
+ $(".material")[i].value = wuliao;
|
|
|
|
|
+ $(".material")[i].setAttribute('style','color:red');
|
|
|
|
|
+ error++;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ if(error===0){
|
|
|
|
|
+ Layer.confirm("此物料不在配方中,请确认!");
|
|
|
|
|
+ //语音播报
|
|
|
|
|
+ var msg = new SpeechSynthesisUtterance("此物料不在配方中,请确认!");
|
|
|
|
|
+ window.speechSynthesis.speak(msg);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
|
|
+ });
|
|
|
|
|
+ }else{//批次号不重复直接赋值
|
|
|
|
|
+ $("#bach").css('cssText','display:none! important');
|
|
|
|
|
+ $("#btn").css('display','none');
|
|
|
|
|
+ $("#c-name").val(res[0].name);
|
|
|
|
|
+ $("#c-specifications").val(res[0].drawer_name);
|
|
|
|
|
+ $("#c-unit").val(res[0].examine_name);
|
|
|
|
|
+ $("#c-operator").val(res.operator);
|
|
|
|
|
+ $("#c-inspector").val(res.inspector);
|
|
|
|
|
+ $.ajax({
|
|
|
|
|
+ method: "POST",
|
|
|
|
|
+ url: "feeding/get_formula",
|
|
|
|
|
+ data: {
|
|
|
|
|
+ bach: $("#c-bach").val(),
|
|
|
|
|
+ num:''
|
|
|
|
|
+ },
|
|
|
|
|
+ success(res) {
|
|
|
|
|
+ var str = '';
|
|
|
|
|
+ for(var i=0;i<res.data.length;i++){
|
|
|
|
|
+ str += "<tr class='tablestr"+i+" tablestr'><td><input class='form-control material' type='text' name='row[material][]' readonly value='"+res.data[i].material+"'></td>";
|
|
|
|
|
+ str += "<td><input class='form-control' type='text' name='row[nweight][]' readonly value='"+res.data[i].nweight+"'></td>";
|
|
|
|
|
+ str += "<input class='form-control' type='hidden' name='row[gy_num][]' value='"+res.data[i].gy_num+"'>";
|
|
|
|
|
+ str += "<td><input class='form-control' type='number' name='row[weight][]' value='";
|
|
|
|
|
+ if (res.data[i].weight) {
|
|
|
|
|
+ str += parseFloat(res.data[i].weight) + "' readonly ";
|
|
|
|
|
+ }
|
|
|
|
|
+ str += "'></td>";
|
|
|
|
|
+ str += "<td><input class='form-control' type='text' name='row[gy_name][]' readonly value='"+res.data[i].gy_name+"'></td>";
|
|
|
|
|
+ str += "</tr>";
|
|
|
|
|
+ }
|
|
|
|
|
+ $("#table").append(str);
|
|
|
|
|
+ $("#c-bach").attr('readonly','readonly');
|
|
|
|
|
+ $("#wuliao").keydown((e)=>{
|
|
|
|
|
+ let key = e.which;
|
|
|
|
|
+ var error = 0;
|
|
|
|
|
+ if(key === 13){
|
|
|
|
|
+ var wuliao = $("#wuliao").val();
|
|
|
|
|
+ for(var i=0;i<res.data.length;i++) {
|
|
|
|
|
+ if(res.data[i].material===wuliao){
|
|
|
|
|
+ $(".material")[i].setAttribute('style','color:red');
|
|
|
|
|
+ error++;
|
|
|
|
|
+ }
|
|
|
|
|
+ if(res.data[i].material.indexOf('/')!==-1){
|
|
|
|
|
+ var arr = res.data[i].material.split('/');
|
|
|
|
|
+ if(arr.indexOf($("#wuliao").val()) !== -1){
|
|
|
|
|
+ $(".material")[i].value = wuliao;
|
|
|
|
|
+ $(".material")[i].setAttribute('style','color:red');
|
|
|
|
|
+ error++;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ if(error===0){
|
|
|
|
|
+ Layer.confirm("此物料不在配方中,且没有替代料,请确认!");
|
|
|
|
|
+ //语音播报
|
|
|
|
|
+ var msg = new SpeechSynthesisUtterance("此物料不在配方中,且没有替代料,请确认!");
|
|
|
|
|
+ window.speechSynthesis.speak(msg);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
|
|
+ num++;
|
|
|
|
|
+ }else{
|
|
|
|
|
+ // return false;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
|
|
+ $('input').keydown( function (e) {
|
|
|
|
|
+ let key = e.which;
|
|
|
|
|
+ if (key == 13) {
|
|
|
|
|
+ return false;
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
|
|
+ $(document).ready(function($) { 'use strict';
|
|
|
|
|
+ $(".print-link").on('click', function() {
|
|
|
|
|
+ var status = 1;
|
|
|
|
|
+ var total = 0;
|
|
|
|
|
+ //开票人
|
|
|
|
|
+ $("#specifications").val($('#c-specifications').val());
|
|
|
|
|
+ //审核
|
|
|
|
|
+ $("#unit").val($('#c-unit').val());
|
|
|
|
|
+ //批次号
|
|
|
|
|
+ var bach = $('#c-bach').val();
|
|
|
|
|
+ //写入到add页面
|
|
|
|
|
+ $("#formula").html(bach);
|
|
|
|
|
+ //添加重量,包装规格,机组到表格内
|
|
|
|
|
+ for(var i=0;i<$(".tablestr").length;i++){
|
|
|
|
|
+ var weight = parseFloat($(".tablestr:eq("+i+")").children("tr td:eq(2)").children().val());
|
|
|
|
|
+ $(".print:eq("+i+")").children("tr td:eq(2)").html(weight);
|
|
|
|
|
+ if(weight){
|
|
|
|
|
+ total += weight;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ $("#total").html(total.toFixed(2));
|
|
|
|
|
+ // console.log(total);
|
|
|
|
|
+ if(!$("#c-pickor").val()){
|
|
|
|
|
+ status = 2;
|
|
|
|
|
+ }
|
|
|
|
|
+ if(!$("#c-warehouseor").val()){
|
|
|
|
|
+ status = 2;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ /*if (status == 2){
|
|
|
|
|
+ layer.confirm('领料人或仓管人为空,请检查!');return false;
|
|
|
|
|
+ }*/
|
|
|
|
|
+
|
|
|
|
|
+ // createQrcode(bach,80,80);
|
|
|
|
|
+ var img = document.getElementById("myImage"); /// get image element
|
|
|
|
|
+ var canvas = document.getElementsByTagName('canvas')[0];
|
|
|
|
|
+ // img.src = canvas.toDataURL(); /// update image
|
|
|
|
|
+ $.print('#print_area');
|
|
|
|
|
+ return false;
|
|
|
|
|
+ });
|
|
|
|
|
+ function createQrcode(txt,width,height) {
|
|
|
|
|
+ $("#qrcode").qrcode({
|
|
|
|
|
+ render: "canvas",//canvas和table两种渲染方式
|
|
|
|
|
+ width: width,
|
|
|
|
|
+ height: height,
|
|
|
|
|
+ correctLevel:2,//二维码纠错级别
|
|
|
|
|
+ background:"#ffffff",//背景颜色
|
|
|
|
|
+ foreground:"#000000", //二维码颜色
|
|
|
|
|
+ text:txt
|
|
|
|
|
+ });
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
|
|
+ Controller.api.bindevent();
|
|
|
|
|
+ },
|
|
|
|
|
+ edit: function () {
|
|
|
|
|
+ Controller.api.bindevent();
|
|
|
|
|
+ },
|
|
|
|
|
+ api: {
|
|
|
|
|
+ bindevent: function () {
|
|
|
|
|
+ Form.api.bindevent($("form[role=form]"));
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ };
|
|
|
|
|
+ return Controller;
|
|
|
|
|
+});
|