transport.js 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769
  1. $(function(){
  2. //定义运费模板主体模板、头模板、单行显示模板
  3. TransTpl = ''; RuleHead = ''; RuleCell = '';
  4. TransTpl += "<div class=\"ncsu-trans-type\" data-delivery=\"TRANSTYPE\">\n";
  5. TransTpl += "<div class=\"entity\">\n";
  6. TransTpl += "<div class=\"default J_DefaultSet\">\n";
  7. TransTpl += "默认运费:\n";
  8. TransTpl += "<input class=\"w30 mr5 text\" type=\"text\" aria-label=\"默认运费"+unit+"数\" maxlength=\"4\" autocomplete=\"off\" data-field=\"start\" value=\"1\" name=\"default[TRANSTYPE][start]\">\n";
  9. TransTpl += ""+unit+"内,\n";
  10. TransTpl += "<input class=\"w60 text\" type=\"text\" aria-label=\"默认运费价格\" maxlength=\"6\" autocomplete=\"off\" value=\"\" name=\"default[TRANSTYPE][postage]\" data-field=\"postage\">";
  11. TransTpl += "<em class=\"add-on\">";
  12. TransTpl += "<i class=\"icon-renminbi\"><\/i>";
  13. TransTpl += "<\/em>, 每增加\n";
  14. TransTpl += "<input class=\"w30 ml5 mr5 text\" type=\"text\" aria-label=\"每加重\" maxlength=\"4\" autocomplete=\"off\" value=\"1\" data-field=\"plus\" name=\"default[TRANSTYPE][plus]\">\n";
  15. TransTpl += ""+unit+", 增加运费\n";
  16. TransTpl += "<input class=\"w50 ml5 text\" type=\"text\" aria-label=\"加重运费\" maxlength=\"6\" autocomplete=\"off\" value=\"\" data-field=\"postageplus\" name=\"default[TRANSTYPE][postageplus]\">";
  17. TransTpl += "<em class=\"add-on\">";
  18. TransTpl += "<i class=\"icon-renminbi\"><\/i>";
  19. TransTpl += "<\/em>\n";
  20. TransTpl += "<div class=\"J_DefaultMessage\"><\/div>\n";
  21. TransTpl += "<\/div>\n";
  22. TransTpl += "<div class=\"tbl-except\">\n";
  23. TransTpl += "<\/div>\n";
  24. TransTpl += "<div class=\"batch\" style=\"display:none\">\n";
  25. TransTpl += "<label><input class=\"J_BatchCheck\" type=\"checkbox\" aria-label=\"全选\" value=\"\" name=\"\">\n";
  26. TransTpl += "全选<\/label>\n";
  27. TransTpl += "&nbsp;<a class=\"J_BatchSet ncsc-btn-mini\" href=\"JavaScript:void(0);\">批量设置<\/a>\n";
  28. TransTpl += "<a class=\"J_BatchDel ncsc-btn-mini\" href=\"JavaScript:void(0);\">批量删除<\/a>\n";
  29. TransTpl += "<\/div>\n";
  30. TransTpl += "<div class=\"tbl-attach\">\n";
  31. TransTpl += "<div class=\"J_SpecialMessage\"><\/div>\n";
  32. TransTpl += "<a class=\"J_AddRule ncsc-btn-mini ml5\" href=\"JavaScript:void(0);\">";
  33. TransTpl += "<i class=\"icon-map-marker\"></i>为指定地区城市设置运费<\/a>\n";
  34. TransTpl += "<a class=\"J_ToggleBatch ncsc-btn-mini\" style=\"display:none\" href=\"JavaScript:void(0);\">";
  35. TransTpl += "<i class=\"icon-map-marker\"></i>批量操作<\/a>\n";
  36. TransTpl += "<\/div>\n";
  37. TransTpl += "<\/div>\n";
  38. TransTpl += "<\/div>\n";
  39. SpecialMessage = '';
  40. SpecialMessage += "<span error_type=\"area\" class=\"msg J_Message\" style=\"display:none\"><i class=\"icon-exclamation-sign\"><\/i>指定地区城市为空或指定错误<\/span>\n";
  41. SpecialMessage += "<span error_type=\"start\" class=\"msg J_Message\" style=\"display:none\"><i class=\"icon-exclamation-sign\"><\/i>首重应输入1至9999的数字<\/span>\n";
  42. SpecialMessage += "<span error_type=\"postage\" class=\"msg J_Message\" style=\"display:none\"><i class=\"icon-exclamation-sign\"><\/i>首费应输入0.00至999.99的数字<\/span>\n";
  43. SpecialMessage += "<span error_type=\"plus\" class=\"msg J_Message\" style=\"display:none\"><i class=\"icon-exclamation-sign\"><\/i>续重应输入1至9999的数字<\/span>\n";
  44. SpecialMessage += "<span error_type=\"postageplus\" class=\"msg J_Message\" style=\"display:none\"><i class=\"icon-exclamation-sign\"><\/i>续费应输入0.00至999.99的数字<\/span>\n";
  45. DefaultMessage = '';
  46. DefaultMessage += "<span error_type=\"start\" class=\"msg J_Message\" style=\"display:none\"><i class=\"icon-exclamation-sign\"><\/i>首重应输入1至9999的数字<\/span>\n";
  47. DefaultMessage += "<span error_type=\"postage\" class=\"msg J_Message\" style=\"display:none\"><i class=\"icon-exclamation-sign\"><\/i>首费应输入0.00至999.99的数字<\/span>\n";
  48. DefaultMessage += "<span error_type=\"plus\" class=\"msg J_Message\" style=\"display:none\"><i class=\"icon-exclamation-sign\"><\/i>续重应输入1至9999的数字<\/span>\n";
  49. DefaultMessage += "<span error_type=\"postageplus\" class=\"msg J_Message\" style=\"display:none\"><i class=\"icon-exclamation-sign\"><\/i>续费应输入0.00至999.99的数字<\/span>\n";
  50. //记录当前起始值
  51. StartNum = $('.tbl-except>table>tbody>tr').size();
  52. //头模板
  53. RuleHead += "<table cellspacing=\"0\" class=\"ncsc-table-style\" cellpadding=\"0\" border=\"0\">\n";
  54. RuleHead += "<colgroup>\n";
  55. RuleHead += "<col class=\"col-area\">\n";
  56. RuleHead += "<col class=\"col-start\">\n";
  57. RuleHead += "<col class=\"col-postage\">\n";
  58. RuleHead += "<col class=\"col-plus\">\n";
  59. RuleHead += "<col class=\"col-postageplus\">\n";
  60. RuleHead += "<col class=\"col-action\">\n";
  61. RuleHead += "<\/colgroup>\n";
  62. RuleHead += "<thead>\n";
  63. RuleHead += "<tr>\n";
  64. RuleHead += "<th>运送到<\/th>\n";
  65. RuleHead += "<th class=\"w60\">首重("+unit+")<\/th>\n";
  66. RuleHead += "<th class=\"w110\">首费(元)<\/th>\n";
  67. RuleHead += "<th class=\"w60\">续重("+unit+")<\/th>\n";
  68. RuleHead += "<th class=\"w110\">续费(元)<\/th>\n";
  69. RuleHead += "<th class=\"w110\">操作<\/th>\n";
  70. RuleHead += "<\/tr>\n";
  71. RuleHead += "<\/thead>\n";
  72. RuleHead += "<tbody>\n";
  73. RuleHead += "<\/tbody>\n";
  74. RuleHead += "<\/table>\n";
  75. //单行内容模板
  76. RuleCell += "<tr class=\"bd-line\" data-group=\"nCurNum\">\n";
  77. RuleCell += "<td class=\"cell-area\">\n";
  78. // RuleCell += "<a class=\"ncu-btn2\" title=\"编辑运送区域\" area-haspopup=\"true\" area-controls=\"J_DialogArea\" entype=\'J_EditArea\' data-acc=\"event:enter\" href=\"JavaScript:void(0);\">编辑<\/a>\n";
  79. RuleCell += "<span class=\"area-group\">\n";
  80. RuleCell += "<input class=\"J_BatchField\" style=\"width:15px; display:none\" type=\"checkbox\" value=\"\" name=\"TRANSTYPE_nCurNum\">\n";
  81. RuleCell += "<p style=\"display:inline-block\">未添加地区<\/p><\/span>\n";
  82. RuleCell += "<input type=\"hidden\" value=\"\" name=\"areas[TRANSTYPE][CurNum]\">\n";
  83. RuleCell += "<\/td>\n";
  84. RuleCell += "<td>\n";
  85. RuleCell += "<input class=\"text w30\" type=\"text\" aria-label=\"首重\" maxlength=\"4\" autocomplete=\"off\" value=\"1\" data-field=\"start\" name=\"special[TRANSTYPE][CurNum][start]\">\n";
  86. RuleCell += "<\/td>\n";
  87. RuleCell += "<td>\n";
  88. RuleCell += "<input class=\"text w60\" type=\"text\" aria-label=\"首费\" maxlength=\"6\" autocomplete=\"off\" value=\"\" data-field=\"postage\" name=\"special[TRANSTYPE][CurNum][postage]\"><em class=\"add-on\">\n";
  89. RuleCell += "<i class=\"icon-renminbi\"><\/i>\n";
  90. RuleCell += "<\/em>\n";
  91. RuleCell += "<\/td>\n";
  92. RuleCell += "<td>\n";
  93. RuleCell += "<input class=\"text w30\" type=\"text\" aria-label=\"续重\" maxlength=\"4\" autocomplete=\"off\" value=\"1\" data-field=\"plus\" name=\"special[TRANSTYPE][CurNum][plus]\">\n";
  94. RuleCell += "<\/td>\n";
  95. RuleCell += "<td>\n";
  96. RuleCell += "<input class=\"text w60\" type=\"text\" aria-label=\"续费\" maxlength=\"6\" autocomplete=\"off\" value=\"\" data-field=\"postageplus\" name=\"special[TRANSTYPE][CurNum][postageplus]\"><em class=\"add-on\">\n";
  97. RuleCell += "<i class=\"icon-renminbi\"><\/i>\n";
  98. RuleCell += "<\/em>\n";
  99. RuleCell += "<\/td>\n";
  100. RuleCell += "<td class=\"nscs-table-handle\">\n";
  101. RuleCell += "<span>\n";
  102. RuleCell += "<a class=\"btn-red J_DeleteRule\" ncNum=\"nCurNum\" href=\"JavaScript:void(0);\">\n";
  103. RuleCell += "<i class=\"icon-trash\"><\/i><p>删除<\/p>\n";
  104. RuleCell += "<\/a>\n";
  105. RuleCell += "<\/span>\n";
  106. RuleCell += "<span>\n";
  107. RuleCell += "<a class=\"btn-blue\" data-group=\"nCurNum\" title=\"编辑运送区域\" area-haspopup=\"true\" area-controls=\"J_DialogArea\" entype=\'J_EditArea\' data-acc=\"event:enter\" href=\"JavaScript:void(0);\">\n";
  108. RuleCell += "<i class=\"icon-edit\"><\/i><p>编辑<\/p>\n";
  109. RuleCell += "<\/a>\n";
  110. RuleCell += "<\/span>\n";
  111. RuleCell += "<\/td>\n";
  112. RuleCell += "<\/tr>\n";
  113. //删除当前行的唯一标识
  114. var curDelNum;
  115. /* 为指定地区设置运费,增加一行运费规则*/
  116. $('.trans-line').on('click','.J_AddRule',function(){
  117. StartNum +=1;
  118. if ($(this).parent().parent().find('.tbl-except').html().replace("\n",'') == ''){
  119. $(this).parent().parent().find('.tbl-except').append(RuleHead);
  120. }
  121. cell = RuleCell.replace(/CurNum/g,StartNum);
  122. cell = cell.replace(/TRANSTYPE/g,$(this).parent().parent().parent().attr('data-delivery'));
  123. $(this).parent().parent().find('.tbl-except').find('table').append(cell);
  124. //如果没有批量操作a链接,则添加
  125. if ($(this).parent().parent().find('input[type="checkbox"]').css('display') == 'none'){
  126. $(this).next().css('display','').html('批量操作');
  127. }else{
  128. $(this).next().css('display','').html('取消批量');
  129. $(this).parent().parent().find('.tbl-except').find('.J_BatchField:last').css('display','');
  130. }
  131. });
  132. /* 自定义转成整形的方法*/
  133. jQuery.fn.toInt = function() {
  134. var s = parseInt(jQuery(this).val().replace( /^0*/,''));
  135. return isNaN(s) ? 0 : s;
  136. };
  137. /* 关闭选择区域层*/
  138. $('#dialog_areas').on('click','.ks-ext-close',function(){
  139. $("#dialog_areas").css('display','none');
  140. $("#dialog_batch").css('display','none');
  141. $('.ks-ext-mask').css('display','none');
  142. return false;
  143. });
  144. $('#dialog_batch').on('click','.ks-ext-close',function(){
  145. $("#dialog_areas").css('display','none');
  146. $("#dialog_batch").css('display','none');
  147. $('.ks-ext-mask').css('display','none');
  148. return false;
  149. });
  150. /* 关闭选择区域层*/
  151. $('#dialog_areas').on('click','.J_Cancel',function(){
  152. $("#dialog_areas").css('display','none');
  153. $("#dialog_batch").css('display','none');
  154. $('.ks-ext-mask').css('display','none');
  155. });
  156. $('#dialog_batch').on('click','.J_Cancel',function(){
  157. $("#dialog_areas").css('display','none');
  158. $("#dialog_batch").css('display','none');
  159. $('.ks-ext-mask').css('display','none');
  160. });
  161. /* 选择完区域后,确定事重*/
  162. $('#dialog_areas').on('click','.J_Submit',function (){
  163. var CityText = '', CityText2 = '', CityValue = '';
  164. //记录已选择的所有省及市的value,SelectArea下标为value值,值为true,如江苏省SelectArea[320000]=true,南京市SelectArea[320100]=true
  165. // SelectArea = new Array();
  166. //取得已选的省市的text,返回给父级窗口,如果省份下的市被全选择,只返回显示省的名称,否则显示已选择的市的名称
  167. //首先找市被全部选择的省份
  168. $('#J_CityList').find('.ncsc-province-tab').each(function(){
  169. var a = $(this).find('input[type="checkbox"]').size();
  170. var b = $(this).find('input:checked').size();
  171. //市被全选的情况
  172. if (a == b){
  173. CityText += ($(this).find('.J_Province').next().html())+',';
  174. }else{
  175. //市被部分选中的情况
  176. $(this).find('.J_City').each(function(){
  177. //计算并准备传输选择的区域值(具体到市级ID),以,隔开
  178. if ($(this).attr('checked')){
  179. CityText2 += ($(this).next().html())+',';
  180. }
  181. });
  182. }
  183. });
  184. CityText += CityText2;
  185. //记录弹出层内所有已被选择的checkbox的值(省、市均记录),记录到CityValue,SelectArea中
  186. $('#J_CityList').find('.ncsc-province-list').find('input[type="checkbox"]').each(function(){
  187. if ($(this).attr('checked')){
  188. CityValue += $(this).val()+',';
  189. }
  190. });
  191. //去掉尾部的逗号
  192. CityText = CityText.replace(/(,*$)/g,'');
  193. CityValue = CityValue.replace(/(,*$)/g,'');
  194. //返回选择的文本内容
  195. if (CityText == '')CityText = '未添加地区';
  196. $(objCurlArea).find('.area-group>p').html(CityText);
  197. //返回选择的值到隐藏域
  198. $('input[name="areas['+curTransType+']['+curIndex.substring(1)+']"]').val(CityValue+'|||'+CityText);
  199. //关闭弹出层与遮罩层
  200. $("#dialog_areas").css('display','none');
  201. $('.ks-ext-mask').css('display','none');
  202. //清空check_num显示的数量
  203. $(".check_num").html('');
  204. $('#J_CityList').find('input[type="checkbox"]').attr('checked',false);
  205. //如果该配送方式,地区都不为空,隐藏地区的提示层
  206. isRemove = true;
  207. $('div[data-delivery="'+curTransType+'"]').find('input[type="hidden"]').each(function(){
  208. if ($(this).val()==''){
  209. isRemove = false;return false;
  210. }
  211. });
  212. if (isRemove == true){
  213. $('div[data-delivery="'+curTransType+'"]').find('span[error_type="area"]').css('display','none');
  214. }
  215. });
  216. /* 省份点击事重*/
  217. $('#dialog_areas').on('click','.J_Province',function(){
  218. if ($(this).attr('checked')){
  219. //选择所有未被disabled的子地区
  220. $(this).parent().find('.ncsc-citys-sub').eq(0).find('input[type="checkbox"]').each(function(){
  221. if (!$(this).attr('disabled')){
  222. $(this).attr('checked',true);
  223. }else{
  224. $(this).attr('checked',false);
  225. }
  226. });
  227. //计算并显示所有被选中的子地区数量
  228. num = '('+$(this).parent().find('.ncsc-citys-sub').eq(0).find('input:checked').size()+')';
  229. if (num == '(0)') num = '';
  230. $(this).parent().parent().find(".check_num").eq(0).html(num);
  231. //如果该大区域所有省都选中,该区域选中
  232. input_checked = $(this).parent().parent().parent().find('input:checked').size();
  233. input_all = $(this).parent().parent().parent().find('input[type="checkbox"]').size();
  234. if (input_all == input_checked){
  235. $(this).parent().parent().parent().parent().find('.J_Group').attr('checked',true);
  236. }
  237. }else{
  238. //取消全部子地区选择,取消显示数量
  239. $(this).parent().parent().find(".check_num").eq(0).html('');
  240. $(this).parent().find('.ncsc-citys-sub').eq(0).find('input[type="checkbox"]').attr('checked',false);
  241. //取消大区域选择
  242. $(this).parent().parent().parent().parent().find('.J_Group').attr('checked',false);
  243. }
  244. });
  245. /* 大区域点击事重(华北、华东、华南...)*/
  246. $('#dialog_areas').on('click','.J_Group',function(){
  247. if ($(this).attr('checked')){
  248. //区域内所有没有被disabled复选框选中,带disabled说明已经被选择过了,不能再选
  249. $(this).parent().parent().parent().find('input[type="checkbox"]').each(function(){
  250. if (!$(this).attr('disabled')){
  251. $(this).attr('checked',true);
  252. }else{
  253. $(this).attr('checked',false);
  254. }
  255. });
  256. //循环显示每个省下面的市级的数量
  257. $(this).parent().parent().parent().find('.ncsc-province-list').find('.ncsc-province').each(function(){
  258. //显示该省下面已选择的市的数量
  259. num = '('+$(this).find('.ncsc-citys-sub').find('input:checked').size()+')';
  260. //如果是0,说明没有选择,不显示数量
  261. if (num != '(0)'){
  262. $(this).find(".check_num").html(num);
  263. }
  264. });
  265. }else{
  266. //区域内所有筛选框取消选中
  267. $(this).parent().parent().parent().find('input[type="checkbox"]').attr('checked',false);
  268. //循环清空每个省下面显示的市级数量
  269. $(this).parent().parent().parent().find('.ncsc-province-list').find('.ncsc-province').each(function(){
  270. $(this).find(".check_num").html('');
  271. });
  272. }
  273. });
  274. /* 关闭弹出的市级小层*/
  275. $('#dialog_areas').on('click','.close_button',function(){
  276. $(this).parent().parent().parent().parent().removeClass('showCityPop');
  277. });
  278. /* 市级地区单事重*/
  279. $('#dialog_areas').on('click','.J_City',function(){
  280. //显示选择市级数量,在所属省后面
  281. num = '('+$(this).parent().parent().find('input:checked').size()+')';
  282. if (num=='(0)')num='';
  283. $(this).parent().parent().parent().find(".check_num").eq(0).html(num);
  284. //如果市级地区全部选中,则父级省份也选中,反之有一个不选中,则省份和大区域也不选中
  285. if (!$(this).attr('checked')){
  286. //取消省份选择
  287. $(this).parent().parent().parent().find('.J_Province').attr('checked',false);
  288. //取消大区域选择
  289. $(this).parent().parent().parent().parent().parent().parent().find('.J_Group').attr('checked',false);
  290. }else{
  291. //如果该省所有市都选中,该省选中
  292. input_checked = $(this).parent().parent().find('input:checked').size();
  293. input_all = $(this).parent().parent().find('input[type="checkbox"]').size();
  294. if (input_all == input_checked){
  295. $(this).parent().parent().parent().find('.J_Province').attr('checked',true);
  296. }
  297. //如果该大区域所有省都选中,该区域选中
  298. input_checked = $(this).parent().parent().parent().parent().parent().find('input:checked').size();
  299. input_all = $(this).parent().parent().parent().parent().parent().find('input[type="checkbox"]').size();
  300. if (input_all == input_checked){
  301. $(this).parent().parent().parent().parent().parent().parent().find('.J_Group').attr('checked',true);
  302. }
  303. }
  304. });
  305. /* 省份下拉事重*/
  306. $('#dialog_areas').on('click','.trigger',function () {
  307. objTrigger = this;objHead = $(this).parent();objPanel = $(this).next();
  308. if ($(this).next().css('display') == 'none'){
  309. //隐藏所有已弹出的省份下拉层,只显示当前点击的层
  310. $('.ks-contentbox').find('.ncsc-province').removeClass('showCityPop');
  311. $(this).parent().parent().addClass('showCityPop');
  312. }else{
  313. //隐藏当前的省份下拉层
  314. $(this).parent().parent().removeClass('showCityPop');
  315. }
  316. //点击省,市所在的head与panel层以外的区域均隐藏当前层
  317. var oHandle = $(this);
  318. // oHandle = document.getElementById($(this).attr('id'));//不兼容Ie8,废弃
  319. var de = document.documentElement?document.documentElement : document.body;
  320. de.onclick = function(e){
  321. var e = e || window.event;
  322. var target = e.target || e.srcElement;
  323. var getTar = target.getAttribute("id");
  324. while(target){
  325. //循环最外层一个时,会出现异常
  326. try{
  327. //jquery 转成DOM对象,比较两个DOM对象
  328. if(target==$(objHead)[0])return true;
  329. if(target==$(objPanel)[0])return true;
  330. //暂不考虑使用ID比较
  331. // if(target.getAttribute("id")==$(objHead).attr('id'))return true;
  332. // if(target.getAttribute("id")==$(objPanel).attr('id'))return true;
  333. }catch(ex){};
  334. target = target.parentNode;
  335. }
  336. $(objTrigger).parent().parent().removeClass('showCityPop');
  337. }
  338. });
  339. /* 选择运送区域*/
  340. $('.trans-line').on('click','a[entype="J_EditArea"]',function () {
  341. // curTransType = $(this).next().next().attr('name').substring(6,8);
  342. curTransType = 'kd';
  343. //取消所有已选择的checkbox
  344. $('#J_CityList').find('input[type="checkbox"]').attr('checked',false).attr('disabled',false);
  345. //取消显示所有统计数量
  346. $('#J_CityList').find('.check_num').html('');
  347. //记录当前行的标识n1,n2,n3....
  348. curIndex = $(this).attr('data-group');
  349. //记录当前操作的行,选择完地区会向该区域抛出值
  350. objCurlArea = $('tr[data-group="'+curIndex+'"]').children(1);
  351. //记录已选择的所有省及市的value,SelectArea下标为value值,值为true,如江苏省SelectArea[320000]=true,南京市SelectArea[320100]=true
  352. SelectArea = new Array();
  353. //取得当前行隐藏域内的city值,放入SelectArea数组中
  354. var expAreas = $('input[name="areas['+curTransType+']['+curIndex.substring(1)+']"]').val();
  355. expAreas = expAreas.split('|||');
  356. expAreas = expAreas[0].split(',');
  357. try{
  358. if(expAreas[0] != ''){
  359. for(var v in expAreas){
  360. SelectArea[expAreas[v]] = true;
  361. }
  362. }
  363. //初始化已选中的checkbox
  364. $('#J_CityList').find('.ncsc-province').each(function(){
  365. var count = 0;
  366. $(this).find('input[type="checkbox"]').each(function(){
  367. if(SelectArea[$(this).val()]==true){
  368. $(this).attr('checked',true);
  369. if($(this)[0].className!='J_Province') count++;
  370. }
  371. });
  372. if (count > 0){
  373. $(this).find('.check_num').html('('+count+')');
  374. }
  375. });
  376. //循环每一行,如果一行省都选中,则大区载选中
  377. $('#J_CityList>li').each(function(){
  378. $(this).find('.J_Group').attr('checked',true);
  379. father = this;
  380. $(this).find('.J_Province').each(function(){
  381. if (!$(this).attr('checked')){
  382. $(father).find('.J_Group').attr('checked',false);
  383. return ;
  384. }
  385. });
  386. });
  387. }catch(ex){}
  388. //其它行已选择的地区,不能再选择了
  389. $(objCurlArea).parent().parent().find('.area-group').each(function(){
  390. if ($(this).next().attr('name') != 'areas['+curTransType+']['+curIndex.substring(1)+']'){
  391. expAreas = $(this).next().val().split('|||');
  392. expAreas = expAreas[0].split(',');
  393. //重置SelectArea
  394. SelectArea = new Array();
  395. try{
  396. if(expAreas[0] != ''){
  397. for(var v in expAreas){
  398. SelectArea[expAreas[v]] = true;
  399. }
  400. }
  401. //其它行已选中的在这里都置灰
  402. $('#J_CityList').find('input[type="checkbox"]').each(function(){
  403. if(SelectArea[$(this).val()]==true){
  404. $(this).attr('disabled',true).attr('checked',false);
  405. }
  406. });
  407. //循环每一行,如果一行的省都被disabled,则大区域也disabled
  408. $('#J_CityList>li').each(function(){
  409. $(this).find('.J_Group').attr('disabled',true);
  410. father = this;
  411. $(this).find('.J_Province').each(function(){
  412. if (!$(this).attr('disabled')){
  413. $(father).find('.J_Group').attr('disabled',false);
  414. return ;
  415. }
  416. });
  417. });
  418. }catch(ex){}
  419. }
  420. });
  421. //定位弹出层的坐标
  422. var pos = $(this).position();
  423. $("#dialog_areas").css({'position' : 'fixed','display' : 'block', 'z-index' : '9999'});
  424. $('.ks-ext-mask').css('display','block');
  425. });
  426. $('#title').blur(function(){
  427. if ($(this).val() !=''){
  428. $('p[error_type="title"]').css('display','none');
  429. }
  430. });
  431. /* 首费离开校验*/
  432. $('.trans-line').on('blur','input[data-field="postage"]',function (){
  433. var oNum = new Number($(this).val());
  434. oNum = oNum.toFixed(2);
  435. if (oNum > 999.99) oNum = 999.99;
  436. if (oNum=='NaN') oNum = '0.00';
  437. $(this).val(oNum);
  438. if($(this)[0].className=='w50 mr5 text input-error') $(this).removeClass('input-error');
  439. if($(this)[0].className=='w50 ml5 mr5 text input-error') $(this).removeClass('input-error');
  440. if($(this).parent()[0].className=='default J_DefaultSet'){
  441. //首费不为空了,如果是默认的首费,隐藏提示层span
  442. $(this).parent().find('.J_DefaultMessage').find('span[error_type="postage"]').css('display','none');
  443. }else{
  444. //如果是动态添加的首费,当所有首费输入框都不为空时,提示层span隐藏
  445. isRemove = true;
  446. $(this).parent().parent().parent().find('input[data-field="postage"]').each(function(){
  447. if ($(this).val()==''){
  448. isRemove = false;return false;
  449. }
  450. });
  451. //提示层span隐藏
  452. if (isRemove == true){
  453. $(this).parent().parent().parent().parent().parent().parent().find('.tbl-attach').find('.J_SpecialMessage').find('span[error_type="postage"]').css('display','none');
  454. }
  455. }
  456. });
  457. /* 续费离开校验*/
  458. $('.trans-line').on('blur','input[data-field="postageplus"]',function (){
  459. var oNum = new Number($(this).val());
  460. oNum = oNum.toFixed(2);
  461. if (oNum > 999.99) oNum = 999.99;
  462. if (oNum=='NaN') oNum = '0.00';
  463. $(this).val(oNum);
  464. if($(this)[0].className=='w50 mr5 text input-error') $(this).removeClass('input-error');
  465. if($(this)[0].className=='w50 ml5 mr5 text input-error') $(this).removeClass('input-error');
  466. if($(this).parent()[0].className=='default J_DefaultSet'){
  467. //续费不为空了,如果是默认的首费,隐藏提示层span
  468. $(this).parent().find('.J_DefaultMessage').find('span[error_type="postageplus"]').css('display','none');
  469. }else{
  470. //如果是动态添加的首费,当所有续费输入框都不为空时,提示层span隐藏
  471. isRemove = true;
  472. $(this).parent().parent().parent().find('input[data-field="postageplus"]').each(function(){
  473. if ($(this).val()==''){
  474. isRemove = false;return false;
  475. }
  476. });
  477. //提示层span隐藏
  478. if (isRemove == true){
  479. $(this).parent().parent().parent().parent().parent().parent().find('.tbl-attach').find('.J_SpecialMessage').find('span[error_type="postageplus"]').css('display','none');
  480. }
  481. }
  482. });
  483. /* 续重离开校验*/
  484. $('.trans-line').on('blur','input[data-field="plus"]',function (){
  485. if ($(this).val() != ''){
  486. $(this).val($(this).toInt());
  487. }else{
  488. $(this).val(1);
  489. }
  490. });
  491. /* 首重离开校验*/
  492. $('.trans-line').on('blur','input[data-field="start"]',function (){
  493. if ($(this).val() != ''){
  494. $(this).val($(this).toInt());
  495. }else{
  496. $(this).val(1);
  497. }
  498. });
  499. /* 删除一行运费规则*/
  500. $('.trans-line').on('click','.J_DeleteRule',function (){
  501. curDelNum = $(this).attr('ncNum');
  502. showDialog('确认删除吗?', 'confirm','', function(){
  503. // curTransType = $(this).parent().parent().parent().find('input[type="hidden"]').eq(0).attr('name').substring(6,8);
  504. // obj_parent = $(this).parent().parent().parent();
  505. curTransType = 'kd';
  506. obj_parent = $('tr[data-group="'+curDelNum+'"]').parent();
  507. $('tr[data-group="'+curDelNum+'"]').remove();
  508. if ($(obj_parent).find('tr').html() == null){
  509. $(obj_parent).parent().parent().parent().find('.batch').css('display','none');
  510. $(obj_parent).parent().parent().parent().find('.J_ToggleBatch').css('display','none');
  511. $(obj_parent).parent().parent().parent().find('.batch').next().find('span').css('display','none');
  512. }else{
  513. //如果该配送方式,地区都不为空,隐藏地区的提示层
  514. isRemove = true;
  515. $('div[data-delivery="'+curTransType+'"]').find('input[type="hidden"]').each(function(){
  516. if ($(this).val()==''){
  517. isRemove = false;return false;
  518. }
  519. });
  520. if (isRemove == true){
  521. $('div[data-delivery="'+curTransType+'"]').find('span[error_type="area"]').css('display','none');
  522. }
  523. }
  524. });
  525. });
  526. /*批量操作*/
  527. $('.trans-line').on('click','.J_ToggleBatch',function(){
  528. if ($(this).parent().parent().find('.J_BatchField').eq(0).css('display')=='none'){
  529. $(this).parent().parent().find('.batch').css('display','');
  530. $(this).parent().parent().find('.batch').find('.J_BatchCheck').attr('checked',false);
  531. $(this).parent().parent().find('.J_BatchField').css('display','');
  532. $(this).html('取消批量');
  533. }else{
  534. $(this).parent().parent().find('.batch').css('display','none');
  535. $(this).parent().parent().find('.J_BatchField').css('display','none');
  536. $(this).html('批量操作');
  537. }
  538. });
  539. /*运费规则单行复选框事重*/
  540. $('.trans-line').on('click','.J_BatchField',function(){
  541. if (!$(this).attr('checked')){
  542. obj_parent = $(this).parent().parent().parent().parent().parent().parent().parent();
  543. $(obj_parent).find('.J_BatchCheck').attr('checked',false);
  544. }else{
  545. obj_tbody = $(this).parent().parent().parent().parent();
  546. checkbox_count = $(obj_tbody).find('.J_BatchField').size();
  547. checked_count = $(obj_tbody).find('input:checked').size();
  548. if (checkbox_count == checked_count){
  549. obj_parent = $(this).parent().parent().parent().parent().parent().parent().parent();
  550. $(obj_parent).find('.J_BatchCheck').attr('checked',true);
  551. }
  552. }
  553. });
  554. /*批量设置全选*/
  555. $('.trans-line').on('click','.J_BatchCheck',function(){
  556. $('.J_BatchField').attr('checked',$(this).attr('checked') == 'checked' ? 'checked' : false);
  557. });
  558. /*批量设置弹出层*/
  559. $('.trans-line').on('click','.J_BatchSet',function(){
  560. if($('.tbl-except').find('input:checked').size()==0){
  561. showDialog('请选择要批量设置的地区', 'error','','','','','','','','',2);return false;
  562. }
  563. //定义当前的父级框,来区分是在EXPRESS,EMS,POST哪种弹出的
  564. // curTrans = $(this).parent().parent();
  565. //定位弹出层的坐标
  566. var pos = $(this).position();
  567. var pos_x = pos.left-20;
  568. var pos_y = pos.top+20;
  569. $("#dialog_batch").css({'position' : 'fixed','display' : 'block', 'z-index' : '9999'});
  570. $('.ks-ext-mask').css('display','block');
  571. });
  572. /*批量删除*/
  573. $('.trans-line').on('click','.J_BatchDel',function(){
  574. if($(this).parent().parent().find('.tbl-except').find('input:checked').size()==0){
  575. showDialog('请选择要批量处理的地区', 'error','','','','','','','','',2);return false;
  576. }
  577. showDialog('确认删除吗?', 'confirm','', function(){
  578. $('tr[class="bd-line"]').each(function(){
  579. if ($(this).find('.J_BatchField').attr('checked')){
  580. $(this).remove();
  581. }
  582. });
  583. if ($('.tbl-except').find('table>tbody>tr').length == 0){
  584. $('.entity').find('.batch').css('display','none');
  585. $('.J_ToggleBatch').css('display','none');
  586. $('.entity').find('.batch').next().find('span').css('display','none');
  587. }else{
  588. // curTransType = $(this).parent().prev().find('input[type="hidden"]').eq(0).attr('name').substring(6,8);
  589. curTransType = 'kd';
  590. //如果该配送方式,地区都不为空,隐藏地区的提示层
  591. isRemove = true;
  592. $('div[data-delivery="'+curTransType+'"]').find('input[type="hidden"]').each(function(){
  593. if ($(this).val()==''){
  594. isRemove = false;return false;
  595. }
  596. });
  597. if (isRemove == true){
  598. $('div[data-delivery="'+curTransType+'"]').find('span[error_type="area"]').css('display','none');
  599. }
  600. }
  601. });
  602. });
  603. /*批量设置页面提交事重*/
  604. $('#dialog_batch').on('click','.J_SubmitPL',function(){
  605. var obj_this = $(this).parent().parent();
  606. $('.tbl-except>table>tbody>tr').each(function(){
  607. if ($(this).find('.J_BatchField').attr('checked')){
  608. $(this).find('input[data-field="start"]').val($(obj_this).find('input[data-field="start"]').val()).removeClass('input-error');
  609. $(this).find('input[data-field="postage"]').val($(obj_this).find('input[data-field="postage"]').val()).removeClass('input-error');
  610. $(this).find('input[data-field="plus"]').val($(obj_this).find('input[data-field="plus"]').val()).removeClass('input-error');
  611. $(this).find('input[data-field="postageplus"]').val($(obj_this).find('input[data-field="postageplus"]').val()).removeClass('input-error');
  612. }
  613. });
  614. $("#dialog_batch").css('display','none');
  615. $('.ks-ext-mask').css('display','none');
  616. });
  617. /*保存运费模板*/
  618. $('#submit_tpl').on('click',function(){
  619. $('.J_SpecialMessage').html(SpecialMessage);
  620. $('.J_DefaultSet').find('.J_DefaultMessage').html(DefaultMessage);
  621. isSubmit = true;
  622. //首重跟续重由于有默认值,鼠标离开也有默认值,这里只需判断首费与续费即可
  623. //首费JS空判断-------------------------------
  624. father = $('.entity');
  625. //只判断已显示的,即只判断EMS、平邮、快递中已选择的内容
  626. var obj = $('.entity').find('.J_DefaultSet').find('input[data-field="postage"]');
  627. if(!$(obj).val()){
  628. isShowError = false;
  629. if($(obj).val()==''){
  630. $(obj).addClass('input-error'); isShowError = true; isSubmit = false;
  631. }else{
  632. $(obj).removeClass('input-error');
  633. }
  634. if (isShowError){
  635. $('.entity').find('.J_DefaultSet').find('span[error_type="postage"]').show();
  636. }
  637. }
  638. //续费JS空判断-------------------------------
  639. //只判断已显示的,即只判断EMS、平邮、快递中已选择的内容
  640. var obj = $('.entity').find('.J_DefaultSet').find('input[data-field="postageplus"]');
  641. if(!$(obj).val()){
  642. isShowError = false;
  643. if($(obj).val()==''){
  644. $(obj).addClass('input-error'); isShowError = true; isSubmit = false;
  645. }else{
  646. $(obj).removeClass('input-error');
  647. }
  648. if (isShowError){
  649. $('.entity').find('.J_DefaultSet').find('span[error_type="postageplus"]').show();
  650. }
  651. }
  652. //地区空判断-------------------------------
  653. //只判断已显示的,即只判断EMS、平邮、快递中已选择的内容
  654. if($('.tbl-except').find('.cell-area').html() != null){
  655. isShowError = false;
  656. $('.tbl-except').find('tbody>tr').each(function(){
  657. if($(this).find('input[type="hidden"]').val()==''){
  658. isShowError = true; isSubmit = false; return false;
  659. }
  660. });
  661. if (isShowError){
  662. $(father).find('.tbl-attach').find('span[error_type="area"]').css('display','');
  663. }
  664. }
  665. //首费JS空判断-------------------------------
  666. //只判断已显示的,即只判断EMS、平邮、快递中已选择的内容
  667. if($('.tbl-except').find('.cell-area').html() != null){
  668. isShowError = false;
  669. $('.tbl-except').find('input[data-field="postage"]').each(function(){
  670. if ($(this).val()==''){
  671. $(this).addClass('input-error');isShowError = true; isSubmit = false;
  672. }
  673. });
  674. if (isShowError){
  675. $('.tbl-attach').find('span[error_type="postage"]').show();
  676. }
  677. }
  678. //续费JS空判断-------------------------------
  679. //只判断已显示的,即只判断EMS、平邮、快递中已选择的内容
  680. if($('.tbl-except').find('.cell-area').html() != null){
  681. isShowError = false;
  682. $('.tbl-except').find('input[data-field="postageplus"]').each(function(){
  683. if ($(this).val()==''){
  684. $(this).addClass('input-error'); isShowError = true; isSubmit = false;
  685. }
  686. });
  687. if (isShowError){
  688. $('.tbl-attach').find('span[error_type="postageplus"]').css('display','');
  689. }
  690. }
  691. //运费模板名称校验
  692. if ($('#title').val()==''){
  693. isSubmit = false;
  694. $('p[error_type="title"]').css('display','');
  695. }else{
  696. $('p[error_type="title"]').css('display','none');
  697. }
  698. //请至少选择一种运送方式
  699. i=0;
  700. $('input[name="tplType[]"]').each(function(){
  701. if (!$(this).attr('checked')){
  702. i++;
  703. }
  704. });
  705. if (i==3){
  706. isSubmit = false;
  707. $('p[error_type="trans_type"]').css('display','');
  708. }
  709. if (isSubmit == true){
  710. return true;
  711. }else{
  712. return false;
  713. }
  714. });
  715. });