purchaseorder-addedit.js 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554
  1. //添加信息框
  2. $(".packing .exptj").click(function() {
  3. if($("select[name=purchase]").children("option:selected").val() < 1)
  4. {
  5. $(".ts p").html("请选择供应商!");
  6. $(".ts").fadeIn();
  7. setTimeout('$(".ts").fadeOut()', 800);
  8. return false;
  9. }
  10. if($("select[name=price]").children("option:selected").val() < 1)
  11. {
  12. $(".ts p").html("请选择供应商价格表!");
  13. $(".ts").fadeIn();
  14. setTimeout('$(".ts").fadeOut()', 800);
  15. return false;
  16. }
  17. $(".exp .title").text("添加信息");
  18. $(".exp .setting").addClass("packing");
  19. $(".expwp .button").html("<font class='datasave packingtj'>提 交</font> <font class='fh'>关 闭</font>");
  20. $(".exp .select").each(function() {
  21. if($(this).children("option:selected").val() != 0)
  22. {
  23. $(this).children("option:selected").prop("selected",false);
  24. }
  25. });
  26. $(".exp .checkbox .ckrows input:checked").each(function(){
  27. $(this).prop("checked",false);
  28. });
  29. $(".exp input[name='money']").val("");
  30. $(".exp .num font").text("1");
  31. $(".exp .tm font").html("");
  32. option();
  33. $(".exp").show();
  34. });
  35. //查找信息单价
  36. $(".exp .ckrows input").click(function() {
  37. $(".exp .tm font").html("0.00");
  38. $(".exp input[name='money']").val("0.00");
  39. $(".exp .num font").text("1");
  40. var num = $(this).index();
  41. var f = "";
  42. $(".exp .datalist .select").each(function() {
  43. f = f + $(this).children("option:selected").val() + "-";
  44. });
  45. $(".exp .post .select").each(function() {
  46. f = f + $(this).children("option:selected").val() + "-";
  47. });
  48. f = f + $(this).val();
  49. $.ajax({
  50. url: "/purchaseorder/describe/",
  51. data: "data="+f+"&priceid="+$("select[name=price]").children("option:selected").val(),
  52. type: "POST",
  53. dataType: "json",
  54. success: function(a) {
  55. if (a && a.success) {
  56. var ma = $(".exp input[name='money']").val()*1;
  57. var mb = a.msg['purchase']*1;
  58. var n = $(".exp .num font").text()*1;
  59. $(".exp input[name='money']").val((ma+mb).toFixed(2));
  60. $(".exp .tm font").html(((ma+mb)*n).toFixed(2));
  61. $(".zm").append("<font class='z"+a.n+"'>"+mb.toFixed(2)+"</span>");
  62. } else {
  63. $('.exp .'+a.n).prop("checked",false);
  64. $(".ts p").html($("select[name=price]").children("option:selected").text()+"供应商"+a.msg);
  65. $(".ts").fadeIn();
  66. setTimeout('$(".ts").fadeOut()', 900);
  67. }
  68. }
  69. });
  70. });
  71. //修改信息时清除原有信息
  72. $(".exp select").click(function() {
  73. $(".zm").html("");
  74. $(".exp .ckrows input").prop("checked",false);
  75. $(".exp .tm font").html("0.00");
  76. $(".exp input[name='money']").val("0.00");
  77. $(".exp .num font").text("1");
  78. });
  79. //关闭添加信息框
  80. $(".exp").on('click',".fh",function() {
  81. $(".exp").hide();
  82. });
  83. //提交时tr增加data信息
  84. $(".exp").on('click',".packingtj",function() {
  85. var f = "";var e = "";var o = "";var checkid = "";
  86. $(".exp .datalist .select").each(function() {
  87. if($(this).children("option:selected").val() != 0)
  88. {
  89. f = f + $(this).children("option:selected").val() + "-";
  90. e = e + $(this).children("option:selected").text() + " ";
  91. }
  92. });
  93. $(".exp .post .select").each(function() {
  94. f = f + $(this).children("option:selected").val() + "-";
  95. e = e + $(this).children("option:selected").text() + " ";
  96. });
  97. var checkname = "";
  98. $(".datalist .checkbox .ckrows input:checked").each(function(){
  99. checkname = $(this).attr("name");
  100. checkid = checkid + $(this).val()+",";
  101. o = o + $(this).next('font').text()+" ";
  102. });
  103. if(checkname == "")
  104. {
  105. $(".ts p").text($(".datalist .checkbox").prevAll("em").text()+"为必填项");
  106. $(".ts").show();
  107. setTimeout('$(".ts").fadeOut()', 600);
  108. return false;
  109. }
  110. else
  111. {
  112. f = checkid + "-" + f;
  113. e = e + o;
  114. }
  115. var ab = 0;
  116. $(".datalist .must").each(function() {
  117. if ($.trim($(this).val()).length == 0) {
  118. $(this).css("border", "1px solid #F66");
  119. ab = ab + 1;
  120. }
  121. });
  122. if (ab > 0) {
  123. $(".ts p").text("红框为必填项");
  124. $(".ts").show();
  125. setTimeout('$(".ts").fadeOut()', 600);
  126. return false;
  127. }
  128. var x = 0
  129. $(".datatext tr").each(function() {
  130. if($(this).data("list") == f)
  131. {
  132. x++;
  133. }
  134. });
  135. if(x > 0)
  136. {
  137. $(".ts p").text("已有相同信息!");
  138. $(".ts").show();
  139. setTimeout('$(".ts").fadeOut()', 700);
  140. return false;
  141. }
  142. else
  143. {
  144. var ts = $(".datalist .checkbox .ckrows input:checked").length*1;
  145. var sl = $(".exp .num font").text()*1
  146. var dj = $(".exp input[name='money']").val()*1;
  147. $(".datatext").append("<tr data-list='"+f+"'><td>"+e+"</td><td>"+ts+"</td><td>"+sl+"</td><td>"+(dj).toFixed(2)+"</td><td>"+ts*sl+"</td><td>"+(sl*dj).toFixed(2)+"</td><td>"+$(".exp .currency").text()+"</td></tr>");
  148. }
  149. //$("input[name='shouldmoney']").val(($("input[name='shouldmoney']").val()*1+(sl*dj)).toFixed(2));//应收价格加上新增价格
  150. //et();
  151. datasort();
  152. $(".exp").hide();
  153. cost();//计算成本价
  154. });
  155. //修改tr-data信息
  156. $(".exp").on('click',".packingxg",function() {
  157. var f = "";var e = "";var o = "";var checkid = "";
  158. $(".exp .datalist .select").each(function() {
  159. if($(this).children("option:selected").val() != 0)
  160. {
  161. f = f + $(this).children("option:selected").val() + "-";
  162. e = e + $(this).children("option:selected").text() + " ";
  163. }
  164. });
  165. $(".exp .post .select").each(function() {
  166. f = f + $(this).children("option:selected").val() + "-";
  167. e = e + $(this).children("option:selected").text() + " ";
  168. });
  169. var checkname = "";
  170. $(".datalist .checkbox .ckrows input:checked").each(function(){
  171. checkname = $(this).attr("name");
  172. checkid = checkid + $(this).val()+",";
  173. o = o + $(this).next('font').text()+" ";
  174. });
  175. if(checkname == "")
  176. {
  177. $(".ts p").text($(".datalist .checkbox").prevAll("em").text()+"为必填项");
  178. $(".ts").show();
  179. setTimeout('$(".ts").fadeOut()', 600);
  180. return false;
  181. }
  182. else
  183. {
  184. f = checkid + "-" + f;
  185. e = e + o;
  186. }
  187. var ab = 0;
  188. $(".datalist .must").each(function() {
  189. if ($.trim($(this).val()).length == 0) {
  190. $(this).css("border", "1px solid #F66");
  191. ab = ab + 1;
  192. }
  193. });
  194. if (ab > 0) {
  195. $(".ts p").text("红框为必填项");
  196. $(".ts").show();
  197. setTimeout('$(".ts").fadeOut()', 600);
  198. return false;
  199. }
  200. var ts = $(".datalist .checkbox .ckrows input:checked").length*1;
  201. var sl = $(".exp .num font").text()*1
  202. var dj = $(".exp input[name='money']").val()*1;
  203. $(".datatext tr.on").data("list",f);
  204. //var xg = $(".datatext tr.on td:eq(8)").text()*1;
  205. // $("input[name='shouldmoney']").val(($("input[name='shouldmoney']").val()*1+((sl*dj)-xg)).toFixed(2));
  206. // et();
  207. $(".datatext tr.on").html("<td>"+e+"</td><td>"+ts+"</td><td>"+sl+"</td><td>"+(dj).toFixed(2)+"</td><td>"+ts*sl+"</td><td>"+(sl*dj).toFixed(2)+"</td><td>"+$(".exp .currency").text()+"</td>");
  208. datasort();
  209. $(".exp").hide();
  210. cost();//计算成本价
  211. });
  212. //修改数量
  213. $(".exp .lengththree .gz").click(function() {
  214. var num = $(".exp .num font").text()*1;
  215. var dj = $(".exp input[name='money']").val()*1;
  216. $(".exp .num font").text(num+1);
  217. if(dj > 0)
  218. {
  219. $(".exp .tm font").text((dj*(num+1)).toFixed(2));
  220. }
  221. });
  222. $(".exp .lengththree .gj").click(function() {
  223. var num = $(".exp .num font").text()*1;
  224. var dj = $(".exp input[name='money']").val()*1;
  225. if(num > 1)
  226. {
  227. $(".exp .num font").text(num-1)*1;
  228. if(dj > 0)
  229. {
  230. $(".exp .tm font").text((dj*(num-1)).toFixed(2));
  231. }
  232. }
  233. });
  234. //点击增加信息是增加标记
  235. $(".datatext").on('click',"tr",function() {
  236. $(".datatext tr").removeClass("on");
  237. $(this).addClass("on");
  238. });
  239. //删除信息
  240. $(".packing .expsc").click(function() {
  241. var b = 0;
  242. $(".packing .datatext .on").each(function() {
  243. b = b+1;
  244. });
  245. if (b>1)
  246. {
  247. $(".ts p").html("每次只可修改一条内容");
  248. $(".ts").show();
  249. setTimeout('$(".ts").fadeOut()', 1000);
  250. }
  251. else if(b<1)
  252. {
  253. $(".ts p").html("请选择需要修改的内容");
  254. $(".ts").show();
  255. setTimeout('$(".ts").fadeOut()', 1000);
  256. }
  257. else
  258. {
  259. // var xg = $(".datatext tr.on td:eq(8)").text()*1;
  260. //$("input[name='shouldmoney']").val(($("input[name='shouldmoney']").val()*1-xg).toFixed(2));et();
  261. $(".packing .datatext .on").remove();
  262. }
  263. cost();//计算成本价
  264. });
  265. //统一修改币种
  266. $("#currency").change(function(){
  267. var index = $(this).find("option:selected").text();
  268. var va = $(this).find("option:selected").val();
  269. $(".currency").text(index);
  270. $(".datatext tr").each(function() {
  271. $(this).find("td:eq(9)").text(index);
  272. });
  273. });
  274. //fullorder 数据库增加currency币种 考虑更改币种是否需要ajax获取美元汇率更改金额
  275. $(".packing .expxg").click(function() {
  276. var b = 0;
  277. $(".packing .datatext .on").each(function() {
  278. b = b+1;
  279. });
  280. if (b>1)
  281. {
  282. $(".ts p").html("每次只可修改一条内容");
  283. $(".ts").show();
  284. setTimeout('$(".ts").fadeOut()', 1000);
  285. }
  286. else if(b<1)
  287. {
  288. $(".ts p").html("请选择需要修改的内容");
  289. $(".ts").show();
  290. setTimeout('$(".ts").fadeOut()', 1000);
  291. }
  292. else
  293. {
  294. $(".exp .select").each(function() {
  295. if($(this).children("option:selected").val() != 0)
  296. {
  297. $(this).children("option:selected").prop("selected",false);
  298. }
  299. });
  300. $(".exp .checkbox .ckrows input:checked").each(function(){
  301. $(this).prop("checked",false);
  302. });
  303. $(".exp input[name='money']").val($(".packing .datatext .on td:eq(3)").text());
  304. $(".exp .num font").text($(".packing .datatext .on td:eq(2)").text());
  305. $(".exp .tm font").text($(".packing .datatext .on td:eq(5)").text());
  306. $(".exp .title").text("修改信息");
  307. $(".exp .setting").addClass("packing");
  308. var list = $(".packing .datatext .on").data("list");
  309. list = list.substring(0,list.length-1);
  310. var data = list.split("-");
  311. var ckrows = data[0].substring(0,data[0].length-1);
  312. ckrows = ckrows.split(",");
  313. for(i=0;i<ckrows.length;i++)
  314. {
  315. $(".exp .ckrows input[type='radio']").each(function() {
  316. if($(this).val() == ckrows[i])
  317. {
  318. $(this).prop("checked",true);
  319. }
  320. });
  321. }
  322. for(i=1;i<data.length+1;i++)
  323. {
  324. $(".exp .select").each(function() {
  325. $(this).find("option[value='"+data[i]+"']").prop("selected","selected");
  326. });
  327. }
  328. option();
  329. $(".expwp .button").html("<font class='datasave packingxg'>提 交</font> <font class='fh'>关 闭</font>");
  330. $(".exp").show();
  331. }
  332. });
  333. //自动显示option
  334. function option() {
  335. var index = $(".cike select").find("option:selected").index();
  336. $(".pttab li").hide(); $(".pttab li").removeClass("post");
  337. $("."+index).show();$("."+index).addClass("post");
  338. $('.pttab select option:eq(0)').prop('selected','selected');
  339. if(index == 1)
  340. {
  341. $(".pttab .a1").show();$(".pttab .a2").hide();
  342. }
  343. var indexb = $(".cikeb.post select").find("option:selected").index();
  344. $(".pttab .a1").hide();$(".pttab .a2").hide();$(".pttab .a1").removeClass("post");$(".pttab .a2").removeClass("post");
  345. if(indexb == 0 || indexb == 4)
  346. {
  347. $(".pttab .a1").show();$(".pttab .a1").addClass("post");
  348. }
  349. else if(indexb == 2)
  350. {
  351. $(".pttab .a2").show();$(".pttab .a2").addClass("post");
  352. }
  353. }
  354. $("select[name='country']").change(function() {
  355. $("select[name=productdescription]").html("");
  356. $("input[name=customs]").val("0");
  357. $("input[name=expressmoney]").val("0.00");
  358. express()
  359. printtype();
  360. });
  361. $("select[name='express']").change(function() {
  362. $("select[name=productdescription]").html("");
  363. $("input[name=customs]").val("0");
  364. $("input[name=expressmoney]").val("0.00");
  365. express()
  366. printtype();
  367. });
  368. $("select[name='printtype']").change(function() {
  369. $("select[name=productdescription]").html("");
  370. $("input[name=customs]").val("0");
  371. printtype();
  372. });
  373. //打印类型
  374. function printtype() {
  375. var index = $("select[name='printtype']").find("option:selected").index();
  376. if(index == 0)
  377. {
  378. var e = $("select[name=express]").find("option:selected").val();
  379. var c = $("select[name=country]").find("option:selected").val();
  380. $.ajax({
  381. url: "/fullorder/customs/",
  382. data: "e="+e+"&c="+c,
  383. type: "POST",
  384. dataType: "json",
  385. success: function(a) {
  386. if (a && a.success) {
  387. $("input[name=customs]").val(a.money);
  388. for(i=0;i<a.msg.length;i++)
  389. {
  390. $("select[name=productdescription]").append("<option value='"+a.msg[i]['id']+"'>"+a.msg[i]['title']+"</option>");
  391. }
  392. $(".productdescription").show();
  393. $(".customs").show();
  394. } else {
  395. $(".productdescription").hide();
  396. $(".customs").hide();
  397. $(".ts p").html(a.msg);
  398. $(".ts").fadeIn();
  399. setTimeout('$(".ts").fadeOut()', 800);
  400. }
  401. }
  402. });
  403. }else
  404. {
  405. $(".productdescription").hide();
  406. $(".customs").hide();
  407. }
  408. }
  409. function express() {
  410. var e = $("select[name=express]").find("option:selected").val();
  411. var c = $("select[name=country]").find("option:selected").val();
  412. $.ajax({
  413. url: "/fullorder/express/",
  414. data: "e="+e+"&c="+c,
  415. type: "POST",
  416. dataType: "json",
  417. success: function(a) {
  418. if (a && a.success) {
  419. $("input[name=expressmoney]").val(a.money);//?这里或许需要根据币种美元转换
  420. } else {
  421. $("input[name=expressmoney]").val("0.00");
  422. }
  423. }
  424. });
  425. }
  426. $(".lengththree input[name='money']").bind("change",function(){
  427. var ma= $(this).val();
  428. var n = $(".exp .num font").text()*1;
  429. $(".exp .tm font").html((ma*n).toFixed(2));
  430. });
  431. //整体提交数据
  432. $(".fullorderdata").click(function() {
  433. $(".ts p").html("<i class='fa fa-2x fa-cog fa-spin'></i> &nbsp; 正在添加中,请稍后...");
  434. $(".ts").show();
  435. var f = "";
  436. var e = "";
  437. $(".need .select").each(function() {
  438. f = f + $(this).attr("name") + "=" + $(this).children("option:selected").val() + "&";
  439. });
  440. $(".need input:text").each(function() {
  441. f = f + $(this).attr("name") + "=" + $(this).val() + "&";
  442. });
  443. $(".need input:hidden").each(function() {
  444. f = f + $(this).attr("name") + "=" + $(this).val() + "&";
  445. });
  446. $(".need textarea").each(function() {
  447. f = f + $(this).attr("name") + "=" + $(this).val() + "&";
  448. });
  449. $(".datatext tr").each(function() {
  450. e = e + $(this).data("list")+ "|" + $(this).find("td:eq(0)").text() + "|" + $(this).find("td:eq(1)").text() + "|" + $(this).find("td:eq(2)").text() + "|" + $(this).find("td:eq(3)").text() + "|" + $(this).find("td:eq(4)").text() + "|" + $(this).find("td:eq(5)").text() + "|" + "*";
  451. });
  452. f = f + "fpdata=" + encodeURI(e) + "&";
  453. f = f + "budget=" + $(".budget").text() + "&";
  454. var ab = 0;
  455. $(".need .must").each(function() {
  456. if ($.trim($(this).val()).length == 0) {
  457. $(this).css("border", "1px solid #F66");
  458. ab = ab + 1;
  459. }
  460. });
  461. if (ab > 0) {
  462. $(".ts p").text("红框为必填项");
  463. $(".ts").show();
  464. setTimeout('$(".ts").fadeOut()', 600);
  465. return false;
  466. }
  467. $.ajax({
  468. url: addedit,
  469. data: f,
  470. type: "POST",
  471. dataType: "json",
  472. success: function(a) {
  473. if (a && a.success) {
  474. $(".ts").hide();
  475. $(".express p:eq(0)").html(a.msg+"是否关闭?");
  476. $(".express p:eq(1)").html("<font class='fh'>确 定</font><font class='esc'>取 消</font>");
  477. $(".express").show();
  478. } else {
  479. $(".ts").hide();
  480. $(".ts p").html("添加失败,请重试");
  481. $(".ts").fadeIn();
  482. setTimeout('$(".ts").fadeOut()', 600);
  483. }
  484. }
  485. });
  486. });
  487. //关联总金额换算穿预计到帐金额
  488. $("input[name='shouldmoney']").bind("change",function(){
  489. et();
  490. });
  491. function et(){
  492. var ma= $("input[name='shouldmoney']").val();
  493. var n= $("input[name='et']").val();
  494. $(".currencymoney").text((ma*n).toFixed(2));
  495. }
  496. //计算成本金额
  497. function cost(){
  498. var money = 0;
  499. $(".datatext tr").each(function() {
  500. money = money+$(this).find("td:eq(8)").text()*1;
  501. });
  502. $("input[name='cost']").val(money);
  503. }
  504. //选择供应商
  505. $("select[name='purchase']").change(function() {
  506. if($(this).find("option:selected").index() == 0)
  507. {
  508. $("select[name='price']").html("<option value=''>需先选择供应商</option>");
  509. return false;
  510. }
  511. $("select[name='price']").html("<option value=''>需先选择供应商</option>");
  512. var id = $(this).children("option:selected").val();
  513. $.ajax({
  514. url: "/purchaseorder/price/",
  515. data: "id="+id,
  516. type: "POST",
  517. dataType: "json",
  518. success: function(a) {
  519. if (a && a.success) {
  520. for(i=0;i<(a.msg).length;i++)
  521. {
  522. $("select[name=price]").append("<option value='"+a.msg[i]['id']+"'>"+a.msg[i]['title']+"</option>");
  523. }
  524. $("select[name=price]").find("option:eq(1)").attr("selected","selected");
  525. } else {
  526. $(".ts p").html("供应商价格表获取失败,请重试");
  527. $(".ts").fadeIn();
  528. setTimeout('$(".ts").fadeOut()', 800);
  529. }
  530. }
  531. });
  532. });