product-add.js 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702
  1. BannerJson = {}
  2. ColoeJson = {}
  3. pattr = []
  4. PageType = true;
  5. ProductId = "";
  6. window.onload = function () {
  7. var uploader = new plupload.Uploader({ //创建实例的构造方法
  8. runtimes: 'html5,flash,silverlight,html4', //上传插件初始化选用那种方式的优先级顺序
  9. // browse_button: 'bannerbtn', // 上传按钮
  10. browse_button: $("#bannerbtn")[0], // 上传按钮
  11. url: "upload.php", //远程上传地址
  12. flash_swf_url: 'plupload/Moxie.swf', //flash文件地址
  13. silverlight_xap_url: 'plupload/Moxie.xap', //silverlight文件地址
  14. filters: {
  15. max_file_size: '200mb', //最大上传文件大小(格式100b, 10kb, 10mb, 1gb)
  16. mime_types: [ //允许文件上传类型
  17. {
  18. title: "files",
  19. extensions: "jpg,png,gif,ico"
  20. }
  21. ]
  22. },
  23. multi_selection: true, //true:ctrl多文件上传, false 单文件上传
  24. init: {
  25. FilesAdded: function (up, files) { //文件上传前
  26. if ($("#ul_pics").children("li").length > 30) {
  27. alert("您上传的图片太多了!");
  28. uploader.destroy();
  29. } else {
  30. var li = '';
  31. plupload.each(files, function (file) { //遍历文件
  32. li += "<li id='" + file['id'] + "'><div class='progress'><span class='bar'></span><span class='percent'>0%</span></div></li>";
  33. });
  34. $("#ul_pics").append(li);
  35. uploader.start();
  36. }
  37. },
  38. UploadProgress: function (up, file) { //上传中,显示进度条
  39. var percent = file.percent;
  40. $("#" + file.id).find('.bar').css({
  41. "width": percent + "%"
  42. });
  43. $("#" + file.id).find(".percent").text(percent + "%");
  44. },
  45. FileUploaded: function (up, file, info) { //文件上传成功的时候触发
  46. var data = eval("(" + info.response + ")");
  47. // $("#" + file.id).html("<div class='img'><img src='" + data.pic + "'/></div><input type='' value='' class='input'><span class='span'>删除</span>");
  48. // $("#" + file.id).html("<div class='img'><img src='" + data.pic + "'/></div><p>" + file.name + "</p><span class='span' onclick='DeleteBanner(" + file.id + ")'>删除</span>");
  49. $("#" + file.id).html(CreateBanner(data.pic, file.name, file.id));
  50. BannerJson[file.id] = data;
  51. },
  52. Error: function (up, err) { //上传出错的时候触发
  53. // alert(err.message);
  54. $.Huimodalalert('服务器错误!请联系管理员', 3000);
  55. }
  56. },
  57. });
  58. var uploader2 = new plupload.Uploader({ //创建实例的构造方法
  59. runtimes: 'html5,flash,silverlight,html4', //上传插件初始化选用那种方式的优先级顺序
  60. browse_button: 'colorbtn', // 上传按钮
  61. url: "upload.php", //远程上传地址
  62. flash_swf_url: 'plupload/Moxie.swf', //flash文件地址
  63. silverlight_xap_url: 'plupload/Moxie.xap', //silverlight文件地址
  64. filters: {
  65. max_file_size: '200mb', //最大上传文件大小(格式100b, 10kb, 10mb, 1gb)
  66. mime_types: [ //允许文件上传类型
  67. {
  68. title: "files",
  69. extensions: "jpg,png,gif,ico"
  70. }
  71. ]
  72. },
  73. multi_selection: true, //true:ctrl多文件上传, false 单文件上传
  74. init: {
  75. FilesAdded: function (up, files) { //文件上传前
  76. if ($("#ul_pics2").children("li").length > 30) {
  77. alert("您上传的图片太多了!");
  78. uploader2.destroy();
  79. } else {
  80. var li = '';
  81. plupload.each(files, function (file) { //遍历文件
  82. li += "<li id='" + file['id'] + "'><div class='progress'><span class='bar'></span><span class='percent'>0%</span></div></li>";
  83. });
  84. $("#ul_pics2").append(li);
  85. uploader2.start();
  86. }
  87. },
  88. UploadProgress: function (up, file) { //上传中,显示进度条
  89. var percent = file.percent;
  90. $("#" + file.id).find('.bar').css({
  91. "width": percent + "%"
  92. });
  93. $("#" + file.id).find(".percent").text(percent + "%");
  94. },
  95. FileUploaded: function (up, file, info) { //文件上传成功的时候触发
  96. var data = eval("(" + info.response + ")");
  97. // $("#" + file.id).html("<div class='img'><img src='" + data.pic + "'/></div><input type='' value='' class='input' placeholder='请输入颜色分类或其他说明'><span class='span' onclick='DeleteColor(" + file.id + ")'>删除</span>");
  98. $("#" + file.id).html(CreateColor(data.pic, "", file.id));
  99. ColoeJson[file.id] = data;
  100. },
  101. Error: function (up, err) { //上传出错的时候触发
  102. // alert(err.message);
  103. $.Huimodalalert('服务器错误!请联系管理员', 3000);
  104. }
  105. },
  106. });
  107. uploader.init();
  108. uploader2.init();
  109. //日历控件
  110. laydate.render({
  111. elem: '#CountDown', //指定元素
  112. type: 'datetime',
  113. // format: 'y/M/d',
  114. // format: 'd/M/y',
  115. });
  116. GetProductInfo();
  117. }
  118. //获取产品信息
  119. var GetProductInfo = function () {
  120. var pid = GetUrlParam("pid");
  121. ProductId = pid;
  122. var parameter = pid ? urlEncode(["SelectProduct", pid]) : urlEncode(["SelectProductNumber"]);
  123. $.ajax({
  124. type: "post",
  125. url: "/taiwan/php/index.php",
  126. data: {mode: parameter},
  127. dataType: "json",
  128. success: function (data) {
  129. if (!pid) {
  130. // if (data[0].number == null) {
  131. // data[0].number += 1;
  132. // }
  133. // $("#ProductRemarks").val(data[0].number);
  134. PageType = true;
  135. }
  136. else {
  137. PrintProductInfo(data);
  138. PageType = false;
  139. }
  140. }
  141. });
  142. }
  143. //打印产品信息
  144. var PrintProductInfo = function (data) {
  145. var input = $('input[type="text"]'), id, value = data[0][0];
  146. for (var i = 0; i < input.length; i++) {
  147. id = input.eq(i).attr("id");
  148. input.eq(i).attr("value", value[id]);
  149. }
  150. $("#ProductIntroduce").html(value.ProductIntroduce);
  151. // $("#ueditor_0").contents().find("body").html($("#ueditor_0").contents().find("body").html() + value.ProductInfo);
  152. $("#ueditor_0").contents().find("body").html(value.ProductInfo);
  153. var banner = JSON.parse(value.ProductAttr)["7b824b9c-738b-11e8-a479-0610c52349b6"],
  154. color = JSON.parse(value.ProductAttr)["69d4e108-738a-11e8-a479-0610c52349b6"],
  155. size = JSON.parse(value.ProductAttr)['d6d6361b-acea-11e8-bbc6-0a4b7569e232'],
  156. classs = JSON.parse(value.ProductAttr)["cfb738c4-bff6-11e8-bbc6-0a4b7569e232"],
  157. comment = JSON.parse(value.ProductAttr)["d5cca263-c224-11e8-bbc6-0a4b7569e232"];
  158. for (var i in banner) {
  159. for (var j in banner[i]) {
  160. var id = NewGuid(),
  161. li = "<li id='" + id + "'></li>";
  162. $("#ul_pics").append(li);
  163. $("#" + id).html(CreateBanner(banner[i][j], "", id));
  164. // BannerJson[id] = banner[i][j];
  165. }
  166. }
  167. for (var i in color) {
  168. for (var j in color[i]) {
  169. var id = NewGuid(),
  170. li = "<li id='" + id + "'></li>";
  171. $("#ul_pics2").append(li);
  172. $("#" + id).html(CreateColor(color[i][j], j, id));
  173. // ColoeJson[id] = color[i][j];
  174. }
  175. }
  176. for (var i in size) {
  177. for (var j in size[i]) {
  178. AddSize(false, size[i][j]);
  179. }
  180. }
  181. $.each(classs, function (i, val) {
  182. AddClass(false, i, val);
  183. })
  184. for (var i in comment) {
  185. CreateComment(false, comment[i]);
  186. }
  187. $(".Submission").html("修改产品信息");
  188. }
  189. //创建banner、打印banner
  190. var CreateBanner = function (src, name, id) {
  191. if (src.split("/taiwan").length > 1) {
  192. src = src;
  193. }
  194. else {
  195. src = "/taiwan/" + src;
  196. }
  197. var str = "<div class='img'><img src='" + src + "'/></div><p>" + name + "</p><span class='span' onclick='DeleteBanner(\"" + id + "\")'>删除</span>";
  198. return str;
  199. }
  200. //删除banner图
  201. var DeleteBanner = function (el) {
  202. var flag = confirm("是否确定删除banner图?");
  203. if (flag) {
  204. var id = el.id;
  205. // delete BannerJson[id];
  206. $("#" + el).remove();
  207. }
  208. }
  209. //创建颜色分类、打印颜色分类
  210. var CreateColor = function (src, name, id) {
  211. if (src.split("/taiwan").length > 1) {
  212. src = src;
  213. }
  214. else {
  215. src = "/taiwan/" + src;
  216. }
  217. name == "" ? "" : name;
  218. var str = "<div class='img'><img src='" + src + "'/></div><input type='' value='" + name + "' class='input' placeholder='请输入颜色分类或其他说明'><span class='span' onclick='DeleteColor(\"" + id + "\")'>删除</span>";
  219. return str;
  220. }
  221. //删除颜色分类图片
  222. var DeleteColor = function (el) {
  223. var flag = confirm("是否确定删除颜色分类?");
  224. if (flag) {
  225. var id = el.id;
  226. delete ColoeJson[id];
  227. $("#" + el).remove();
  228. }
  229. }
  230. //添加尺寸
  231. var AddSize = function (flag, size) {
  232. if (flag) {
  233. var li = '<li><input type="" value="" class="input" placeholder="请输入尺寸"><span class="span" onclick="DeleteSize()">删除</span></li>';
  234. }
  235. else {
  236. var li = '<li><input type="" value="' + size + '" class="input" placeholder="请输入尺寸"><span class="span" onclick="DeleteSize()">删除</span></li>';
  237. }
  238. $("#ul_pics3").append(li);
  239. }
  240. //删除尺寸
  241. var DeleteSize = function () {
  242. var flag = confirm("是否确定删除尺寸?");
  243. if (flag) {
  244. event.target.parentNode.remove();
  245. }
  246. }
  247. //添加套餐
  248. var AddClass = function (flag, indexof, obj) {
  249. var li, ul, ul_length;
  250. li = '<li>' +
  251. '<div class="number_select">' +
  252. '<span>销售数量选择</span>' +
  253. '<select>' +
  254. '<option>0</option>' +
  255. '<option>1</option>' +
  256. '<option>2</option>' +
  257. '<option>3</option>' +
  258. '<option>4</option>' +
  259. '<option>5</option>' +
  260. '</select>' +
  261. '</div>' +
  262. '<input type="" value="" class="input" placeholder="请输入套餐说明">' +
  263. '<input type="" value="" class="input" placeholder="请输入套餐价格">' +
  264. '<span class="span" onclick="DeleteClass()">删除</span>' +
  265. '</li>';
  266. ul = $("#ul_pics4").append($(li));
  267. if (flag) {
  268. ul_length = ul.find("li").length;
  269. ul.find("select").eq(ul_length - 1).val(ul_length);
  270. if (ul_length == 1) {
  271. ul.find("input").eq(1).val($("#ProductPrice").val())
  272. }
  273. }
  274. else {
  275. $.each(obj, function (i, val) {
  276. if (i == "type") {
  277. ul.find("select").eq(indexof).val(val);
  278. }
  279. else {
  280. ul.find("li").eq(indexof).find("input").eq(0).val(val);
  281. ul.find("li").eq(indexof).find("input").eq(1).val(i);
  282. }
  283. });
  284. }
  285. }
  286. //删除套餐
  287. var DeleteClass = function () {
  288. var flag = confirm("是否确定删除套餐?");
  289. if (flag) {
  290. event.target.parentNode.remove();
  291. }
  292. }
  293. //添加评价
  294. var CreateComment = function (flag, obj) {
  295. var id = NewGuid();
  296. var li = '<li>' +
  297. '<div class="comment_header">' +
  298. '<input class="comment_username" placeholder="请输入用户名" type="text"/>' +
  299. '<span class="comment_delete" onclick="DeleteComment()">删除</span>' +
  300. '</div>' +
  301. '<div class="comment_content">' +
  302. '<textarea placeholder="请输入评价"></textarea>' +
  303. '</div>' +
  304. '<div class="comment_picture_warp">' +
  305. '<div class="comment_picture" id="' + id + '" style="cursor: pointer">' +
  306. '<img src="../images/addphoto.png" style="cursor: pointer"/>' +
  307. '</div>' +
  308. '</div>' +
  309. '<div class="comment_footer">' +
  310. '<input type="text" class="comment_footer_input" placeholder="请输入评价日期">' +
  311. '</div>' +
  312. '</li>';
  313. $(".ul_pics_comment").append(li);
  314. var el = $("#" + id)[0];
  315. FileUpload(el, function (r) {
  316. CreateCommentImg(el, r.pic, true);
  317. console.log(r);
  318. });
  319. //日历控件
  320. laydate.render({
  321. elem: $(el).parents().eq(1).find(".comment_footer_input").eq(0)[0], //指定元素
  322. type: 'datetime',
  323. format: 'd/M/y'
  324. });
  325. if (!flag) {
  326. $(el).parents().eq(1).find("input[type=text]").eq(0).val(obj['name']);
  327. $(el).parents().eq(1).find("textarea").val(obj['text']);
  328. $(el).parents().eq(1).find("input[type=text]").eq(1).val(obj['time']);
  329. var img = obj['imgurl'].split(",");
  330. img.forEach(function (val) {
  331. CreateCommentImg(el, val, false);
  332. });
  333. }
  334. }
  335. var CreateCommentImg = function (el, img, flag) {
  336. if (img == "" && !flag) {
  337. return;
  338. }
  339. img = flag ? '/taiwan/' + img : img;
  340. var div = '<div class="comment_picture" ><img src="' + img + '"><img src="../images/close.png" class="closeimg" onclick="CreateCommentImgDelete()"/></div>';
  341. $(el).parents().eq(0).append(div);
  342. }
  343. var CreateCommentImgDelete = function () {
  344. var flag = confirm("是否确定此图片?");
  345. if (flag) {
  346. event.target.parentNode.remove();
  347. }
  348. }
  349. //删除评价
  350. var DeleteComment = function () {
  351. var flag = confirm("是否确定删除评价?");
  352. if (flag) {
  353. event.target.parentNode.parentNode.remove();
  354. }
  355. }
  356. //上传产品
  357. var UploadNewProduct = function () {
  358. var pn = $("#ProductName").val(),
  359. pt1 = $("#ProductIntroduce").val(),
  360. pt2 = $("#ueditor_0").contents().find("body")[0].innerHTML,
  361. pr1 = $("#ProductPrice").val(),
  362. pr2 = $("#ProductPrimeCost").val(),
  363. num = $("#ProductRemarks").val(),
  364. dis = $("#Discount").val(),
  365. so = $("#Sold").val(),
  366. prom = $("#Promotion").val(),
  367. cd = $("#CountDown").val(),
  368. meal = $("#ul_pics4 li");
  369. if (pn.trim() == "") {
  370. $.Huimodalalert('请输入产品名称', 3000);
  371. }
  372. // else if (pt1.trim() == "") {
  373. // $.Huimodalalert('产品介绍', 3000);
  374. // return;
  375. // }
  376. else if (pr1.trim() == "") {
  377. $.Huimodalalert('请输入产品原价', 3000);
  378. }
  379. else if (pr2.trim() == "") {
  380. $.Huimodalalert('请输入产品售价', 3000);
  381. }
  382. else if (dis.trim() == "") {
  383. $.Huimodalalert('请输入产品折扣', 3000);
  384. }
  385. else if (so.trim() == "") {
  386. $.Huimodalalert('请输入产品已售', 3000);
  387. }
  388. else if (prom.trim() == "") {
  389. $.Huimodalalert('请输入产品促销信息', 3000);
  390. }
  391. else if (cd.trim() == "") {
  392. $.Huimodalalert('请输入产品倒计时', 3000);
  393. }
  394. // else if ($.isEmptyObject(BannerJson)) {
  395. // $.Huimodalalert('请上传banner图', 3000);
  396. // }
  397. // else if ($.isEmptyObject(ColoeJson)) {
  398. // $.Huimodalalert('请上传颜色分类图片', 3000);
  399. // }
  400. else if (pr2 == "<p><br></p>") {
  401. $.Huimodalalert('请填写详细内容', 3000);
  402. }
  403. else if (meal.length == 0) {
  404. $.Huimodalalert('请填写产品套餐', 3000);
  405. }
  406. else {
  407. //公用变量
  408. var flag,
  409. src,
  410. obj = {},
  411. colorarray = [],
  412. bannerarray = [],
  413. sizearray = [],
  414. classsarray = [],
  415. commentarray = [];
  416. /************************************************************************************banner整合(必填)************************************************************************************/
  417. var banner = $("#ul_pics li img");
  418. if (banner.length == 0) {
  419. $.Huimodalalert('请上传banner图', 3000);
  420. return;
  421. }
  422. else {
  423. for (var i = 0; i < banner.length; i++) {
  424. flag = i;
  425. src = banner.eq(i).attr("src");
  426. obj = {};
  427. obj[flag] = src;
  428. bannerarray.push(obj);
  429. }
  430. pattr["7b824b9c-738b-11e8-a479-0610c52349b6"] = bannerarray;
  431. }
  432. /************************************************************************************产品颜色分类整合(必填)*******************************************************************************/
  433. var color = $("#ul_pics2 li"),
  434. color_input = $("#ul_pics2 li input");
  435. if (color.length == 0) {
  436. $.Huimodalalert('请上传颜色分类图', 3000);
  437. return;
  438. }
  439. else {
  440. for (var i = 0; i < color_input.length; i++) {
  441. if (color_input.eq(i).val().trim() == "") {
  442. $.Huimodalalert('请输入第' + (i + 1) + '个颜色或者说明', 3000);
  443. return;
  444. }
  445. flag = color_input.eq(i).val();
  446. src = $($("#ul_pics2 li input")[i]).parent().find("img").attr("src");
  447. obj = {};
  448. obj[flag] = src;
  449. colorarray.push(obj);
  450. pattr["69d4e108-738a-11e8-a479-0610c52349b6"] = colorarray;
  451. }
  452. }
  453. /************************************************************************************尺寸整合(可填)***************************************************************************************/
  454. var size = $("#ul_pics3 .input");
  455. for (var i = 0; i < size.length; i++) {
  456. if (size.eq(i).val().trim() == "") {
  457. $.Huimodalalert('请输入尺寸', 3000);
  458. return;
  459. }
  460. flag = i;
  461. src = size.eq(i).val();
  462. obj = {};
  463. obj[flag] = src;
  464. sizearray.push(obj);
  465. }
  466. pattr["d6d6361b-acea-11e8-bbc6-0a4b7569e232"] = sizearray;
  467. /************************************************************************************套餐整合(必填)***************************************************************************************/
  468. var classs = $("#ul_pics4 li"),
  469. classs_select, classs_input;
  470. for (var i = 0; i < classs.length; i++) {
  471. obj = {};
  472. classs_select = classs.eq(i).find("select");
  473. if (classs_select == 0) {
  474. $.Huimodalalert('请选择第' + (i + 1) + "个套餐框中的销售数量", 3000);
  475. return;
  476. }
  477. obj["type"] = classs_select.eq(0).val();
  478. classs_input = classs.eq(i).find("input");
  479. for (var j = 0; j < classs_input.length; j++) {
  480. if (classs_input.eq(j).val() == "") {
  481. $.Huimodalalert('请填写第' + (i + 1) + '个套餐框中的第' + (j + 1) + '个输入框说明', 3000);
  482. return;
  483. }
  484. }
  485. flag = classs_input.eq(1).val();
  486. src = classs_input.eq(0).val();
  487. obj[flag] = src;
  488. classsarray.push(obj);
  489. }
  490. pattr['cfb738c4-bff6-11e8-bbc6-0a4b7569e232'] = classsarray;
  491. /************************************************************************************评价整合(可填)***************************************************************************************/
  492. var comment = $(".ul_pics_comment li");
  493. for (var i = 0; i < comment.length; i++) {
  494. if (comment.eq(i).find('input[type=text]').eq(0).val().trim() == "") {
  495. $.Huimodalalert('请输入第' + (i + 1) + "个评价框中的用户名", 3000);
  496. return;
  497. }
  498. if (comment.eq(i).find('textarea').val().trim() == "") {
  499. $.Huimodalalert('请输入第' + (i + 1) + "个评价框中的评价内容", 3000);
  500. return;
  501. }
  502. if (comment.eq(i).find('input[type=text]').eq(1).val().trim() == "") {
  503. $.Huimodalalert('请输入第' + (i + 1) + "个评价框中的评价时间", 3000);
  504. return;
  505. }
  506. obj = {};
  507. obj['name'] = comment.eq(i).children().eq(0).children('input').val();
  508. obj['text'] = comment.eq(i).children().eq(1).children().val();
  509. obj['time'] = comment.eq(i).find("input[type=text]").eq(1).val();
  510. flag = comment.eq(i).children().eq(2).children(".comment_picture");
  511. src = "";
  512. for (var j = 1; j < flag.length; j++) {
  513. j == 1 ? "" : src += ',';
  514. src += flag.eq(j).children("img").eq(0).attr("src");
  515. }
  516. obj['imgurl'] = src;
  517. commentarray.push(obj);
  518. }
  519. pattr["d5cca263-c224-11e8-bbc6-0a4b7569e232"] = commentarray;
  520. /************************************************************************************所有整合结束***************************************************************************************/
  521. var str = JsonToString(pattr);
  522. var parameter = PageType ? urlEncode(["UploadNewProduct", pn, pt1, pt2, pr1, pr2, num, str, dis, so, prom, cd]) : urlEncode(["UpdateProductInfo", ProductId, pn, pt1, pt2, pr1, pr2, str, dis, so, prom, cd]);
  523. $(".Submission")[0].onclick = function () {
  524. }
  525. $.ajax({
  526. type: "post",
  527. url: "/taiwan/php/index.php",
  528. data: {mode: parameter},
  529. dataType: "json",
  530. success: function (data) {
  531. if (PageType) {
  532. if (data.length == 1 && data != -1) {
  533. alert("上传成功!");
  534. window.location.href = "product.html?pid=" + data[0].ProductId;
  535. }
  536. }
  537. else {
  538. if (data.length == 1 && data != -1) {
  539. alert("修改成功!");
  540. window.location.href = "product-add.html?pid=" + data[0].ProductId;
  541. }
  542. }
  543. }
  544. });
  545. }
  546. }
  547. //文件上传接口
  548. var FileUpload = function (el, cb) {
  549. var file = new plupload.Uploader({ //创建实例的构造方法
  550. runtimes: 'html5,flash,silverlight,html4', //上传插件初始化选用那种方式的优先级顺序
  551. browse_button: el, // 上传按钮
  552. url: "upload.php", //远程上传地址
  553. flash_swf_url: 'plupload/Moxie.swf', //flash文件地址
  554. silverlight_xap_url: 'plupload/Moxie.xap', //silverlight文件地址
  555. filters: {
  556. max_file_size: '200mb', //最大上传文件大小(格式100b, 10kb, 10mb, 1gb)
  557. mime_types: [ //允许文件上传类型
  558. {
  559. title: "files",
  560. extensions: "jpg,png,gif,ico"
  561. }
  562. ]
  563. },
  564. multi_selection: true, //true:ctrl多文件上传, false 单文件上传
  565. init: {
  566. FilesAdded: function (up, files) { //文件上传前
  567. file.start();
  568. },
  569. UploadProgress: function (up, file) { //上传中,显示进度条
  570. },
  571. FileUploaded: function (up, file, info) { //文件上传成功的时候触发
  572. var data = eval("(" + info.response + ")");
  573. cb && cb(data);
  574. },
  575. Error: function (up, err) { //上传出错的时候触发
  576. // alert(err.message);
  577. alert();
  578. $.Huimodalalert('服务器错误!请联系管理员', 3000);
  579. }
  580. },
  581. });
  582. file.init();
  583. }
  584. //连接字符串
  585. var urlEncode = function (arr) {
  586. var i; //循环初始化
  587. for (i = 0; i < arr.length; i++) {
  588. arr[i] = encodeURIComponent(encodeURIComponent(arr[i]));
  589. }
  590. return arr.join();
  591. }
  592. //获取网址
  593. var GetUrlParam = function (name) {
  594. var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)"); //构造一个含有目标参数的正则表达式对象
  595. var r = window.location.search.substr(1).match(reg); //匹配目标参数
  596. if (r != null) return unescape(r[2]);
  597. return null; //返回参数值
  598. }
  599. //json转换为string
  600. var JsonToString = function (obj) {
  601. var i,
  602. _type = false,
  603. _str = "",
  604. _type = typeof (obj); //获取类型
  605. //开始序列化
  606. if (obj == null) {
  607. }
  608. else {
  609. obj = obj.valueOf(); //获取值 同时类型也为对应
  610. if ("boolean,number".indexOf(_type) > -1) {//bool和number类型转化
  611. _str = obj.toString();
  612. }
  613. else if (_type == "string") {//json处理字符串时需要加上 "\""符号
  614. _str = "\"" + obj + "\"";
  615. }
  616. else if (typeof obj == "array") { //数组处理
  617. _str = "[";
  618. for (i = 0; i < obj.length; i++) {
  619. _str += JsonToString(obj[i]) + ((i < obj.length - 1) ? "," : "")
  620. }
  621. ;_str += "]";
  622. return _str
  623. }
  624. else {//object处理
  625. _str = "{";
  626. for (i in obj) {
  627. if (obj.hasOwnProperty(i)) {
  628. if (_str.length > 1) {
  629. _str += ","
  630. }
  631. ;_str += "\"" + i + "\":" + JsonToString(obj[i]);
  632. }
  633. }
  634. _str += "}";
  635. }
  636. return _str;
  637. }
  638. }
  639. //生成GUID
  640. var NewGuid = function () {
  641. var _UN, i, _UGID = "";
  642. for (i = 0; i < 32; i++) {
  643. _UGID += Math.floor(Math.random() * 16).toString(16); //随机0 - 16 的数字 转变为16进制的字符串
  644. _UN = Math.floor((i - 7) / 4); //计算 (i-7)除4
  645. if (_UN > -1 && _UN < 4 && (i == (7 + 4 * _UN))) { //会使guid中间加 "-" 形式为xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
  646. _UGID += "-";
  647. }
  648. }
  649. return _UGID;
  650. }