Address.js 8.7 KB

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