tablegrid-edit.js 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473
  1. define(function (require) {
  2. return function (context) {
  3. var $grid;
  4. var addRowId = 0;
  5. return {
  6. center: {
  7. border: false,
  8. items: {
  9. onRender: function () {
  10. $grid = $(this);
  11. },
  12. xtype: 'yvgrid',
  13. data: [],
  14. rownumbers: true,
  15. idField: 'skuid',
  16. editable: true,
  17. autoSizeColumns: false,
  18. pagination: false,
  19. onRowBeginEdit: function (event) {
  20. console.log('onRowBeginEdit', event);
  21. },
  22. onRowEndEdit: function (event) {
  23. console.log('onRowEndEdit', event);
  24. },
  25. onSelectRow: function (rowid) {
  26. console.log('onSelectRow', rowid);
  27. },
  28. toolbar: {
  29. xtype: 'toolbar',
  30. title: '本地批量编辑',
  31. items: [{
  32. text: '新增', iconCls: 'fa fa-plus-circle', onClick: function () {
  33. addRowId++;
  34. var s = "99.";
  35. for (var j = 0; j < addRowId; j++) {
  36. s = s + "9";
  37. }
  38. $grid.yvgrid('addRow', {
  39. remark: '备注' + addRowId,
  40. skuid: $.yvan.createId('row'),
  41. skucode: 'aa',
  42. uom: 5,
  43. orderqty: addRowId + '3',
  44. orderqtyeach: s,
  45. unitprice: addRowId + '9',
  46. totalprice: addRowId + '27',
  47. createAt: '2019-07-15',
  48. excereceperc: addRowId * 2,
  49. allowexcerece: (addRowId % 2 === 0 ? 'YES' : 'NO')
  50. });
  51. }
  52. }, {
  53. text: 'beginEdit',
  54. onClick: function () {
  55. $grid.yvgrid('beginEdit');
  56. }
  57. }, {
  58. text: 'endEdit',
  59. onClick: function () {
  60. $grid.yvgrid('endEdit');
  61. }
  62. }, {
  63. text: 'cancelEdit',
  64. onClick: function () {
  65. $grid.yvgrid('cancelEdit');
  66. }
  67. }, {
  68. text: '刷新',
  69. onClick: function () {
  70. $grid.yvgrid('refresh');
  71. }
  72. }, {
  73. text: 'getData',
  74. onClick: function () {
  75. $.yvan.alert(
  76. '<pre>' +
  77. JSON.stringify(
  78. $grid.yvgrid('getData'), null, ' '
  79. )
  80. + '</pre>'
  81. );
  82. }
  83. }, {
  84. text: 'getEditRow',
  85. onClick: function () {
  86. $.yvan.alert(
  87. '<pre>' +
  88. JSON.stringify(
  89. $grid.yvgrid('getEditRow'), null, ' '
  90. )
  91. + '</pre>'
  92. );
  93. }
  94. }, {
  95. text: 'setEditRow',
  96. onClick: function () {
  97. $grid.yvgrid('setEditRow', {
  98. skuid: '111',
  99. polineno: '222',
  100. skucode: '我的编号',
  101. skuname: '我的产品名称',
  102. manufacturer: '我的厂家',
  103. createAt: moment().format('YYYY-MM-DD'),
  104. packcode: '我的包装编号',
  105. uom: 5,
  106. orderqty: '11',
  107. orderqtyeach: '22',
  108. unitprice: '33',
  109. totalprice: '44',
  110. allowexcerece: 'YES',
  111. excereceperc: '55',
  112. packid: 'ep',
  113. packtype: 'ep2',
  114. packmeasspec: 'ep3',
  115. zpackMeasspec: 'ep4',
  116. pono: 'ep5',
  117. packunit: 'ep6'
  118. });
  119. $grid.focus();
  120. }
  121. }, {
  122. text: 'setPresentRow',
  123. onClick: function () {
  124. $grid.yvgrid('setPresentRow', {
  125. skuid: '111',
  126. polineno: '222',
  127. skucode: '新编号',
  128. skuname: '新产品名称',
  129. manufacturer: '我的厂家',
  130. createAt: '2013-01-01',
  131. packcode: '新包装编号',
  132. uom: 5,
  133. orderqty: '1111',
  134. orderqtyeach: '2222',
  135. unitprice: '3333',
  136. totalprice: '4444',
  137. allowexcerece: 1,
  138. excereceperc: '5555',
  139. packid: 'np',
  140. packtype: 'np2',
  141. packmeasspec: 'np3',
  142. zpackMeasspec: 'np4',
  143. pono: 'np5',
  144. packunit: 'np6'
  145. });
  146. $grid.focus();
  147. }
  148. }, {
  149. text: '判断编辑中',
  150. onClick: function () {
  151. $.yvan.msg('isEditing:' + $grid.yvgrid('isEditing'));
  152. }
  153. }, {
  154. text: '当前编辑行ID',
  155. onClick: function () {
  156. $.yvan.msg('editRowIndex:' + $grid.yvgrid('editRowIndex'));
  157. }
  158. }, '|', {
  159. text: '删除当前行',
  160. onClick: function () {
  161. $grid.yvgrid('deleteSelectedRow');
  162. }
  163. }
  164. ],
  165. },
  166. columns: [[
  167. {field: 'skuid', hidden: true},
  168. {field: 'polineno', hidden: true},
  169. {
  170. field: 'remark', title: '产品备注', width: 120, editor: {
  171. required: true,
  172. maxlength: 10,
  173. minlength: 2,
  174. onChange: function (value, event) {
  175. console.log('产品备注 onChange', value, event);
  176. },
  177. validate: function (value, row) {
  178. if (value.length < 3) {
  179. return '自定义校验,要求字符必须大于3';
  180. }
  181. if ($.trim(value) === 'abc') {
  182. return '自定义校验,要求不允许是abc';
  183. }
  184. }
  185. }
  186. },
  187. {
  188. field: 'skucode', title: '产品编号', width: 120
  189. },
  190. {
  191. field: 'skuname', title: '产品名称', width: 210, editor: {
  192. required: true,
  193. xtype: 'searchbox',
  194. onChange: function (row) {
  195. console.log('产品名称 onChange', row);
  196. },
  197. widget: {
  198. url: '/yvanui/example/widget/selectDocSku.js',
  199. onWidgetLoadData: function (option, sender) {
  200. return {
  201. ownerId: 'CNT00000022'
  202. };
  203. },
  204. bind: {
  205. skuid: 'skuId',
  206. skucode: 'skuCode',
  207. skuname: 'skuName',
  208. manufacturer: 'manufacturer',
  209. packcode: 'packCode',
  210. packid: 'packId',
  211. packmeasspec: 'packMeasspec',
  212. zpackMeasspec: 'zpackMeasspec',
  213. uom: 'defCustomerPack'
  214. },
  215. clear: {
  216. orderqty: 0,
  217. orderqtyeach: 0,
  218. unitprice: 0,
  219. totalprice: 0,
  220. skuid: '',
  221. skucode: '',
  222. skuname: '',
  223. manufacturer: '',
  224. packcode: '',
  225. packid: '',
  226. packmeasspec: '',
  227. zpackMeasspec: '',
  228. excereceperc: 0,
  229. packunit: '',
  230. uom: '',
  231. allowexcerece: 'NO',
  232. },
  233. success: function (data) {
  234. if (data.defCustomerPack == 0) {
  235. data.defCustomerPack = '';
  236. }
  237. $grid.yvgrid('setEditRow', {
  238. skuid: data.skuId, skucode: data.skuCode, skuname: data.skuName,
  239. manufacturer: data.manufacturer, packcode: data.packCode, packid: data.packId,
  240. packmeasspec: data.packMeasspec,
  241. zpackMeasspec: data.zpackMeasspec,
  242. uom: data.defCustomerPack,
  243. allowexcerece: (data.allowExceRece === '1' ? 'YES' : 'NO'),
  244. excereceperc: data.exceRecePerc
  245. }, this);
  246. }
  247. }
  248. }
  249. },
  250. {field: 'manufacturer', title: '生产厂家', width: 140},
  251. {
  252. field: 'createAt', title: '生产日期', width: 120, editor: {
  253. xtype: 'datebox',
  254. required: true,
  255. min: '2018-12-31',
  256. max: '2019-12-31',
  257. validate: function (value, row) {
  258. if (moment().format('YYYY-MM-DD') !== value) {
  259. return '自定义校验,要求时间必须是' + moment().format('YYYY-MM-DD');
  260. }
  261. },
  262. onChange: function (value) {
  263. console.log('生产日期 changed to:', value);
  264. }
  265. }
  266. },
  267. {field: 'packcode', title: '包装编号', width: 100},
  268. {
  269. field: 'uom',
  270. title: '收货单位',
  271. width: 120,
  272. editor: {
  273. xtype: 'combobox',
  274. required: true,
  275. data: [
  276. {id: '1', text: '主单位'},
  277. {id: '2', text: '内包装'},
  278. {id: '3', text: '箱'},
  279. {id: '4', text: '托盘'},
  280. {id: '5', text: '其他'},
  281. ],
  282. valueField: 'id',
  283. textField: 'text',
  284. validate: function (value, row) {
  285. if (value === '5') {
  286. return '自定义校验,要求不允许是5(其他)';
  287. }
  288. },
  289. onChange: function (newValue) {
  290. console.log('收货单位 onChange', newValue);
  291. var row = $grid.yvgrid('getEditRow', this);
  292. if (!row.skuid) {
  293. $.yvan.msg("请先选择当前行商品信息!");
  294. $grid.yvgrid('setEditRow', {uom: ''}, this);
  295. return;
  296. }
  297. row.uom = newValue;
  298. //$.yvan.ajax({
  299. // url: whUrl('/wms/inbound/docpo/changeUom'),
  300. // type: 'get',
  301. // async: false,
  302. // data: {
  303. // skuid: row.skuid,
  304. // uom: row.uom
  305. // },
  306. // success: function (data) {
  307. // row.packtype = 1;
  308. // row.packmeasspec = data.data.packMeasspec;
  309. // row.packunit = data.data.packUnit;
  310. // row.zpackMeasspec = data.data.zpackMeasspec;
  311. // if (row.orderqty) {
  312. // row.orderqtyeach = (row.orderqty * row.zpackMeasspec / row.packmeasspec).toFixed(2);
  313. // }
  314. // $grid.setEditRow(row);
  315. // }
  316. //});
  317. }
  318. }
  319. },
  320. {
  321. field: 'orderqty', title: '订单数量(主单位)', width: 120, type: 'number',
  322. editor: {
  323. xtype: 'numberbox',
  324. precision: 1,
  325. required: true,
  326. min: 0,
  327. max: 100,
  328. validate: function (value, row) {
  329. if (value > 50) {
  330. return '自定义校验,必须小于50';
  331. }
  332. },
  333. onChange: function () {
  334. console.log('订单数量(主单位) changed');
  335. var row = $grid.yvgrid('getEditRow', this);
  336. var obj = {};
  337. if (row.orderqty) {
  338. //obj.orderqtyeach = (row.orderqty * row.zpackMeasspec / row.packmeasspec).toFixed(2);
  339. obj.orderqtyeach = row.orderqty;
  340. }
  341. if (row.unitprice && row.orderqty) {
  342. obj.totalprice = row.unitprice * row.orderqty;
  343. }
  344. $grid.yvgrid('setEditRow', obj, this);
  345. }
  346. }
  347. },
  348. {
  349. field: 'orderqtyeach', title: '订单数量(收货单位)', width: 120, type: 'number',
  350. editor: {
  351. xtype: 'numberbox',
  352. precision: 2,
  353. required: true,
  354. min: 0,
  355. max: 100,
  356. validate: function (value, row) {
  357. if (value > 50) {
  358. return '自定义校验,必须小于50';
  359. }
  360. },
  361. onChange: function () {
  362. console.log('订单数量(收货单位) changed');
  363. var row = $grid.yvgrid('getEditRow', this);
  364. if (row.orderqtyeach) {
  365. $grid.yvgrid('setEditRow', {
  366. //orderqty: ((row.orderqtyeach * row.packmeasspec) / row.zpackMeasspec).toFixed(2)
  367. orderqty: row.orderqtyeach
  368. }, this);
  369. }
  370. }
  371. }
  372. },
  373. {
  374. field: 'unitprice', title: '含税单价', width: 100, type: 'number',
  375. editor: {
  376. xtype: 'numberbox',
  377. precision: 3,
  378. required: true,
  379. min: 0,
  380. max: 100,
  381. validate: function (value, row) {
  382. if (value <= 10) {
  383. return '自定义校验,业务要求必须大于10';
  384. }
  385. },
  386. onChange: function () {
  387. console.log('含税单价 changed');
  388. var row = $grid.yvgrid('getEditRow', this);
  389. if (row.unitprice && row.orderqty) {
  390. $grid.yvgrid('setEditRow', {
  391. totalprice: row.unitprice * row.orderqty
  392. }, this);
  393. }
  394. }
  395. }
  396. },
  397. {
  398. field: 'totalprice', title: '含税金额', width: 100, type: 'number',
  399. editor: {
  400. xtype: 'numberbox',
  401. precision: 4,
  402. required: true,
  403. min: 0,
  404. max: 100,
  405. validate: function (value, row) {
  406. if (value <= 10) {
  407. return '自定义校验,要求必须大于10';
  408. }
  409. if (value > 50) {
  410. return '自定义校验,必须小于50';
  411. }
  412. },
  413. onChange: function () {
  414. console.log('含税金额 changed');
  415. var row = $grid.yvgrid('getEditRow', this);
  416. if (row.totalprice && row.orderqty) {
  417. $grid.yvgrid('setEditRow', {
  418. unitprice: (row.totalprice / row.orderqty).toFixed(2)
  419. }, this);
  420. }
  421. }
  422. }
  423. },
  424. {
  425. field: 'allowexcerece', title: '超量收货', width: 100,
  426. editor: {
  427. xtype: 'checkbox',
  428. on: 'YES',
  429. off: 'NO',
  430. validate: function (value, row) {
  431. if (value !== 'YES') {
  432. return '自定义校验,要求必须勾选';
  433. }
  434. },
  435. onChange: function (value) {
  436. console.log('超量收货 changed', value);
  437. }
  438. }
  439. },
  440. {
  441. field: 'excereceperc', title: '超量百分比(%)', width: 100, type: 'number',
  442. editor: {
  443. xtype: 'numberbox',
  444. required: true,
  445. precision: 0,
  446. min: 0,
  447. max: 100,
  448. validate: function (value, row) {
  449. if (value < 5) {
  450. return '自定义校验,要求必须大于5';
  451. }
  452. if (value > 80) {
  453. return '自定义校验,必须小于80';
  454. }
  455. },
  456. onChange: function () {
  457. console.log('超量百分比 changed');
  458. }
  459. }
  460. },
  461. {field: 'packid', hidden: true},
  462. {field: 'packtype', hidden: true, value: '1'},
  463. {field: 'packmeasspec', hidden: true},
  464. {field: 'zpackMeasspec', hidden: true},
  465. {field: 'pono', hidden: true},
  466. {field: 'packunit', hidden: true}
  467. ]]
  468. }
  469. }
  470. };
  471. };
  472. });