test2.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322
  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 = un