stockout.js 47 KB

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