Address.js 8.7 KB

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