define(['jquery', 'bootstrap', 'backend', 'table', 'form','jQuery.print'], function ($, undefined, Backend, Table, Form) {
var Controller = {
index: function () {
$(".btn-add").data("area",["100%","100%"]);
$(".btn-edit").data("area",["100%","100%"]);
// 初始化表格参数配置
Table.api.init({
extend: {
index_url: 'product/index' + location.search,
add_url: 'product/add',
edit_url: 'product/edit',
del_url: 'product/del',
multi_url: 'product/multi',
import_url: 'product/import',
table: 'product',
}
});
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: 'batch', title: __('Batch'), operate: 'LIKE'},
{field: 'pname', title: __('Pname'),operate: 'LIKE'},
{field: 'specifications', title: __('Specifications'),operate: 'LIKE'},
{field: 'audit', title: __('Audit'),operate: 'LIKE'},
{field: 'unit', title: __('Unit'),operate: 'LIKE'},
{field: 'status', title: __('Status'), searchList: {"1":__('Status 1'),"2":__('Status 2')}, formatter: Table.api.formatter.normal},
// {field: 'time', title: __('Time'), formatter: Table.api.formatter.datetime, operate: 'RANGE', addclass: 'datetimerange', sortable: true},
// {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate},
{field: 'operate', title: '操作', buttons:[{
name:'task',
text:'查看',
title:'查看',
icon:'fa fa-add',
extend: 'data-area=["100%","100%"]',
classname:'btn btn-xs btn-info btn-fields btn-dialog ',
url:'product/show',
}],
table: table,
events: Table.api.events.operate, formatter: Table.api.formatter.operate
},
]
]
});
table.on('post-body.bs.table',function(){
$(".btn-editone").data("area",["100%","100%"]);
});
// 为表格绑定事件
Table.api.bindevent(table);
},
add: function () {
//扫描批次号
$("#c-batch").keydown(function(e){
var key = e.which;
if (key == 13) {
$.ajax({
type:"POST",
url:"product/ajax",
data:{
bach:$("#c-batch").val()
},
//获取头部信息
success(res){
$("#c-batch").val($("#c-batch").val()+';');
$("#c-time").val(res.create);
$("#c-audit").val(res.examine_name);
$("#c-pname").val(res.name);
var str = '';
str += "";
str += "";
str += "";
$("#table").append(str);
}
});
return false;
}
});
window.i=0;
var i=0;
//扫描物料
$("#wuliao").keydown( function (e) {
var key = e.which;
if (key == 13) {
var str = '';
var html = '';
$.ajax({
type: "POST",
url: "product/get_formula",
data: {
formula: $("#wuliao").val(),
bach:$("#c-batch").val()
},
//扫描一个物料添加一行表格
success(res) {
str += "
| ";
str += " | ";
str += " | ";
// str += " | ";
str += " | ";
str += " | ";
str += " | ";
str += "";
str += ' |
';
//添加打印表格
html += `
| ${res.bach} |
${res.pname} |
${res.material} |
|
`;
//写入页面
$("#print_gy").append(html);
$("#table").append(str);
// $("#print_gy").append(html);
//清空物料扫描后的值,下次直接重新扫描即可
$("#wuliao").val('');
if($("#status").val()==1){
if(res.error === 1){
// Layer.confirm("此物料不在配方中,请确认!");
layer.confirm("此物料不在配方中,请确认!", { //物料不存在提示错误信息
title: ['信息'],
btn: ['确认', '取消'],
area: ['60%', '60%'],
},function(index) { //点击确定写入打印页面
layer.close(index);
},function(){ //点击取消删除添加的最后一个元素
$("#table tr:last").remove();
$("#print_gy tr:last").remove();
});
//语音播报
var synth = window.speechSynthesis;
var msg = new window.SpeechSynthesisUtterance('此物料不在配方中,请确认!');
window.speechSynthesis.cancel();
synth.speak(msg);
}
}
i++;
}
});
return false;
}
});
//删除当前行内容及打印表格当前行内容
$(document).on('click','.del',function () {
$(this).parent().parent().remove();
var i = $(this).parent().prev().val();
$(".print"+i).remove();
});
//阻止回车事件
$('input').keydown( function (e) {
let key = e.which;
if (key == 13) {
return false;
}
});
Controller.api.bindevent();
//打印
$(document).ready(function($) { 'use strict';
$(".print-link").on('click', function() {
var status = 1;
//领料人
$("#pickor").html($('#c-pickor').val());
//仓管人
$("#warehouseor").html($('#c-warehouseor').val());
//批次
var bach = $('#c-batch').val();
//写入到add页面
$("#formula").html(bach);
//添加重量,包装规格,机组到表格内
for(var i=0;i<$(".tablestr").length;i++){
var weight = $(".tablestr:eq("+i+")").children("tr td:eq(3)").children().val();
var specifications = $(".tablestr:eq("+i+")").children("tr td:eq(4)").children().val();
var unit = $(".tablestr:eq("+i+")").children("tr td:eq(5)").children().val();
// $(".print:eq("+i+")").children("tr td:eq(3)").html(weight);
// $(".print:eq("+i+")").children("tr td:eq(4)").html(specifications);
$(".print:eq("+i+")").children("tr td:eq(5)").html(unit);
}
if(!$("#c-pickor").val()){
status = 2;
}
if(!$("#c-warehouseor").val()){
status = 2;
}
if (status == 2){
// layer.confirm('领料人或仓管人为空,请检查!');
layer.confirm("领料人或仓管人为空,请检查!",{//物料不存在提示错误信息
title:['信息'],
area:['60%','60%'],
});
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:3,//二维码纠错级别
background:"#ffffff",//背景颜色
foreground:"#000000", //二维码颜色
text:txt
});
}
});
},
edit: function () {
Controller.api.bindevent();
},
api: {
bindevent: function () {
Form.api.bindevent($("form[role=form]"));
}
},
};
return Controller;
});