123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440 |
- * Created by TT on 2017/10/23.
- */
- ;
- spa_define(function () {
- return $.use(["spa", "util", "form", "upload"], function (spa, util, fb, upload) {
- return {
- modal: function (data) {
- var root = spa.findInModal(".sys_result_new");
- var ca = {ready: true, items: []},
- ba = {ready: true, items: []};
- var form = fb.build(root.find(".newForm"), {
- industryList: ca,
- subjectList: ca,
- researcherList: ba,
- researcher: {
- keyPressInterval: 1,
- hide: function () {
- this.shown = false;
- this.ctn.removeClass("open");
- this.lastQuerying = null;
- this.lastQueryed = null;
- },
- select: function () {
- if (this.shown) {
- var item = this.menu.find(".active");
- this.rv = item.attr('code');
- this.caption = item.attr("caption");
- var caption = this.caption.toString();
- var name = caption.substr(0, caption.indexOf(","));
- this.ve.val("");
- var res = this.rv + "," + name;
- part2(name, form.val().researcherList, res, 20);
- form.val({researcherList: oJudge});
- return this.hide();
- }
- }
- },
- orgName: {
- keyPressInterval: 1,
- hide: function () {
- this.shown = false;
- this.ctn.removeClass("open");
- this.lastQuerying = null;
- this.lastQueryed = null;
- }
- },
- newSubject: {
- keyPressInterval: 1,
- hide: function () {
- this.shown = false;
- this.ctn.removeClass("open");
- this.lastQuerying = null;
- this.lastQueryed = null;
- },
- select: function () {
- if (this.shown) {
- var item = this.menu.find(".active");
- this.rv = item.attr('code');
- this.caption = item.attr("caption");
- var caption = this.caption.toString();
- this.ve.val("");
- part(caption, form.val().subjectList, 20);
- form.val({subjectList: oJudge});
- return this.hide();
- }
- }
- },
- newIndustry: {
- keyPressInterval: 1,
- hide: function () {
- this.shown = false;
- this.ctn.removeClass("open");
- this.lastQuerying = null;
- this.lastQueryed = null;
- },
- select: function () {
- if (this.shown) {
- var item = this.menu.find(".active");
- this.rv = item.attr('code');
- this.caption = item.attr("caption");
- var caption = this.caption.toString();
- this.ve.val("");
- part(caption, form.val().industryList, 20);
- form.val({industryList: oJudge});
- return this.hide();
- }
- }
- }
- });
- var oValue;
- var oJudge;
- var trim = function (str) {
- return str.replace(/(^\s*)|(\s*$)/g, "");
- };
- var saveBtn = root.find(".opt-save"),
- headArea = root.find(".head-ctn"),
- save = function () {
-
- var pic = [];
- $('#fileList').find('img').each(function () {
- pic.push($(this).attr("name"));
- });
- form.val({pic: oString(pic), researchers: form.val().researcherList});
- form.val({
- industry: oString(form.val().industryList),
- subject: oString(form.val().subjectList),
- orgName: $(".org").find("input").val()
- });
- if (form.val().name == null) {
- util.alert("请输入成果名称");
- return;
- }
- else form.doPost("../ajax/resResult/update", function () {
- spa.closeModal();
- if (data.hand) {
- data.hand();
- }
-
- }, {});
- };
- util.get("../ajax/resResult/queryResearcher", {id: data.data.id}, function (res) {
- if (res) {
- var arr = [];
- for (var m = 0; m < res.length; m++) {
- var caption = res[m].name;
- var code = res[m].professorId + "," + res[m].name;
- ba.items.push({code: code, caption: caption});
- arr.push(code);
- }
- form.val({researcherList: arr});
- }
- });
- form.val(data.data);
- $(".org").find("input").val(data.data.orgName);
- if (data.data.industry) {
- form.val({industryList: split1(data.data.industry)});
- }
- if (data.data.subject) {
- form.val({subjectList: split1(data.data.subject)});
- }
- var part = function (one, list, num) {
- oValue = one;
- oJudge = list || [];
- if (oJudge.length >= num) {
- util.alert("最多" + num + "个");
- return;
- }
- var repeat,
- b;
- if (!oValue) {
- util.alert('提示', '请先填写内容');
- return;
- }
- if (oValue.length > 15) {
- util.alert('提示', '添加内容不能超过15个字');
- return;
- } else {
- var oValueList = oValue.split(","),
- length = oValueList.length;
- for (var j = 0; j < length; j++) {
- for (var n = j + 1; n < oValueList.length + 1;) {
- if (oValueList[j] == oValueList[n]) {
- oValueList.remove(n);
- repeat = false;
- } else {
- n++;
- }
- }
- }
- for (var j = 0; j < oValueList.length;) {
- for (var i = 0; i < oJudge.length; i++) {
- if (oValueList[j] == oJudge[i]) {
- oValueList.remove(j);
- repeat = false;
- b = true;
- }
- }
- if (b) {
- b = false
- } else j++;
- }
- if (repeat == false) {
- util.alert('提示', '添加内容不能重复');
- }
- for (var m = 0; m < oValueList.length; m++) {
- ca.items.push({code: oValueList[m], caption: oValueList[m]});
- oJudge.push(oValueList[m]);
- }
- }
- };
- var part2 = function (one, list, value, num) {
- oValue = one;
- oJudge = list || [];
- if (oJudge.length >= num) {
- util.alert("最多" + num + "个");
- return;
- }
-
-
- if (!oValue) {
- util.alert('提示', '请先填写内容');
- return;
- }
- if (oValue.length > 50) {
- util.alert('提示', '添加内容不能超过50个字');
- return;
- } else {
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- ba.items.push({code: value, caption: oValue});
- oJudge.push(value);
-
- }
- };
- Array.prototype.remove = function (obj) {
- for (var i = 0; i < this.length; i++) {
- var temp = this[i];
- if (!isNaN(obj)) {
- temp = i;
- }
- if (temp == obj) {
- for (var j = i; j < this.length; j++) {
- this[j] = this[j + 1];
- }
- this.length = this.length - 1;
- }
- }
- };
- function split1(data) {
- var index = data.split(",");
- var arr = [];
- for (var m = 0; m < index.length; m++) {
- ca.items.push({code: index[m], caption: index[m]});
- arr.push(index[m]);
- }
- return arr;
- }
- function oString(data) {
- var arry = new Array();
- if (data) {
- for (var i = 0; i < data.length; i++) {
- arry.push(data[i]);
- }
- }
- return arry.join(",");
- }
- root.find(".modal-ctrl .icon-times").on("click", function () {
- spa.closeModal();
- });
- root.find(".opt-industry").on("click", function () {
- var ind = $(".ind").find("input");
- part(trim(ind.val()), form.val().industryList, 20);
- ind.val("");
- form.val({newIndustry: "", industryList: oJudge});
- });
- root.find(".opt-subject").on("click", function () {
- var sub = $(".sub").find("input");
- part(trim(sub.val()), form.val().subjectList, 20);
- sub.val("");
- form.val({newSubject: "", subjectList: oJudge});
- });
- root.find(".opt-res").on("click", function () {
- var res = $(".typeahead").find("input");
- var value = "################################," + trim(res.val());
- part2(trim(res.val()), form.val().researcherList, value, 20);
- res.val("");
- form.val({researcherList: oJudge});
- });
- var $list = $('#fileList'),
- ratio = window.devicePixelRatio || 1,
- thumbnailWidth = 100 * ratio,
- thumbnailHeight = 100 * ratio,
- uploader;
- uploader = WebUploader.create({
- auto: true,
- server: '../ajax/cachedFileUpload',
- pick: '#filePicker',
- duplicate: true,
-
-
- accept: {
- title: 'Images',
- extensions: 'gif,jpg,jpeg,bmp,png',
- mimeTypes: 'image/jpg,image/jpeg,image/png'
- }
- });
- uploader.on('fileQueued', function (file) {
- if ($(".file-item").length < 5) {
- var $li = $(
- '<div id="' + file.id + '" class="file-item thumbnail">' +
- '<img>' +
- '</div>'
- ),
- $img = $li.find('img');
- $list.append($li);
- if ($('#fileList').find('img').length > 4) {
- $('#filePicker').hide();
- }
- }
- });
- uploader.on('uploadSuccess', function (file, data) {
- $('#' + file.id).addClass('upload-state-done');
- $.ajax({
- type: "post",
- url: "../ajax/image/researchResult",
- async: false,
- data: {fn: data.data[0].cacheKey},
- contentType: "application/x-www-form-urlencoded"
- }).done(function (rd) {
- if (rd.success) {
- $('#' + file.id).find('img').attr('name', rd.data);
- }
- });
- uploader.makeThumb(file, function (error, src) {
- var $img = $("#" + file.id).find('img');
- if (error) {
- $img.replaceWith('<span>不能预览</span>');
- return;
- }
- $img.attr('src', src);
- }, thumbnailWidth, thumbnailHeight);
- if ($('#fileList').find('img').length < 5) {
- $('#filePicker').show();
- }
- if (uploader.getStats().progressNum == 0 || uploader.getStats().queueNum == 0) {
- saveBtn.on("click", save);
- }
- });
- uploader.on('uploadComplete', function (file) {
- var $li = $('#' + file.id);
- $li.find('.progress').remove();
- $('<div class="file-panel">' +
- '<span class="cancel icon-remove-sign">删除</span>' +
- '</div>').appendTo($li);
- });
- $list.on("click", ".cancel", function () {
- $(this).parent().parent().remove();
- if ($('#fileList').find('img').length < 5) {
- $('#filePicker').show();
- }
- uploader.refresh();
- });
- uploader.on('uploadProgress', function (file, percentage) {
- var $li = $('#' + file.id),
- $percent = $li.find('.progress span');
-
- if (!$percent.length) {
- $percent = $('<p class="progress"><span></span></p>')
- .appendTo($li)
- .find('span');
- }
- $percent.css('width', percentage * 100 + '%');
- $('#filePicker').hide();
- saveBtn.unbind("click");
- });
- uploader.on('error', function (type) {
- switch (type) {
- case 'Q_EXCEED_NUM_LIMIT':
- alert("错误:上传文件数量过多!");
- break;
- case 'Q_EXCEED_SIZE_LIMIT':
- alert("错误:文件总大小超出限制!");
- break;
- case 'F_EXCEED_SIZE':
- alert("错误:文件大小超出限制!");
- break;
- case 'Q_TYPE_DENIED':
- alert("错误:禁止上传该类型文件!");
- break;
- default:
- alert('错误代码:' + type);
- break;
- }
- });
- if (data.data.pic) {
- var image = split1(data.data.pic);
- for (var i = 0; i < image.length; i++) {
- var $li = $(
- '<div class="file-item thumbnail">' +
- '<img src="http://www.ekexiu.com/data/researchResult/" id="oimg" />' +
- '</div>'
- ),
- $btn = $('<div class="file-panel">' +
- '<span class="cancel icon-remove-sign">删除</span>' +
- '</div>').appendTo($li),
- $img = $li.find('img');
- $list.append($li);
- $img.attr('src', "http://www.ekexiu.com/data/researchResult/" + data.data.id + ".jpg");
-
- $img.attr('name', image[i]);
- }
- if ($('#fileList').find('img').length > 4) {
- $('#filePicker').hide();
- }
- }
- saveBtn.on("click", save);
- }
- }
- });
- });
|