Address.js 8.7 KB

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