| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619 |
- /**
- * 重要事项增加或编辑(正式)
- * */
- var bigLogoImg; //保存重要事项logo大图
- var smallLogoImg; //保存重要事项logo小图
- var proimglist = []; //保存附件的数组
- var uploader; //上传实例
- //var limitNum = 6; //限制数量
- $(function() {
- autosize($('textarea'));
- var n_id = helper.request.queryString("edit_id");
- if(n_id) { //修改
- //项目所在地 重要事项类型下拉
-
- getProLocations($('#pro_province'), $('#pro_city'), $('#pro_title'))
- .then(function() {
- getNews(n_id);
- });
- /* $.when(helper.getDropList.getlistDropByDic($('#news_property'), 'XWLX'),
- getProLocations($('#pro_province'), $('#pro_city'), $('#pro_title')))
- .done(function() {
- getNews(n_id);
- });*/
- } else {
- // helper.getDropList.getlistDropByDic($('#news_property'), 'XWLX'); //重要事项类型下拉
- getProLocations($('#pro_province'), $('#pro_city'), $('#pro_title')); //项目所在地
- $(".image-crop > img").attr('src', '');
- // imgEditor(); //重要事项logo裁剪
- // uploaderImages(); //初始化附件上传
- }
- //添加编辑保存按钮点击
- $('#news_save').on('click', saveNews);
- });
- //获取详情
- function getNews(ids) {
- $.getJSON(huayi.config.callcenter_url + "messageapi/api/News/getdetails", {
- id: ids,
- }, function(data) {
- if(data.state == "success") {
- var res = data.data;
- $('#news_title').val(res.title); //重要事项标题
- // if(decodeURIComponent(res.content) != "null") {
- // $('#news_content').val(decodeURIComponent(res.content)); //重要事项内容
- // }
- $('#news_sort').val(res.sort); //排序
- // $('#news_property').selectpicker('val', res.typeid).trigger('change'); //重要事项类型
- // $('#news_level').selectpicker('val', res.level).trigger('change'); //重要事项紧急程度
- $('#pro_province').selectpicker('val', res.province).trigger('change'); //省
- $('#pro_city').selectpicker('val', res.city).trigger('change'); //市
- $('#pro_title').selectpicker('val', res.projectid).trigger('change'); //项目
- // //重要事项logo
- // if(res.headimg) {
- // $('.crop_left img').attr('src', res.headimg);
- // } else {
- // $('.crop_left img').attr('src', '../../img/pro_default.png');
- // }
- // imgEditor();
- //附件
- // proimglist = res.files;
- // proimglist = proimglist == null ? [] : proimglist;
- // // limitNum -= proimglist.length;
- // uploaderImages(); //附件上传
- // if(proimglist.length > 0) {
- // $('#fileNum').text(proimglist.length);
- // var $list = $("#fileList");
- // $.each(proimglist, 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(proimglist, function(i, v) {
- // if(v && v.filename == itemFileName) {
- // proimglist.splice(i, 1);
- // //helper.methods.delImgs(v.filesmallurl, v.fileurl);
- // }
- // });
- // $('#fileNum').text(proimglist.length);
- // // limitNum = 6 - proimglist.length;
- // uploaderImages();
- // });
- // }
- //
- }
- });
- }
- //保存重要事项
- function saveNews() {
- var n_id = helper.request.queryString("edit_id");
- var wUrl, loadIndex;
- if(!$.trim($('#news_title').val())) {
- layer.confirm('重要事项标题不能为空', {
- icon: 2,
- btn: ['确定'] //按钮
- });
- return;
- }
- // if(!$('#news_property').val()) {
- // layer.confirm('请选择重要事项类型', {
- // icon: 2,
- // btn: ['确定'] //按钮
- // });
- // return;
- // }
- //
- // if(!Number($('#news_level').val())) {
- // layer.confirm('请选择重要事项紧急程度', {
- // icon: 2,
- // btn: ['确定'] //按钮
- // });
- // return;
- // }
- if(!$('#pro_province').val()) {
- layer.confirm('请选择所属项目所在地省份!', {
- icon: 2,
- btn: ['确定'] //按钮
- });
- return;
- }
- if(!$('#pro_city').val()) {
- layer.confirm('请选择所属项目所在地市!', {
- icon: 2,
- btn: ['确定'] //按钮
- });
- return;
- }
- if(!$('#pro_title').val()) {
- layer.confirm('请选择所属项目!', {
- icon: 2,
- btn: ['确定'] //按钮
- });
- return;
- }
- // if(!$.trim($('#news_content').val())) {
- // layer.confirm('重要事项内容不能为空', {
- // icon: 2,
- // btn: ['确定'] //按钮
- // });
- // return;
- // }
- if(!regexs.integerReg.test($.trim($('#news_sort').val()))) {
- layer.confirm('请输入有效的排序编号(正整数、负整数、0)', {
- icon: 2,
- btn: ['确定'] //按钮
- });
- return;
- }
- if(n_id) {
- wURL = "messageapi/api/News/update";
- } else {
- wURL = "messageapi/api/News/add";
- }
- $.ajax({
- type: "post",
- url: huayi.config.callcenter_url + wURL,
- dataType: 'json',
- async: true,
- beforeSend: function() { //触发ajax请求开始时执行
- $('#news_save').attr("disabled", true);
- $('#news_save').text('保存中...');
- loadIndex = layer.load();
- },
- data: {
- id: n_id, // 是 string 重要事项id
- title: $('#news_title').val(), // 是 string 标题
- // typeid: $('#news_property').val(), // 是 string 类型id
- // level: $('#news_level').val(), // 是 int 级别:1最大
- province: $('#pro_province').val(), //是 string 省code
- city: $('#pro_city').val(), // 是 string 市code
- projectid: $('#pro_title').val(), //是 string 项目id
- // content: $('#news_content').val(), // 是 string 类型
- sort: $('#news_sort').val(), // 是 int 排序字段
- // headimg: bigLogoImg, // 否 string 图片
- // headsmallimg: smallLogoImg, //否 string 缩略图
- // files: proimglist, // 否 list 附件json
- },
- success: function(data) {
- layer.close(loadIndex);
- if(data.state == "success") {
- var index = parent.layer.getFrameIndex(window.name);
- parent.layer.close(index);
- parent.$('#table_all').bootstrapTable('refresh');
- parent.layer.msg("保存成功");
- }
- },
- error: function(textStatus) {
- layer.close(loadIndex);
- layer.confirm('网络繁忙,请稍后再试...', {
- closeBtn: 0,
- btn: ['确定'] //按钮
- });
- $('#news_save').text('保存');
- $('#news_save').attr("disabled", false);
- },
- complete: function(XMLHttpRequest, textStatus) {
- layer.close(loadIndex);
- if(textStatus == 'timeout') {
- var xmlhttp = window.XMLHttpRequest ? new window.XMLHttpRequest() : new ActiveXObject("Microsoft.XMLHttp");
- xmlhttp.abort();
- layer.confirm('网络超时,请稍后再试...', {
- closeBtn: 0,
- btn: ['确定'] //按钮
- });
- }
- $('#news_save').text('保存');
- $('#news_save').attr("disabled", false);
- },
- });
- }
- //重要事项logo剪切
- function imgEditor() {
- var o = $(".image-crop > img");
- o.cropper("destroy");
- o.cropper({
- aspectRatio: 1 / 1,
- resizable: true,
- dragCrop: true,
- preview: ".img-preview",
- done: function() {
- }
- });
- var r = $("#inputImage");
- var fileName = $("#file_name").val();
- if(window.FileReader) {
- r.change(function() {
- $('.progress-bar').css('width', '0%');
- $('.progress-bar').text('0%');
- var e, i = new FileReader,
- t = this.files;
- if(t.length && (e = t[0], /^image\/\w+$/.test(e.type))) {
- i.readAsDataURL(e);
- fileName = e.name;
- i.onload = function() {
- r.val("");
- o.cropper("reset", !0).cropper("replace", this.result);
- }
- } else {
- layer.msg("请选择本地图片文件");
- }
- });
- $("#setDrag").click(function() {
- var self = $(this);
- o.cropper("setDragMode", "crop");
- var imgUrl = o.cropper("getCroppedCanvas").toDataURL('image/png');
- var filesjson;
- var list = [],
- listItem = {};
- listItem.filename = fileName;
- listItem.fileurl = imgUrl;
- list.push(listItem);
- filesjson = JSON.stringify(list);
- upLoadFile(filesjson, self);
- });
- $("#zoomIn").click(function() {
- $('.progress-bar').css('width', '0%');
- $('.progress-bar').text('0%');
- o.cropper("zoom", .1)
- });
- $("#zoomOut").click(function() {
- $('.progress-bar').css('width', '0%');
- $('.progress-bar').text('0%');
- o.cropper("zoom", -.1)
- });
- $("#rotateLeft").click(function() {
- $('.progress-bar').css('width', '0%');
- $('.progress-bar').text('0%');
- o.cropper("rotate", 45)
- });
- $("#rotateRight").click(function() {
- $('.progress-bar').css('width', '0%');
- $('.progress-bar').text('0%');
- o.cropper("rotate", -45)
- });
- } else {
- r.addClass("hide");
- }
- }
- /**
- * 图片的上传
- * fjson 上传图片 的数据
- * self 调用者的this
- */
- function upLoadFile(fjson, self) {
- var formData = new FormData();
- formData.append("uploadtype", 'proManagement');
- formData.append("filesjson", fjson);
- $.ajax({
- type: "post",
- url: huayi.config.callcenter_url + "fileserverapi/Api/Upload",
- data: formData, //这里上传的数据使用了formData 对象
- processData: false,
- contentType: false, //必须false才会自动加上正确的Content-Type
- xhr: function() { //这是关键 获取原生的xhr对象 做以前做的所有事情
- var xhr = jQuery.ajaxSettings.xhr();
- xhr.upload.onload = function() {
- //alert('finish downloading')
- }
- xhr.upload.onprogress = function(ev) {
- //console.log(ev);
- //if(ev.lengthComputable) {
- var percent = 100 * ev.loaded / ev.total;
- //console.log(percent, ev);
- $('.progress-bar').css('width', percent + '%');
- $('.progress-bar').text(percent + '%');
- //}
- }
- return xhr;
- },
- async: true,
- beforeSend: function() { //触发ajax请求开始时执行
- self.attr("disabled", true);
- self.text('图片上传中...');
- $('.anniu').find('.btnn').css('backgroundColor', '#778592');
- },
- // data: {
- // uploadtype: 'proManagement',
- // filesjson: fjson,
- // },
- success: function(result) {
- result = $.parseJSON(result);
- self.attr("disabled", false);
- self.text('上传图片');
- $('.anniu').find('.btnn').css('backgroundColor', '#2f4050');
- /*验证请求*/
- if(result.state.toLowerCase() == "success") {
- bigLogoImg = result.data[0].fileurl;
- smallLogoImg = result.data[0].filesmallurl;
- layer.msg("图片上传成功");
- } else {
- layer.msg(result.message);
- }
- },
- error: function(textStatus) {
- $('.progress-bar').css('width', '0%');
- $('.progress-bar').text('0%');
- layer.confirm('网络繁忙,请稍后再试...', {
- btn: ['确定'] //按钮
- });
- self.text('上传图片');
- self.attr("disabled", false);
- $('.anniu').find('.btnn').css('backgroundColor', '#2f4050');
- },
- complete: function(XMLHttpRequest, textStatus) {
- //$('.progress-bar').css('width', '0%');
- //$('.progress-bar').text('0%');
- if(textStatus == 'timeout') {
- var xmlhttp = window.XMLHttpRequest ? new window.XMLHttpRequest() : new ActiveXObject("Microsoft.XMLHttp");
- xmlhttp.abort();
- layer.confirm('网络超时,请稍后再试...', {
- btn: ['确定'] //按钮
- });
- }
- self.text('上传图片');
- self.attr("disabled", false);
- $('.anniu').find('.btnn').css('backgroundColor', '#2f4050');
- },
- });
- }
- //上传附件
- 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: 'proDrawings'
- },
- // 只允许选择图片文件。
- accept: {
- // title: 'Images',
- // extensions: 'gif,jpg,jpeg,bmp,png',
- // mimeTypes: 'image/*'
- },
- compress: false, //webuploader默认压缩图片,设置compress:false,可以按照原始比例上传图片
- //fileVal: "upFile",//设置文件上传域的name。
- // threads: limitNum, //上传并发数。允许同时最大上传进程数,为了保证文件上传顺序
- // fileNumLimit: limitNum,
- fileSizeLimit: 50 * 1024 * 1024, // 50 M
- fileSingleSizeLimit: 20 * 1024 * 1024 // 20 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(proimglist, function(i, v) {
- if(v && v.filename == itemFileName) {
- proimglist.splice(i, 1);
- helper.methods.delImgs(v.filesmallurl, v.fileurl);
- }
- });
- $('#fileNum').text(proimglist.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) {
- proimglist.push(res.data[0]);
- $('#fileNum').text(proimglist.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;
- case "F_EXCEED_SIZE":
- layer.msg('单文件大小不能超过20M。');
- break;
- case "Q_EXCEED_SIZE_LIMIT":
- layer.msg('总文件大小不能超过50M。');
- break;
- default:
- break;
- }
- };
- }
- ////项目所在地 省/市/项目 联动
- function getProLocations(obj, obj1, obj2) {
- var dtd = $.Deferred(); //在函数内部,新建一个Deferred对象
- obj.empty();
- obj1.empty();
- obj2.empty();
- obj.append('<option selected="selected" value="">请选择所在省</option>');
- obj1.append('<option selected="selected" value="">请选择所在市</option>');
- obj2.append('<option selected="selected" value="">请选择项目</option>');
- $.ajax({
- type: "get",
- url: huayi.config.callcenter_url + "equipmentapi/api/equipment/getprojecttree",
- dataType: 'json',
- async: true,
- success: function(data) {
- var content = data.data; //省信息
- var cityInfos = []; //市信息
- var proInfos = []; //项目信息
- //初始化省
- $(content).each(function(i, n) {
- if(n.parentcode === -1) {
- $("<option value='" + n.code + "'>" + n.name + "</option>").appendTo(obj);
- if(n.entityJson != -1 && n.entityJson.length > 0) {
- cityInfos.push(n.entityJson);
- }
- }
- });
- obj.selectpicker('refresh');
- //市
- obj.change(function() {
- obj1.empty();
- for(var i = 0; i < cityInfos.length; i++) {
- $(cityInfos[i]).each(function(j, v) {
- if(v.parentcode > 0) {
- if(obj.find("option:selected").val() == v.parentcode) {
- $("<option value='" + v.code + "'>" + v.name + "</option>").appendTo(obj1);
- if(v.entityJson != -1 && v.entityJson.length > 0) {
- proInfos.push(v.entityJson);
- }
- }
- }
- });
- }
- obj1.selectpicker('refresh');
- if(obj.find("option:selected").val() == '') {
- obj1.append('<option selected="selected" value="">请选择所在市</option>');
- }
- if(obj1.val() == -1) {
- obj1.append('<option selected="selected" value="">没有数据</option>');
- }
- obj1.trigger('change');
- });
- //项目
- obj1.change(function() {
- obj2.empty();
- for(var j = 0; j < proInfos.length; j++) {
- $(proInfos[j]).each(function(i, n) {
- if(n.parentcode > 0) {
- if(obj1.find("option:selected").val() == n.parentcode) {
- $("<option value='" + n.code + "'>" + n.name + "</option>").appendTo(obj2);
- }
- }
- });
- }
- obj2.selectpicker('refresh');
- if(obj1.find("option:selected").val() == '') {
- obj2.append('<option selected="selected" value="">请选择项目</option>');
- }
- if(obj2.val() == -1 || obj1.val() == '') {
- obj2.append('<option selected="selected" value="">没有项目</option>');
- }
- });
- dtd.resolve(); // 改变Deferred对象的执行状态
- },
- });
- return dtd.promise(); // 返回promise对象
- }
|