Address.js 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  1. //MWF.require("MWF.widget.PinYin", null, false);
  2. MWF.xDesktop.requireApp("process.Xform", "Combox", null, false);
  3. /** @class Address 地址选择组件。
  4. * @o2cn 地址选择
  5. * @example
  6. * //可以在脚本中获取该组件
  7. * //方法1:
  8. * var address = this.form.get("name"); //获取组件
  9. * //方法2
  10. * var address = this.target; //组件本身的事件和脚本中获取
  11. * @extends MWF.xApplication.process.Xform.Combox
  12. * @o2category FormComponents
  13. * @o2range {Process|CMS}
  14. * @hideconstructor
  15. */
  16. MWF.xApplication.process.Xform.Address = MWF.APPAddress = new Class(
  17. /** @lends MWF.xApplication.process.Xform.Address# */
  18. {
  19. Implements: [Events],
  20. Extends: MWF.APPCombox,
  21. options: {
  22. "moduleEvents": ["load", "queryLoad", "postLoad", "commitInput", "change"]
  23. },
  24. initialize: function(node, json, form){
  25. this.node = $(node);
  26. this.node.store("module", this);
  27. this.json = json;
  28. this.form = form;
  29. this.field = true;
  30. this.fieldModuleLoaded = false;
  31. },
  32. _loadNode: function(){
  33. if (this.isReadonly()){
  34. this._loadNodeRead();
  35. }else{
  36. this._loadNodeEdit();
  37. }
  38. },
  39. _loadNodeRead: function(){
  40. this.node.empty();
  41. this.node.set({
  42. "nodeId": this.json.id,
  43. "MWFType": this.json.type
  44. });
  45. this.loadVal();
  46. //new Element("select").inject(this.node);
  47. },
  48. _loadNodeEdit: function(){
  49. this.node.empty();
  50. MWF.require(["MWF.widget.Combox","MWF.widget.PinYin"], function(){
  51. this.combox = new MWF.widget.Combox({
  52. "style": this.form.json.addressStyle ? this.form.json.addressStyle.style : "blue",
  53. "positionX": this.form.json.addressStyle ? this.form.json.addressStyle.positionX : "left",
  54. "onlySelect": true,
  55. "count": 4,
  56. "focusList": true,
  57. "onCommitInput": function(){
  58. this.fireEvent("commitInput");
  59. }.bind(this),
  60. "onChange": function(e, oldValues){
  61. var thisValues = this.combox.values.map(function(v){ return v.data || v.value});
  62. if ((oldValues && (oldValues.join() !== thisValues.join()))){
  63. while (this.combox.values.length-1>e.index){
  64. this.combox.deleteItem(this.combox.values[this.combox.values.length-1])
  65. }
  66. this.fireEvent("change");
  67. }
  68. }.bind(this),
  69. "optionsMethod": this._searchOptions.bind(this)
  70. });
  71. this.combox.intoEdit = function(e){
  72. if (this.options.count){
  73. if (this.values.length>=this.options.count){
  74. // if (this.input) this.input.noBlur = true;
  75. if (this.input) this.input.node.hide();
  76. // this.getLast().edit();
  77. return false;
  78. }
  79. }
  80. if (!this.input){
  81. this.input = new MWF.widget.Combox.Input(this, this, "");
  82. this.input.node.inject(this.node);
  83. this.input.node.setStyle("width", "1px");
  84. }
  85. this.input.node.show();
  86. this.input.setInputNodeStyles();
  87. //this.input.node.set("value", "111");
  88. this.input.node.focus();
  89. this.input.setInputPosition();
  90. if (this.options.focusList) this.input.searchItems();
  91. }
  92. }.bind(this), false);
  93. this.combox.inject(this.node);
  94. this.node.set({
  95. "id": this.json.id,
  96. "MWFType": this.json.type
  97. });
  98. this.combox.addEvent("change", function(){
  99. this.validationMode();
  100. if (this.validation()){
  101. var v = this.getInputData("change");
  102. this._setBusinessData(v);
  103. //this._setEnvironmentData(v);
  104. }
  105. }.bind(this));
  106. this.loadVal();
  107. },
  108. _searchOptions: function(value, callback, comboxValueObject){
  109. value = value.toLowerCase();
  110. var i;
  111. if( comboxValueObject ){
  112. i = comboxValueObject.index;
  113. }else{
  114. i = (this.combox.editItem) ? this.combox.editItem.getItemPosition() : this.combox.values.length;
  115. }
  116. if(this.json.selectRange==="province"){
  117. if( i > 0 ){
  118. if (callback) callback([]);
  119. return;
  120. }
  121. }else if(this.json.selectRange==="city"){
  122. if( i > 1 ){
  123. if (callback) callback([]);
  124. return;
  125. }
  126. }
  127. switch (i) {
  128. case 0: //省
  129. o2.Actions.get("x_general_assemble_control").listProvince(function(json){
  130. var list = [];
  131. json.data.each(function(text){
  132. var k = text.name;
  133. var keyword = k+MWF.widget.PinYin.toPY(k).toLowerCase()+MWF.widget.PinYin.toPYFirst(k).toLowerCase();
  134. if (value){
  135. //if (keyword.indexOf(value)!==-1)
  136. list.push({"text": k, "value": k});
  137. }else{
  138. list.push({"text": k, "value": k});
  139. }
  140. }.bind(this));
  141. // if (list.length) if (callback) callback(list);
  142. if (callback) callback(list);
  143. }.bind(this));
  144. // MWF.UD.getPublicData("addr_province", function(json){
  145. // var list = [];
  146. // json.each(function(text){
  147. // var keyword = text+MWF.widget.PinYin.toPY(text).toLowerCase()+MWF.widget.PinYin.toPYFirst(text).toLowerCase();
  148. // if (value){
  149. // if (keyword.indexOf(value)!==-1) list.push({"text": text, "value": text});
  150. // }else{
  151. // list.push({"text": text, "value": text});
  152. // }
  153. //
  154. // }.bind(this));
  155. // if (list.length) if (callback) callback(list);
  156. // });
  157. break;
  158. case 1: //市
  159. var item = this.combox.getFirst();
  160. o2.Actions.get("x_general_assemble_control").listCity(item.data || item.value, function(json){
  161. var list = [];
  162. json.data.each(function(text){
  163. var k = text.name;
  164. var keyword = k+MWF.widget.PinYin.toPY(k).toLowerCase()+MWF.widget.PinYin.toPYFirst(k).toLowerCase();
  165. if (value){
  166. //if (keyword.indexOf(value)!==-1)
  167. list.push({"text": k, "value": k});
  168. }else{
  169. list.push({"text": k, "value": k});
  170. }
  171. }.bind(this));
  172. // if (list.length) if (callback) callback(list);
  173. if (callback) callback(list);
  174. }.bind(this));
  175. // MWF.UD.getPublicData("addr_city_"+item.data, function(json){
  176. // var list = [];
  177. // json.each(function(text){
  178. // var keyword = text+MWF.widget.PinYin.toPY(text).toLowerCase()+MWF.widget.PinYin.toPYFirst(text).toLowerCase();
  179. // if (value){
  180. // if (keyword.indexOf(value)!==-1) list.push({"text": text, "value": text});
  181. // }else{
  182. // list.push({"text": text, "value": text});
  183. // }
  184. // }.bind(this));
  185. // if (list.length) if (callback) callback(list);
  186. // });
  187. break;
  188. case 2: //区
  189. var f = this.combox.getFirst();
  190. var p = f.data || f.value;
  191. var item = this.combox.getFirst().getNextItem();
  192. o2.Actions.get("x_general_assemble_control").listDistrict(p, item.data||item.value, function(json){
  193. var list = [];
  194. json.data.each(function(text){
  195. var k = text.name;
  196. var keyword = k+MWF.widget.PinYin.toPY(k).toLowerCase()+MWF.widget.PinYin.toPYFirst(k).toLowerCase();
  197. if (value){
  198. //if (keyword.indexOf(value)!==-1)
  199. list.push({"text": k, "value": k});
  200. }else{
  201. list.push({"text": k, "value": k});
  202. }
  203. }.bind(this));
  204. if (list.length) if (callback) callback(list);
  205. }.bind(this));
  206. // MWF.UD.getPublicData("addr_district_"+item.data, function(json){
  207. // var list = [];
  208. // json.each(function(text){
  209. // var keyword = text+MWF.widget.PinYin.toPY(text).toLowerCase()+MWF.widget.PinYin.toPYFirst(text).toLowerCase();
  210. // if (value){
  211. // if (keyword.indexOf(value)!==-1) list.push({"text": text, "value": text});
  212. // }else{
  213. // list.push({"text": text, "value": text});
  214. // }
  215. // }.bind(this));
  216. // if (list.length) if (callback) callback(list);
  217. // });
  218. break;
  219. default:
  220. if (callback) callback([]);
  221. }
  222. }
  223. });