| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124 |
- define(['jquery', 'bootstrap', 'backend', 'table', 'form','editable'], 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: 'material', title: __('Material'), operate: 'LIKE'},
- {field: 'weight', title: __('Weight'),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}
- ]
- ]
- });
- 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);
- }
- });
- return false;
- }
- });
- $("#wuliao").keydown( function (e) {
- var key = e.which;
- if (key == 13) {
- var str = '';
- $.ajax({
- type: "POST",
- url: "product/get_formula",
- data: {
- formula: $("#wuliao").val(),
- },
- success(res) {
- str += "<tr><td><input class='form-control' type='text' name='row[batch][]' readonly value='"+res.bach+"'></td>";
- str += "<td><input class='form-control' type='text' name='row[pname][]' readonly value='"+res.pname+"'></td>";
- str += "<td><input class='form-control' type='text' name='row[material][]' readonly value='"+res.material+"'></td>";
- str += "<td><input class='form-control' type='text' name='row[specifications][]' value='"+ (res.specifications?res.specifications:'')+"'></td>";
- str += "<td><input class='form-control' type='number' name='row[weight][]' data-rule='required' value=''></td>";
- str += "<td><input class='form-control' type='text' name='row[unit][]' value=''></td>";
- str += "<td><input class='form-control' type='text' name='row[time][]' readonly value='"+res.time+"'></td>";
- str += '<td><button type="button" class="btn btn-danger del">删除</button></td></tr>';
- $("#table").append(str);
- $("#wuliao").val('');
- if($("#status").val()==1){
- if(res.error === 1){
- Layer.confirm("此物料不在配方中,请确认!");
- //语音播报
- var msg = new SpeechSynthesisUtterance("此物料不在配方中,请确认!");
- window.speechSynthesis.speak(msg);
- }
- }
- }
- });
- return false;
- }
- });
- $(document).on('click','.del',function () {
- $(this).parent().parent().remove();
- });
- $('input').keydown( function (e) {
- let key = e.which;
- if (key == 13) {
- return false;
- }
- });
- Controller.api.bindevent();
- },
- edit: function () {
- Controller.api.bindevent();
- },
- api: {
- bindevent: function () {
- Form.api.bindevent($("form[role=form]"));
- }
- },
- };
- return Controller;
- });
|