CustomerUU.js 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345
  1. /**
  2. * 修改客户UU按钮
  3. */
  4. Ext.define('erp.view.core.button.CustomerUU', {
  5. extend : 'Ext.Button',
  6. alias : 'widget.erpCustomerUUButton',
  7. iconCls : 'x-btn-uu-medium',
  8. cls : 'x-btn-gray',
  9. text : $I18N.common.button.erpCustomerUUButton,
  10. style : {
  11. marginLeft : '10px'
  12. },
  13. width : 120,
  14. initComponent : function() {
  15. this.callParent(arguments);
  16. },
  17. listeners: {
  18. afterrender: function(btn) {
  19. var status = Ext.getCmp('cu_auditstatuscode');
  20. if(status && status.value == 'ENTERING'){
  21. btn.hide();
  22. }
  23. }
  24. },
  25. handler: function() {
  26. var me = this, win = Ext.getCmp('customeruu-win');
  27. if(!win) {
  28. var f = Ext.getCmp('cu_uu'),
  29. id = Ext.getCmp('cu_id').getValue(), uu = f ? f.value : null;
  30. me.isEnable(id, function(enable){
  31. var items = [me.createCheckForm(uu, enable)];
  32. if(!enable)
  33. items.push(me.createCheckGrid());
  34. win = Ext.create('Ext.Window', {
  35. id: 'customeruu-win',
  36. title: '设置客户 ' + Ext.getCmp('cu_code').value + ' 的UU号',
  37. width: '80%',
  38. items: items,
  39. closeAction: 'hide',
  40. modal: true,
  41. autoShow: true
  42. });
  43. if(!enable)
  44. me.check(uu);
  45. });
  46. } else
  47. win.show();
  48. },
  49. createCheckForm: function(uu, enable) {
  50. var me = this;
  51. return new Ext.form.Panel({
  52. xtype: 'form',
  53. height: 120,
  54. bodyStyle: 'background:#f1f2f5;',
  55. layout: 'hbox',
  56. fieldDefaults: {
  57. margin: '15'
  58. },
  59. items: [{
  60. xtype: 'numberfield',
  61. name:'cu_uu',
  62. fieldLabel: '客户UU号',
  63. hideTrigger: true,
  64. readOnly: enable,
  65. value: uu,
  66. flex: 3
  67. },{
  68. xtype: 'displayfield',
  69. flex: 4,
  70. id: 'b2benable',
  71. fieldCls: 'x-form-field-help',
  72. checkedIcon: 'x-button-icon-agree',
  73. uncheckedIcon: 'x-button-icon-unagree',
  74. value: (enable ? '<i class="x-button-icon-agree"></i>验证通过' : null),
  75. setChecked: function(checked) {
  76. this.checked = checked;
  77. this.setValue(('<i class="' + (checked ? this.checkedIcon : this.uncheckedIcon) + '"></i>') +
  78. (checked ? '验证通过' : '验证失败'));
  79. }
  80. }],
  81. buttonAlign: 'center',
  82. buttons: [{
  83. text: '检测',
  84. cls: 'x-btn-gray',
  85. hidden: enable,
  86. handler: function(btn) {
  87. var form = btn.ownerCt.ownerCt,
  88. a = form.down('numberfield[name=cu_uu]');
  89. if(a.value) {
  90. me.check(a.value);
  91. } else
  92. form.down('#b2benable').setChecked(false);
  93. }
  94. }, {
  95. text: $I18N.common.button.erpSaveButton,
  96. cls: 'x-btn-gray',
  97. handler: function(btn) {
  98. var form = btn.ownerCt.ownerCt,
  99. a = form.down('numberfield[name=cu_uu]');
  100. if(a.value) {
  101. me.onConfirm(Ext.getCmp('cu_id').value, a.value);
  102. } else
  103. form.down('#b2benable').setChecked(false);
  104. }
  105. }, {
  106. text: $I18N.common.button.erpCloseButton,
  107. cls: 'x-btn-gray',
  108. handler: function(btn) {
  109. btn.up('window').hide();
  110. }
  111. }]
  112. });
  113. },
  114. createCheckGrid: function() {
  115. var me = this;
  116. return new Ext.grid.Panel({
  117. xtype: 'grid',
  118. title: '查找平台注册企业资料',
  119. height: 400,
  120. columnLines: true,
  121. columns: [{
  122. text: '企业名称',
  123. dataIndex: 'name',
  124. cls: 'x-grid-header-1',
  125. flex: 5,
  126. renderer: function(val, meta, record, x, y, store, view) {
  127. var c = view.ownerCt.searchConfig;
  128. if(c && c.name) {
  129. if(val.length > c.name.length)
  130. val = val.replace(c.name, '<font style="color:#c00">' + c.name + '</font>');
  131. else if(c.name.indexOf(val) > -1)
  132. val = '<font style="color:#c00">' + val + '</font>';
  133. }
  134. return val;
  135. }
  136. },{
  137. text: '简称',
  138. dataIndex: 'shortName',
  139. cls: 'x-grid-header-1',
  140. flex: 2,
  141. renderer: function(val, meta, record, x, y, store, view) {
  142. var c = view.ownerCt.searchConfig;
  143. if(c && c.shortName) {
  144. if(val.length > c.shortName.length)
  145. val = val.replace(c.shortName, '<font style="color:#c00">' + c.shortName + '</font>');
  146. else if(c.shortName.indexOf(val) > -1)
  147. val = '<font style="color:#c00">' + val + '</font>';
  148. }
  149. return val;
  150. }
  151. },{
  152. text: 'UU',
  153. xtype: 'numbercolumn',
  154. dataIndex: 'uu',
  155. flex: 2,
  156. cls: 'x-grid-header-1',
  157. align: 'right',
  158. renderer: function(val, meta, record, x, y, store, view) {
  159. var c = view.ownerCt.searchConfig;
  160. if(c && c.uu && val == c.uu) {
  161. val = '<font style="color:#c00">' + val + '</font>';
  162. }
  163. return val;
  164. }
  165. },{
  166. text: '地址',
  167. dataIndex: 'address',
  168. cls: 'x-grid-header-1',
  169. flex: 5
  170. },{
  171. text: '操作',
  172. xtype:'actioncolumn',
  173. cls: 'x-grid-header-1',
  174. flex: 1,
  175. align: 'center',
  176. items: [{
  177. icon: basePath + 'resource/images/32/select.png',
  178. tooltip: '选择',
  179. handler: function(grid, rowIndex, colIndex) {
  180. me.selectRecord(grid, grid.getStore().getAt(rowIndex));
  181. }
  182. }]
  183. }],
  184. features : [Ext.create('Ext.grid.feature.Grouping',{
  185. groupHeaderTpl: '按{name}查找到的全部可能结果:'
  186. })],
  187. store: new Ext.data.Store({
  188. fields: ['group','name','shortName','uu'],
  189. groupField: 'group'
  190. }),
  191. html: '<p class="x-grid-empty alert">没有查找到匹配的企业,您的供应商还未注册<a href="http://www.ubtob.com" target="_blank">优软商务平台</a>或您填写的供应商资料有误,请联系供应商确认!</p>' +
  192. '<p class="x-grid-tip alert arrow-border arrow-bottom-right">从查找到的结果中选择正确的供应商信息<a href="javascript:void(0);" class="pull-right close">知道了&times;</a></p>',
  193. checkEmpty: function(checked) {
  194. var empEl = this.getEl().select('.x-grid-empty'), tipEl = this.getEl().select('.x-grid-tip');
  195. empEl.applyStyles({'display': this.store.getCount() == 0 ? 'block' : 'none'});
  196. tipEl.applyStyles({'display': !checked && this.store.getCount() > 0 ? 'block' : 'none'});
  197. if(!checked && this.store.getCount() > 0) {
  198. Ext.EventManager.on(tipEl.el.dom.childNodes[1], {
  199. click: function(event, el) {
  200. tipEl.applyStyles({'display': 'none'});
  201. Ext.EventManager.stopEvent(event);
  202. },
  203. buffer: 50
  204. });
  205. }
  206. }
  207. });
  208. },
  209. onConfirm: function(veId, uu) {
  210. var me = this, grid = Ext.getCmp('customeruu-win').down('grid');
  211. if(!grid)
  212. me.updateVendorUU(veId, uu, null, null, 1);
  213. else {
  214. if(me.selectedConfig && me.selectedConfig.uu == uu)
  215. me.updateVendorUU(veId, uu, me.selectedConfig.name, me.selectedConfig.shortName, dev, 1);
  216. else
  217. me.check(uu, function(checked){
  218. if(checked)
  219. me.updateVendorUU(veId, uu, null, null, 1);
  220. else
  221. warnMsg('UU号还未验证通过,是否继续保存?', function(btn){
  222. if(btn == 'yes')
  223. me.updateVendorUU(veId, uu, null, null, 0);
  224. });
  225. });
  226. }
  227. },
  228. updateVendorUU: function(veId, uu, name, shortName, checked) {
  229. Ext.Ajax.request({
  230. url: basePath + 'scm/customer/updateUU.action',
  231. params: {
  232. id: veId,
  233. uu: uu,
  234. name: name,
  235. shortName: shortName,
  236. checked: checked
  237. },
  238. callback: function(opt, s, r) {
  239. var rs = Ext.decode(r.responseText);
  240. if(rs.exceptionInfo) {
  241. showError(rs.exceptionInfo);
  242. } else {
  243. alert('设置成功!');
  244. window.location.reload();
  245. }
  246. }
  247. });
  248. },
  249. check: function(uu, callback) {
  250. var name = Ext.getCmp('cu_name').getValue(), shortName = Ext.getCmp('cu_shortname').getValue();
  251. var grid = Ext.getCmp('customeruu-win').down('grid'), me = this;
  252. if(grid) {
  253. grid.setLoading(true);
  254. this.getMembers(name, shortName, uu, function(data){
  255. var s = [], checked = false;
  256. if(data) {
  257. for(var k in data) {
  258. Ext.Array.each(data[k], function(d){
  259. d.group = k == 'name' ? ('名称(' + name + ')') : (k == 'shortName' ?
  260. ('简称(' + shortName + ')') : ('UU号(' + uu + ')'));
  261. s.push(d);
  262. });
  263. if(!checked && k == 'uu' && data[k])
  264. checked = true;
  265. }
  266. }
  267. grid.searchConfig = {name: name, shortName: shortName, uu: uu};
  268. me.selectedConfig = null;
  269. grid.store.loadData(s);
  270. grid.checkEmpty(checked);
  271. Ext.getCmp('b2benable').setChecked(checked);
  272. grid.setLoading(false);
  273. callback && callback.call(null, checked);
  274. });
  275. }
  276. },
  277. isEnable: function(veId, callback) {
  278. Ext.Ajax.request({
  279. url : basePath + 'common/getFieldData.action',
  280. params: {
  281. caller: 'Customer',
  282. field: 'cu_b2benable',
  283. condition: 'cu_id=' + veId
  284. },
  285. method : 'post',
  286. callback : function(opt, s, res){
  287. var r = new Ext.decode(res.responseText);
  288. if(r.exceptionInfo){
  289. showError(r.exceptionInfo);
  290. }
  291. callback && callback.call(null, (!r.data || r.data != 1) ? false : true);
  292. }
  293. });
  294. },
  295. getMembers: function(name, shortName, uu, callback) {
  296. Ext.Ajax.request({
  297. url: basePath + 'b2b/queriable/members.action',
  298. params: {
  299. name: name,
  300. shortName: shortName,
  301. uu: uu
  302. },
  303. method: 'GET',
  304. callback: function(opt, s, r) {
  305. var d = [];
  306. if(r && r.responseText) {
  307. var rs = Ext.decode(r.responseText);
  308. if(rs.exceptionInfo) {
  309. showError(rs.exceptionInfo);
  310. } else
  311. d = rs;
  312. }
  313. callback.call(null, d);
  314. }
  315. });
  316. },
  317. selectRecord: function(grid, record) {
  318. var win = grid.up('window'), u = win.down('field[name=cu_uu]'), e = win.down('#b2benable')
  319. _n = Ext.getCmp('cu_name').getValue(), _t = Ext.getCmp('cu_shortname').getValue(), me = this;
  320. u.setValue(record.get('uu'));
  321. e.setChecked(true);
  322. me.selectedConfig = {uu: record.get('uu')};
  323. var s = '', n = record.get('name'), t = record.get('shortName');
  324. if(_n) {
  325. if(_n != n)
  326. s = '客户名称【' + _n + '】与您选择的企业注册信息【' + n + '】不一致,是否按平台的企业注册信息修改?<br>';
  327. } else {
  328. me.selectedConfig.name = n;// 为空时,直接写入
  329. }
  330. if(_t) {
  331. if(_t != t)
  332. s += '客户名称简称【' + _t + '】与您选择的企业注册信息【' + t + '】不一致,是否按平台的企业注册信息修改?<br>';
  333. } else {
  334. me.selectedConfig.shortName = t;// 为空时,直接写入
  335. }
  336. if(s.length > 0)
  337. warnMsg(s, function(btn){
  338. if(btn == 'yes') {
  339. me.selectedConfig.name = n;
  340. me.selectedConfig.shortName = t;
  341. }
  342. });
  343. }
  344. });