stockout.js 46 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900
  1. requirejs.config({
  2. paths: {
  3. vue: 'backend/stock/libs/vue',
  4. ELEMENT: 'backend/stock/libs/element-ui',
  5. },
  6. shim: {
  7. ELEMENT: ['vue']
  8. }
  9. })
  10. define(['jquery', 'bootstrap', 'backend', 'table', 'form', 'vue', 'ELEMENT', 'moment'], function ($, undefined, Backend, Table, Form, Vue, ELEMENT, Moment) {
  11. var Controller = {
  12. index: function () {
  13. $('.btn-add,.btn-edit,.btn-audit,.btn-settle,.btn-split').data("area", ['100%', '100%']);
  14. // 初始化表格参数配置
  15. Table.api.init({
  16. extend: {
  17. index_url: 'stock/stockout/index',
  18. add_url: 'stock/stockout/add',
  19. edit_url: 'stock/stockout/edit',
  20. del_url: 'stock/stockout/del',
  21. multi_url: 'stock/stockout/multi',
  22. table: 'stock_stockout',
  23. }
  24. });
  25. var table = $("#table");
  26. $.fn.bootstrapTable.locales[Table.defaults.locale]['formatSearch'] = function () {
  27. return '搜索[单据编号、客户名称]';
  28. };
  29. var selfOperate = {
  30. 'click .btn-editone': function (e, value, row, index) {
  31. e.stopPropagation();
  32. e.preventDefault();
  33. if (!row.audittime) {
  34. var table = $(this).closest('table');
  35. var options = table.bootstrapTable('getOptions');
  36. var ids = row[options.pk];
  37. row = $.extend({}, row ? row : {}, { ids: ids });
  38. var url = options.extend.edit_url;
  39. Fast.api.open(Table.api.replaceurl(url, row, table), __('Edit'), $(this).data() || {});
  40. } else {
  41. Toastr.error('该出库记录已通过审核,不能修改!')
  42. }
  43. ;
  44. },
  45. 'click .btn-delone': function (e, value, row, index) {
  46. e.stopPropagation();
  47. e.preventDefault();
  48. var that = this;
  49. var top = $(that).offset().top - $(window).scrollTop();
  50. var left = $(that).offset().left - $(window).scrollLeft() - 260;
  51. if (top + 154 > $(window).height()) {
  52. top = top - 154;
  53. }
  54. if ($(window).width() < 480) {
  55. top = left = undefined;
  56. }
  57. if (!row.auditTime) {
  58. Layer.confirm(
  59. __('Are you sure you want to delete this item?'), { icon: 3, title: __('Warning'), offset: [top, left], shadeClose: true },
  60. function (index) {
  61. var table = $(that).closest('table');
  62. var options = table.bootstrapTable('getOptions');
  63. Table.api.multi("del", row[options.pk], table, that);
  64. Layer.close(index);
  65. }
  66. );
  67. } else {
  68. Toastr.error('该出库记录已通过审核,不能删除!')
  69. }
  70. ;
  71. }
  72. }
  73. // 初始化表格
  74. table.bootstrapTable({
  75. url: $.fn.bootstrapTable.defaults.extend.index_url,
  76. sortName: 'createtime',
  77. singleSelect: true, //是否启用单选
  78. columns: [
  79. [
  80. { checkbox: true },
  81. {
  82. field: 'id',
  83. title: __('Id'),
  84. operate: false,
  85. width: 50,
  86. },
  87. { field: 'docnum', operate: "LIKE", title: __('单据编号'), sortable: true },
  88. { field: 'outboundtime', title: __('Outboundtime'), operate: 'RANGE', formatter: Table.api.formatter.datetime, datetimeFormat: 'YYYY-MM-DD', addclass: 'datetimerange', sortable: true },
  89. { field: 'customer.name', title: __('客户名称'), sortable: true },
  90. { field: 'totaloutamount', title: __('单据总重量(kg)'), sortable: true },
  91. { field: 'remark', title: __('Remark') },
  92. { field: 'audittime', title: __('审核状态'), formatter: Controller.api.formatter.audit },
  93. // { field: 'settletime', title: __('结算状态'), formatter: Controller.api.formatter.settle },
  94. { field: 'operate', title: __('Operate'), table: table, events: selfOperate, formatter: Table.api.formatter.operate }
  95. ]
  96. ],
  97. onPostBody: function () {
  98. $(".btn-editone ").data("area", ['100%', '100%']);
  99. }
  100. });
  101. // 为表格绑定事件
  102. Table.api.bindevent(table);
  103. // 打印按钮事件
  104. $('.toolbar').on('click', '.btn-print', function () {
  105. var that = this;
  106. var selectedrow = table.bootstrapTable('getSelections');
  107. if (selectedrow.length == 1) {
  108. Fast.api.open('stock/stockout/printer?id=' + selectedrow[0]['id'], __('打印'), $(that).data() || {});
  109. } else {
  110. Toastr.error(selectedrow.length > 1 ? '只能选择一条入库记录' : '请选择入库记录')
  111. }
  112. });
  113. // 批量编辑按钮事件
  114. $('.btn-edit').click(function (event) {
  115. event.stopPropagation();
  116. var selectedrow = table.bootstrapTable('getSelections');
  117. console.log(selectedrow);
  118. if (selectedrow.length == 1 && !selectedrow[0]['audittime']) {
  119. var that = this;
  120. var url = 'stock/stockout/edit';
  121. selectedrow[0] = $.extend({}, selectedrow[0] ? selectedrow[0] : {}, { ids: selectedrow[0]['id'] });
  122. var url = Table.api.replaceurl(url, selectedrow[0], table);
  123. Fast.api.open(url, __('Edit'), $(that).data() || {});
  124. } else {
  125. if (selectedrow[0]['audittime']) {
  126. Toastr.error('该记录已审核,不能修改!')
  127. } else {
  128. Toastr.error(selectedrow.length > 1 ? '只能选择一条记录' : '请选择一条记录')
  129. }
  130. }
  131. });
  132. // 审核/反审核按钮事件 结算/反结算按钮事件
  133. $('.toolbar').on('click', '.btn-audit,.btn-settle', function () {
  134. var that = this;
  135. var selectedrow = table.bootstrapTable('getSelections');
  136. var title = "审核";
  137. if (selectedrow.length == 1) {
  138. var operatetype = $(this).data("operatetype");
  139. if (operatetype == "audit") {
  140. console.log(selectedrow[0].settletime);
  141. if (selectedrow[0].settletime !== null) {
  142. Toastr.error("该出库单已结算,请先进行反结算!");
  143. return;
  144. } else {
  145. title = selectedrow[0].audittime == null ? "审核" : "反审核";
  146. }
  147. } else if (operatetype == "settle") {
  148. if (selectedrow[0].audittime == null) {
  149. Toastr.error("该出库单未审核,请先进行审核!");
  150. return;
  151. } else {
  152. title = selectedrow[0].settletime == null ? "结算" : "反结算";
  153. }
  154. }
  155. var url = 'stock/stockout/look?operatetype=' + operatetype;
  156. selectedrow[0] = $.extend({}, selectedrow[0] ? selectedrow[0] : {}, { ids: selectedrow[0]['id'] });
  157. var url = Table.api.replaceurl(url, selectedrow[0], table);
  158. Fast.api.open(url, title, $(that).data() || {});
  159. } else {
  160. Toastr.error(selectedrow.length > 1 ? '只能选择一条记录' : '请选择一条记录')
  161. }
  162. });
  163. },
  164. getlist: function () {
  165. // 初始化表格参数配置
  166. Table.api.init({
  167. extend: {
  168. list_url: 'stock/stockout/getlist',
  169. }
  170. });
  171. var table = $("#table");
  172. // 初始化表格
  173. table.bootstrapTable({
  174. url: $.fn.bootstrapTable.defaults.extend.list_url,
  175. pk: 'id',
  176. sortName: 'stockoutlist.id',
  177. height: $(window).height() - 97,
  178. columns: [
  179. [
  180. { checkbox: true },
  181. {
  182. field: 'id',
  183. title: __('Id'),
  184. },
  185. { field: 'stockout.docnum', operate: "LIKE", title: __('单据编号') },
  186. { field: 'stockout.customer.name', operate: "LIKE", title: __('客户名称'), sortable: true },
  187. { field: 'goods.volnum', title: '商品代码' },
  188. { field: 'goods.goodsname', title: '商品名称' },
  189. { field: 'goods.productmodel', title: '规格型号' },
  190. { field: 'goods.measureunit', title: '单位' },
  191. { field: 'stockoutnums', type: "Number", title: '出库数量' },
  192. { field: 'stockin.inboundprice', title: '单价', operate: 'BETWEEN' },
  193. { field: 'amount', title: '重量(kg)', operate: 'BETWEEN' },
  194. { field: 'stockout.outboundtime', title: '出库日期', operate: 'RANGE', formatter: Table.api.formatter.datetime, datetimeFormat: 'YYYY-MM-DD', addclass: 'datetimerange', sortable: true },
  195. { field: 'remark', title: __('Remark') },
  196. ]
  197. ]
  198. });
  199. // 为表格绑定事件
  200. Table.api.bindevent(table);
  201. },
  202. look: function () {
  203. Vue.use(ELEMENT);
  204. var vm = new Vue({
  205. el: "#app",
  206. data: function () {
  207. return {
  208. row: { stock_customer_id: "", remark: "", outboundtime: "", docnum:"" },
  209. selectedgoodsdata: {
  210. table: { height: ($(window).height() - 355) + "px" },
  211. list: [],
  212. },
  213. commiturl: "",
  214. }
  215. },
  216. computed: {
  217. goodslist: function () { return JSON.stringify(this.selectedgoodsdata.list) },
  218. },
  219. created() {
  220. this.loadstockoutinfo()
  221. },
  222. methods: {
  223. loadstockoutinfo() {
  224. let operatetype = Fast.api.query("operatetype")
  225. let that = this;
  226. $.ajax({
  227. url: 'stock/stockout/info',
  228. type: "POST",
  229. data: { id: Fast.api.query("ids") },
  230. async: false,
  231. success: function (res) {
  232. res.row.outboundtime = Moment(parseInt(res.row.outboundtime) * 1000).format("YYYY-MM-DD");
  233. if (operatetype == "audit") {
  234. if (res.row.audittime) {
  235. that.commiturl = 'stock/stockout/unaudit';
  236. $('#audit').html('反审核');
  237. } else {
  238. that.commiturl = 'stock/stockout/audit';
  239. $('#audit').html('审核');
  240. }
  241. } else if (operatetype == "settle") {
  242. if (res.row.settletime) {
  243. that.commiturl = 'stock/stockout/unsettle';
  244. $('#audit').html('反结算');
  245. } else {
  246. that.commiturl = 'stock/stockout/settle';
  247. $('#audit').html('结算');
  248. }
  249. }
  250. that.row = res.row;
  251. that.selectedgoodsdata.list = res.goodslist;
  252. },
  253. error: function (res) {
  254. Toastr.error("加载失败!")
  255. }
  256. })
  257. }
  258. }
  259. })
  260. // 提交事件
  261. $(document).on('click', '#audit', function (e) {
  262. e.preventDefault();
  263. var url = $("#c-commiturl").val();
  264. Layer.confirm(
  265. __('确认提交?'), { icon: 3, title: __('Warning'), offset: 200, shadeClose: true },
  266. function (index) {
  267. $('#form').attr('action', url);
  268. $('#form').submit();
  269. Layer.close(index);
  270. }
  271. );
  272. });
  273. Form.api.bindevent($("form[role=form]"));
  274. },
  275. add: function () {
  276. Vue.use(ELEMENT);
  277. var vm = new Vue({
  278. el: "#app",
  279. data: function () {
  280. return {
  281. searchvalue: "",
  282. row: { stock_customer_id: "", remark: "", outboundtime: new Date() },
  283. curgood: { stock_goods_id: "", volnum: "", goodsname: "", productmodel: "", measureunit: "件", stocknum: "", stockoutnums: 0, stockoutgoodsremark: "", barcode: "" },
  284. defaultgood: { stock_goods_id: "", volnum: "", goodsname: "", productmodel: "", measureunit: "件", stocknum: "", stockoutnums: 0, stockoutgoodsremark: "", barcode: "" },
  285. customerlist: [],
  286. goodsdata: {
  287. table: { height: ($(window).height() - 490) + "px" },
  288. list: [],
  289. pagenation: {
  290. currentpage: 1,
  291. pagesize: 10,
  292. total: 0
  293. }
  294. },
  295. selectedgoodsdata: {
  296. table: { height: ($(window).height() - 310) + "px" },
  297. list: [],
  298. },
  299. rules: {
  300. stockinnums: [
  301. { required: true, message: '出库数量不能为空' },
  302. { type: 'number', message: '出库数量必须为数字值' }
  303. ],
  304. }
  305. }
  306. },
  307. computed: {
  308. main: function () { return JSON.stringify(this.row) },
  309. goodslist: function () { return JSON.stringify(this.selectedgoodsdata.list) }
  310. },
  311. created() {
  312. this.loadgoodslist()
  313. this.loadcustomerlist()
  314. },
  315. methods: {
  316. loadcustomerlist() {
  317. let that = this;
  318. $.ajax({
  319. url: 'stock/customer/index',
  320. data: {},
  321. success: function (res) {
  322. that.customerlist = res.rows;
  323. },
  324. error: function (res) {
  325. Toastr.error("加载失败!")
  326. }
  327. })
  328. },
  329. loadgoodslist() {
  330. let that = this;
  331. $.ajax({
  332. url: 'stock/goods/getlist',
  333. data: { sort: 'goods.id', order: 'desc', offset: this.goodsdata.pagenation.pagesize * (this.goodsdata.pagenation.currentpage - 1), limit: this.goodsdata.pagenation.pagesize, searchvalue: this.searchvalue },
  334. success: function (res) {
  335. that.goodsdata.list = res.rows;
  336. that.goodsdata.pagenation.total = res.total;
  337. },
  338. error: function (res) {
  339. Toastr.error("加载失败!")
  340. }
  341. })
  342. },
  343. handleSizeChange(val) {
  344. this.goodsdata.pagenation.pagesize = val;
  345. this.loadgoodslist();
  346. },
  347. handleCurrentChange(val) {
  348. this.goodsdata.pagenation.currentpage = val;
  349. this.loadgoodslist();
  350. },
  351. debounce(fn, delay) {
  352. let timeout = null;
  353. delay = delay || 500;
  354. return function (e) {
  355. let args = arguments;
  356. let that = this;
  357. clearTimeout(timeout);
  358. timeout = setTimeout(function () {
  359. fn.apply(that, args);
  360. }, delay);
  361. };
  362. },
  363. barcodeinputenter() {
  364. let that = this;
  365. if (this.curgood.barcode == "") {
  366. Fast.api.msg("请输入商品条码并按回车键!")
  367. } else {
  368. Fast.api.ajax({
  369. url: "stock/goods/getgoodsbybarcodeorid",
  370. data: { barcode: this.curgood.barcode }
  371. }, function (data) {
  372. if (data !== null) {
  373. that.curgood.stock_goods_id = data.id;
  374. that.curgood.volnum = data.volnum;
  375. that.curgood.goodsname = data.goodsname;
  376. that.curgood.productmodel = data.productmodel;
  377. that.curgood.measureunit = data.measureunit;
  378. that.curgood.stockoutnums = data.curstocknum >= 1 ? 1 : 0;
  379. that.curgood.stocknum = data.curstocknum;
  380. that.curgood.stockoutgoodsremark = "";
  381. }
  382. })
  383. }
  384. },
  385. onSearchvalueChange() {
  386. this.debounce(this.loadgoodslist, 1000)();
  387. },
  388. selectonegood(currentrow) {
  389. let that = this;
  390. Fast.api.ajax({
  391. url: "stock/goods/getgoodsbybarcodeorid",
  392. data: { id: currentrow.id }
  393. }, function (data) {
  394. if (data !== null) {
  395. that.curgood.stock_goods_id = data.id;
  396. that.curgood.volnum = data.volnum;
  397. that.curgood.goodsname = data.goodsname;
  398. that.curgood.productmodel = data.productmodel;
  399. that.curgood.measureunit = data.measureunit;
  400. that.curgood.barcode = data.barcode;
  401. that.curgood.stockoutnums = data.curstocknum >= 1 ? 1 : 0;
  402. that.curgood.stocknum = data.curstocknum;
  403. that.curgood.stockoutgoodsremark = "";
  404. }
  405. })
  406. },
  407. addtolist() {
  408. let that = this;
  409. let hasadded = false;
  410. if (this.curgood.stock_goods_id != "") {
  411. if (this.curgood.stockoutnums == 0) {
  412. Fast.api.msg("出库数量不能为0!");
  413. return;
  414. }
  415. if (this.curgood.stockoutnums > this.curgood.stocknum) {
  416. Fast.api.msg("出库数量不能大于库存数量,请修改!");
  417. return;
  418. }
  419. this.selectedgoodsdata.list.forEach(item => {
  420. if (item.stock_goods_id == that.curgood.stock_goods_id) {
  421. Fast.api.msg("该商品已添加,请勿重复添加!")
  422. hasadded = true;
  423. }
  424. });
  425. if (!hasadded) {
  426. let good = JSON.parse(JSON.stringify(this.curgood));
  427. this.selectedgoodsdata.list.unshift(good);
  428. this.curgood = JSON.parse(JSON.stringify(this.defaultgood));
  429. }
  430. } else {
  431. Fast.api.msg("请选择出库商品!")
  432. }
  433. },
  434. reset() {
  435. this.curgood = JSON.parse(JSON.stringify(this.defaultgood));
  436. },
  437. getcurgoodamount() {
  438. this.curgood.amount = this.accMul(this.curgood.stockinnums, this.curgood.inboundprice);
  439. },
  440. accMul(arg1, arg2) {
  441. var m = 0, s1 = arg1.toString(), s2 = arg2.toString();
  442. try {
  443. m += s1.split(".")[1].length
  444. } catch (e) {
  445. }
  446. try {
  447. m += s2.split(".")[1].length
  448. } catch (e) {
  449. }
  450. return Number(s1.replace(".", "")) * Number(s2.replace(".", "")) / Math.pow(10, m)
  451. },
  452. accAdd(arg1, arg2) {
  453. var r1, r2, m;
  454. try {
  455. r1 = arg1.toString().split(".")[1].length
  456. } catch (e) {
  457. r1 = 0
  458. }
  459. try {
  460. r2 = arg2.toString().split(".")[1].length
  461. } catch (e) {
  462. r2 = 0
  463. }
  464. m = Math.pow(10, Math.max(r1, r2))
  465. return (arg1 * m + arg2 * m) / m
  466. },
  467. accSub(arg1, arg2) {
  468. var r1, r2, m, n;
  469. try {
  470. r1 = arg1.toString().split(".")[1].length;
  471. } catch (e) {
  472. r1 = 0;
  473. }
  474. try {
  475. r2 = arg2.toString().split(".")[1].length;
  476. } catch (e) {
  477. r2 = 0;
  478. }
  479. m = Math.pow(10, Math.max(r1, r2));
  480. //last modify by deeka
  481. //动态控制精度长度
  482. n = (r1 >= r2) ? r1 : r2;
  483. return ((arg1 * m - arg2 * m) / m).toFixed(n);
  484. },
  485. deleteselected(row) {
  486. this.selectedgoodsdata.list = this.selectedgoodsdata.list.filter(item => {
  487. return item != row;
  488. });
  489. this.row.totalamount = this.accSub(this.row.totalamount, row.amount);
  490. }
  491. }
  492. })
  493. Form.api.bindevent($("form[role=form]"), "", "", function () {
  494. let main = JSON.parse($("#c-main").val());
  495. let goodslist = JSON.parse($("#c-goodslist").val());
  496. if (main.stock_customer_id == "") {
  497. Toastr.error("请选择客户");
  498. return false;
  499. } else if (goodslist.length < 1) {
  500. Toastr.error("请添加出库商品");
  501. return false;
  502. }
  503. });
  504. },
  505. edit: function () {
  506. Vue.use(ELEMENT);
  507. var vm = new Vue({
  508. el: "#app",
  509. data: function () {
  510. return {
  511. searchvalue: "",
  512. row: { stock_customer_id: "", remark: "", outboundtime: new Date() },
  513. curgood: { stock_goods_id: "", volnum: "", goodsname: "", productmodel: "", measureunit: "件", stocknum: "", stockoutnums: 0, stockoutgoodsremark: "", barcode: "" },
  514. defaultgood: { stock_goods_id: "", volnum: "", goodsname: "", productmodel: "", measureunit: "件", stocknum: "", stockoutnums: 0, stockoutgoodsremark: "", barcode: "" },
  515. customerlist: [],
  516. goodsdata: {
  517. table: { height: ($(window).height() - 490) + "px" },
  518. list: [],
  519. pagenation: {
  520. currentpage: 1,
  521. pagesize: 10,
  522. total: 0
  523. }
  524. },
  525. selectedgoodsdata: {
  526. table: { height: ($(window).height() - 350) + "px" },
  527. list: [],
  528. },
  529. deselectedgoodslist: [],
  530. rules: {
  531. stockinnums: [
  532. { required: true, message: '出库数量不能为空' },
  533. { type: 'number', message: '出库数量必须为数字值' }
  534. ],
  535. }
  536. }
  537. },
  538. computed: {
  539. main: function () { return JSON.stringify(this.row) },
  540. goodslist: function () { return JSON.stringify(this.selectedgoodsdata.list) }
  541. },
  542. created() {
  543. this.loadstockoutinfo()
  544. this.loadgoodslist()
  545. this.loadcustomerlist()
  546. },
  547. methods: {
  548. loadstockoutinfo() {
  549. let that = this;
  550. $.ajax({
  551. url: 'stock/stockout/info',
  552. type: "POST",
  553. data: { id: Fast.api.query("ids") },
  554. success: function (res) {
  555. res.row.outboundtime = Moment(parseInt(res.row.outboundtime) * 1000).format("YYYY-MM-DD");
  556. console.log(res.row);
  557. that.row = res.row;
  558. that.selectedgoodsdata.list = res.goodslist;
  559. },
  560. error: function (res) {
  561. Toastr.error("加载失败!")
  562. }
  563. })
  564. },
  565. loadcustomerlist() {
  566. let that = this;
  567. $.ajax({
  568. url: 'stock/customer/index',
  569. data: {},
  570. success: function (res) {
  571. that.customerlist = res.rows;
  572. },
  573. error: function (res) {
  574. Toastr.error("加载失败!")
  575. }
  576. })
  577. },
  578. loadgoodslist() {
  579. let that = this;
  580. $.ajax({
  581. url: 'stock/goods/getlist',
  582. data: { sort: 'goods.id', order: 'desc', offset: this.goodsdata.pagenation.pagesize * (this.goodsdata.pagenation.currentpage - 1), limit: this.goodsdata.pagenation.pagesize, searchvalue: this.searchvalue },
  583. success: function (res) {
  584. that.goodsdata.list = res.rows;
  585. that.goodsdata.pagenation.total = res.total;
  586. },
  587. error: function (res) {
  588. Toastr.error("加载失败!")
  589. }
  590. })
  591. },
  592. handleSizeChange(val) {
  593. this.goodsdata.pagenation.pagesize = val;
  594. this.loadgoodslist();
  595. },
  596. handleCurrentChange(val) {
  597. this.goodsdata.pagenation.currentpage = val;
  598. this.loadgoodslist();
  599. },
  600. debounce(fn, delay) {
  601. let timeout = null;
  602. delay = delay || 500;
  603. return function (e) {
  604. let args = arguments;
  605. let that = this;
  606. clearTimeout(timeout);
  607. timeout = setTimeout(function () {
  608. fn.apply(that, args);
  609. }, delay);
  610. };
  611. },
  612. barcodeinputenter() {
  613. let that = this;
  614. if (this.curgood.barcode == "") {
  615. Fast.api.msg("请输入商品条码并按回车键!")
  616. } else {
  617. Fast.api.ajax({
  618. url: "stock/goods/getgoodsbybarcodeorid",
  619. data: { barcode: this.curgood.barcode }
  620. }, function (data) {
  621. if (data !== null) {
  622. that.curgood.stock_goods_id = data.id;
  623. that.curgood.volnum = data.volnum;
  624. that.curgood.goodsname = data.goodsname;
  625. that.curgood.productmodel = data.productmodel;
  626. that.curgood.measureunit = data.measureunit;
  627. that.curgood.stockoutnums = data.curstocknum >= 1 ? 1 : 0;
  628. that.curgood.stocknum = data.curstocknum;
  629. that.curgood.stockoutgoodsremark = "";
  630. }
  631. })
  632. }
  633. },
  634. onSearchvalueChange() {
  635. this.debounce(this.loadgoodslist, 1000)();
  636. },
  637. selectonegood(currentrow) {
  638. let that = this;
  639. Fast.api.ajax({
  640. url: "stock/goods/getgoodsbybarcodeorid",
  641. data: { id: currentrow.id }
  642. }, function (data) {
  643. if (data !== null) {
  644. that.curgood.stock_goods_id = data.id;
  645. that.curgood.volnum = data.volnum;
  646. that.curgood.goodsname = data.goodsname;
  647. that.curgood.productmodel = data.productmodel;
  648. that.curgood.measureunit = data.measureunit;
  649. that.curgood.barcode = data.barcode;
  650. that.curgood.stockoutnums = data.curstocknum >= 1 ? 1 : 0;
  651. that.curgood.stocknum = data.curstocknum;
  652. that.curgood.stockoutgoodsremark = "";
  653. }
  654. })
  655. },
  656. addtolist() {
  657. let that = this;
  658. let hasadded = false;
  659. if (this.curgood.stock_goods_id != "") {
  660. if (this.curgood.stockoutnums == 0) {
  661. Fast.api.msg("出库数量不能为0!");
  662. return;
  663. }
  664. if (this.curgood.stockoutnums > this.curgood.stocknum) {
  665. Fast.api.msg("出库数量不能大于库存数量,请修改!");
  666. return;
  667. }
  668. this.selectedgoodsdata.list.forEach(item => {
  669. if (item.stock_goods_id == that.curgood.stock_goods_id) {
  670. Fast.api.msg("该商品已添加,请勿重复添加!")
  671. hasadded = true;
  672. }
  673. });
  674. if (!hasadded) {
  675. let good = JSON.parse(JSON.stringify(this.curgood));
  676. this.selectedgoodsdata.list.unshift(good);
  677. this.curgood = JSON.parse(JSON.stringify(this.defaultgood));
  678. }
  679. } else {
  680. Fast.api.msg("请选择出库商品!")
  681. }
  682. },
  683. reset() {
  684. this.curgood = JSON.parse(JSON.stringify(this.defaultgood));
  685. },
  686. getcurgoodamount() {
  687. this.curgood.amount = this.accMul(this.curgood.stockinnums, this.curgood.inboundprice);
  688. },
  689. accMul(arg1, arg2) {
  690. var m = 0, s1 = arg1.toString(), s2 = arg2.toString();
  691. try {
  692. m += s1.split(".")[1].length
  693. } catch (e) {
  694. }
  695. try {
  696. m += s2.split(".")[1].length
  697. } catch (e) {
  698. }
  699. return Number(s1.replace(".", "")) * Number(s2.replace(".", "")) / Math.pow(10, m)
  700. },
  701. accAdd(arg1, arg2) {
  702. var r1, r2, m;
  703. try {
  704. r1 = arg1.toString().split(".")[1].length
  705. } catch (e) {
  706. r1 = 0
  707. }
  708. try {
  709. r2 = arg2.toString().split(".")[1].length
  710. } catch (e) {
  711. r2 = 0
  712. }
  713. m = Math.pow(10, Math.max(r1, r2))
  714. return (arg1 * m + arg2 * m) / m
  715. },
  716. accSub(arg1, arg2) {
  717. var r1, r2, m, n;
  718. try {
  719. r1 = arg1.toString().split(".")[1].length;
  720. } catch (e) {
  721. r1 = 0;
  722. }
  723. try {
  724. r2 = arg2.toString().split(".")[1].length;
  725. } catch (e) {
  726. r2 = 0;
  727. }
  728. m = Math.pow(10, Math.max(r1, r2));
  729. //last modify by deeka
  730. //动态控制精度长度
  731. n = (r1 >= r2) ? r1 : r2;
  732. return ((arg1 * m - arg2 * m) / m).toFixed(n);
  733. },
  734. deleteselected(row) {
  735. if (row.id) {
  736. this.deselectedgoodslist.unshift(row.id);
  737. }
  738. this.selectedgoodsdata.list = this.selectedgoodsdata.list.filter(item => {
  739. return item != row;
  740. });
  741. this.row.totalamount = this.accSub(this.row.totalamount, row.amount);
  742. }
  743. }
  744. })
  745. Form.api.bindevent($("form[role=form]"), "", "", function () {
  746. let main = JSON.parse($("#c-main").val());
  747. let goodslist = JSON.parse($("#c-goodslist").val());
  748. if (main.stock_customer_id == "") {
  749. Toastr.error("请选择客户");
  750. return false;
  751. } else if (goodslist.length < 1) {
  752. Toastr.error("请添加出库商品");
  753. return false;
  754. }
  755. });
  756. },
  757. printer: function () {
  758. $.ajax({
  759. type: "POST",
  760. url: Fast.api.fixurl('stock/stockout/info'),
  761. data: { "id": Fast.api.query("id") },
  762. async: true, //或false,是否异步
  763. timeout: 5000, //超时时间
  764. dataType: 'json', //返回的数据格式:json/xml/html/script/jsonp/text
  765. success: function (data) {
  766. madehtml(data);
  767. }
  768. });
  769. function madehtml(data) {
  770. var h = "<div id=\"top\" class=\"page\"><div style=\"text-align: center;font-size:22px;line-height:38px\" >出库单</div>" +
  771. "<table style=\"width:100%;\">" +
  772. " <tr>" +
  773. " <td width=\"40%\"></td>" +
  774. "<td width=\"25%\"></td>" +
  775. "<td width=\"12%\" tdata=\"pageNO\" format=\"##\" style=\"text-align:right;\">第##页</td>" +
  776. "<td width=\"13%\" tdata=\"pageCount\" format=\"##\" style=\"text-align:right;\">&nbsp共##页</td>" +
  777. " </tr>" +
  778. "<tr>" +
  779. "<td >单位:" + data.row.customer.name+ "</td>" +
  780. "<td>日期:" + Moment(Number(data.row.outboundtime) * 1000).format("YYYY-MM-DD") + "</td>" +
  781. "<td colspan=\"2\" style=\"text-align:right;\">编号:" + data.row.docnum + "</td>" +
  782. "</tr>" +
  783. "</table>" +
  784. "</div>" +
  785. "<div id=\"maintable\"><table border=\"1\" style=\"width:100%;\">" +
  786. "<thead ><tr >" +
  787. "<th width=\"5%\" style=\"text-align:center;\"><div style=\"line-height:20px;\">序号</th>" +
  788. "<th width=\"10%\" style=\"text-align:center;\"><div style=\"line-height:20px;\">商品</br>代码</th>" +
  789. "<th width=\"20%\" style=\"text-align:center;\"><div style=\"line-height:20px;\">商品</br>名称</th>" +
  790. "<th width=\"10%\" style=\"text-align:center;\"><div style=\"line-height:20px;\">规格</br>型号</th>" +
  791. "<th width=\"8%\" style=\"text-align:center;\"><div style=\"line-height:20px;\">单位</th>" +
  792. "<th width=\"6%\" style=\"text-align:center;\"><div style=\"line-height:20px;\">数量</th>" +
  793. "<th width=\"10%\" style=\"text-align:center;\"><div style=\"line-height:20px;\">重量(kg)</th>" +
  794. "<th width=\"12%\" style=\"text-align:center;\"><div style=\"line-height:20px;\">总重量(kg)</th>" +
  795. "<th width=\"20%\" style=\"text-align:center;\"><div style=\"line-height:20px;\">备注</th>" +
  796. "</tr></thead> ";
  797. for (var i = 0; i < data.goodslist.length; i++) {
  798. h += maderow(data.goodslist[i], i)
  799. }
  800. h += "<tfoot> <tr><td tindex=\"8\" tdata=\"SubSum\" format=\"UpperMoney\" colspan=\"5\" ><div style=\"line-height:25px;text-align: left;\">本页小计:</td>" +
  801. "<td align=\"center\" tdata=\"SubSum\" format=\"#,##\">###</td>" +
  802. "<td></td>" +
  803. "<td align=\"center\" tdata=\"SubSum\" format=\"#,##0.00\">###</td>" +
  804. "<td></td>" +
  805. "</tr>" +
  806. "<tr><td colspan=\"5\" tindex=\"8\" tdata=\"AllSum\" format=\"UpperMoney\" ><div style=\"line-height:25px;text-align: left;\">合&nbsp;&nbsp;计: </td>" +
  807. "<td align=\"center\" tdata=\"AllSum\" format=\"#,##\">###</td>" +
  808. "<td></td>" +
  809. "<td align=\"center\" tdata=\"AllSum\" format=\"#,##0.00\">###</td>" +
  810. "<td></td>" +
  811. "</tr>" +
  812. " </tfoot></table>" +
  813. "</div>" +
  814. "<div id=\"foot\"><table style=\"width:100%;\">" +
  815. "<tr >" +
  816. "<td width=\"30%\"><div style=\"line-height:30px;\">负责人:</td>" +
  817. "<td width=\"30%\"><div style=\"line-height:30px;\">经办人:</td>" +
  818. "<td width=\"30%\"><div style=\"line-height:30px;\">库管员:</td>" +
  819. "</tr>" +
  820. "<tr>" +
  821. "</tr>" +
  822. "</table></div>";
  823. $('.printContent').append(h);
  824. }
  825. function maderow(row, currow) {
  826. var h = " <tr align=\"center\">\n" +
  827. " <td >" + (currow + 1) + "</td>\n" +
  828. " <td >" + row.volnum + "</td>\n" +
  829. " <td >" + row.goodsname + "</td>\n" +
  830. " <td >" + row.productmodel + "</td>\n" +
  831. " <td >" + row.measureunit + "</td>\n" +
  832. " <td >" + row.stockoutnums + "</td>\n" +
  833. // " <td > <input type='text'> </td>\n" +
  834. " <td >" + row.inboundprice + "</td>\n" +
  835. " <td >" + row.amount + "</td>\n" +
  836. " <td >" + row.stockoutgoodsremark + "</td>\n" +
  837. " </tr>"
  838. return h;
  839. }
  840. require(['lodop'], function (locop) {
  841. $(".btn-print").click(function () {
  842. var LODOP = getLodop();
  843. if (typeof (LODOP) != "undefined") {
  844. var strStyle = "<style>table{table-layout:fixed;word-break:break-all;} table,td,th {border-width: 1px;border-style: solid;border-color:black;border-collapse: collapse}</style>"
  845. LODOP.ADD_PRINT_TABLE("30mm", "5%", "90%", "70mm", strStyle + document.getElementById("maintable").innerHTML);
  846. LODOP.SET_PRINT_STYLEA(0, "Vorient", 3);
  847. LODOP.ADD_PRINT_HTM("2mm", "5%", "90%", "25mm", document.getElementById("top").innerHTML);
  848. LODOP.SET_PRINT_STYLEA(0, "ItemType", 1);
  849. LODOP.ADD_PRINT_HTM("120mm", "5%", "90%", "25mm", document.getElementById("foot").innerHTML);
  850. LODOP.SET_PRINT_STYLEA(0, "LinkedItem", 4);
  851. LODOP.SET_PRINT_STYLEA(0, "FontSize", 12);
  852. LODOP.SET_PRINT_STYLEA(0, "FontColor", "#FF0000");
  853. LODOP.SET_PRINT_STYLEA(0, "Alignment", 2);
  854. LODOP.SET_PRINT_STYLEA(0, "ItemType", 1);
  855. LODOP.SET_PRINT_STYLEA(0, "Horient", 3);
  856. LODOP.SET_PRINT_PAGESIZE(2, 0, 0, "A5")
  857. LODOP.PREVIEW();
  858. }
  859. });
  860. });
  861. },
  862. api: {
  863. formatter: {
  864. audit: function (value, row, index) {
  865. //颜色状态数组,可使用red/yellow/aqua/blue/navy/teal/olive/lime/fuchsia/purple/maroon
  866. var colorArr = { normal: 'success', hidden: 'grey', deleted: 'danger', locked: 'info' };
  867. // 如果字段列有定义custom
  868. var newValue = value == null ? '未审核' : '已审核';
  869. var color = value == null ? 'danger' : 'primary';
  870. var html = '<span class="text-' + color + '"><i class="fa fa-circle"></i> ' + __(newValue) + '</span>';
  871. return html;
  872. },
  873. settle: function (value, row, index) {
  874. //颜色状态数组,可使用red/yellow/aqua/blue/navy/teal/olive/lime/fuchsia/purple/maroon
  875. var colorArr = { normal: 'success', hidden: 'grey', deleted: 'danger', locked: 'info' };
  876. // 如果字段列有定义custom
  877. var newValue = value == null ? '未结算' : '已结算';
  878. var color = value == null ? 'danger' : 'primary';
  879. var html = '<span class="text-' + color + '"><i class="fa fa-circle"></i> ' + __(newValue) + '</span>';
  880. return html;
  881. },
  882. },
  883. bindevent: function () {
  884. $('form[role=form]').data('validator-options', { msgClass: "n-bottom" });
  885. //重置
  886. $('#btnreset').click(function () {
  887. $('#paneladdgoods :text').val('');
  888. $('#paneladdgoods [type=number]').val('');
  889. });
  890. Form.api.bindevent($("form[role=form]"));
  891. }
  892. }
  893. };
  894. return Controller;
  895. }
  896. );