Test.js 92 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273
  1. MWF.xDesktop.requireApp("Template", "MPopupForm", null, false);
  2. MWF.xDesktop.requireApp("cms.Module", "ExcelForm", null, false);
  3. this.define("dipatchNumberToCity", function(){
  4. var ids = this.getSelectedId();
  5. if( ids.length == 0 ){
  6. this.form.app.notice("先选择号码","error");
  7. return;
  8. }
  9. var units = this.getLevel1Unit();
  10. var unitList = [];
  11. units.each( function( u ){
  12. unitList.push({
  13. name : u.name,
  14. id : u.distinguishedName
  15. })
  16. });
  17. MWF.xDesktop.requireApp("Template", "Selector.Custom", null, false);
  18. var opt = {
  19. "count": 1,
  20. "title": "选择分配的组织",
  21. "selectableItems" : unitList,
  22. "values": [],
  23. "onComplete": function( array ){
  24. if( !array || array.length == 0 )return;
  25. var unit = array[0].data.id;
  26. if( !unit )return;
  27. this.saveDocList( ids, unit, "", "" );
  28. }.bind(this)
  29. };
  30. var selector = new MWF.xApplication.Template.Selector.Custom(this.form.app.content, opt );
  31. selector.load();
  32. }.bind(this));
  33. this.define("dipatchNumberToCounty", function( city, range ){
  34. var ids = this.getSelectedId();
  35. if( ids.length == 0 ){
  36. this.form.app.notice("先选择号码","error");
  37. return;
  38. }
  39. var units = [];
  40. if( city ){
  41. var unit = this.org.listSubUnit( city , false );
  42. unit.each( function( u ){
  43. units.push({
  44. name : u.name,
  45. id : u.distinguishedName
  46. })
  47. });
  48. }
  49. if( city ){
  50. MWF.xDesktop.requireApp("Template", "Selector.Custom", null, false);
  51. var opt = {
  52. "count": 1,
  53. "title": "选择分配的组织",
  54. "selectableItems" : units,
  55. "values": [],
  56. "onComplete": function( array ){
  57. if( !array || array.length == 0 )return;
  58. var unit = array[0].data.id;
  59. this.saveDocList(ids, city, unit, "" )
  60. }.bind(this)
  61. };
  62. var selector = new MWF.xApplication.Template.Selector.Custom(this.form.app.content, opt );
  63. selector.load();
  64. }else{
  65. MWF.xDesktop.requireApp("Selector", "package", null, false);
  66. var opt = {
  67. "count": 1,
  68. "title": "选择分配的组织",
  69. "type" : "unit",
  70. "values": [],
  71. "onComplete": function( array ){
  72. if( !array || array.length == 0 )return;
  73. var unit = array[0].data.distinguishedName;
  74. debugger;
  75. var levelName = array[0].data.levelName;
  76. if( levelName.split("/").length != 2 ){
  77. this.form.app.notice("请选择县级分公司", "error");
  78. return false;
  79. }
  80. this.getAllUnit();
  81. var c = this.name_dnName[levelName.split("/")[0]];
  82. this.saveDocList(ids, c, unit, "")
  83. }.bind(this)
  84. };
  85. if( range )opt.units = [range];
  86. var selector = new MWF.O2Selector(this.form.app.content, opt );
  87. }
  88. }.bind(this));
  89. this.define("dipatchNumberToBranch", function( county, range ){
  90. var ids = this.getSelectedId();
  91. if( ids.length == 0 ){
  92. this.form.app.notice("先选择号码","error");
  93. return;
  94. }
  95. var units = [];
  96. if( county ){
  97. var unit = this.org.listSubUnit( county , false );
  98. unit.each( function( u ){
  99. units.push({
  100. name : u.name,
  101. id : u.distinguishedName
  102. })
  103. });
  104. }
  105. if( county ){
  106. MWF.xDesktop.requireApp("Template", "Selector.Custom", null, false);
  107. var opt = {
  108. "count": 1,
  109. "title": "选择分配的组织",
  110. "selectableItems" : units,
  111. "values": [],
  112. "onComplete": function( array ){
  113. if( !array || array.length == 0 )return;
  114. var unit = array[0].data.id;
  115. this.getAllUnit();
  116. var levelName = this.dnName_levelName[unit];
  117. if( levelName.split("/").length != 3 ){
  118. this.form.app.notice("请选择网格", "error");
  119. return false;
  120. }
  121. var c = this.name_dnName[levelName.split("/")[0]];
  122. this.saveDocList(ids, c, county, unit )
  123. }.bind(this)
  124. };
  125. var selector = new MWF.xApplication.Template.Selector.Custom(this.form.app.content, opt );
  126. selector.load();
  127. }else{
  128. MWF.xDesktop.requireApp("Selector", "package", null, false);
  129. var opt = {
  130. "count": 1,
  131. "title": "选择分配的组织",
  132. "type" : "unit",
  133. "values": [],
  134. "onComplete": function( array ){
  135. if( !array || array.length == 0 )return;
  136. var unit = array[0].data.distinguishedName;
  137. debugger;
  138. this.getAllUnit();
  139. var levelName = this.dnName_levelName[unit];
  140. if( levelName.split("/").length != 3 ){
  141. this.form.app.notice("请选择网格", "error");
  142. return false;
  143. }
  144. var city2 = this.name_dnName[levelName.split("/")[0]];
  145. var county2 = this.name_dnName[levelName.split("/")[1]];
  146. this.saveDocList(ids, city2, county2, unit );
  147. }.bind(this)
  148. };
  149. if( range )opt.units = [range];
  150. var selector = new MWF.O2Selector(this.form.app.content, opt );
  151. }
  152. }.bind(this));
  153. this.define("saveDocList", function( ids, city, county, branch ){
  154. ids.each( function(id){
  155. debugger;
  156. var oldData = this.form.selectedItemJson[id];
  157. var newData = { docStatus : "published", city : city, county : county , branch : branch };
  158. if( !this.form.statJson ){
  159. this.form.statJson = new StatJson(this);
  160. }
  161. this.form.statJson.changeData( newData, oldData, oldData.batch );
  162. this.form.statJson.submit();
  163. }.bind(this));
  164. if( this.form.currentView.docStatus == "error" ){
  165. var changeCount = 0;
  166. ids.each( function( id ){
  167. this.saveDoc( id, city, county, branch, function(){
  168. changeCount++;
  169. if( changeCount == ids.length ){
  170. this.setUploadedUnit( function(){
  171. this.form.app.notice("分配成功","");
  172. this.createImportBatchDiv();
  173. this.loadStatTable( this.statTableOptions ? this.statTableOptions.container : this.form.get("statContaienr").node );
  174. this.form.view.reload();
  175. this.form.view.selectedItems = [];
  176. if( this.form.view_error ){
  177. this.form.view_error.reload();
  178. this.form.view_error.selectedItems = [];
  179. }
  180. }.bind(this));
  181. }
  182. }.bind(this))
  183. }.bind(this))
  184. }else{
  185. this.saveDcc(ids, ["city","county","branch"], [city,county,branch], function(){
  186. this.setUploadedUnit( function(){
  187. this.form.app.notice("分配成功","");
  188. this.createImportBatchDiv();
  189. this.loadStatTable( this.statTableOptions ? this.statTableOptions.container : this.form.get("statContaienr").node );
  190. this.form.currentView.reload();
  191. this.form.currentView.selectedItems = [];
  192. }.bind(this));
  193. }.bind(this))
  194. }
  195. }.bind(this));
  196. this.define("saveDoc", function( id, city, county, branch, callback ){
  197. MWF.Actions.get("x_cms_assemble_control").getDocument(id, function( json ){
  198. var docData = json.data;
  199. docData.data.city = city;
  200. docData.data.county = county;
  201. docData.data.branch = branch;
  202. docData.data.errorText = "";
  203. docData.data.docStatus = "published";
  204. docData.data.status = "成功";
  205. docData.data.title = docData.data.subject;
  206. delete docData.data.$document;
  207. delete docData.document.viewCount;
  208. delete docData.document.publishTime;
  209. delete docData.document.hasIndexPic;
  210. delete docData.document.readPersonList;
  211. delete docData.document.readUnitList;
  212. delete docData.document.readGroupList;
  213. delete docData.document.authorPersonList;
  214. delete docData.document.authorUnitList;
  215. delete docData.document.authorGroupList;
  216. delete docData.document.managerList;
  217. delete docData.document.pictureList;
  218. delete docData.documentLogList;
  219. delete docData.isAppAdmin;
  220. delete docData.isCategoryAdmin;
  221. delete docData.isManager;
  222. delete docData.isCreator;
  223. delete docData.isEditor;
  224. docData.document.docData = docData.data;
  225. delete docData.data;
  226. docData.document.docStatus = "published";
  227. docData.document.subject = docData.document.title;
  228. MWF.Actions.get("x_cms_assemble_control").updateDocument( docData.document , function(){
  229. if( callback )callback();
  230. }.bind(this));
  231. }.bind(this))
  232. }.bind(this));
  233. this.define("dipatchNumber", function(){
  234. // var flag = (this.workContext.getControl().allowSave && this.workContext.getActivity().alias == "draft") ;
  235. // if( !flag ){
  236. // this.form.app.notice( "发起节点才能分配号码","error" );
  237. // return;
  238. // }
  239. var ids = this.getSelectedId();
  240. if( ids.length == 0 ){
  241. this.form.app.notice("先选择号码","error");
  242. return;
  243. }
  244. var units = this.getSubUnit();
  245. if( units ){
  246. MWF.xDesktop.requireApp("Template", "Selector.Custom", null, false);
  247. var opt = {
  248. "count": 1,
  249. "title": "选择分配的组织",
  250. "selectableItems" : units,
  251. "values": [],
  252. "onComplete": function( array ){
  253. if( !array || array.length == 0 )return;
  254. var unit = array[0].data.id;
  255. this.setUnit(ids, unit )
  256. }.bind(this)
  257. };
  258. var selector = new MWF.xApplication.Template.Selector.Custom(this.form.app.content, opt );
  259. selector.load();
  260. }else{
  261. MWF.xDesktop.requireApp("Selector", "package", null, false);
  262. var opt = {
  263. "count": 1,
  264. "title": "选择分配的组织",
  265. "type" : "unit",
  266. "values": [],
  267. "onComplete": function( array ){
  268. if( !array || array.length == 0 )return;
  269. var unit = array[0].data.distinguishedName;
  270. debugger;
  271. this.setUnit(ids, unit)
  272. }.bind(this)
  273. };
  274. var selector = new MWF.O2Selector(this.form.app.content, opt );
  275. }
  276. });
  277. this.define("getSelectedId", function(){
  278. var ids = [];
  279. if( !this.form.currentView ){
  280. this.form.currentView = this.form.view;
  281. }
  282. this.form.selectedItemJson = {};
  283. this.form.currentView.selectedItems.each( function( item ){
  284. ids.push( item.data.bundle );
  285. this.form.selectedItemJson[ item.data.bundle ] = {
  286. batch : item.data.data.batch,
  287. city : item.data.data.city,
  288. county : item.data.data.county,
  289. branch : item.data.data.branch,
  290. docStatus : this.form.currentView.docStatus || "published"
  291. }
  292. }.bind(this));
  293. return ids;
  294. });
  295. this.define("getSubUnit", function(){
  296. var units = this.data.currentUnit;
  297. if( units ){
  298. var unit = this.org.listSubUnit( units , false );
  299. }else if( !this.data.newFlag ){
  300. var unit = this.getLevel1Unit(); //this.workContext.getWork().creatorUnitLevelName.split("/")[0];
  301. }else{
  302. return null;
  303. }
  304. //unit = unit.split("@")[0];
  305. var array = [];
  306. unit.each( function( u ){
  307. array.push({
  308. name : u.name,
  309. id : u.distinguishedName
  310. })
  311. });
  312. return array;
  313. });
  314. this.define("getLevel1Unit", function( callback){
  315. var array = [];
  316. var action = new this.Action("x_organization_assemble_express", {
  317. "lookup":{"uri": "/jaxrs/unit/list/level/object", "method": "POST"}
  318. });
  319. action.invoke({"name": "lookup","parameter": {}, "data": {"levelList":[ "1" ]}, "success": function(json){
  320. array = json.data;
  321. if(callback)callback(json);
  322. }.bind(this), async : false
  323. });
  324. return array;
  325. }.bind(this));
  326. this.define("setUnit", function(ids, unit){
  327. debugger;
  328. if( !unit )return;
  329. var flag = this.data.flag || this.data.newFlag;
  330. var f;
  331. if( !flag ){
  332. f = "city"
  333. }else if( flag == "city" ){
  334. f = "county"
  335. }else if( flag == "county" ){
  336. f = "branch"
  337. }
  338. this.saveDcc(ids, f, unit, function(){
  339. debugger;
  340. var value = this.data[f+"TaskPerson"];
  341. var array = [];
  342. ( value.length ? value : [] ).each( function( v ){
  343. array.push( typeOf( v ) == "string" ? v : v.distinguishedName )
  344. }.bind(this));
  345. array.push( unit );
  346. array = array.unique();
  347. this.data[f+"TaskPerson"] = array;
  348. this.form.app.notice("分配成功","");
  349. //this.context.data.save();
  350. this.form.save();
  351. this.form.view.reload();
  352. this.form.view.selectedItems = [];
  353. }.bind(this))
  354. });
  355. this.define("saveDcc", function( ids, field, value, callback){
  356. var action = new this.Action("x_cms_assemble_control", {
  357. "save":{"uri": "/jaxrs/document/batch/data/modify", "method": "PUT"}
  358. });
  359. var array = [];
  360. if( typeOf( field ) == "array" ){
  361. for( var i=0; i<field.length; i++ ){
  362. array.push({
  363. "dataPath": field[i],
  364. "dataType": "String",
  365. "dataString": value[i],
  366. "dataInteger": null,
  367. "dataBoolean": null,
  368. "dataDate": null
  369. })
  370. }
  371. }else{
  372. array.push({
  373. "dataPath": field,
  374. "dataType": "String",
  375. "dataString": value,
  376. "dataInteger": null,
  377. "dataBoolean": null,
  378. "dataDate": null
  379. })
  380. }
  381. action.invoke({"name": "save", "data": {
  382. "docIds" : ids,
  383. "dataChanges" : array
  384. }, "success": function(json){
  385. if(callback)callback(json);
  386. }.bind(this)
  387. });
  388. }.bind(this));
  389. var UploadExcelDialog = new Class({
  390. Extends: MWF.xApplication.cms.Module.ImportForm,
  391. Implements: [Options, Events],
  392. options: {
  393. "style": "minder",
  394. "width": "650",
  395. "height": "430",
  396. "hasTop": true,
  397. "hasIcon": false,
  398. "draggable": true,
  399. "maxAction" : true,
  400. "title" : "导入号码"
  401. },
  402. _createTableContent: function () {
  403. this.formTableContainer.setStyles({"margin":"0px auto 20px atuo"});
  404. var html = "<table width='100%' bordr='0' cellpadding='7' cellspacing='0' styles='formTable' style='margin-top: 20px; '>" +
  405. "<tr><td styles='formTableTitle' width='20%'>说明:</td>" +
  406. " <td styles='formTableValue' colspan='3' width='80%' style='font-size:12px;color:#666;line-height:20px;'>"+
  407. " 您可以直接在Excel表格里填写地市分公司、区县分公司和网格的名称,系统会以您导入的分公司名称进行流转分发。<br/>"+
  408. "请注意填写的名称需要与系统内的分公司/组织名称一致。<div item='openUnit''></div>"+ "<div item='url2'></div>"+//如果名称有重名,请使用层次名。
  409. "</td></tr>" +
  410. "<tr><td styles='formTableTitle' lable='url' width='20%'></td>" +
  411. " <td styles='formTableValue' item='url' colspan='3' width='80%'></td></tr>" +
  412. "<tr><td styles='formTableTitle' lable='file' ></td>" +
  413. " <td styles='formTableValue' colspan='3'><div item='filename'></div><div item='file'></div></td></tr>" +
  414. "</table>";
  415. this.formTableArea.set("html", html);
  416. MWF.xDesktop.requireApp("Template", "MForm", null, false);
  417. this.form = new MForm(this.formTableArea, {}, {
  418. isEdited: true,
  419. style : "cms",
  420. hasColon : true,
  421. itemTemplate: {
  422. openUnit : { type : "Innerhtml", value : "<a href='javascript:void(0)'>点击查看组织名称</a>",
  423. event : { click : function(item, ev){
  424. debugger;
  425. layout.desktop.openApplication(ev, "Org", {
  426. onQueryLoad : function(){
  427. this.status = { navi : 0 }
  428. }
  429. });
  430. }.bind(this)}
  431. },
  432. url2: { type : "Innerhtml", text : "下载模板", value : "<a target='_blank' href='/x_component_cms_Module/$ExcelForm/"+encodeURIComponent("Excel导入合法性说明.xls")+"'>点击查看校验说明</a>" },
  433. url: { type : "Innerhtml", text : "下载模板", value : "<a target='_blank' href='/x_component_cms_Module/$ExcelForm/"+encodeURIComponent("Excel模板下载.xls")+"'>Excel模板下载</a>" },
  434. file: { type : "button", value : "选择Excel文件",text : "选择文件", event :{
  435. click : function(){
  436. this.selectFile();
  437. }.bind(this)
  438. } }
  439. }
  440. }, this.app);
  441. this.form.load();
  442. },
  443. _setCustom : function(){
  444. this.formBottomNode.setStyles({
  445. "margin":"0px auto 0px auto",
  446. "width" : "300px"
  447. });
  448. },
  449. ok: function( callback ){
  450. if( !this.formData ){
  451. this.app.notice( "请先选择Excel文件", "error" );
  452. }else{
  453. var json = {
  454. //"title": "新建数据的文档标题(前缀)",
  455. "title_column": "subject",
  456. "identity": "",
  457. "docType": "数据",
  458. "wiParameters": [
  459. {
  460. "dataPath": "workName",
  461. "dataType": "String",
  462. "dataString": this.data.workName,
  463. "dataInteger": "",
  464. "dataBoolean": "",
  465. "dataDate": ""
  466. },
  467. {
  468. "dataPath": "workId",
  469. "dataType": "String",
  470. "dataString": this.data.workId,
  471. "dataInteger": "",
  472. "dataBoolean": "",
  473. "dataDate": ""
  474. },
  475. {
  476. "dataPath": "jobId",
  477. "dataType": "String",
  478. "dataString": this.data.jobId,
  479. "dataInteger": "",
  480. "dataBoolean": "",
  481. "dataDate": ""
  482. }
  483. ]
  484. };
  485. this.formData.append("json_data", JSON.stringify(json) );
  486. var checkImportStatus = function( json ){
  487. this.action.checkImportStatus( json.data.importBatchName, function( js ){
  488. debugger;
  489. this.importedResultJson = js;
  490. this.importBatchName = json.data.importBatchName;
  491. if( js.data.dataTotal <= js.data.processTotal ){
  492. debugger;
  493. this.progressBar.setProgress(js.data.processTotal, js.data.dataTotal, "正在导入数据");
  494. var array = this.context.data.importBatchNames ? this.context.data.importBatchNames.split(",") : [];
  495. array.push( json.data.importBatchName );
  496. this.context.data.importBatchNames = array.toString();
  497. this.context.form.save();
  498. this.allUnit = this.getAllUnit();
  499. this.checkImportedData(true, json.data.importBatchName);
  500. this.formData = null;
  501. this.file = null;
  502. //this.app.notice("总共导入"+json.data.total+"条数据,成功"+json.data.success_count+"条数据,错误"+json.data.error_count+"条!");
  503. }else{
  504. setTimeout( function(){
  505. this.progressBar.setProgress(js.data.processTotal, js.data.dataTotal, "正在导入数据");
  506. checkImportStatus( json )
  507. }.bind(this), 500 );
  508. }
  509. }.bind(this)), function(){
  510. debugger;
  511. setTimeout( function(){
  512. this.progressBar.setProgress(js.data.processTotal, js.data.dataTotal, "正在导入数据");
  513. checkImportStatus( json )
  514. }.bind(this), 500 );
  515. }.bind(this);
  516. }.bind(this);
  517. this.loadProgressBar();
  518. this.action.importDocumentFormExcel(this.data.categoryId, function (json) { //导入excel
  519. checkImportStatus(json);
  520. }.bind(this), null, this.formData, this.file);
  521. }
  522. },
  523. checkImportedData : function( isFirst, importBatchName ){
  524. var _form = this.context.form;
  525. if( isFirst ){
  526. this.checked = 0;
  527. if( !_form.statJson ){
  528. _form.statJson = new StatJson(this.context);
  529. }
  530. _form.statJson.addBatch(importBatchName, true);
  531. }
  532. //http://ahpp.zoneland.net:20020/x_cms_assemble_control/jaxrs/document/filter/list/(0)/next/20?v=0.4.2&jio4cwnm
  533. this.action.listDocumentFilterNext( "(0)", 1000, {
  534. "importBatchNames" : [importBatchName],
  535. "categoryAliasList":["渠道-手机号码设置-手机号码"],
  536. "statusList":["checking"], //,"published","error"
  537. "orderField":null,"orderType":null,
  538. "documentType":"全部",
  539. "needData" : true
  540. }, function( json ){
  541. if( !this.totalCount ){
  542. this.totalCount = json.count;
  543. this.progressBar.gotoStep(2);
  544. this.progressBar.setProgress(0,this.totalCount,"正在校验导入数据");
  545. }
  546. var length = (json.data || []).length;
  547. var loaded = 0;
  548. ( json.data || [] ).each( function( d, i ){
  549. this.checkDocData( d , function(){
  550. this.checked ++;
  551. loaded ++;
  552. this.progressBar.setProgress(this.checked,this.totalCount,"正在校验导入数据");
  553. if( loaded == length && this.checked < this.totalCount ){
  554. window.setTimeout( function(){
  555. this.checkImportedData( false, importBatchName );
  556. }.bind(this), 1000 );
  557. }
  558. if( this.checked == this.totalCount ){
  559. debugger;
  560. this.progressBar.gotoStep(3);
  561. this.setResult();
  562. _form.statJson.submit();
  563. this.context.setUploadedUnit( function(){
  564. _form.view.reload();
  565. _form.view.selectedItems = [];
  566. if( _form.view_error ){
  567. _form.view_error.reload();
  568. _form.view_error.selectedItems = [];
  569. }
  570. this.context.createImportBatchDiv();
  571. this.context.loadStatTable( this.context.statTableOptions ? this.context.statTableOptions.container : this.context.form.get("statContaienr").node );
  572. }.bind(this));
  573. }
  574. }.bind(this), function(){
  575. this.checked ++;
  576. loaded ++;
  577. }.bind(this));
  578. }.bind(this));
  579. }.bind(this))
  580. },
  581. checkDocData : function( d, callback ){
  582. if( d.docStatus != "checking" ){
  583. if(callback)callback();
  584. return;
  585. }
  586. var data = d.data;
  587. var errorTexts = [];
  588. var cityDn, countyDn, branchDn;
  589. if( data.branch || data.county || data.city ){
  590. if(data.branch)data.branch = data.branch.trim();
  591. if(data.county)data.county = data.county.trim();
  592. if(data.city)data.city = data.city.trim();
  593. if( data.city ){
  594. cityDn = this.name_dnName[ data.city ];
  595. if( !cityDn )errorTexts.push( "未在系统中找到"+data.city +"。");
  596. }
  597. if( errorTexts.length == 0 && data.county ){
  598. countyDn = this.name_dnName[ data.county ];
  599. if( !countyDn ){
  600. errorTexts.push( "未在系统中找到"+data.county+"。");
  601. }else{
  602. if( data.city ){
  603. if( !this.allUnit.contains( data.city + "/" +data.county ) ){
  604. errorTexts.push( "未在系统中找到"+data.city + "/" +data.county +"。" );
  605. }
  606. }else{
  607. var levelName = this.name_levelName[ data.county ];
  608. if( !levelName ){
  609. errorTexts.push( "未在系统中找到"+data.county +"所在的市公司。" );
  610. }else{
  611. cityDn = this.name_dnName[ levelName.split("/")[0] ];
  612. if( !cityDn )errorTexts.push( "未在系统中找到"+data.county +"所在的市公司。" );
  613. }
  614. }
  615. }
  616. }
  617. if( errorTexts.length == 0 && data.branch ){
  618. branchDn = this.name_dnName[ data.branch ];
  619. if( !branchDn ){
  620. errorTexts.push( "未在系统中找到"+data.branch+"。");
  621. }else{
  622. if( data.city && data.county ){
  623. if( !this.allUnit.contains( data.city + "/" +data.county + "/" +data.branch ) ){
  624. errorTexts.push( "未在系统中找到"+data.city + "/" +data.county + "/" +data.branch );
  625. }
  626. }else{
  627. var levelName = this.name_levelName[ data.branch ];
  628. if( !levelName ){
  629. errorTexts.push( "未在系统中找到"+ data.branch +"所在的县公司。" );
  630. }else{
  631. if( !cityDn ){
  632. cityDn = this.name_dnName[ levelName.split("/")[0] ];
  633. if( !cityDn )errorTexts.push( "未在系统中找到"+data.branch +"所在的市公司。" );
  634. }
  635. if( !countyDn ){
  636. countyDn = this.name_dnName[ levelName.split("/")[1] ];
  637. if( !countyDn )errorTexts.push( "未在系统中找到"+data.branch +"所在的县公司。" );
  638. }
  639. }
  640. }
  641. }
  642. }
  643. }
  644. if( errorTexts.length == 0 ){
  645. d.docStatus = "published";
  646. data.docStatus = "published";
  647. data.status = "成功";
  648. if( cityDn ){
  649. data.city_import = data.city;
  650. data.city = cityDn;
  651. }
  652. if( countyDn ){
  653. data.county_import = data.county;
  654. data.county = countyDn;
  655. }
  656. if( branchDn ){
  657. data.branch_import = data.branch;
  658. data.branch = branchDn;
  659. }
  660. }else{
  661. d.docStatus = "error";
  662. data.docStatus = "error";
  663. data.status = "错误";
  664. data.errorText = errorTexts.join("");
  665. }
  666. d.docData = data;
  667. delete d.data;
  668. this.context.form.statJson.addData( data );
  669. this.action.updateDocument( d , function(){
  670. if( callback )callback();
  671. });
  672. //if( d.data.branch && )
  673. // if( d.data.city ){
  674. // }
  675. // if( d.data.branch && )
  676. // county
  677. // branch
  678. },
  679. setResult : function(){
  680. this.formTableArea.empty();
  681. //if(this.okActionNode)this.okActionNode.setStyle("display","none");
  682. //if( this.cancelActionNode ){
  683. // this.cancelActionNode.setStyles({
  684. // "display":"",
  685. // "width" : "200px"
  686. // });
  687. //
  688. //}
  689. //this.formBottomNode.setStyle("display","");
  690. this.formTopCloseActionNode.setStyle("display","");
  691. this.formTopTextNode.set("text","导入结束");
  692. var data = this.importedResultJson.data;
  693. //this.app.notice("总共导入"+json.data.total+"条数据,成功"+json.data.success_count+"条数据,错误"+json.data.error_count+"条!");
  694. new Element("div", {
  695. styles : {
  696. "margin-top" : "10px",
  697. "font-size" : "14px",
  698. "margin-left" : "10px"
  699. },
  700. text : "本批次共导入"+data.dataTotal+"条数据,成功导入"+data.successTotal+"条数据,发生错误"+data.errorTotal+"条"
  701. }).inject(this.formTableArea);
  702. if( !this.context.form.statJson ){
  703. this.context.form.statJson = new StatJson(this.context);
  704. }
  705. this.context.form.statJson.loadTable(this.formTableArea, this.importBatchName )
  706. this.setFormNodeSize();
  707. },
  708. loadProgressBar : function(){
  709. this.formTableArea.empty();
  710. this.formBottomNode.setStyle("display","none");
  711. this.formTopCloseActionNode.setStyle("display","none");
  712. this.formTopTextNode.set("text","正在导入数据,请不要关闭窗口...");
  713. this.progressBar = new ProgressBar( this.formTableArea );
  714. this.progressBar.load();
  715. },
  716. getAllUnit : function( callback){
  717. if( this.name_all ){
  718. if(callback)callback();
  719. }
  720. var array = this.name_all = [];
  721. this.name_levelName = {};
  722. this.dnName_levelName = {};
  723. this.name_dnName = {};
  724. var action = new this.context.Action("x_organization_assemble_express", {
  725. "lookup":{"uri": "/jaxrs/unit/list/all/object", "method": "GET"}
  726. });
  727. action.invoke({"name": "lookup","parameter": {}, data:null, "success": function(json){
  728. json.data.each( function(d){
  729. this.name_levelName[ d.name ] = d.levelName;
  730. this.dnName_levelName[ d.distinguishedName ] = d.levelName;
  731. this.name_dnName[ d.name ] = d.distinguishedName;
  732. array.push( d.name );
  733. array.push( d.distinguishedName );
  734. array.push( d.shortName );
  735. array.push( d.levelName );
  736. }.bind(this));
  737. if(callback)callback(json);
  738. }.bind(this), async : false
  739. });
  740. return array;
  741. }
  742. });
  743. this.define("setNumberCount",function(){
  744. if( this.data.currentUnit ){
  745. if( !this.form.statJson ){
  746. this.form.statJson = new StatJson(this);
  747. }
  748. var count = this.form.statJson.getUnitCount( this.data.currentUnit );
  749. if( this.data.numberCount != count ){
  750. this.data.numberCount = count;
  751. this.form.save();
  752. }
  753. }
  754. }.bind(this));
  755. this.define("getErrorCount", function(){
  756. if( !this.form.statJson ){
  757. this.form.statJson = new StatJson(this);
  758. }
  759. return this.form.statJson.getErrorCount();
  760. }.bind(this));
  761. // this.define("getErrorCount", function(){
  762. // if( this.form.view_error ){
  763. // return this.form.view_error.gridJson.length;
  764. // }
  765. // var workId = this.data.provinceWorkId || this.data.cityWorkId || this.data.countyWorkId;
  766. // var filter = [{
  767. // "logic":"and",
  768. // "path": "workId",
  769. // "title": "workId",
  770. // "comparison":"equals",
  771. // "comparisonTitle":"等于",
  772. // "value": workId,
  773. // "formatType":"textValue"
  774. // }];
  775. // var count = 0;
  776. // MWF.Actions.get("x_query_assemble_surface").loadView("手机号码-导入失败", "渠道-手机号码设置", {"filterList": filter }, function(json){
  777. // count = json.data.grid.length;
  778. // }.bind(this), null, false);
  779. // return count;
  780. // }.bind(this))
  781. this.define("setUploadedUnit", function( callback ){
  782. if( !this.form.statJson ){
  783. this.form.statJson = new StatJson(this);
  784. }
  785. var unit = this.data.currentUnit;
  786. if( unit == "" && !this.data.newFlag ){
  787. //unit = this.workContext.getWork().creatorUnitLevelName.split("/")[0];
  788. var creatorUnitLevelName = this.workContext.getWork().creatorUnitLevelName;
  789. if( creatorUnitLevelName ){
  790. var u = creatorUnitLevelName.split("/")[0];
  791. var unit = this.org.getUnit( u );
  792. }
  793. }
  794. var flag = this.data.flag || this.data.newFlag;
  795. debugger;
  796. var array = [];
  797. if( !flag ){
  798. array = this.form.statJson.getCity();
  799. this.data.numberCount = this.form.statJson.getUnitCount();
  800. }else if( flag=="city" ){
  801. if( unit ){
  802. array = this.form.statJson.getCounty( unit );
  803. this.data.numberCount = this.form.statJson.getUnitCount(unit);
  804. }else{
  805. this.data.numberCount = this.form.statJson.getUnitCount();
  806. array = this.form.statJson.getAllCounty();
  807. }
  808. }else if( flag == "county" ){
  809. if( unit ){
  810. var city = this.data.city;
  811. if( !city ){
  812. var creatorUnitLevelName = this.workContext.getWork().creatorUnitLevelName;
  813. if( creatorUnitLevelName ){
  814. var u = creatorUnitLevelName.split("/")[0];
  815. city = this.org.getUnit( u );
  816. }else{
  817. var u = this.org.listSupUnit( unit );
  818. city = u[0].distinguishedName;
  819. }
  820. }
  821. this.data.numberCount = this.form.statJson.getUnitCount( unit );
  822. array = this.form.statJson.getBranch( city, unit );
  823. }else{
  824. this.data.numberCount = this.form.statJson.getUnitCount();
  825. array = this.form.statJson.getAllBranch();
  826. }
  827. }
  828. debugger;
  829. var f;
  830. if( !flag ){
  831. f = "city";
  832. }else if( flag=="city" ){
  833. f = "county";
  834. }else if( flag == "county" ){
  835. f = "branch"
  836. }
  837. this.data[f+"TaskPerson"] = array;
  838. this.form.save(function(){
  839. if(callback)callback()
  840. });
  841. });
  842. this.define( "loadView", function( status, isSetCurrent ){
  843. var workId = this.data.provinceWorkId || this.data.cityWorkId || this.data.countyWorkId;
  844. var unit = this.data.currentUnit;
  845. if( unit == "" && !this.data.newFlag ){
  846. unit = this.workContext.getWork().creatorUnitLevelName.split("/")[0];
  847. }
  848. //unit = unit.split("@")[0];
  849. var flag = this.data.flag || this.data.newFlag;
  850. var control = this.workContext.getControl();
  851. var viewName;
  852. if( status == "published" ){
  853. viewName = "手机号码-导入成功"
  854. }else if( status == "error" ){
  855. viewName = "手机号码-导入失败"
  856. }else{
  857. viewName = "手机号码"
  858. }
  859. var viewJson = {
  860. "application": "渠道-手机号码设置",
  861. "viewName": viewName,
  862. "isTitle": "yes",
  863. "select": control.allowSave ? "multi" : "none", //none , single, multi
  864. //"titleStyles": this.json.titleStyles,
  865. // "itemStyles": this.json.itemStyles,
  866. "isExpand": "no",
  867. "filter": [{
  868. "logic":"and",
  869. "path": "workId",
  870. "title": "workId",
  871. "comparison":"equals",
  872. "comparisonTitle":"等于",
  873. "value": workId,
  874. "formatType":"textValue"
  875. }]
  876. };
  877. if( flag && unit){
  878. viewJson.filter.push({
  879. "logic":"and",
  880. "path": flag,
  881. "title": flag,
  882. "comparison":"equals",
  883. "comparisonTitle":"等于",
  884. "value": unit,
  885. "formatType":"textValue"
  886. })
  887. }
  888. var container;
  889. if( status == "published" ){
  890. container = this.form.get("view_container_published").node
  891. }else if( status == "error" ){
  892. container = this.form.get("view_container_error").node
  893. }else{
  894. container = this.form.get("view_container").node
  895. }
  896. MWF.xDesktop.requireApp("query.Query", "Viewer", function(){
  897. var view = new MWF.xApplication.query.Query.Viewer(container, viewJson, {
  898. "resizeNode": true, //(this.node.getStyle("height").toString().toLowerCase()!=="auto" && this.node.getStyle("height").toInt()>0),
  899. "onSelect": function(){
  900. //this.fireEvent("select");
  901. }.bind(this)
  902. });
  903. if( status == "published" ){
  904. view.docStatus = "published";
  905. this.form.view = view;
  906. }else if( status == "error" ){
  907. view.docStatus = "error";
  908. this.form.view_error = view;
  909. }else{
  910. this.form.view = view;
  911. }
  912. if( isSetCurrent )this.form.currentView = view;
  913. }.bind(this));
  914. });
  915. this.define("createImportBatchDiv", function(){
  916. if(!this.data.importBatchNames)return;
  917. if( !this.form.statJson ){
  918. this.form.statJson = new StatJson(this);
  919. }
  920. var _self = this;
  921. var div = this.form.get("importBatchDiv").node;
  922. div.empty();
  923. var tdCss = { "border-right" : "1px solid #ccc", "border-bottom" : "1px solid #ccc", "text-align" : "center" };
  924. var table = new Element( "table", {
  925. "width":"90%",
  926. "border":"0",
  927. "cellpadding":"5",
  928. "cellspacing":"0",
  929. "styles" : {"border-top" : "1px solid #ccc", "border-left" : "1px solid #ccc", "margin" : "20px auto 10px auto"}
  930. }).inject( div );
  931. var tr = new Element("tr").inject( table );
  932. new Element("th", { "styles": tdCss, text : "导入时间" }).inject( tr );
  933. new Element("th", { "styles": tdCss, text : "校验通过条数" }).inject( tr );
  934. new Element("th", { "styles": tdCss, text : "校验未通过条数" }).inject( tr );
  935. new Element("th", { "styles": tdCss, text : "操作" }).inject( tr );
  936. this.data.importBatchNames.split(",").each( function(d){
  937. var timeStr = d.split("_")[1];
  938. var year = timeStr.substring(0,4);
  939. var month = timeStr.substring(4,6);
  940. var date = timeStr.substring(6,8);
  941. var hour = timeStr.substring(8,10);
  942. var minture = timeStr.substring(10,12);
  943. var second = timeStr.substring(12,14);
  944. var time = year+"-"+month+"-"+date + " " + hour + ":" + minture + ":" + second;
  945. var tr = new Element("tr").inject( table );
  946. new Element("td", { "styles": tdCss, text : time }).inject( tr );
  947. new Element("td", { "styles": tdCss, text : this.form.statJson.getPublishedCount( d ) }).inject( tr );
  948. new Element("td", { "styles": tdCss, text : this.form.statJson.getErrorCount( d ) }).inject( tr );
  949. var td = new Element("td", { "styles": tdCss }).inject( tr );
  950. var button = new Element("button", { styles : {
  951. "border-radius": "5px", "border": "1px solid rgb(204, 204, 204)", "height": "26px", "color": "rgb(119, 119, 119)", "cursor" : "pointer", "margin-right" : "20px"
  952. } , text : "只查看该批次导入的数据" }).inject(td);
  953. button.store("data",d);
  954. button.addEvent("click", function(e){
  955. var btn = e.target;
  956. var data = {
  957. "logic":"and",
  958. "path": "$document.importBatchName",
  959. "title": "workId",
  960. "comparison":"equals",
  961. "comparisonTitle":"等于",
  962. "value": btn.retrieve("data"),
  963. "formatType":"textValue"
  964. };
  965. if( this.form.view ){
  966. var view = this.form.view;
  967. var filter = view.json.filter ? view.json.filter.clone() : [];
  968. filter.push( data );
  969. var filterList = {"filterList": filter };
  970. view.createViewNode( filterList );
  971. }
  972. if( this.form.view_error ){
  973. var view_error = this.form.view_error;
  974. var filter = view_error.json.filter ? view_error.json.filter.clone() : [];
  975. filter.push( data );
  976. var filterList = {"filterList": filter };
  977. view_error.createViewNode( filterList );
  978. }
  979. this.loadStatTable( this.statTableOptions ? this.statTableOptions.contaier : this.form.get("statContaienr").node , btn.retrieve("data") );
  980. }.bind(this));
  981. var button = new Element("button", { styles : {
  982. "border-radius": "5px", "border": "1px solid rgb(204, 204, 204)", "height": "26px", "color": "rgb(119, 119, 119)", "cursor" : "pointer"
  983. } , text : "删除该批次导入的数据" }).inject(td);
  984. button.store("data",d);
  985. button.store("time",time);
  986. button.addEvent("click", function(e){
  987. this.form.app.confirm("infor", e, "删除确认", "删除后无法恢复,确定要删除"+e.target.retrieve("time")+"导入的数据?", 380, 150, function(){
  988. MWF.Actions.get("x_cms_assemble_control").deleteDocumentWithBatchName( e.target.retrieve("data"), function(){
  989. var array = _self.data.importBatchNames.split(",");
  990. var batch = e.target.retrieve("data");
  991. _self.form.statJson.deleteBatch( batch );
  992. _self.form.statJson.submit();
  993. array.erase( batch );
  994. _self.data.importBatchNames = array.toString();
  995. _self.form.save(function(){
  996. _self.setUploadedUnit( function(){
  997. _self.form.app.notice( "删除成功" );
  998. _self.form.loadErrorView = false;
  999. _self.form.app.refresh();
  1000. });
  1001. });
  1002. });
  1003. this.close();
  1004. }, function(){
  1005. this.close();
  1006. });
  1007. }.bind(this))
  1008. }.bind(this));
  1009. var tr = new Element("tr").inject( table );
  1010. new Element("td", { "styles": tdCss, text : "总数" }).inject( tr );
  1011. new Element("td", { "styles": tdCss, text : this.form.statJson.getPublishedCount() }).inject( tr );
  1012. new Element("td", { "styles": tdCss, text : this.form.statJson.getErrorCount() }).inject( tr );
  1013. var td = new Element("td", { "styles": tdCss }).inject( tr );
  1014. var button = new Element("button", { styles : {
  1015. "border-radius": "5px", "border": "1px solid rgb(204, 204, 204)", "height": "26px", "color": "rgb(119, 119, 119)", "cursor" : "pointer", "margin-right" : "20px"
  1016. } , text : "查看全部" }).inject(td);
  1017. button.addEvent("click", function(e){
  1018. var btn = e.target;
  1019. if( this.form.view ){
  1020. var view = this.form.view;
  1021. var filter = view.json.filter ? view.json.filter.clone() : [];
  1022. var filterList = {"filterList": filter };
  1023. view.createViewNode( filterList );
  1024. }
  1025. if( this.form.view_error ){
  1026. var view_error = this.form.view_error;
  1027. var filter = view_error.json.filter ? view_error.json.filter.clone() : [];
  1028. var filterList = {"filterList": filter };
  1029. view_error.createViewNode( filterList );
  1030. }
  1031. this.loadStatTable( this.statTableOptions ? this.statTableOptions.contaier : this.form.get("statContaienr").node );
  1032. }.bind(this));
  1033. });
  1034. //this.define("checkImportedData", function( isFirst, importBatchName ){
  1035. // if( isFirst ){
  1036. // this.form.checked = 0;
  1037. // if( !this.form.statJson ){
  1038. // this.form.statJson = new StatJson(this);
  1039. // }
  1040. // this.form.statJson.addBatch(importBatchName, true);
  1041. // }
  1042. //
  1043. // //http://ahpp.zoneland.net:20020/x_cms_assemble_control/jaxrs/document/filter/list/(0)/next/20?v=0.4.2&jio4cwnm
  1044. // MWF.Actions.get("x_cms_assemble_control").listDocumentFilterNext( "(0)", 1000, {
  1045. // "importBatchNames" : [importBatchName],
  1046. // "categoryAliasList":["渠道-手机号码设置-手机号码"],
  1047. // "statusList":["checking"], //,"published","error"
  1048. // "orderField":null,"orderType":null,
  1049. // "documentType":"全部",
  1050. // "needData" : true
  1051. // }, function( json ){
  1052. // if( !this.form.totalCount ){
  1053. // this.form.totalCount = json.count;
  1054. // this.form.uploadExcelDialog.progressBar.gotoStep(2);
  1055. // this.form.uploadExcelDialog.progressBar.setProgress(0,this.form.totalCount,"正在校验导入数据");
  1056. // }
  1057. // var length = (json.data || []).length;
  1058. // var loaded = 0;
  1059. // ( json.data || [] ).each( function( d, i ){
  1060. // this.checkDocData( d , function(){
  1061. // this.form.checked ++;
  1062. // loaded ++;
  1063. // this.form.uploadExcelDialog.progressBar.setProgress(this.form.checked,this.form.totalCount,"正在校验导入数据");
  1064. // if( loaded == length && this.form.checked < this.form.totalCount ){
  1065. // window.setTimeout( function(){
  1066. // this.checkImportedData( false, importBatchName );
  1067. // }.bind(this), 1000 );
  1068. // }
  1069. // if( this.form.checked == this.form.totalCount ){
  1070. // this.form.uploadExcelDialog.progressBar.gotoStep(3);
  1071. // this.form.uploadExcelDialog.setResult();
  1072. // this.form.statJson.submit();
  1073. // this.setUploadedUnit( function(){
  1074. // this.form.view.reload();
  1075. // this.form.view.selectedItems = [];
  1076. // if( this.form.view_error ){
  1077. // this.form.view_error.reload();
  1078. // this.form.view_error.selectedItems = [];
  1079. // }
  1080. // this.createImportBatchDiv();
  1081. // }.bind(this));
  1082. // }
  1083. // }.bind(this), function(){
  1084. // this.form.checked ++;
  1085. // loaded ++;
  1086. // }.bind(this));
  1087. // }.bind(this));
  1088. // }.bind(this))
  1089. //}.bind(this));
  1090. this.define("getAllUnit", function( callback){
  1091. if( this.name_all ){
  1092. if(callback)callback();
  1093. }
  1094. var array = this.name_all = [];
  1095. this.name_levelName = {};
  1096. this.dnName_levelName = {};
  1097. this.name_dnName = {};
  1098. var action = new this.Action("x_organization_assemble_express", {
  1099. "lookup":{"uri": "/jaxrs/unit/list/all/object", "method": "GET"}
  1100. });
  1101. action.invoke({"name": "lookup","parameter": {}, data:null, "success": function(json){
  1102. json.data.each( function(d){
  1103. this.name_levelName[ d.name ] = d.levelName;
  1104. this.dnName_levelName[ d.distinguishedName ] = d.levelName;
  1105. this.name_dnName[ d.name ] = d.distinguishedName;
  1106. array.push( d.name );
  1107. array.push( d.distinguishedName );
  1108. array.push( d.shortName );
  1109. array.push( d.levelName );
  1110. }.bind(this));
  1111. if(callback)callback(json);
  1112. }.bind(this), async : false
  1113. });
  1114. return array;
  1115. }.bind(this));
  1116. //this.define( "checkDocData", function( d, callback ){
  1117. // if( d.docStatus != "checking" ){
  1118. // if(callback)callback();
  1119. // return;
  1120. // }
  1121. // var data = d.data;
  1122. // var errorTexts = [];
  1123. // var cityDn, countyDn, branchDn;
  1124. // if( data.branch || data.county || data.city ){
  1125. // if(data.branch)data.branch = data.branch.trim();
  1126. // if(data.county)data.county = data.county.trim();
  1127. // if(data.city)data.city = data.city.trim();
  1128. // if( data.city ){
  1129. // cityDn = this.name_dnName[ data.city ];
  1130. // if( !cityDn )errorTexts.push( "未在系统中找到"+data.city +"。");
  1131. // }
  1132. // if( errorTexts.length == 0 && data.county ){
  1133. // countyDn = this.name_dnName[ data.county ];
  1134. // if( !countyDn ){
  1135. // errorTexts.push( "未在系统中找到"+data.county+"。");
  1136. // }else{
  1137. // if( data.city ){
  1138. // if( !this.allUnit.contains( data.city + "/" +data.county ) ){
  1139. // errorTexts.push( "未在系统中找到"+data.city + "/" +data.county +"。" );
  1140. // }
  1141. // }else{
  1142. // var levelName = this.name_levelName[ data.county ];
  1143. // if( !levelName ){
  1144. // errorTexts.push( "未在系统中找到"+data.county +"所在的市公司。" );
  1145. // }else{
  1146. // cityDn = this.name_dnName[ levelName.split("/")[0] ];
  1147. // if( !cityDn )errorTexts.push( "未在系统中找到"+data.county +"所在的市公司。" );
  1148. // }
  1149. // }
  1150. // }
  1151. // }
  1152. // if( errorTexts.length == 0 && data.branch ){
  1153. // branchDn = this.name_dnName[ data.branch ];
  1154. // if( !branchDn ){
  1155. // errorTexts.push( "未在系统中找到"+data.branch+"。");
  1156. // }else{
  1157. // if( data.city && data.county ){
  1158. // if( !this.allUnit.contains( data.city + "/" +data.county + "/" +data.branch ) ){
  1159. // errorTexts.push( "未在系统中找到"+data.city + "/" +data.county + "/" +data.branch );
  1160. // }
  1161. // }else{
  1162. // var levelName = this.name_levelName[ data.branch ];
  1163. // if( !levelName ){
  1164. // errorTexts.push( "未在系统中找到"+ data.branch +"所在的县公司。" );
  1165. // }else{
  1166. // if( !cityDn ){
  1167. // cityDn = this.name_dnName[ levelName.split("/")[0] ];
  1168. // if( !cityDn )errorTexts.push( "未在系统中找到"+data.branch +"所在的市公司。" );
  1169. // }
  1170. // if( !countyDn ){
  1171. // countyDn = this.name_dnName[ levelName.split("/")[1] ];
  1172. // if( !countyDn )errorTexts.push( "未在系统中找到"+data.branch +"所在的县公司。" );
  1173. // }
  1174. // }
  1175. // }
  1176. // }
  1177. //
  1178. // }
  1179. // }
  1180. //
  1181. // if( errorTexts.length == 0 ){
  1182. // d.docStatus = "published";
  1183. // data.docStatus = "published";
  1184. // data.status = "成功";
  1185. // if( cityDn ){
  1186. // data.city_import = data.city;
  1187. // data.city = cityDn;
  1188. // }
  1189. // if( countyDn ){
  1190. // data.county_import = data.county;
  1191. // data.county = countyDn;
  1192. // }
  1193. // if( branchDn ){
  1194. // data.branch_import = data.branch;
  1195. // data.branch = branchDn;
  1196. // }
  1197. // }else{
  1198. // d.docStatus = "error";
  1199. // data.docStatus = "error";
  1200. // data.status = "错误";
  1201. // data.errorText = errorTexts.join("");
  1202. // }
  1203. // d.docData = data;
  1204. // delete d.data;
  1205. // this.form.statJson.addData( data );
  1206. // MWF.Actions.get("x_cms_assemble_control").updateDocument( d , function(){
  1207. // if( callback )callback();
  1208. // });
  1209. //
  1210. //}.bind(this));
  1211. this.define("setWorkId", function(){
  1212. if (this.workContext.getWork().activityName=="发起"){
  1213. this.form.get("provinceWorkId").setData(this.workContext.getWork().id);
  1214. this.form.get("currentWorkId").setData(this.workContext.getWork().id)
  1215. }
  1216. if (this.workContext.getWork().activityName=="市级接收单元负责人处理"){
  1217. this.form.get("cityWorkId").setData(this.workContext.getWork().id);
  1218. this.form.get("currentWorkId").setData(this.workContext.getWork().id)
  1219. }
  1220. if (this.workContext.getWork().activityName=="县级接收单元负责人处理"){
  1221. this.form.get("countyWorkId").setData(this.workContext.getWork().id);
  1222. this.form.get("currentWorkId").setData(this.workContext.getWork().id)
  1223. }
  1224. if (this.workContext.getWork().activityName=="网格接收单元负责人处理"){
  1225. this.form.get("branchWorkId").setData(this.workContext.getWork().id);
  1226. this.form.get("currentWorkId").setData(this.workContext.getWork().id)
  1227. }
  1228. });
  1229. this.define("getUnitLevel", function(level, isObject){
  1230. var identity = this.workContext.getWork().creatorIdentityDn;
  1231. var topUnit;
  1232. MWF.Actions.get("x_organization_assemble_express")[isObject ? "getUnitWithIdentityAndLevel" : "getUnitWithIdentityAndLevelValue" ]( {"identity":identity,"level":level}, function( json ){
  1233. topUnit = json.data.unit;
  1234. }.bind(this), null, false);
  1235. return topUnit;
  1236. }.bind(this));
  1237. this.define("openMinder", function( workId ){
  1238. debugger;
  1239. layout.desktop.openApplication(null, "portal.Portal", {
  1240. pageId : "71acdde6-97cc-4c6d-abe2-817ea5afad4f",
  1241. portalId : "b66420c3-dee9-4b4c-9d52-050fd0921864",
  1242. workId : workId,
  1243. "appId": "portal_"+workId
  1244. })
  1245. });
  1246. this.define("openUploadForm", function(){
  1247. // var flag = (this.workContext.getControl().allowSave && this.workContext.getActivity().alias == "draft") ;
  1248. // if( !flag ){
  1249. // this.form.app.notice( "发起节点才能上传Excel","error" );
  1250. // return;
  1251. // }
  1252. if( !this.data.subject ){
  1253. this.form.app.notice( "请填写任务名称并保存","error" );
  1254. return;
  1255. }
  1256. var dialog = this.form.uploadExcelDialog = new UploadExcelDialog( { app : this.form.app }, {
  1257. workName : this.data.subject,
  1258. workId : this.data.provinceWorkId || this.data.currentWorkId,
  1259. jobId : this.workContext.getWork().job,
  1260. categoryId:"288a0f05-78dd-4650-af79-236e33832a7e"
  1261. }, {
  1262. });
  1263. dialog.contextForm = this.form;
  1264. dialog.context = this;
  1265. dialog.edit();
  1266. });
  1267. var ProgressBar = new Class({
  1268. initialize: function ( container ) {
  1269. this.container = container;
  1270. },
  1271. load : function(){
  1272. this.getCss();
  1273. this.loadSteps();
  1274. this.loadProgressBar();
  1275. },
  1276. setProgress : function( processed, total, text ){
  1277. var width = Math.floor(( processed / total ) * 100 );
  1278. this.progressFront.setStyles({ width: width+"%" });
  1279. this.textNode.set("text", text + ",共"+total+"条,已处理"+ processed + "条,进度" + width + "%" );
  1280. },
  1281. loadProgressBar : function(){
  1282. this.progressNode = new Element("div", { styles : this.css.progressNode }).inject( this.container );
  1283. this.progressBack = new Element("div.progressBack", { styles: this.css.progressBack }).inject(this.progressNode);
  1284. this.progressBack.setStyle("width", "100%");
  1285. this.progressFront = new Element("div.progressFront", { styles: this.css.progressFront, text : " " }).inject(this.progressBack);
  1286. this.progressFront.setStyle("width", "0px");
  1287. this.textNode = new Element("div", { styles : this.css.textNode }).inject( this.container );
  1288. },
  1289. loadSteps: function() {
  1290. var stepsContainer = new Element("div", { styles : this.css.stepsContainer }).inject( this.container );
  1291. this.step_1 = new Element( "div", {
  1292. styles : this.css.step_1_active,
  1293. text : "导入数据"
  1294. }).inject(stepsContainer);
  1295. this.stepLink_1 = new Element( "div", { styles : this.css.stepLink_1 }).inject(this.step_1);
  1296. this.step_2 = new Element( "div", {
  1297. styles : this.css.step_2,
  1298. text : "校验数据"
  1299. }).inject(stepsContainer);
  1300. this.stepLink_2 = new Element( "div", { styles : this.css.stepLink_2 }).inject(this.step_2);
  1301. this.step_3 = new Element( "div", {
  1302. styles : this.css.step_3,
  1303. text : "完成"
  1304. }).inject(stepsContainer);
  1305. },
  1306. gotoStep: function( step ){
  1307. var i;
  1308. for( i = 1; i<=step; i++ ){
  1309. this["step_"+i].setStyles( this.css["step_"+i+"_active"] );
  1310. if( i!==step && this["stepLink_"+i]){
  1311. this["stepLink_"+i].setStyles( this.css["stepLink_"+i+"_active"] );
  1312. }
  1313. }
  1314. for( i = step+1; i<=3; i++ ){
  1315. this["step_"+i].setStyles( this.css["step_"+i] );
  1316. if( i!==3 ){
  1317. this["stepLink_"+i].setStyles( this.css["stepLink_"+i] );
  1318. }
  1319. }
  1320. },
  1321. getCss : function(){
  1322. this.css = {
  1323. "loadingNode" : {
  1324. },
  1325. "textNode" : {
  1326. "margin-top" : "10px",
  1327. "font-size" : "12px",
  1328. "margin-left" : "10px"
  1329. },
  1330. "progressNode" : {
  1331. "margin" : "10px 0px",
  1332. "overflow" : "hidden"
  1333. },
  1334. "progressBack" : {
  1335. "float":"left",
  1336. "border-radius" : "10px",
  1337. "background-color" : "#f4f4f4",
  1338. "height" : "16px"
  1339. },
  1340. "progressFront" : {
  1341. "height" : "16px",
  1342. "background-color" : "#4a9adb"
  1343. },
  1344. "stepsContainer" : {
  1345. "margin-top" : "30px",
  1346. "margin-bottom" : "30px",
  1347. "margin-left" : "70px",
  1348. "overflow" : "hidden"
  1349. },
  1350. "stepLink_1" : {
  1351. "position" : "absolute",
  1352. "top" : "11px",
  1353. "left" : "42px",
  1354. "border-top" : "2px solid #b3b3b3",
  1355. "height" : "2px",
  1356. "width" : "150px"
  1357. },
  1358. "stepLink_1_active" : {
  1359. "position" : "absolute",
  1360. "top" : "11px",
  1361. "left" : "42px",
  1362. "border-top" : "2px solid #3c75b7",
  1363. "height" : "2px",
  1364. "width" : "150px"
  1365. },
  1366. "stepLink_2" : {
  1367. "position" : "absolute",
  1368. "top" : "11px",
  1369. "left" : "47px",
  1370. "border-top" : "2px solid #b3b3b3",
  1371. "height" : "2px",
  1372. "width" : "150px"
  1373. },
  1374. "stepLink_2_active" : {
  1375. "position" : "absolute",
  1376. "top" : "11px",
  1377. "left" : "47px",
  1378. "border-top" : "2px solid #3c75b7",
  1379. "height" : "2px",
  1380. "width" : "150px"
  1381. },
  1382. "step_1" : {
  1383. "float" : "left",
  1384. "position" : "relative",
  1385. "color" : "#b3b3b3",
  1386. "font-size" : "15px",
  1387. "width" : "165px",
  1388. "height" : "25px",
  1389. "padding-top" : "30px",
  1390. "background" : "url("+MWF.defaultPath+"/xDesktop/$Authentication/default/icon/pic_1_pre.png) 20px 1px no-repeat"
  1391. },
  1392. "step_1_active" : {
  1393. "float" : "left",
  1394. "position" : "relative",
  1395. "color" : "#3c75b7",
  1396. "font-size" : "15px",
  1397. "width" : "165px",
  1398. "height" : "25px",
  1399. "padding-top" : "30px",
  1400. "background" : "url("+MWF.defaultPath+"/xDesktop/$Authentication/default/icon/pic_1_nor.png ) 20px 1px no-repeat"
  1401. },
  1402. "step_2" : {
  1403. "float" : "left",
  1404. "position" : "relative",
  1405. "color" : "#b3b3b3",
  1406. "font-size" : "15px",
  1407. "width" : "175px",
  1408. "height" : "25px",
  1409. "padding-top" : "30px",
  1410. "background" : "url("+MWF.defaultPath+"/xDesktop/$Authentication/default/icon/pic_2_pre.png) 25px 1px no-repeat"
  1411. },
  1412. "step_2_active" : {
  1413. "float" : "left",
  1414. "position" : "relative",
  1415. "color" : "#3c75b7",
  1416. "font-size" : "15px",
  1417. "width" : "175px",
  1418. "height" : "25px",
  1419. "padding-top" : "30px",
  1420. "background" : "url("+MWF.defaultPath+"/xDesktop/$Authentication/default/icon/pic_2_nor.png ) 25px 1px no-repeat"
  1421. },
  1422. "step_3" : {
  1423. "float" : "left",
  1424. "position" : "relative",
  1425. "color" : "#b3b3b3",
  1426. "font-size" : "15px",
  1427. "width" : "50px",
  1428. "height" : "25px",
  1429. "padding-top" : "30px",
  1430. "background" : "url("+MWF.defaultPath+"/xDesktop/$Authentication/default/icon/pic_3_pre.png) 5px 1px no-repeat"
  1431. },
  1432. "step_3_active" : {
  1433. "float" : "left",
  1434. "position" : "relative",
  1435. "color" : "#3c75b7",
  1436. "font-size" : "15px",
  1437. "width" : "50px",
  1438. "height" : "25px",
  1439. "padding-top" : "30px",
  1440. "background" : "url("+MWF.defaultPath+"/xDesktop/$Authentication/default/icon/pic_3_nor.png ) 5px 1px no-repeat"
  1441. }
  1442. }
  1443. }
  1444. });
  1445. this.define("loadStatTable", function( container , batchName, unitLevel, unitName ){
  1446. container.empty();
  1447. if( !this.form.statJson ){
  1448. this.form.statJson = new StatJson(this);
  1449. }
  1450. if( !unitLevel && this.statTableOptions ){
  1451. unitLevel = this.statTableOptions.unitLevel
  1452. }
  1453. if( !unitName && this.statTableOptions ){
  1454. unitName = this.statTableOptions.unitName
  1455. }
  1456. this.form.statJson.loadTable( container, batchName, unitLevel, unitName );
  1457. });
  1458. var StatJson = new Class({
  1459. initialize: function ( context ) {
  1460. this.context = context;
  1461. if( this.context.data.statJson ){
  1462. this.json = JSON.parse(this.context.data.statJson);
  1463. }else{
  1464. this.json = {
  1465. total : {
  1466. publishedCount : 0,
  1467. errorCount : 0
  1468. },
  1469. batch: {}
  1470. }
  1471. }
  1472. },
  1473. submit : function(){
  1474. this.deleteEmptyUnit();
  1475. for( var key in this.json.batch ){
  1476. this.deleteEmptyUnit(key);
  1477. }
  1478. this.context.data.statJson = JSON.stringify(this.json);
  1479. },
  1480. addBatch : function( batchName, isSetCurrent ){
  1481. if( !this.json.batch[batchName] ){
  1482. this.json.batch[batchName] = {
  1483. publishedCount : 0,
  1484. errorCount : 0
  1485. };
  1486. }
  1487. if( isSetCurrent )this.currentBatch = this.json.batch[batchName];
  1488. },
  1489. deleteBatch : function( batchName ){
  1490. var json = this.json;
  1491. var batchData = json.batch[batchName];
  1492. if( batchData ){
  1493. if( batchData.publishedCount ){
  1494. json.total.publishedCount = json.total.publishedCount - batchData.publishedCount;
  1495. }
  1496. if( batchData.errorCount ){
  1497. json.total.errorCount = json.total.errorCount - batchData.errorCount;
  1498. }
  1499. this.reduceByBatchData( batchData );
  1500. delete this.json.batch[batchName];
  1501. }
  1502. },
  1503. reduceByBatchData : function( batchData ){
  1504. var totalData = this.json.total;
  1505. for( var key in batchData ){
  1506. if( key != "publishedCount" && key != "errorCount" ){
  1507. var totalD = totalData[key];
  1508. var batchD = batchData[key];
  1509. if( batchData.publishedCount )totalD.publishedCount = totalD.publishedCount - batchD.publishedCount;
  1510. if( batchData.errorCount )totalD.errorCount = totalD.errorCount - batchD.errorCount;
  1511. for( var key_2 in batchD ){
  1512. if( key_2 != "publishedCount" && key_2 != "errorCount" ){
  1513. var totalD_2 = totalD[key_2];
  1514. var batchD_2 = batchD[key_2];
  1515. if( batchD_2.publishedCount )totalD_2.publishedCount = totalD_2.publishedCount - batchD_2.publishedCount;
  1516. if( batchD_2.errorCount )totalD_2.errorCount = totalD_2.errorCount - batchD_2.errorCount;
  1517. for(var key_3 in batchD_2 ){
  1518. if( key_3 != "publishedCount" && key_3 != "errorCount" ) {
  1519. var totalD_3 = totalD_2[key_3];
  1520. var batchD_3 = batchD_2[key_3];
  1521. if( batchD_3.publishedCount )totalD_3.publishedCount = totalD_3.publishedCount - batchD_3.publishedCount;
  1522. if( batchD_3.errorCount )totalD_3.errorCount = totalD_3.errorCount - batchD_3.errorCount;
  1523. }
  1524. }
  1525. }
  1526. }
  1527. }
  1528. }
  1529. },
  1530. addData: function( cmsDocData ){
  1531. var d = cmsDocData;
  1532. var totalJson = this.json.total;
  1533. var batchJson = this.currentBatch;
  1534. if( d.docStatus == "published" ){
  1535. totalJson.publishedCount++;
  1536. batchJson.publishedCount++;
  1537. this.addCount( totalJson, d );
  1538. this.addCount( batchJson, d );
  1539. }else if( d.docStatus == "error" ){
  1540. totalJson.errorCount++;
  1541. batchJson.errorCount++;
  1542. }
  1543. },
  1544. addCount : function( json, d ){
  1545. if( d.city ){
  1546. var cityJson = json[ d.city ];
  1547. if( !cityJson ){
  1548. cityJson = json[ d.city ] = { publishedCount : 0 };
  1549. }
  1550. cityJson.publishedCount ++;
  1551. if( d.county ){
  1552. var countyJson = cityJson[ d.county ];
  1553. if( !countyJson ){
  1554. countyJson = cityJson[ d.county ] = { publishedCount : 0 };
  1555. }
  1556. countyJson.publishedCount ++;
  1557. if( d.branch ) {
  1558. var branchJson = countyJson[d.branch];
  1559. if (!branchJson) {
  1560. branchJson = countyJson[d.branch] = {publishedCount: 0};
  1561. }
  1562. branchJson.publishedCount++;
  1563. }
  1564. }
  1565. }else{
  1566. var city = "未设置组织";
  1567. var cityJson = json[ city ];
  1568. if( !cityJson ){
  1569. cityJson = json[ city ] = { publishedCount : 0 };
  1570. }
  1571. cityJson.publishedCount ++;
  1572. }
  1573. },
  1574. reduceCount : function( json, d ){
  1575. if( d.city ){
  1576. var cityJson = json[ d.city ];
  1577. if( !cityJson ){
  1578. cityJson = json[ d.city ] = { publishedCount : 0 };
  1579. }
  1580. cityJson.publishedCount --;
  1581. if( d.county ){
  1582. var countyJson = cityJson[ d.county ];
  1583. if( !countyJson ){
  1584. countyJson = cityJson[ d.county ] = { publishedCount : 0 };
  1585. }
  1586. countyJson.publishedCount --;
  1587. if( d.branch ) {
  1588. var branchJson = countyJson[d.branch];
  1589. if (!branchJson) {
  1590. branchJson = countyJson[d.branch] = {publishedCount: 0};
  1591. }
  1592. branchJson.publishedCount--;
  1593. }
  1594. }
  1595. }else{
  1596. var city = "未设置组织";
  1597. var cityJson = json[ city ];
  1598. if( !cityJson ){
  1599. cityJson = json[ city ] = { publishedCount : 0 };
  1600. }
  1601. cityJson.publishedCount--;
  1602. }
  1603. },
  1604. getCity : function(){
  1605. var totalJson = this.json.total;
  1606. var city = [];
  1607. for( var key in totalJson ){
  1608. if( key != "publishedCount" && key != "errorCount" && key != "未设置组织"){
  1609. if( totalJson[key].publishedCount > 0 ){
  1610. city.push(key);
  1611. }
  1612. }
  1613. }
  1614. return city;
  1615. },
  1616. getCounty : function( city ){
  1617. var totalJson = this.json.total;
  1618. var county = [];
  1619. if( totalJson[city] ){
  1620. var cityJson = totalJson[city];
  1621. for( var key in cityJson ){
  1622. if( key != "publishedCount" && key != "errorCount" && key != "未设置组织"){
  1623. if( cityJson[key].publishedCount > 0 ){
  1624. county.push(key);
  1625. }
  1626. }
  1627. }
  1628. }
  1629. return county;
  1630. },
  1631. getBranch : function( city, county ){
  1632. var totalJson = this.json.total;
  1633. var branch = [];
  1634. if( totalJson[city] ){
  1635. var cityJson = totalJson[city];
  1636. if( cityJson[county] ){
  1637. var countyJson = cityJson[county];
  1638. for( var key in countyJson ){
  1639. if( key != "publishedCount" && key != "errorCount" && key != "未设置组织"){
  1640. if( countyJson[key].publishedCount > 0 ){
  1641. branch.push(key);
  1642. }
  1643. }
  1644. }
  1645. }
  1646. }
  1647. return branch;
  1648. },
  1649. getAllCounty : function(){
  1650. debugger;
  1651. var totalJson = this.json.total;
  1652. var county = [];
  1653. for(var key in totalJson ){
  1654. if( key != "publishedCount" && key != "errorCount" && key != "未设置组织"){
  1655. for( var key_2 in totalJson[key] ){
  1656. if( key_2 != "publishedCount" && key_2 != "errorCount" && key_2 != "未设置组织"){
  1657. if( totalJson[key][key_2].publishedCount > 0 ){
  1658. county.push(key_2);
  1659. }
  1660. }
  1661. }
  1662. }
  1663. }
  1664. return county;
  1665. },
  1666. getAllBranch : function(){
  1667. var totalJson = this.json.total;
  1668. var branch = [];
  1669. for(var key in totalJson ){
  1670. if( key != "publishedCount" && key != "errorCount" && key != "未设置组织"){
  1671. for( var key_2 in totalJson[key] ){
  1672. if( key_2 != "publishedCount" && key_2 != "errorCount" && key_2 != "未设置组织"){
  1673. for( var key_3 in totalJson[key][key_2] ){
  1674. if( key_3 != "publishedCount" && key_3 != "errorCount" && key_3 != "未设置组织"){
  1675. if( totalJson[key][key_2][key_3].publishedCount > 0 ){
  1676. branch.push(key_3);
  1677. }
  1678. }
  1679. }
  1680. }
  1681. }
  1682. }
  1683. }
  1684. return branch;
  1685. },
  1686. getUnitCount : function( unit, importBatchName ){
  1687. var data;
  1688. if( importBatchName && this.json.batch[importBatchName]) {
  1689. data = this.json.batch[importBatchName];
  1690. }else{
  1691. data = this.json.total;
  1692. }
  1693. if( !unit )return data.publishedCount;
  1694. for( var city in data ){
  1695. var cityData = data[city];
  1696. if( city == unit )return cityData.publishedCount;
  1697. for( var county in cityData ){
  1698. var countyData = cityData[county];
  1699. if( county == unit )return countyData.publishedCount;
  1700. for( var branch in countyData ){
  1701. var branchData = countyData[branch];
  1702. if( branch == unit )return branchData.publishedCount;
  1703. }
  1704. }
  1705. }
  1706. return 0;
  1707. },
  1708. changeData : function( newData, oldData, importBatchName ){
  1709. debugger;
  1710. //var oldData = {
  1711. // status : "error",
  1712. // city : "",
  1713. // county : "",
  1714. // branch : ""
  1715. //};
  1716. var batchJson;
  1717. if( importBatchName && this.json.batch[importBatchName]) {
  1718. batchJson = this.json.batch[importBatchName];
  1719. }
  1720. var totalJson = this.json.total;
  1721. if( oldData.docStatus == "error" ){
  1722. totalJson.errorCount--;
  1723. if( batchJson )batchJson.errorCount--;
  1724. }
  1725. if( oldData.docStatus == "published" ){
  1726. totalJson.publishedCount--;
  1727. this.reduceCount( totalJson, oldData );
  1728. if( batchJson ){
  1729. batchJson.publishedCount--;
  1730. this.reduceCount( batchJson, oldData );
  1731. }
  1732. }
  1733. if( newData.docStatus == "error"){
  1734. totalJson.errorCount++;
  1735. if( batchJson )batchJson.errorCount++;
  1736. }
  1737. if( newData.docStatus == "published"){
  1738. totalJson.publishedCount++;
  1739. this.addCount( totalJson, newData );
  1740. if( batchJson ){
  1741. batchJson.publishedCount++;
  1742. this.addCount( batchJson, newData );
  1743. }
  1744. }
  1745. },
  1746. getPublishedCount : function( importBatchName ){
  1747. if( !importBatchName ){
  1748. return this.json.total.publishedCount;
  1749. }else{
  1750. if( this.json.batch[importBatchName]) {
  1751. var batchJson = this.json.batch[importBatchName];
  1752. return batchJson.publishedCount;
  1753. }
  1754. }
  1755. },
  1756. getErrorCount : function( importBatchName ){
  1757. if( !importBatchName ){
  1758. return this.json.total.errorCount;
  1759. }else{
  1760. if( this.json.batch[importBatchName]) {
  1761. var batchJson = this.json.batch[importBatchName];
  1762. return batchJson.errorCount;
  1763. }
  1764. }
  1765. },
  1766. deleteEmptyUnit : function( batchName ){
  1767. if( batchName ){
  1768. var data = this.json.batch[batchName];
  1769. }else{
  1770. var data = this.json.total;
  1771. }
  1772. for( var key in data ){
  1773. if( key != "publishedCount" && key != "errorCount" ){
  1774. var cityData = data[key];
  1775. if( !cityData.publishedCount && !cityData.errorCount ){
  1776. delete data[key]
  1777. }else{
  1778. for( var key_2 in cityData ){
  1779. if( key_2 != "publishedCount" && key_2 != "errorCount" ){
  1780. var countyData = cityData[key_2];
  1781. if( !countyData.publishedCount && !countyData.errorCount ){
  1782. delete data[key][key_2]
  1783. }else{
  1784. for(var key_3 in countyData ){
  1785. if( key_3 != "publishedCount" && key_3 != "errorCount" ) {
  1786. var branchData = countyData[key_3];
  1787. if( !branchData.publishedCount && !branchData.errorCount ) {
  1788. delete data[key][key_2][key_3]
  1789. }
  1790. }
  1791. }
  1792. }
  1793. }
  1794. }
  1795. }
  1796. }
  1797. }
  1798. },
  1799. getNoUnitJson : function( d ){
  1800. var data = Object.clone(d);
  1801. for( var key in data ){
  1802. if( key != "publishedCount" && key != "errorCount" ){
  1803. var cityData = data[key];
  1804. var cityCount = cityData.publishedCount;
  1805. var countyCount = 0;
  1806. for( var county in cityData ){
  1807. if( county != "publishedCount" && county != "errorCount" ){
  1808. var countyData = cityData[county];
  1809. countyCount = countyCount + countyData.publishedCount;
  1810. var branchCount = 0;
  1811. for( var branch in countyData ) {
  1812. if( branch != "publishedCount" && branch != "errorCount" ) {
  1813. var branchData = countyData[branch];
  1814. branchCount = branchCount + branchData.publishedCount
  1815. }
  1816. }
  1817. if( countyData.publishedCount > branchCount ){
  1818. countyData["未设置"] = { publishedCount : countyData.publishedCount - branchCount };
  1819. }
  1820. }
  1821. }
  1822. if( cityData.publishedCount > countyCount ){
  1823. cityData["未设置"] = { publishedCount : cityData.publishedCount - countyCount };
  1824. }
  1825. }
  1826. }
  1827. return data;
  1828. },
  1829. loadTable : function( container, batchName, unitLevel, unitName ){
  1830. if( !unitLevel ){
  1831. this._loadTable(container, batchName);
  1832. }else{
  1833. this._loadTableByUnit( container, batchName, unitLevel, unitName )
  1834. }
  1835. },
  1836. _loadTableByUnit : function(container, batchName, unitLevel, unitName ){
  1837. if (batchName) {
  1838. var d = this.json.batch[batchName];
  1839. } else {
  1840. var d = this.json.total;
  1841. }
  1842. var data = this.getNoUnitJson( d );
  1843. debugger;
  1844. var table = this.table = new Element( "table", {
  1845. "width":"90%",
  1846. "border":"0",
  1847. "cellpadding":"5",
  1848. "cellspacing":"0",
  1849. "styles" : {"border-top" : "1px solid #ccc", "border-left" : "1px solid #ccc", "margin" : "20px auto 10px auto", "font-size":"14px"}
  1850. }).inject( container );
  1851. if( batchName ){
  1852. var timeStr = batchName.split("_")[1];
  1853. var year = timeStr.substring(0,4);
  1854. var month = timeStr.substring(4,6);
  1855. var date = timeStr.substring(6,8);
  1856. var hour = timeStr.substring(8,10);
  1857. var minture = timeStr.substring(10,12);
  1858. var second = timeStr.substring(12,14);
  1859. var title = year+"-"+month+"-"+date + " " + hour + ":" + minture + ":" + second + "批次数据统计"
  1860. }else{
  1861. var title = "数据统计";
  1862. }
  1863. if( unitLevel == "city" )this._loadTableByCity(title, data, table, unitName );
  1864. if( unitLevel == "county" )this._loadTableByCounty(title, data, table, unitName );
  1865. if( unitLevel == "branch" )this._loadTableByBranch(title, data, table, unitName );
  1866. },
  1867. _loadTableByCity : function(title, data, table, unitName){
  1868. var tdCss = { "border-right" : "1px solid #ccc", "border-bottom" : "1px solid #ccc", "text-align" : "center" };
  1869. var tdTitleCss = { "border-right" : "1px solid #ccc", "border-bottom" : "1px solid #ccc", "text-align" : "center" , "font-size":"16px", "font-weight" : "bold"};
  1870. var tr = new Element("tr").inject( table );
  1871. new Element("td", { "styles": tdTitleCss, text : title, colspan:3 }).inject( tr );
  1872. var tr = new Element("tr").inject( table );
  1873. new Element("th", { "styles": tdCss, text : "市分" }).inject( tr );
  1874. new Element("th", { "styles": tdCss, text : "县分" }).inject( tr );
  1875. new Element("th", { "styles": tdCss, text : "网格" }).inject( tr );
  1876. debugger;
  1877. for( var city in data ){
  1878. if( city != unitName )continue;
  1879. if( city != "publishedCount" && city!="errorCount" ){
  1880. var cityTr = new Element("tr").inject( table );
  1881. var cityData = data[city];
  1882. var cityShow = city == "未设置组织" ? "未设置" : city.split("@")[0];
  1883. var cityTd = new Element("td", { "styles": tdCss, text : cityShow + "(" + cityData.publishedCount + ")" }).inject( cityTr );
  1884. var citySpan = 1;
  1885. var countyIndex = 0;
  1886. var countyTr = null;
  1887. var countyTd = null;
  1888. var branchTd = null;
  1889. for( var county in cityData ){
  1890. if( county != "publishedCount" && county!="errorCount" ){
  1891. if( countyIndex != 0 ){
  1892. citySpan++;
  1893. countyTr = new Element("tr").inject( table );
  1894. }
  1895. countyIndex ++;
  1896. var countySpan = 1;
  1897. var countyData = cityData[county];
  1898. countyTd = new Element("td", { "styles": tdCss, text : county.split("@")[0] + "(" + countyData.publishedCount + ")" }).inject( countyTr || cityTr );
  1899. var branchIndex = 0;
  1900. var branchTr = null;
  1901. for( var branch in countyData ){
  1902. if( branch != "publishedCount" && branch!="errorCount" ) {
  1903. if( branchIndex != 0 ){
  1904. branchTr = new Element("tr").inject( table );
  1905. citySpan++;
  1906. countySpan++;
  1907. }
  1908. branchIndex++;
  1909. var branchData = countyData[branch];
  1910. branchTd = new Element("td", {"styles": tdCss, text: branch.split("@")[0]+ "(" + branchData.publishedCount + ")" }).inject( branchTr || countyTr || cityTr );
  1911. }
  1912. }
  1913. if( branchIndex == 0 ){
  1914. branchTd = new Element("td", { "styles": tdCss, text :"" }).inject( branchTr || countyTr || cityTr );
  1915. }
  1916. countyTd.set("rowspan",countySpan);
  1917. }
  1918. }
  1919. if( countyIndex == 0 ){
  1920. countyTd = new Element("td", { "styles": tdCss, text :"" }).inject( countyTr || cityTr );
  1921. }
  1922. if( !branchTd ){
  1923. new Element("td", { "styles": tdCss, text :"" }).inject( countyTr || cityTr );
  1924. }
  1925. cityTd.set("rowspan",citySpan);
  1926. }
  1927. }
  1928. },
  1929. _loadTableByCounty : function(title, data, table, unitName){
  1930. var tdCss = { "border-right" : "1px solid #ccc", "border-bottom" : "1px solid #ccc", "text-align" : "center" };
  1931. var tdTitleCss = { "border-right" : "1px solid #ccc", "border-bottom" : "1px solid #ccc", "text-align" : "center" , "font-size":"16px", "font-weight" : "bold"};
  1932. var tr = new Element("tr").inject( table );
  1933. new Element("td", { "styles": tdTitleCss, text : title, colspan:2 }).inject( tr );
  1934. var tr = new Element("tr").inject( table );
  1935. new Element("th", { "styles": tdCss, text : "县分" }).inject( tr );
  1936. new Element("th", { "styles": tdCss, text : "网格" }).inject( tr );
  1937. debugger;
  1938. for( var city in data ){
  1939. if( city != "publishedCount" && city!="errorCount" ){
  1940. var cityData = data[city];
  1941. var countyIndex = 0;
  1942. var countyTr = null;
  1943. var countyTd = null;
  1944. var branchTd = null;
  1945. for( var county in cityData ){
  1946. if( unitName != county )continue;
  1947. if( county != "publishedCount" && county!="errorCount" ){
  1948. countyTr = new Element("tr").inject( table );
  1949. countyIndex ++;
  1950. var countySpan = 1;
  1951. var countyData = cityData[county];
  1952. countyTd = new Element("td", { "styles": tdCss, text : county.split("@")[0] + "(" + countyData.publishedCount + ")" }).inject( countyTr );
  1953. var branchIndex = 0;
  1954. var branchTr = null;
  1955. for( var branch in countyData ){
  1956. if( branch != "publishedCount" && branch!="errorCount" ) {
  1957. if( branchIndex != 0 ){
  1958. branchTr = new Element("tr").inject( table );
  1959. countySpan++;
  1960. }
  1961. branchIndex++;
  1962. var branchData = countyData[branch];
  1963. branchTd = new Element("td", {"styles": tdCss, text: branch.split("@")[0]+ "(" + branchData.publishedCount + ")" }).inject( branchTr || countyTr );
  1964. }
  1965. }
  1966. if( branchIndex == 0 ){
  1967. branchTd = new Element("td", { "styles": tdCss, text :"" }).inject( branchTr || countyTr );
  1968. }
  1969. countyTd.set("rowspan",countySpan);
  1970. }
  1971. }
  1972. if( !branchTd && countyTr ){
  1973. new Element("td", { "styles": tdCss, text :"" }).inject( countyTr );
  1974. }
  1975. }
  1976. }
  1977. },
  1978. _loadTableByBranch : function(title, data, table, unitName){
  1979. var tdCss = { "border-right" : "1px solid #ccc", "border-bottom" : "1px solid #ccc", "text-align" : "center" };
  1980. var tdTitleCss = { "border-right" : "1px solid #ccc", "border-bottom" : "1px solid #ccc", "text-align" : "center" , "font-size":"16px", "font-weight" : "bold"};
  1981. var tr = new Element("tr").inject( table );
  1982. new Element("td", { "styles": tdTitleCss, text : title }).inject( tr );
  1983. for( var city in data ){
  1984. if( city != "publishedCount" && city!="errorCount" ){
  1985. var cityData = data[city];
  1986. var branchTd = null;
  1987. for( var county in cityData ){
  1988. if( county != "publishedCount" && county!="errorCount" ){
  1989. var countyData = cityData[county];
  1990. for( var branch in countyData ){
  1991. if( branch != unitName )continue;
  1992. if( branch != "publishedCount" && branch!="errorCount" ) {
  1993. var branchTr = new Element("tr").inject( table );
  1994. var branchData = countyData[branch];
  1995. branchTd = new Element("td", {"styles": tdCss, text: branch.split("@")[0]+ "(" + branchData.publishedCount + ")" }).inject( branchTr );
  1996. }
  1997. }
  1998. }
  1999. }
  2000. }
  2001. }
  2002. },
  2003. _loadTable : function( container, batchName ) {
  2004. if (batchName) {
  2005. var d = this.json.batch[batchName];
  2006. } else {
  2007. var d = this.json.total;
  2008. }
  2009. var data = this.getNoUnitJson( d );
  2010. debugger;
  2011. var tdCss = { "border-right" : "1px solid #ccc", "border-bottom" : "1px solid #ccc", "text-align" : "center" };
  2012. var tdTitleCss = { "border-right" : "1px solid #ccc", "border-bottom" : "1px solid #ccc", "text-align" : "center" , "font-size":"16px", "font-weight" : "bold"};
  2013. var table = this.table = new Element( "table", {
  2014. "width":"90%",
  2015. "border":"0",
  2016. "cellpadding":"5",
  2017. "cellspacing":"0",
  2018. "styles" : {"border-top" : "1px solid #ccc", "border-left" : "1px solid #ccc", "margin" : "20px auto 10px auto", "font-size":"14px"}
  2019. }).inject( container );
  2020. var tr = new Element("tr").inject( table );
  2021. if( batchName ){
  2022. var timeStr = batchName.split("_")[1];
  2023. var year = timeStr.substring(0,4);
  2024. var month = timeStr.substring(4,6);
  2025. var date = timeStr.substring(6,8);
  2026. var hour = timeStr.substring(8,10);
  2027. var minture = timeStr.substring(10,12);
  2028. var second = timeStr.substring(12,14);
  2029. var title = year+"-"+month+"-"+date + " " + hour + ":" + minture + ":" + second + "批次数据统计"
  2030. }else{
  2031. var title = "数据统计";
  2032. }
  2033. new Element("td", { "styles": tdTitleCss, text : title, colspan:3 }).inject( tr );
  2034. var tr = new Element("tr").inject( table );
  2035. new Element("td", { "styles": tdCss, text : "校验未通过(条)" }).inject( tr );
  2036. new Element("td", { "styles": tdCss, colspan:2, text : data.errorCount || "" }).inject( tr );
  2037. var tr = new Element("tr").inject( table );
  2038. new Element("td", { "styles": tdCss, text : "校验通过(条)" }).inject( tr );
  2039. new Element("td", { "styles": tdCss, colspan:2, text : data.publishedCount || "" }).inject( tr );
  2040. var tr = new Element("tr").inject( table );
  2041. new Element("th", { "styles": tdCss, text : "市分" }).inject( tr );
  2042. new Element("th", { "styles": tdCss, text : "县分" }).inject( tr );
  2043. new Element("th", { "styles": tdCss, text : "网格" }).inject( tr );
  2044. debugger;
  2045. for( var city in data ){
  2046. if( city != "publishedCount" && city!="errorCount" ){
  2047. var cityTr = new Element("tr").inject( table );
  2048. var cityData = data[city];
  2049. var cityShow = city == "未设置组织" ? "未设置" : city.split("@")[0];
  2050. var cityTd = new Element("td", { "styles": tdCss, text : cityShow + "(" + cityData.publishedCount + ")" }).inject( cityTr );
  2051. var citySpan = 1;
  2052. var countyIndex = 0;
  2053. var countyTr = null;
  2054. var countyTd = null;
  2055. var branchTd = null;
  2056. for( var county in cityData ){
  2057. if( county != "publishedCount" && county!="errorCount" ){
  2058. if( countyIndex != 0 ){
  2059. citySpan++;
  2060. countyTr = new Element("tr").inject( table );
  2061. }
  2062. countyIndex ++;
  2063. var countySpan = 1;
  2064. var countyData = cityData[county];
  2065. countyTd = new Element("td", { "styles": tdCss, text : county.split("@")[0] + "(" + countyData.publishedCount + ")" }).inject( countyTr || cityTr );
  2066. var branchIndex = 0;
  2067. var branchTr = null;
  2068. for( var branch in countyData ){
  2069. if( branch != "publishedCount" && branch!="errorCount" ) {
  2070. if( branchIndex != 0 ){
  2071. branchTr = new Element("tr").inject( table );
  2072. citySpan++;
  2073. countySpan++;
  2074. }
  2075. branchIndex++;
  2076. var branchData = countyData[branch];
  2077. branchTd = new Element("td", {"styles": tdCss, text: branch.split("@")[0]+ "(" + branchData.publishedCount + ")" }).inject( branchTr || countyTr || cityTr );
  2078. }
  2079. }
  2080. if( branchIndex == 0 ){
  2081. branchTd = new Element("td", { "styles": tdCss, text :"" }).inject( branchTr || countyTr || cityTr );
  2082. }
  2083. countyTd.set("rowspan",countySpan);
  2084. }
  2085. }
  2086. if( countyIndex == 0 ){
  2087. countyTd = new Element("td", { "styles": tdCss, text :"" }).inject( countyTr || cityTr );
  2088. }
  2089. if( !branchTd ){
  2090. new Element("td", { "styles": tdCss, text :"" }).inject( countyTr || cityTr );
  2091. }
  2092. cityTd.set("rowspan",citySpan);
  2093. }
  2094. }
  2095. }
  2096. });
  2097. // this.define("setUploadedUnit", function( callback ){
  2098. // var workId = this.data.provinceWorkId || this.data.cityWorkId || this.data.countyWorkId;
  2099. // var unit = this.data.currentUnit;
  2100. // if( unit == "" && !this.data.newFlag ){
  2101. // unit = this.workContext.getWork().creatorUnitLevelName.split("/")[0];
  2102. // }
  2103. // var flag = this.data.flag || this.data.newFlag;
  2104. // debugger;
  2105. // var viewName;
  2106. // if( !flag ){
  2107. // viewName = "byCity";
  2108. // }else if( flag=="city" ){
  2109. // viewName = "byCounty";
  2110. // }else if( flag == "county" ){
  2111. // viewName = "byBranch"
  2112. // }
  2113. // var filter = [{
  2114. // "logic":"and",
  2115. // "path": "workId",
  2116. // "title": "workId",
  2117. // "comparison":"equals",
  2118. // "comparisonTitle":"等于",
  2119. // "value": workId,
  2120. // "formatType":"textValue"
  2121. // }];
  2122. // if( flag && unit){
  2123. // filter.push({
  2124. // "logic":"and",
  2125. // "path": flag,
  2126. // "title": flag,
  2127. // "comparison":"equals",
  2128. // "comparisonTitle":"等于",
  2129. // "value": unit,
  2130. // "formatType":"textValue"
  2131. // })
  2132. // }
  2133. // MWF.Actions.get("x_query_assemble_surface").loadView(viewName, "渠道-手机号码设置", {"filterList": filter }, function(json){
  2134. // //;
  2135. // debugger;
  2136. // var f;
  2137. // if( !flag ){
  2138. // f = "city";
  2139. // }else if( flag=="city" ){
  2140. // f = "county";
  2141. // }else if( flag == "county" ){
  2142. // f = "branch"
  2143. // }
  2144. // var array = []
  2145. // json.data.groupGrid.each( function(d){
  2146. // if( d.group.split("@").getLast().toLowerCase() == "u" ){
  2147. // array.push( d.group );
  2148. // }
  2149. // }.bind(this))
  2150. // this.data[f+"TaskPerson"] = array;
  2151. // this.form.save(function(){
  2152. // if(callback)callback()
  2153. // });
  2154. // }.bind(this));
  2155. // })