stockin.js 46 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893
  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: '商品名称', operate: 'LIKE' },
  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. let that = this;
  342. $.ajax({
  343. url: 'stock/supplier/index',
  344. data: {},
  345. success: function (res) {
  346. that.supplierlist = res.rows;
  347. },
  348. error: function (res) {
  349. Toastr.error("加载失败!")
  350. }
  351. })
  352. },
  353. loadgoodslist() {
  354. let that = this;
  355. $.ajax({
  356. url: 'stock/goods/getlist',
  357. data: { sort: 'goods.id', order: 'desc', offset: this.goodsdata.pagenation.pagesize * (this.goodsdata.pagenation.currentpage - 1), limit: this.goodsdata.pagenation.pagesize, searchvalue: this.searchvalue },
  358. success: function (res) {
  359. that.goodsdata.list = res.rows;
  360. that.goodsdata.pagenation.total = res.total;
  361. },
  362. error: function (res) {
  363. Toastr.error("加载失败!")
  364. }
  365. })
  366. },
  367. handleSizeChange(val) {
  368. this.goodsdata.pagenation.pagesize = val;
  369. this.loadgoodslist();
  370. },
  371. handleCurrentChange(val) {
  372. this.goodsdata.pagenation.currentpage = val;
  373. this.loadgoodslist();
  374. },
  375. debounce(fn, delay) {
  376. let timeout = null;
  377. delay = delay || 500;
  378. return function (e) {
  379. let args = arguments;
  380. let that = this;
  381. clearTimeout(timeout);
  382. timeout = setTimeout(function () {
  383. fn.apply(that, args);
  384. }, delay);
  385. };
  386. },
  387. barcodeinputenter() {
  388. let that=this;
  389. if (this.curgood.barcode == "") {
  390. Fast.api.msg("请输入商品条码并按回车键!")
  391. } else {
  392. Fast.api.ajax({
  393. url: "stock/goods/getgoodsbybarcodeorid",
  394. data: { barcode: this.curgood.barcode }
  395. }, function (data) {
  396. if (data !== null) {
  397. that.curgood.stock_goods_id = data.id;
  398. that.curgood.volnum = data.volnum;
  399. that.curgood.goodsname = data.goodsname;
  400. that.curgood.productmodel = data.productmodel;
  401. that.curgood.measureunit = data.measureunit;
  402. that.curgood.inboundprice = data.univalence;
  403. that.curgood.barcode = data.barcode;
  404. that.curgood.stockinnums = 1;
  405. that.curgood.stockingoodsremark = "";
  406. that.curgood.amount = data.univalence;
  407. }
  408. })
  409. }
  410. },
  411. onSearchvalueChange() {
  412. this.debounce(this.loadgoodslist, 1000)();
  413. },
  414. selectonegood(currentrow) {
  415. this.curgood.stock_goods_id = currentrow.id;
  416. this.curgood.volnum = currentrow.volnum;
  417. this.curgood.goodsname = currentrow.goodsname;
  418. this.curgood.productmodel = currentrow.productmodel;
  419. this.curgood.measureunit = currentrow.measureunit;
  420. this.curgood.inboundprice = currentrow.univalence;
  421. this.curgood.barcode = currentrow.barcode;
  422. this.curgood.stockinnums = 1;
  423. this.curgood.stockingoodsremark = "";
  424. this.curgood.amount = currentrow.univalence;
  425. },
  426. addtolist() {
  427. let that = this;
  428. let hasadded = false;
  429. if (this.curgood.stock_goods_id != "") {
  430. this.selectedgoodsdata.list.forEach(item => {
  431. if (item.stock_goods_id == that.curgood.stock_goods_id) {
  432. Fast.api.msg("该商品已添加,请勿重复添加!")
  433. hasadded = true;
  434. }
  435. });
  436. if (!hasadded) {
  437. let good = JSON.parse(JSON.stringify(this.curgood));
  438. this.selectedgoodsdata.list.unshift(good);
  439. this.curgood = JSON.parse(JSON.stringify(this.defaultgood));
  440. this.row.totalamount = this.accAdd(this.row.totalamount, good.amount);
  441. }
  442. } else {
  443. Fast.api.msg("请选择入库商品!")
  444. }
  445. },
  446. reset() {
  447. this.curgood = JSON.parse(JSON.stringify(this.defaultgood));
  448. },
  449. getcurgoodamount() {
  450. this.curgood.amount = this.accMul(this.curgood.stockinnums, this.curgood.inboundprice);
  451. },
  452. accMul(arg1, arg2) {
  453. var m = 0, s1 = arg1.toString(), s2 = arg2.toString();
  454. try {
  455. m += s1.split(".")[1].length
  456. } catch (e) {
  457. }
  458. try {
  459. m += s2.split(".")[1].length
  460. } catch (e) {
  461. }
  462. return Number(s1.replace(".", "")) * Number(s2.replace(".", "")) / Math.pow(10, m)
  463. },
  464. accAdd(arg1, arg2) {
  465. var r1, r2, m;
  466. try {
  467. r1 = arg1.toString().split(".")[1].length
  468. } catch (e) {
  469. r1 = 0
  470. }
  471. try {
  472. r2 = arg2.toString().split(".")[1].length
  473. } catch (e) {
  474. r2 = 0
  475. }
  476. m = Math.pow(10, Math.max(r1, r2))
  477. return (arg1 * m + arg2 * m) / m
  478. },
  479. accSub(arg1, arg2) {
  480. var r1, r2, m, n;
  481. try {
  482. r1 = arg1.toString().split(".")[1].length;
  483. } catch (e) {
  484. r1 = 0;
  485. }
  486. try {
  487. r2 = arg2.toString().split(".")[1].length;
  488. } catch (e) {
  489. r2 = 0;
  490. }
  491. m = Math.pow(10, Math.max(r1, r2));
  492. //last modify by deeka
  493. //动态控制精度长度
  494. n = (r1 >= r2) ? r1 : r2;
  495. return ((arg1 * m - arg2 * m) / m).toFixed(n);
  496. },
  497. deleteselected(row) {
  498. this.selectedgoodsdata.list = this.selectedgoodsdata.list.filter(item => {
  499. return item != row;
  500. });
  501. this.row.totalamount = this.accSub(this.row.totalamount, row.amount);
  502. }
  503. }
  504. })
  505. Form.api.bindevent($("form[role=form]"), "", "", function () {
  506. let main = JSON.parse($("#c-main").val());
  507. let goodslist = JSON.parse($("#c-goodslist").val());
  508. if (main.stock_supplier_id == "") {
  509. Toastr.error("请选择供应商");
  510. return false;
  511. } else if (goodslist.length < 1) {
  512. Toastr.error("请添加入库商品");
  513. return false;
  514. }
  515. });
  516. },
  517. edit: function () {
  518. Vue.use(ELEMENT);
  519. var vm = new Vue({
  520. el: "#app",
  521. data: function () {
  522. return {
  523. searchvalue: "",
  524. row: { stock_supplier_id: "", remark: "", inboundtime: "", totalamount: 0.00 },
  525. curgood: { stock_goods_id: "", volnum: "", goodsname: "", productmodel: "", measureunit: "件", inboundprice: "", stockinnums: 0, stockingoodsremark: "", amount: "", barcode: "" },
  526. defaultgood: { stock_goods_id: "", volnum: "", goodsname: "", productmodel: "", measureunit: "件", inboundprice: "", stockinnums: 0, stockingoodsremark: "", amount: "" },
  527. supplierlist: [],
  528. goodsdata: {
  529. table: { height: ($(window).height() - 490) + "px" },
  530. list: [],
  531. pagenation: {
  532. currentpage: 1,
  533. pagesize: 10,
  534. total: 0
  535. }
  536. },
  537. selectedgoodsdata: {
  538. table: { height: ($(window).height() - 355) + "px" },
  539. list: [],
  540. },
  541. deselectedgoodslist: [],
  542. rules: {
  543. inboundprice: [
  544. { required: true, type: 'string', trigger: 'blur', message: '金额不能为空' },
  545. { pattern: /(^[1-9]([0-9]+)?(\.[0-9]{1,2})?$)|(^(0){1}$)|(^[0-9]\.[0-9]([0-9])?$)/, message: '请输入正确额格式,可保留两位小数' }
  546. ],
  547. stockinnums: [
  548. { required: true, message: '入库数量不能为空' },
  549. { type: 'number', message: '入库数量必须为数字值' }
  550. ],
  551. }
  552. }
  553. },
  554. computed: {
  555. main: function () { return JSON.stringify(this.row) },
  556. goodslist: function () { return JSON.stringify(this.selectedgoodsdata.list) },
  557. deletedgoodslist: function () { return JSON.stringify(this.deselectedgoodslist) }
  558. },
  559. created() {
  560. this.loadgoodslist()
  561. this.loadsupplierlist()
  562. this.loadstockininfo()
  563. },
  564. methods: {
  565. loadstockininfo() {
  566. let that = this;
  567. $.ajax({
  568. url: 'stock/stockin/info',
  569. type: "POST",
  570. data: { id: Fast.api.query("ids") },
  571. success: function (res) {
  572. res.row.inboundtime = Moment(parseInt(res.row.inboundtime) * 1000).format("YYYY-MM-DD");
  573. console.log(res.row);
  574. that.row = res.row;
  575. that.selectedgoodsdata.list = res.goodslist;
  576. },
  577. error: function (res) {
  578. Toastr.error("加载失败!")
  579. }
  580. })
  581. },
  582. loadsupplierlist() {
  583. let that = this;
  584. $.ajax({
  585. url: 'stock/supplier/index',
  586. data: {},
  587. success: function (res) {
  588. that.supplierlist = res.rows;
  589. },
  590. error: function (res) {
  591. Toastr.error("加载失败!")
  592. }
  593. })
  594. },
  595. loadgoodslist() {
  596. let that = this;
  597. $.ajax({
  598. url: 'stock/goods/getlist',
  599. data: { sort: 'goods.id', order: 'desc', offset: this.goodsdata.pagenation.pagesize * (this.goodsdata.pagenation.currentpage - 1), limit: this.goodsdata.pagenation.pagesize, searchvalue: this.searchvalue },
  600. success: function (res) {
  601. that.goodsdata.list = res.rows;
  602. that.goodsdata.pagenation.total = res.total;
  603. },
  604. error: function (res) {
  605. Toastr.error("加载失败!")
  606. }
  607. })
  608. },
  609. handleSizeChange(val) {
  610. this.goodsdata.pagenation.pagesize = val;
  611. this.loadgoodslist();
  612. },
  613. handleCurrentChange(val) {
  614. this.goodsdata.pagenation.currentpage = val;
  615. this.loadgoodslist();
  616. },
  617. debounce(fn, delay) {
  618. let timeout = null;
  619. delay = delay || 500;
  620. return function (e) {
  621. let args = arguments;
  622. let that = this;
  623. clearTimeout(timeout);
  624. timeout = setTimeout(function () {
  625. fn.apply(that, args);
  626. }, delay);
  627. };
  628. },
  629. barcodeinputenter() {
  630. let that=this;
  631. if (this.curgood.barcode == "") {
  632. Fast.api.msg("请输入商品条码并按回车键!")
  633. } else {
  634. Fast.api.ajax({
  635. url: "stock/goods/getgoodsbybarcodeorid",
  636. data: { barcode: this.curgood.barcode }
  637. }, function (data) {
  638. if (data !== null) {
  639. that.curgood.stock_goods_id = data.id;
  640. that.curgood.volnum = data.volnum;
  641. that.curgood.goodsname = data.goodsname;
  642. that.curgood.productmodel = data.productmodel;
  643. that.curgood.measureunit = data.measureunit;
  644. that.curgood.inboundprice = data.univalence;
  645. that.curgood.barcode = data.barcode;
  646. that.curgood.stockinnums = 1;
  647. that.curgood.stockingoodsremark = "";
  648. that.curgood.amount = data.univalence;
  649. }
  650. })
  651. }
  652. },
  653. onSearchvalueChange() {
  654. this.debounce(this.loadgoodslist, 1000)();
  655. },
  656. selectonegood(currentrow) {
  657. this.curgood.stock_goods_id = currentrow.id;
  658. this.curgood.volnum = currentrow.volnum;
  659. this.curgood.goodsname = currentrow.goodsname;
  660. this.curgood.productmodel = currentrow.productmodel;
  661. this.curgood.measureunit = currentrow.measureunit;
  662. this.curgood.inboundprice = currentrow.univalence;
  663. this.curgood.barcode = currentrow.barcode;
  664. this.curgood.stockinnums = 1;
  665. this.curgood.stockingoodsremark = "";
  666. this.curgood.amount = currentrow.univalence;
  667. },
  668. addtolist() {
  669. let that = this;
  670. let hasadded = false;
  671. if (this.curgood.stock_goods_id != "") {
  672. this.selectedgoodsdata.list.forEach(item => {
  673. if (item.stock_goods_id == that.curgood.stock_goods_id) {
  674. Fast.api.msg("该商品已添加,请勿重复添加!")
  675. hasadded = true;
  676. }
  677. });
  678. if (!hasadded) {
  679. let good = JSON.parse(JSON.stringify(this.curgood));
  680. this.selectedgoodsdata.list.unshift(good);
  681. this.curgood = JSON.parse(JSON.stringify(this.defaultgood));
  682. this.row.totalamount = this.accAdd(this.row.totalamount, good.amount);
  683. }
  684. } else {
  685. Fast.api.msg("请选择入库商品!")
  686. }
  687. },
  688. reset() {
  689. this.curgood = JSON.parse(JSON.stringify(this.defaultgood));
  690. },
  691. getcurgoodamount() {
  692. this.curgood.amount = this.accMul(this.curgood.stockinnums, this.curgood.inboundprice);
  693. },
  694. accMul(arg1, arg2) {
  695. var m = 0, s1 = arg1.toString(), s2 = arg2.toString();
  696. try {
  697. m += s1.split(".")[1].length
  698. } catch (e) {
  699. }
  700. try {
  701. m += s2.split(".")[1].length
  702. } catch (e) {
  703. }
  704. return Number(s1.replace(".", "")) * Number(s2.replace(".", "")) / Math.pow(10, m)
  705. },
  706. accAdd(arg1, arg2) {
  707. var r1, r2, m;
  708. try {
  709. r1 = arg1.toString().split(".")[1].length
  710. } catch (e) {
  711. r1 = 0
  712. }
  713. try {
  714. r2 = arg2.toString().split(".")[1].length
  715. } catch (e) {
  716. r2 = 0
  717. }
  718. m = Math.pow(10, Math.max(r1, r2))
  719. return (arg1 * m + arg2 * m) / m
  720. },
  721. accSub(arg1, arg2) {
  722. var r1, r2, m, n;
  723. try {
  724. r1 = arg1.toString().split(".")[1].length;
  725. } catch (e) {
  726. r1 = 0;
  727. }
  728. try {
  729. r2 = arg2.toString().split(".")[1].length;
  730. } catch (e) {
  731. r2 = 0;
  732. }
  733. m = Math.pow(10, Math.max(r1, r2));
  734. //last modify by deeka
  735. //动态控制精度长度
  736. n = (r1 >= r2) ? r1 : r2;
  737. return ((arg1 * m - arg2 * m) / m).toFixed(n);
  738. },
  739. deleteselected(row) {
  740. if (row.id) {
  741. this.deselectedgoodslist.unshift(row.id);
  742. }
  743. this.selectedgoodsdata.list = this.selectedgoodsdata.list.filter(item => {
  744. return item != row;
  745. });
  746. this.row.totalamount = this.accSub(this.row.totalamount, row.amount);
  747. }
  748. }
  749. })
  750. Form.api.bindevent($("form[role=form]"), "", "", function () {
  751. let main = JSON.parse($("#c-main").val());
  752. let goodslist = JSON.parse($("#c-goodslist").val());
  753. if (main.stock_supplier_id == "") {
  754. Toastr.error("请选择供应商");
  755. return false;
  756. } else if (goodslist.length < 1) {
  757. Toastr.error("请添加入库商品");
  758. return false;
  759. }
  760. });
  761. },
  762. printer: function () {
  763. $.ajax({
  764. type: "POST",
  765. url: Fast.api.fixurl('stock/stockin/info'),
  766. data: { "id": Fast.api.query("id") },
  767. async: true, //或false,是否异步
  768. timeout: 5000, //超时时间
  769. dataType: 'json', //返回的数据格式:json/xml/html/script/jsonp/text
  770. success: function (data) {
  771. madehtml(data);
  772. }
  773. });
  774. function madehtml(data) {
  775. var h = "<div id=\"top\" class=\"page\" ><div style=\"text-align: center;font-size:22px;line-height:38px\" >入库单</div>" +
  776. "<table style=\"width:100%;\">" +
  777. " <tr>" +
  778. " <td width=\"40%\"></td>" +
  779. "<td width=\"25%\"></td>" +
  780. "<td width=\"12%\" tdata=\"pageNO\" format=\"##\" style=\"text-align:right;\">第##页</td>" +
  781. "<td width=\"13%\" tdata=\"pageCount\" format=\"##\" style=\"text-align:right;\">&nbsp共##页</td>" +
  782. " </tr>" +
  783. "<tr>" +
  784. "<td >供应商:" + data.row.supplier.name + "</td>" +
  785. "<td>日期:" + Moment(Number( data.row.inboundtime) * 1000).format("YYYY-MM-DD") + "</td>" +
  786. "<td colspan=\"2\" style=\"text-align:right;\">编号:" + data.row.docnum + "</td>" +
  787. "</tr>" +
  788. "</table>" +
  789. "</div>" +
  790. "<div id=\"maintable\"><table border=\"1\" style=\"width:100%;\">" +
  791. "<thead><tr align=\"center\">" +
  792. "<th width=\"5%\" style=\"text-align:center;\"><div style=\"line-height:20px;\">序号</th>" +
  793. "<th width=\"10%\" style=\"text-align:center;\"><div style=\"line-height:20px;\">商品</br>代码</th>" +
  794. "<th width=\"20%\" style=\"text-align:center;\"><div style=\"line-height:20px;\">商品</br>名称</th>" +
  795. "<th width=\"10%\" style=\"text-align:center;\"><div style=\"line-height:20px;\">规格</br>型号</th>" +
  796. "<th width=\"8%\" style=\"text-align:center;\"><div style=\"line-height:20px;\">单位</th>" +
  797. "<th width=\"6%\" style=\"text-align:center;\"><div style=\"line-height:20px;\">数量</th>" +
  798. "<th width=\"10%\" style=\"text-align:center;\"><div style=\"line-height:20px;\">重量(kg)</th>" +
  799. "<th width=\"12%\" style=\"text-align:center;\"><div style=\"line-height:20px;\">总重量(kg)</th>" +
  800. "<th width=\"20%\" style=\"text-align:center;\"><div style=\"line-height:20px;\">备注</th>" +
  801. "</tr></thead> ";
  802. for (var i = 0; i < data.goodslist.length; i++) {
  803. h += maderow(data.goodslist[i], i)
  804. }
  805. h += "<tfoot> <tr><td tindex=\"8\" tdata=\"SubSum\" format=\"UpperMoney\" colspan=\"5\" ><div style=\"line-height:25px;text-align: left;\">本页小计:</td>" +
  806. "<td align=\"center\" tdata=\"SubSum\" format=\"#,##\">###</td>" +
  807. "<td></td>" +
  808. "<td align=\"center\" tdata=\"SubSum\" format=\"#,##0.00\">###</td>" +
  809. "<td></td>" +
  810. "</tr>" +
  811. "<tr><td colspan=\"5\" tindex=\"8\" tdata=\"AllSum\" format=\"UpperMoney\" ><div style=\"line-height:25px;text-align: left;\">合&nbsp;&nbsp;计: </td>" +
  812. "<td align=\"center\" tdata=\"AllSum\" format=\"#,##\">###</td>" +
  813. "<td></td>" +
  814. "<td align=\"center\" tdata=\"AllSum\" format=\"#,##0.00\">###</td>" +
  815. "<td></td>" +
  816. "</tr>" +
  817. " </tfoot></table>" +
  818. "</div>" +
  819. "<div id=\"foot\"><table style=\"width:100%;\">" +
  820. "<tr >" +
  821. "<td width=\"30%\"><div style=\"line-height:30px;\">负责人:</td>" +
  822. "<td width=\"30%\"><div style=\"line-height:30px;\">经办人:</td>" +
  823. "<td width=\"40%\"><div style=\"line-height:30px;\">库管员:</td>" +
  824. "</tr>" +
  825. "<tr>" +
  826. "</tr>" +
  827. "</table></div>";
  828. $('.printContent').append(h);
  829. }
  830. function maderow(row, currow) {
  831. var h = " <tr align=\"center\">\n" +
  832. " <td >" + (currow + 1) + "</td>\n" +
  833. " <td >" + row.volnum + "</td>\n" +
  834. " <td >" + row.goodsname + "</td>\n" +
  835. " <td >" + row.productmodel + "</td>\n" +
  836. " <td >" + row.measureunit + "</td>\n" +
  837. " <td >" + row.stockinnums + "</td>\n" +
  838. " <td >" + row.inboundprice + "</td>\n" +
  839. " <td >" + row.amount + "</td>\n" +
  840. " <td >" + row.stockingoodsremark + "</td>\n" +
  841. " </tr>"
  842. return h;
  843. }
  844. require(['lodop'], function (lodop) {
  845. $(".btn-print").click(function () {
  846. var LODOP = getLodop();
  847. if (typeof (LODOP) != "undefined") {
  848. 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>"
  849. var strStyle2 = "<style>div{font-family:'思源黑体 CN Medium'} table{font-family:'思源黑体 CN Medium','times'}</style>";
  850. LODOP.ADD_PRINT_TABLE("30mm", "5%", "90%", "70mm", strStyle + document.getElementById("maintable").innerHTML);
  851. LODOP.SET_PRINT_STYLEA(0, "Vorient", 3);
  852. LODOP.ADD_PRINT_HTM("2mm", "5%", "90%", "25mm",strStyle2+ document.getElementById("top").innerHTML);
  853. LODOP.SET_PRINT_STYLEA(0, "ItemType", 1);
  854. LODOP.ADD_PRINT_HTM("120mm", "5%", "90%", "25mm", strStyle2+document.getElementById("foot").innerHTML);
  855. LODOP.SET_PRINT_STYLEA(0, "LinkedItem", 4);
  856. LODOP.SET_PRINT_STYLEA(0, "FontSize", 12);
  857. LODOP.SET_PRINT_STYLEA(0, "FontColor", "#FF0000");
  858. LODOP.SET_PRINT_STYLEA(0, "Alignment", 2);
  859. LODOP.SET_PRINT_STYLEA(0, "ItemType", 1);
  860. LODOP.SET_PRINT_STYLEA(0, "Horient", 3);
  861. LODOP.SET_PRINT_PAGESIZE(2, 0, 0, "A5")
  862. LODOP.PREVIEW();
  863. }
  864. });
  865. });
  866. },
  867. api: {
  868. formatter: {
  869. audit: function (value, row, index) {
  870. var colorArr = { normal: 'success', hidden: 'grey', deleted: 'danger', locked: 'info' };
  871. // 如果字段列有定义custom
  872. var newValue = value == null ? '未审核' : '已审核';
  873. var color = value == null ? 'danger' : 'primary';
  874. var html = '<span class="text-' + color + '"><i class="fa fa-circle"></i> ' + __(newValue) + '</span>';
  875. return html;
  876. },
  877. settle: function (value, row, index) {
  878. var colorArr = { normal: 'success', hidden: 'grey', deleted: 'danger', locked: 'info' };
  879. // 如果字段列有定义custom
  880. var newValue = value == null ? '未结算' : '已结算';
  881. var color = value == null ? 'danger' : 'primary';
  882. var html = '<span class="text-' + color + '"><i class="fa fa-circle"></i> ' + __(newValue) + '</span>';
  883. return html;
  884. },
  885. },
  886. bindevent: function () {
  887. }
  888. }
  889. };
  890. return Controller;
  891. });