| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356 |
- /**
- * 处理设备巡检工单
- * */
- var maintainpiclist = []; //保存附件的数组
- var limitNum = 6; //限制数量
- var uploader; //上传实例
- $(function() {
- autosize($('textarea'));
- var edit_id = helper.request.queryString("edit_id") && helper.request.queryString("edit_id").split(',')[0];
- // var pro_id = helper.request.queryString("edit_id") && helper.request.queryString("edit_id").split(',')[1];
-
- if(edit_id) {
- // if(pro_id) {
- // helper.getDropList.getProUser(pro_id, $('#checkby')); //获取巡检人下拉
- // }
- //获取自定义字段
- getDetail(edit_id);
- uploaderImages(); //附件上传
- //本次设备巡检时间
- // laydate.render({
- // elem: '#inspectionTime',
- // type: 'datetime',
- // value: helper.DateFormat.getNowDateTime(),
- // theme: '#249fea',
- // });
- $('#pro_save').on('click', saveProject);
- }
- $('#quipmenttype').find('input[type="radio"]').on('change', function() {
- if($(this).val() === '0') {
- $('#checkcontents').show();
- } else {
- $('#checkcontents').hide();
- }
- });
- });
- //获取详情
- function getDetail(ids) {
- $.getJSON(huayi.config.callcenter_url + "equipmentapi/api/WoEquipmentRunning/getdetails", {
- id: ids,
- }, function(data) {
- if(data.state.toLowerCase() === 'success') {
- var res = data.data;
- //设备状态
- $('#quipmenttype').find('input[name="inlineRadioOptions"][value="' + res.quipmenttype + '"]').prop('checked', true).trigger('change');
- if(res.quipmenttype === 0) {
- $('#checkcontent').val(helper.filter.content(res.checkcontent));
- }
- //自定义字段
- if(res.extensionlist && res.extensionlist.length > 0) {
- $('#customLists').show();
- var shtml = '';
- for(var i = 0, len = res.extensionlist.length; i < len; i++) {
- if(res.systemid && res.systemid === '5ab3773e157ac914fb139fbb'){//日常类
- shtml = '<li class="form-group custom_item_radio">'+
- '<label for="fieldOptionValue_' + i + '" class="col-md-8 text-left"><b class="text_require">*</b><span id="fieldname_'+ i +'">' + res.extensionlist[i].name + '</span></label>'+
- '<div class="col-md-4" id="fieldOptionValue_' + i + '">'+
- '<label class="radio-inline">'+
- '<input type="radio" name="fieldvalueOptions_'+ i +'" value="正常" checked="checked"> 正常'+
- '</label>'+
- '<label class="radio-inline">'+
- '<input type="radio" name="fieldvalueOptions_'+ i +'" value="异常"> 异常'+
- '</label>'+
- '</div>'+
- '</li>';
- }else{
- // shtml = '<li class="form-group custom_item_input">'+
- // '<label for="fieldvalue_' + i + '" class="col-md-12 deal_label"><span id="fieldname_'+ i +'">' + res.extensionlist[i].name + '</span></label>'+
- // '<div class="col-md-12">'+
- // '<input value="'+ (res.extensionlist[i].value === null ? '' : res.extensionlist[i].value) +'" id="fieldvalue_' + i + '" class="form-control" type="text" placeholder="请输入' + res.extensionlist[i].name + '的值" />'+
- // '</div>'+
- // '</li>';
- shtml = '<li class="form-group custom_item_radio col-md-6">'+
- '<label for="fieldOptionValue_' + i + '" class="col-md-6 text-right deal_label"><span id="fieldname_'+ i +'">' + res.extensionlist[i].name + '</span></label>'+
- '<div class="col-md-6" id="fieldOptionValue_' + i + '">'+
- '<label class="radio-inline">'+
- '<input type="radio" name="fieldvalueOptions_'+ i +'" value="正常" checked="checked"> 正常'+
- '</label>'+
- '<label class="radio-inline">'+
- '<input type="radio" name="fieldvalueOptions_'+ i +'" value="异常"> 异常'+
- '</label>'+
- '</div>'+
- '</li>';
-
-
- }
- $('#customLists').append(shtml);
- }
- }
-
- //工单状态
- // $('#wostate').find('input[name="inlineRadioOptions1"][value="' + res.wostate + '"]').prop('checked', true);
- //附件
- maintainpiclist = res.checkpic;
- maintainpiclist = maintainpiclist == null ? [] : maintainpiclist;
- limitNum -= maintainpiclist.length;
- uploaderImages(); //附件上传
- if(maintainpiclist.length > 0) {
- $('#fileNum').text(maintainpiclist.length);
- var $list = $("#fileList");
- $.each(maintainpiclist, function(i, v) {
- if(v.filesmallurl) {
- //原来的图片
- var $li = $(
- '<li><span class="img_mask"><i class="img_del"></i></span>' +
- '<img src="' + v.filesmallurl + '" title="原来的图片"/>' +
- '<span class="file_name">' + v.filename + '</span>' +
- '</li>'
- );
- $list.append($li);
- } else {
- var $liFile = $(
- '<li><span class="img_mask"><i class="img_del"></i></span>' +
- '<div class="noThumb" title="原来的文件"><i class="glyphicon glyphicon-paperclip"></i><p>无法预览</p></div>' +
- '<span class="file_name">' + v.filename + '</span>' +
- '</li>'
- );
- $list.append($liFile);
- }
- });
- $list.find('li').off('click');
- $list.find('li').on('click', '.img_del', function() {
- $(this).parent().parent().remove();
- var itemFileName = $(this).parent().parent().find('.file_name').text();
- $.each(maintainpiclist, function(i, v) {
- if(v && v.filename == itemFileName) {
- maintainpiclist.splice(i, 1);
- }
- });
- $('#fileNum').text(maintainpiclist.length);
- limitNum = 6 - maintainpiclist.length;
- uploaderImages(); //附件上传
- });
- }
- }
- });
- }
- //保存
- function saveProject() {
- var edit_id = helper.request.queryString("edit_id") && helper.request.queryString("edit_id").split(',')[0];
- // if(!regexs.proTitle.test($.trim($('#maintaintime').val()))) {
- // if(!$.trim($('#inspectionTime').val())) {
- // layer.confirm('本次巡检时间不能为空!', {
- // icon: 2,
- // btn: ['确定'] //按钮
- // });
- // return;
- // }
- //
- // if(!$.trim($('#checkby').val())) {
- // layer.confirm('巡检人不能为空!', {
- // icon: 2,
- // btn: ['确定'] //按钮
- // });
- // return;
- // }
- if($('#quipmenttype').find('input[type="radio"]:checked').val() === '0') {
- if(!$.trim($('#checkcontent').val())) {
- layer.confirm('异常内容不能为空!', {
- icon: 2,
- btn: ['确定'] //按钮
- });
- return;
- }
- } else {
- $('#checkcontent').val('');
- }
- if(maintainpiclist.length <= 0) {
- layer.confirm('巡检图片不能为空!', {
- icon: 2,
- btn: ['确定'] //按钮
- });
- return;
- }
- $.post(huayi.config.callcenter_url + "equipmentapi/api/WoEquipmentRunning/deal", {
- id: edit_id, // 是 string id标识
- // thischeckime: $('#inspectionTime').val(), //是 本次巡检时间
- // checkby: $('#checkby').val(), //是 string 巡检人
- quipmenttype: $('#quipmenttype').find('input[type="radio"]:checked').val(), //是 string 设备状态 1正常,0异常
- checkcontent: $('#checkcontent').val(), //是 string 异常内容
- checkpic: maintainpiclist, //是 List<FileBaseModel> 巡检图片
- // wostate: $('#wostate').find('input[type="radio"]:checked').val(), //是 int 任务状态:3已处理,6挂起
- wostate: 3, //是 int 任务状态:3已处理,6挂起
- extensionlist: getFields(), //自定义字段的数组[{“name”:”字段名”,”value”:”字段值”}]
- }, function(data) {
- data = JSON.parse(data);
- if(data.state == "success") {
- var index = parent.layer.getFrameIndex(window.name);
- parent.layer.close(index);
- parent.$('#table_all').bootstrapTable('refresh');
- parent.layer.msg("保存成功");
- }
- });
- }
- //上传图片
- function uploaderImages() {
- if(uploader) {
- uploader.destroy();
- }
- uploader = WebUploader.create({
- auto: true, // 选完文件后,是否自动上传
- swf: '../plugins/webuploader/Uploader.swf', // swf文件路径
- server: huayi.config.callcenter_url + "fileserverapi/Api/Upload", // 文件接收服务端
- pick: '#imgPicker', // 选择文件的按钮。可选
- formData: {
- uploadtype: 'dealRunOrder'
- },
- // 只允许选择图片文件。
- accept: {
- title: 'Images',
- extensions: 'gif,jpg,jpeg,bmp,png',
- mimeTypes: 'image/*'
- },
- compress: false, //webuploader默认压缩图片,设置compress:false,可以按照原始比例上传图片
- //fileVal: "upFile",//设置文件上传域的name。
- threads: limitNum, //上传并发数。允许同时最大上传进程数,为了保证文件上传顺序
- fileNumLimit: limitNum,
- fileSizeLimit: 30 * 1024 * 1024, // 30 M
- fileSingleSizeLimit: 5 * 1024 * 1024 // 5 M
- });
- uploader.on('fileQueued', function(file) {
- var $list = $("#fileList"),
- $li = $(
- '<li id="' + file.id + '"><span class="img_mask"><i class="img_del"></i></span>' +
- '<img/>' +
- '<span class="img_state"><i></i></span>' +
- '<span class="file_name">' + file.name + '</span>' +
- '</li>'
- ),
- $img = $li.find('img');
- // $list为容器jQuery实例
- $list.append($li);
- // 创建缩略图
- uploader.makeThumb(file, function(error, src) {
- if(error) {
- $img.replaceWith('<div class="noThumb"><i class="glyphicon glyphicon-paperclip"></i><p>无法预览</p></div>');
- return;
- }
- $img.attr('src', src);
- }, 109, 109); //109*109为缩略图尺寸
- //绑定删除
- $('#' + file.id).on('click', '.img_del', function() {
- uploader.removeFile(file);
- var $fileLi = $('#' + file.id);
- $fileLi.off().find('.img_del').off().end().remove();
- var itemFileName = $(this).parent().parent().find('.file_name').text();
- $.each(maintainpiclist, function(i, v) {
- if(v && v.filename == itemFileName) {
- maintainpiclist.splice(i, 1);
- }
- });
- $('#fileNum').text(maintainpiclist.length);
- });
- });
- // 文件上传过程中创建进度条实时显示。
- uploader.on('uploadProgress', function(file, percentage) {
- var $li = $('#' + file.id),
- $percent = $li.find('.progress span');
- // 避免重复创建
- if(!$percent.length) {
- $percent = $('<div class="progress" style="">' +
- '<span class="text">0%</span>' +
- '<span class="percentage"></span>' +
- '</div>')
- .appendTo($li)
- .find('span');
- }
- $percent.eq(0).text(Math.round(percentage * 100) + '%');
- $percent.eq(1).css('width', Math.round(percentage * 100) + '%');
- });
- // 文件上传成功,给item添加成功class, 用样式标记上传成功。
- uploader.on('uploadSuccess', function(file, res) {
- maintainpiclist.push(res.data[0]);
- $('#fileNum').text(maintainpiclist.length);
- $('#' + file.id).addClass('upload-state-done');
- });
- // 文件上传失败,显示上传出错。
- uploader.on('uploadError', function(file) {
- var $li = $('#' + file.id),
- $error = $li.find('div.error');
- // 避免重复创建
- if(!$error.length) {
- $error = $('<div class="error"></div>').appendTo($li);
- }
- $error.text('上传失败');
- });
- // 完成上传完了,成功或者失败,先删除进度条。
- uploader.on('uploadComplete', function(file) {
- $('#' + file.id).find('.progress').remove();
- });
- uploader.onError = function(code) {
- //console.log('Error:' + code);
- switch(code) {
- case "Q_EXCEED_NUM_LIMIT":
- layer.msg('只能上传六张图片。');
- break;
- case "Q_TYPE_DENIED":
- layer.msg('图片类型不正确。');
- break;
- case "F_DUPLICATE":
- layer.msg('该文件已上传,请选择其它文件。');
- break;
- default:
- break;
- }
- };
- }
- //获取自定义字段的值
- function getFields() {
- var extensionlist = []; //自定义字段的数组[{“name”:”字段名”,”value”:”字段值”}]
- var custom_items_input = $('#customLists').find('.custom_item_input');
- var custom_items_radio = $('#customLists').find('.custom_item_radio');
- if(custom_items_input.length > 0){
- $.each(custom_items_input, function(i, v) {
- var inObj = {};
- var fieldname = $(v).find('span[id*="fieldname_"]').text();
- var fieldvalue = $(v).find('input[id*="fieldvalue_"]').val();
- inObj.name = fieldname;
- inObj.value = fieldvalue;
- extensionlist.push(inObj);
- });
- }
- if(custom_items_radio.length > 0){
- $.each(custom_items_radio, function(i, v) {
- extensionlist.push({
- "name": $(v).find('span[id*="fieldname_"]').text(),
- "value": $(v).find('div[id*="fieldOptionValue_"]').find('input[type=radio]:checked').val()
- });
- });
- }
- return extensionlist;
- }
|