| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358 |
- /**
- * 客户增加或编辑
- * */
- //var EnclosureList = []; //保存附件的数组
- //var uploader; //上传实例
- //var limitNum = 6; //限制数量
- $(function() {
- var pro_Id = helper.request.queryString("edit_id");
- autosize($('textarea'));
-
- if(pro_Id) { //修改
- helper.getDropList.getProLocation($('#customer_province'), $('#customer_city'))
- .then(function() {
- getProject(pro_Id);
- });
- } else {
- // uploaderImages(); //附件上传
- //省市二级联动
- helper.getDropList.getProLocation($('#customer_province'), $('#customer_city'));
- }
- //添加编辑保存按钮点击
- $('#pro_save').on('click', saveProject);
- });
- //获取详情
- function getProject(ids) {
- $.getJSON(huayi.config.callcenter_url + "callcenterapi/api/CusUser/getsingle", {
- id: ids,// 是 string 客户id
- }, function(data) {
- if(data.state == "success") {
- var res = data.data;
- $('#customer_name').val(res.name); //姓名
- $('#customer_tel').val(res.mobilephone); //手机号码
- $('#customer_telphone').val(res.telephone);// 是 string 固话号码
- $('#customer_sex').find('input[type="radio"][value="'+ res.sex +'"]').prop('checked', true); //性别
- $('#customer_province').selectpicker('val', res.province).trigger('change'); //所在省
- $('#customer_city').selectpicker('val', res.city).trigger('change'); //所在市
- $('#customer_address').val(res.address); //具体地址
- $('#customer_qq').val(res.qq);// 否 string qq
- $('#customer_email').val(res.email);// 否 string 邮箱
- $('#customer_companyname').val(res.companyname);// 是 string 公司名称
- $('#customer_companyphone').val(res.companyphone);// 是 string 公司号码
- $('#customer_companyposition').val(res.companyposition);// 否 string 公司职位
-
-
- /*EnclosureList = res.files;
- EnclosureList = EnclosureList == null ? [] : EnclosureList;
- limitNum -= EnclosureList.length;
-
- uploaderImages(); //附件上传
- if(EnclosureList.length > 0) {
- $('#fileNum').text(EnclosureList.length);
- var $list = $("#fileList");
- $.each(EnclosureList, 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(EnclosureList, function(i, v) {
- if(v && v.filename == itemFileName) {
- EnclosureList.splice(i, 1);
- }
- });
- $('#fileNum').text(EnclosureList.length);
- limitNum = 6 - EnclosureList.length;
- uploaderImages();
- });
- }*/
- }
- });
- }
- //保存
- function saveProject() {
- var pro_Id = helper.request.queryString("edit_id");
- var wUrl, loadIndex;
- if(!regexs.userNameReg.test($.trim($('#customer_name').val()))) {
- layer.confirm('请输入有效的客户姓名(2-20位汉字可以包含·•)!', {
- icon: 2,
- btn: ['确定']
- });
- return;
- }
- if(!regexs.phone.test($.trim($('#customer_tel').val()))) {
- layer.confirm('请输入正确的手机号码!', {
- icon: 2,
- btn: ['确定']
- });
- return;
- }
-
- if($.trim($('#customer_telphone').val())){
- if(!regexs.fax.test($.trim($('#customer_telphone').val()))) {
- layer.confirm('请输入正确的固话号码!', {
- icon: 2,
- btn: ['确定']
- });
- return;
- }
- }
-
- if($.trim($('#customer_qq').val())){
- if(!regexs.QQreg.test($.trim($('#customer_qq').val()))) {
- layer.confirm('请输入正确的QQ号!', {
- icon: 2,
- btn: ['确定']
- });
- return;
- }
- }
-
- if($.trim($('#customer_email').val())){
- if(!regexs.email.test($.trim($('#customer_email').val()))) {
- layer.confirm('请输入正确的邮箱!', {
- icon: 2,
- btn: ['确定']
- });
- return;
- }
- }
- if(pro_Id) {
- wURL = "callcenterapi/api/CusUser/update";
- } else {
- wURL = "callcenterapi/api/CusUser/add";
- }
- $.ajax({
- type: 'post',
- url: huayi.config.callcenter_url + wURL,
- dataType: 'json',
- async: true,
- beforeSend: function() { //触发ajax请求开始时执行
- $('#pro_save').attr("disabled", true);
- $('#pro_save').text('保存中...');
- loadIndex = layer.load();
- },
- data: {
- id: pro_Id,// 是 string 客户id
- // typeid: ,// 否 string 类型id
- name: $('#customer_name').val(),// 否 string 姓名
- mobilephone: $('#customer_tel').val(),// 是 string 手机号码
- telephone: $('#customer_telphone').val(),// 是 string 固话号码
- sex: $('#customer_sex').find('input[type="radio"]:checked').val(), // 否 string 性别
- province: $('#customer_province').val(), // 否 string 省code
- city: $('#customer_city').val(), // 否 string 市code
- address: $('#customer_address').val(), // 否 string 地址
- qq: $('#customer_qq').val(),// 否 string qq
- email: $('#customer_email').val(),// 否 string 邮箱
- companyname: $('#customer_companyname').val(),// 是 string 公司名称
- companyphone: $('#customer_companyphone').val(),// 是 string 公司号码
- companyposition: $('#customer_companyposition').val(),// 否 string 公司职位
- },
- 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("保存成功");
- } else {
- $('#pro_save').attr("disabled", false);
- $('#pro_save').text('保存');
- }
- },
- error: function(textStatus) {
- layer.close(loadIndex);
- layer.confirm('网络繁忙,请稍后再试...', {
- icon: 7,
- closeBtn: 0,
- btn: ['确定'] //按钮
- });
- $('#pro_save').attr("disabled", false);
- $('#pro_save').text('保存');
- },
- 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('网络超时,请稍后再试...', {
- icon: 7,
- closeBtn: 0,
- btn: ['确定'] //按钮
- });
- }
- $('#pro_save').attr("disabled", false);
- $('#pro_save').text('保存');
- },
- });
- }
- //上传图片
- 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", // 文件接收服务端
- //server: "http://192.168.1.21:28270/api/upload", // 本地测试
- pick: '#imgPicker', // 选择文件的按钮。可选
- formData: {
- uploadtype: 'equipRunPlan'
- },
- // 只允许选择图片文件。
- 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(EnclosureList, function(i, v) {
- if(v && v.filename == itemFileName) {
- EnclosureList.splice(i, 1);
- helper.methods.delImgs(v.filesmallurl, v.fileurl);
- }
- });
- // var indexDel = $.inArray(itemFileName, EnclosureList);
- // if(indexDel > -1) {
- // EnclosureList.splice(indexDel, 1);
- // }
- $('#fileNum').text(EnclosureList.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) {
- EnclosureList.push(res.data[0]);
- $('#fileNum').text(EnclosureList.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('单文件大小不能超过5M。');
- break;
- case "Q_EXCEED_SIZE_LIMIT":
- layer.msg('总文件大小不能超过30M。');
- break;
- default:
- break;
- }
- };
- }
|