stockin.js 46 KB

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