123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169 |
- var detailtbl, datas;
- layui.use(['form', 'table'], function () {
- var form = layui.form;
- var table = layui.table;
- console.log(window.location.href);
- var id = QueryString('id');
- var exCode = QueryString('exCode');
- if (id == null || id == undefined || id == '') {
- id = '0';
- }
- if (id != '0') {
- $.ajax({
- url: '/mes/api/mesexception/' + id,
- type: 'get',
- dataType: 'json',
- success: function (res) {
- console.log('查看详情');
- console.log(res);
- form.val('addForm', {
- FCode: res.fcode,
- FName: res.fname,
- Remark: res.remark
- });
- }
- });
- }
- loadDetail(id);
- form.on('submit(*)', function (data) {
- var obj = {
- Id: id,
- Fcode: data.field.FCode,
- Fname: data.field.FName,
- Remark: data.field.Remark,
- JsonDetail: JSON.stringify(datas)
- };
- $.ajax({
- url: '/mes/api/mesexception/add',
- contentType: 'application/json',
- type: 'post',
- dataType: 'text',
- data: JSON.stringify(obj),
- success: function (res) {
- var result = res == '0' ? '失败' : '成功';
- var content = id == '0' ? '添加' : '修改';
- var iconId = res == '0' ? 2 : 1;
- var animateId = res == '0' ? 6 : 0;
- id = res;
- if (res != '0') {
- layer.msg(content + result, {
- icon: iconId,
- anim: animateId
- });
- $.ajax({
- url: '/mes/api/mesexception/' + res,
- type: 'get',
- dataType: 'json',
- success: function (res) {
- form.val('addForm', {
- FCode: res.fcode,
- FName: res.fname,
- Remark: res.remark
- });
- loadDetail(res.FCode);
- }
- });
- parent.reloadTable();
- } else {
- layer.msg('网络错误,请联系管理员', {
- icon: 2,
- animateId: 6
- })
- }
- }
- });
- return false;
- });
- function loadDetail(exCode) {
- if (exCode == '0') {
- datas = [
- ];
- loadTable(datas);
- } else {
- $.ajax({
- url: '/mes/api/mesexception/getdetails?exCode=' + exCode,
- dataType: 'json',
- type: 'get',
- success: function (res) {
- console.log('=====================');
- console.log(res);
- datas = res.data;
- if (datas) {
- loadTable(datas);
- }
- }
- });
- }
- }
- function loadTable() {
- detailtbl = table.render({
- elem: '#tbl',
- data: datas, //数据接口
- page: true, //开启分页
- toolbar: '#toolbar',
- cols: [[ //表头
- { checkbox: true },
- { field: 'macCode', title: '机型代码', width: 160, sort: true },
- { field: 'excCode', title: '异常代码', width: 120, sort: true },
- { field: 'reccode', title: '录入人', width: 120, sort: true },
- {
- field: 'rectime', title: '录入日期', width: 240, sort: true, templet: function (d) {
- return (d.rectime == null || d.rectime == undefined) ? '' : timeFormat(d.rectime);
- }
- },
- { field: 'remark', title: '备注', width: 380 }
- ]]
- });
- }
- window.refreshTable = function () {
- loadTable(datas);
- }
- table.on('toolbar(exdetail)', function (obj) {
- if (obj.event == 'add') {
- layer.open({
- type: 2,
- content: 'exceptionDetailAdd.html',
- area: ['600px', '350px']
- });
- } else if (obj.event == 'delete') {
- var checkStatus = table.checkStatus('tbl');
- console.log(checkStatus);
- if (checkStatus.data.length === 0) {
- layer.msg('请先选中需要操作的异常明细!', {
- icon: 2,
- anim: 6
- });
- return;
- }
- for (var i = 0; i < checkStatus.data.length; i++) {
- for (var j = 0; j < datas.length; j++) {
- if (checkStatus.data[i].id == datas[j].id) {
- datas.splice(j, 1);
- }
- }
- }
- //重新加载异常明细
- refreshTable();
- }
- });
- $('#btnAddContinue').click(function () {
- id = '0';
- datas = [];
- refreshTable();
- });
- });
- function reloadTable() {
- detailtbl.reload();
- }
|