VendorUU.js 10 KB

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