transport.js 35 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779
  1. $(function(){
  2. //定义售卖区域主体模板、头模板、单行显示模板
  3. TransTpl = ''; RuleHead = ''; RuleCell = '';
  4. TransTpl += "<div class=\"dssu-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=\"默认运费件数\" maxlength=\"4\" autocomplete=\"off\" data-field=\"start\" value=\"1\" name=\"default[TRANSTYPE][start]\">\n";
  9. TransTpl += "<span class=\"content_1\">件</span>内,\n";
  10. TransTpl += "<input class=\"w60 text\" type=\"text\" aria-label=\"默认运费价格\" maxlength=\"6\" autocomplete=\"off\" value=\"0\" name=\"default[TRANSTYPE][postage]\" data-field=\"postage\">";
  11. TransTpl += "<em class=\"add-on\">";
  12. TransTpl += "<i class=\"iconfont\">&#xe65c;<\/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 += "<span class=\"content_1\">件</span>, 增加运费\n";
  16. TransTpl += "<input class=\"w50 ml5 text\" type=\"text\" aria-label=\"加件运费\" maxlength=\"6\" autocomplete=\"off\" value=\"0\" data-field=\"postageplus\" name=\"default[TRANSTYPE][postageplus]\">";
  17. TransTpl += "<em class=\"add-on\">";
  18. TransTpl += "<i class=\"iconfont\">&#xe65c;<\/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 dssc-btn-mini\" href=\"JavaScript:void(0);\">批量设置<\/a>\n";
  28. TransTpl += "<a class=\"J_BatchDel dssc-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 dssc-btn-mini ml5\" href=\"JavaScript:void(0);\">";
  33. TransTpl += "<i class=\"iconfont\">&#xe720;</i>为指定地区城市设置运费<\/a>\n";
  34. TransTpl += "<a class=\"J_ToggleBatch dssc-btn-mini\" style=\"display:none\" href=\"JavaScript:void(0);\">";
  35. TransTpl += "<i class=\"iconfont\">&#xe720;</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=\"iconfont\">&#xe64c;<\/i>指定地区城市为空或指定错误<\/span>\n";
  41. SpecialMessage += "<span error_type=\"start\" class=\"msg J_Message\" style=\"display:none\"><i class=\"iconfont\">&#xe64c;<\/i>首件应输入1至9999的数字<\/span>\n";
  42. SpecialMessage += "<span error_type=\"postage\" class=\"msg J_Message\" style=\"display:none\"><i class=\"iconfont\">&#xe64c;<\/i>首费应输入0.00至999.99的数字<\/span>\n";
  43. SpecialMessage += "<span error_type=\"plus\" class=\"msg J_Message\" style=\"display:none\"><i class=\"iconfont\">&#xe64c;<\/i>续件应输入1至9999的数字<\/span>\n";
  44. SpecialMessage += "<span error_type=\"postageplus\" class=\"msg J_Message\" style=\"display:none\"><i class=\"iconfont\">&#xe64c;<\/i>续费应输入0.00至999.99的数字<\/span>\n";
  45. DefaultMessage = '';
  46. DefaultMessage += "<span error_type=\"start\" class=\"msg J_Message\" style=\"display:none\"><i class=\"iconfont\">&#xe64c;<\/i>首件应输入1至9999的数字<\/span>\n";
  47. DefaultMessage += "<span error_type=\"postage\" class=\"msg J_Message\" style=\"display:none\"><i class=\"iconfont\">&#xe64c;<\/i>首费应输入0.00至999.99的数字<\/span>\n";
  48. DefaultMessage += "<span error_type=\"plus\" class=\"msg J_Message\" style=\"display:none\"><i class=\"iconfont\">&#xe64c;<\/i>续件应输入1至9999的数字<\/span>\n";
  49. DefaultMessage += "<span error_type=\"postageplus\" class=\"msg J_Message\" style=\"display:none\"><i class=\"iconfont\">&#xe64c;<\/i>续费应输入0.00至999.99的数字<\/span>\n";
  50. //记录当前起始值
  51. StartNum = $('.tbl-except>table>tbody>tr').size();
  52. //头模板
  53. RuleHead += "<table cellspacing=\"0\" class=\"dssc-table-style\" style=\"width:100%\" 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 style='border-bottom: 1px solid #ddd;'>\n";
  64. RuleHead += "<th style='padding-left:5px'>运送到<\/th>\n";
  65. RuleHead += "<th class=\"w60\"><span class=\"title_1\">首件</span>(<span class=\"content_1\">件</span>)<\/th>\n";
  66. RuleHead += "<th class=\"w110\">首费(元)<\/th>\n";
  67. RuleHead += "<th class=\"w60\"><span class=\"title_2\">续件</span>(<span class=\"content_1\">件</span>)<\/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\" style='padding-left:5px'>\n";
  78. // RuleCell += "<a class=\"dsu-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=\"iconfont\">&#xe65c;<\/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=\"iconfont\">&#xe65c;<\/i>\n";
  98. RuleCell += "<\/em>\n";
  99. RuleCell += "<\/td>\n";
  100. RuleCell += "<td class=\"dscs-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=\"iconfont\">&#xe725;<\/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=\"iconfont\">&#xe61d;<\/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('.dssc-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).is(':checked')){
  179. CityText2 += ($(this).next().html())+',';
  180. }
  181. });
  182. }
  183. });
  184. CityText += CityText2;
  185. //记录弹出层内所有已被选择的checkbox的值(省、市均记录),记录到CityValue,SelectArea中
  186. $('#J_CityList').find('.dssc-province-list').find('input[type="checkbox"]').each(function(){
  187. if ($(this).is(':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"]').prop('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).is(':checked')){
  219. //选择所有未被disabled的子地区
  220. $(this).parent().find('.dssc-citys-sub').eq(0).find('input[type="checkbox"]').each(function(){
  221. if ($(this).is(':checked')==false){
  222. $(this).prop('checked',true);
  223. }else{
  224. $(this).prop('checked',false);
  225. }
  226. });
  227. //计算并显示所有被选中的子地区数量
  228. num = '('+$(this).parent().find('.dssc-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').prop('checked',true);
  236. }
  237. }else{
  238. //取消全部子地区选择,取消显示数量
  239. $(this).parent().parent().find(".check_num").eq(0).html('');
  240. $(this).parent().find('.dssc-citys-sub').eq(0).find('input[type="checkbox"]').prop('checked',false);
  241. //取消大区域选择
  242. $(this).parent().parent().parent().parent().find('.J_Group').prop('checked',false);
  243. }
  244. });
  245. /* 大区域点击事件(华北、华东、华南...)*/
  246. $('#dialog_areas').on('click','.J_Group',function(){
  247. if ($(this).prop('checked')){
  248. //区域内所有没有被disabled复选框选中,带disabled说明已经被选择过了,不能再选
  249. $(this).parent().parent().parent().find('input[type="checkbox"]').each(function(){
  250. if (!$(this).prop('disabled')){
  251. $(this).prop('checked',true);
  252. }else{
  253. $(this).prop('checked',false);
  254. }
  255. });
  256. //循环显示每个省下面的市级的数量
  257. $(this).parent().parent().parent().find('.dssc-province-list').find('.dssc-province').each(function(){
  258. //显示该省下面已选择的市的数量
  259. num = '('+$(this).find('.dssc-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"]').prop('checked',false);
  268. //循环清空每个省下面显示的市级数量
  269. $(this).parent().parent().parent().find('.dssc-province-list').find('.dssc-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).prop('checked')){
  286. //取消省份选择
  287. $(this).parent().parent().parent().find('.J_Province').prop('checked',false);
  288. //取消大区域选择
  289. $(this).parent().parent().parent().parent().parent().parent().find('.J_Group').prop('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').prop('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').prop('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('.dssc-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"]').prop('checked',false).prop('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('.dssc-province').each(function(){
  365. var count = 0;
  366. $(this).find('input[type="checkbox"]').each(function(){
  367. if(SelectArea[$(this).val()]==true){
  368. $(this).prop('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').prop('checked',true);
  379. father = this;
  380. $(this).find('.J_Province').each(function(){
  381. if (!$(this).prop('checked')){
  382. $(father).find('.J_Group').prop('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).prop('disabled',true).prop('checked',false);
  405. }
  406. });
  407. //循环每一行,如果一行的省都被disabled,则大区域也disabled
  408. $('#J_CityList>li').each(function(){
  409. $(this).find('.J_Group').prop('disabled',true);
  410. father = this;
  411. $(this).find('.J_Province').each(function(){
  412. if (!$(this).prop('disabled')){
  413. $(father).find('.J_Group').prop('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. layer.confirm('确认删除吗?', {
  503. btn: ['确定', '取消'],
  504. }, function (delete_confirm) {
  505. // curTransType = $(this).parent().parent().parent().find('input[type="hidden"]').eq(0).attr('name').substring(6,8);
  506. // obj_parent = $(this).parent().parent().parent();
  507. curTransType = 'kd';
  508. obj_parent = $('tr[data-group="' + curDelNum + '"]').parent();
  509. $('tr[data-group="' + curDelNum + '"]').remove();
  510. if ($(obj_parent).find('tr').html() == null) {
  511. $(obj_parent).parent().parent().parent().find('.batch').css('display', 'none');
  512. $(obj_parent).parent().parent().parent().find('.J_ToggleBatch').css('display', 'none');
  513. $(obj_parent).parent().parent().parent().find('.batch').next().find('span').css('display', 'none');
  514. } else {
  515. //如果该配送方式,地区都不为空,隐藏地区的提示层
  516. isRemove = true;
  517. $('div[data-delivery="' + curTransType + '"]').find('input[type="hidden"]').each(function () {
  518. if ($(this).val() == '') {
  519. isRemove = false;
  520. return false;
  521. }
  522. });
  523. if (isRemove == true) {
  524. $('div[data-delivery="' + curTransType + '"]').find('span[error_type="area"]').css('display', 'none');
  525. }
  526. }
  527. layer.close(delete_confirm);
  528. });
  529. });
  530. /*批量操作*/
  531. $('.trans-line').on('click','.J_ToggleBatch',function(){
  532. if ($(this).parent().parent().find('.J_BatchField').eq(0).css('display')=='none'){
  533. $(this).parent().parent().find('.batch').css('display','');
  534. $(this).parent().parent().find('.batch').find('.J_BatchCheck').prop('checked',false);
  535. $(this).parent().parent().find('.J_BatchField').css('display','');
  536. $(this).html('取消批量');
  537. }else{
  538. $(this).parent().parent().find('.batch').css('display','none');
  539. $(this).parent().parent().find('.J_BatchField').css('display','none');
  540. $(this).html('批量操作');
  541. }
  542. });
  543. /*运费规则单行复选框事件*/
  544. $('.trans-line').on('click','.J_BatchField',function(){
  545. if (!$(this).prop('checked')){
  546. obj_parent = $(this).parent().parent().parent().parent().parent().parent().parent();
  547. $(obj_parent).find('.J_BatchCheck').prop('checked',false);
  548. }else{
  549. obj_tbody = $(this).parent().parent().parent().parent();
  550. checkbox_count = $(obj_tbody).find('.J_BatchField').size();
  551. checked_count = $(obj_tbody).find('input:checked').size();
  552. if (checkbox_count == checked_count){
  553. obj_parent = $(this).parent().parent().parent().parent().parent().parent().parent();
  554. $(obj_parent).find('.J_BatchCheck').prop('checked',true);
  555. }
  556. }
  557. });
  558. /*批量设置全选*/
  559. $('.trans-line').on('click','.J_BatchCheck',function(){
  560. $('.J_BatchField').prop('checked',$(this).prop('checked') == true ? 'checked' : false);
  561. });
  562. /*批量设置弹出层*/
  563. $('.trans-line').on('click','.J_BatchSet',function(){
  564. if($('.tbl-except').find('input:checked').size()==0){
  565. layer.alert('请选择要批量设置的地区');return false;
  566. }
  567. //定义当前的父级框,来区分是在EXPRESS,EMS,POST哪种弹出的
  568. // curTrans = $(this).parent().parent();
  569. //定位弹出层的坐标
  570. var pos = $(this).position();
  571. var pos_x = pos.left-20;
  572. var pos_y = pos.top+20;
  573. $("#dialog_batch").css({'position' : 'fixed','display' : 'block', 'z-index' : '9999'});
  574. $('.ks-ext-mask').css('display','block');
  575. });
  576. /*批量删除*/
  577. $('.trans-line').on('click', '.J_BatchDel', function () {
  578. if ($(this).parent().parent().find('.tbl-except').find('input:checked').size() == 0) {
  579. layer.alert('请选择要批量处理的地区');
  580. return false;
  581. }
  582. layer.confirm('确认删除吗?', {
  583. btn: ['确定', '取消'],
  584. }, function (batch_delete_confirm) {
  585. $('tr[class="bd-line"]').each(function () {
  586. if ($(this).find('.J_BatchField').prop('checked')) {
  587. $(this).remove();
  588. }
  589. });
  590. if ($('.tbl-except').find('table>tbody>tr').length == 0) {
  591. $('.entity').find('.batch').css('display', 'none');
  592. $('.J_ToggleBatch').css('display', 'none');
  593. $('.entity').find('.batch').next().find('span').css('display', 'none');
  594. } else {
  595. // curTransType = $(this).parent().prev().find('input[type="hidden"]').eq(0).attr('name').substring(6,8);
  596. curTransType = 'kd';
  597. //如果该配送方式,地区都不为空,隐藏地区的提示层
  598. isRemove = true;
  599. $('div[data-delivery="' + curTransType + '"]').find('input[type="hidden"]').each(function () {
  600. if ($(this).val() == '') {
  601. isRemove = false;
  602. return false;
  603. }
  604. });
  605. if (isRemove == true) {
  606. $('div[data-delivery="' + curTransType + '"]').find('span[error_type="area"]').css('display', 'none');
  607. }
  608. }
  609. layer.close(batch_delete_confirm);
  610. });
  611. });
  612. /*批量设置页面提交事件*/
  613. $('#dialog_batch').on('click','.J_SubmitPL',function(){
  614. var obj_this = $(this).parent().parent();
  615. $('.tbl-except>table>tbody>tr').each(function(){
  616. if ($(this).find('.J_BatchField').prop('checked')){
  617. $(this).find('input[data-field="start"]').val($(obj_this).find('input[data-field="start"]').val()).removeClass('input-error');
  618. $(this).find('input[data-field="postage"]').val($(obj_this).find('input[data-field="postage"]').val()).removeClass('input-error');
  619. $(this).find('input[data-field="plus"]').val($(obj_this).find('input[data-field="plus"]').val()).removeClass('input-error');
  620. $(this).find('input[data-field="postageplus"]').val($(obj_this).find('input[data-field="postageplus"]').val()).removeClass('input-error');
  621. }
  622. });
  623. $("#dialog_batch").css('display','none');
  624. $('.ks-ext-mask').css('display','none');
  625. });
  626. /*保存售卖区域*/
  627. $('#submit_tpl').on('click',function(){
  628. $('.J_SpecialMessage').html(SpecialMessage);
  629. $('.J_DefaultSet').find('.J_DefaultMessage').html(DefaultMessage);
  630. isSubmit = true;
  631. //首件跟续件由于有默认值,鼠标离开也有默认值,这里只需判断首费与续费即可
  632. //首费JS空判断-------------------------------
  633. father = $('.entity');
  634. //只判断已显示的,即只判断EMS、平邮、快递中已选择的内容
  635. var obj = $('.entity').find('.J_DefaultSet').find('input[data-field="postage"]');
  636. if(!$(obj).val()){
  637. isShowError = false;
  638. if($(obj).val()==''){
  639. $(obj).addClass('input-error'); isShowError = true; isSubmit = false;
  640. }else{
  641. $(obj).removeClass('input-error');
  642. }
  643. if (isShowError){
  644. $('.entity').find('.J_DefaultSet').find('span[error_type="postage"]').show();
  645. }
  646. }
  647. //续费JS空判断-------------------------------
  648. //只判断已显示的,即只判断EMS、平邮、快递中已选择的内容
  649. var obj = $('.entity').find('.J_DefaultSet').find('input[data-field="postageplus"]');
  650. if(!$(obj).val()){
  651. isShowError = false;
  652. if($(obj).val()==''){
  653. $(obj).addClass('input-error'); isShowError = true; isSubmit = false;
  654. }else{
  655. $(obj).removeClass('input-error');
  656. }
  657. if (isShowError){
  658. $('.entity').find('.J_DefaultSet').find('span[error_type="postageplus"]').show();
  659. }
  660. }
  661. //地区空判断-------------------------------
  662. //只判断已显示的,即只判断EMS、平邮、快递中已选择的内容
  663. if($('.tbl-except').find('.cell-area').html() != null){
  664. isShowError = false;
  665. $('.tbl-except').find('tbody>tr').each(function(){
  666. if($(this).find('input[type="hidden"]').val()==''){
  667. isShowError = true; isSubmit = false; return false;
  668. }
  669. });
  670. if (isShowError){
  671. $(father).find('.tbl-attach').find('span[error_type="area"]').css('display','');
  672. }
  673. }
  674. //首费JS空判断-------------------------------
  675. //只判断已显示的,即只判断EMS、平邮、快递中已选择的内容
  676. if($('.tbl-except').find('.cell-area').html() != null){
  677. isShowError = false;
  678. $('.tbl-except').find('input[data-field="postage"]').each(function(){
  679. if ($(this).val()==''){
  680. $(this).addClass('input-error');isShowError = true; isSubmit = false;
  681. }
  682. });
  683. if (isShowError){
  684. $('.tbl-attach').find('span[error_type="postage"]').show();
  685. }
  686. }
  687. //续费JS空判断-------------------------------
  688. //只判断已显示的,即只判断EMS、平邮、快递中已选择的内容
  689. if($('.tbl-except').find('.cell-area').html() != null){
  690. isShowError = false;
  691. $('.tbl-except').find('input[data-field="postageplus"]').each(function(){
  692. if ($(this).val()==''){
  693. $(this).addClass('input-error'); isShowError = true; isSubmit = false;
  694. }
  695. });
  696. if (isShowError){
  697. $('.tbl-attach').find('span[error_type="postageplus"]').css('display','');
  698. }
  699. }
  700. //售卖区域名称校验
  701. if ($('#title').val()==''){
  702. isSubmit = false;
  703. $('p[error_type="title"]').css('display','');
  704. }else{
  705. $('p[error_type="title"]').css('display','none');
  706. }
  707. //请至少选择一种运送方式
  708. i=0;
  709. $('input[name="tplType[]"]').each(function(){
  710. if (!$(this).prop('checked')){
  711. i++;
  712. }
  713. });
  714. if (i==3){
  715. isSubmit = false;
  716. $('p[error_type="trans_type"]').css('display','');
  717. }
  718. if (isSubmit == true){
  719. return true;
  720. }else{
  721. return false;
  722. }
  723. });
  724. });