| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893 |
- requirejs.config({
- paths: {
- vue: 'backend/stock/libs/vue',
- ELEMENT: 'backend/stock/libs/element-ui',
- },
- shim: {
- ELEMENT: ['vue']
- }
- })
- define(['jquery', 'bootstrap', 'backend', 'table', 'form', 'vue', 'ELEMENT', 'moment'], function ($, undefined, Backend, Table, Form, Vue, ELEMENT, Moment) {
- var Controller = {
- index: function () {
- $(".btn-add, .btn-edit,.btn-audit,.btn-settle,.btn-split").data("area", ['100%', '100%']);
- // 初始化表格参数配置
- Table.api.init({
- extend: {
- index_url: 'stock/stockin/index',
- add_url: 'stock/stockin/add',
- edit_url: 'stock/stockin/edit',
- del_url: 'stock/stockin/del',
- multi_url: 'stock/stockin/multi',
- look_url: 'stock/stockin/look',
- table: 'stock_stockin',
- }
- });
- var table = $("#table");
- var selfOperate = {
- 'click .btn-editone': function (e, value, row, index) {
- e.stopPropagation();
- e.preventDefault();
- if (!row.audittime) {
- var table = $(this).closest('table');
- var options = table.bootstrapTable('getOptions');
- var ids = row[options.pk];
- row = $.extend({}, row ? row : {}, { ids: ids });
- var url = options.extend.edit_url;
- Fast.api.open(Table.api.replaceurl(url, row, table), __('Edit'), $(this).data() || {});
- } else {
- Toastr.error('该入库记录已审核,不能修改!')
- }
- },
- 'click .btn-delone': function (e, value, row, index) {
- e.stopPropagation();
- e.preventDefault();
- var that = this;
- var top = $(that).offset().top - $(window).scrollTop();
- var left = $(that).offset().left - $(window).scrollLeft() - 260;
- if (top + 154 > $(window).height()) {
- top = top - 154;
- }
- if ($(window).width() < 480) {
- top = left = undefined;
- }
- if (!row.audittime) {
- Layer.confirm(
- __('Are you sure you want to delete this item?'), { icon: 3, title: __('Warning'), offset: [top, left], shadeClose: true },
- function (index) {
- var table = $(that).closest('table');
- var options = table.bootstrapTable('getOptions');
- Table.api.multi("del", row[options.pk], table, that);
- Layer.close(index);
- }
- );
- } else {
- Toastr.error('该入库记录已审核,不能删除!')
- }
- }
- }
- // 初始化表格
- table.bootstrapTable({
- url: $.fn.bootstrapTable.defaults.extend.index_url,
- sortName: 'createtime',
- singleSelect: true, //是否启用单选
- height: $(window).height() - 97,
- columns: [
- [
- { checkbox: true },
- {
- field: 'id',
- title: __('Id'),
- operate: false,
- width: 50,
- },
- { field: 'docnum', title: '单据编号', sortable: true },
- { field: 'supplier.name', title: '供应商', operate: 'LIKE' },
- { field: 'inboundtime', title: '入库时间', operate: 'RANGE', addclass: 'datetimerange', formatter: Table.api.formatter.datetime },
- { field: 'totalamount', title: '总重量(kg)', operate: 'BETWEEN' },
- { field: 'remark', title: __('Remark'), searchable: false },
- { field: 'charged', visible: false },
- { field: 'audittime', title: '审核状态', formatter: Controller.api.formatter.audit },
- // { field: 'settletime', title: '结算状态', formatter: Controller.api.formatter.settle },
- { field: 'operate', title: 'Operate', table: table, events: selfOperate, formatter: Table.api.formatter.operate }
- ]
- ],
- onPostBody: function () {
- $(".btn-editone").data("area", ['100%', '100%']);
- }
- });
- // 为表格绑定事件
- Table.api.bindevent(table);
- // 批量编辑按钮事件
- $('.btn-edit').click(function (event) {
- event.stopPropagation();
- var selectedrow = table.bootstrapTable('getSelections');
- if (selectedrow.length == 1 && !selectedrow[0]['audittime']) {
- var that = this;
- var url = 'stock/stockin/edit';
- selectedrow[0] = $.extend({}, selectedrow[0] ? selectedrow[0] : {}, { ids: selectedrow[0]['id'] });
- var url = Table.api.replaceurl(url, selectedrow[0], table);
- Fast.api.open(url, __('Edit'), $(that).data() || {});
- } else {
- if (selectedrow[0]['audittime']) {
- Toastr.error('该入库记录已审核,不能修改!')
- } else {
- Toastr.error(selectedrow.length > 1 ? '只能选择一条入库记录' : '请选择入库记录')
- }
- }
- });
- // 批量删除按钮事件
- $('.btn-del').click(function (event) {
- event.stopPropagation();
- var selectedrow = table.bootstrapTable('getSelections');
- if (selectedrow.length == 1 && !selectedrow[0]['audittime']) {
- var that = this;
- Layer.confirm(
- __('Are you sure you want to delete the %s selected item?', selectedrow.length), { icon: 3, title: __('Warning'), offset: 0, shadeClose: true },
- function (index) {
- Table.api.multi("del", selectedrow[0]['id'], table, that);
- Layer.close(index);
- }
- );
- } else {
- if (selectedrow[0]['audittime']) {
- Toastr.error('该入库记录已审核,不能删除!')
- } else {
- Toastr.error(selectedrow.length > 1 ? '只能选择一条入库记录' : '请选择入库记录')
- }
- }
- });
- // 打印按钮事件
- $('.toolbar').on('click', '.btn-print', function () {
- var that = this;
- var selectedrow = table.bootstrapTable('getSelections');
- if (selectedrow.length == 1) {
- Fast.api.open('stock/stockin/printer?id=' + selectedrow[0]['id'], __('打印'), $(that).data() || {});
- } else {
- Toastr.error(selectedrow.length > 1 ? '只能选择一条入库记录' : '请选择入库记录')
- }
- });
- // 审核/反审核按钮事件 结算/反结算按钮事件
- $('.toolbar').on('click', '.btn-audit,.btn-settle', function () {
- var that = this;
- var selectedrow = table.bootstrapTable('getSelections');
- var title = "审核";
- if (selectedrow.length == 1) {
- var operatetype = $(this).data("operatetype");
- if (operatetype == "audit") {
- console.log(selectedrow[0].settletime);
- if (selectedrow[0].settletime !== null) {
- Toastr.error("该入库单已结算,请先进行反结算!");
- return;
- } else {
- title = selectedrow[0].audittime == null ? "审核" : "反审核";
- }
- } else if (operatetype == "settle") {
- if (selectedrow[0].audittime == null) {
- Toastr.error("该入库单未审核,请先进行审核!");
- return;
- } else {
- title = selectedrow[0].settletime == null ? "结算" : "反结算";
- }
- }
- var url = 'stock/stockin/look?operatetype=' + operatetype;
- selectedrow[0] = $.extend({}, selectedrow[0] ? selectedrow[0] : {}, { ids: selectedrow[0]['id'] });
- var url = Table.api.replaceurl(url, selectedrow[0], table);
- Fast.api.open(url, title, $(that).data() || {});
- } else {
- Toastr.error(selectedrow.length > 1 ? '只能选择一条记录' : '请选择一条记录')
- }
- });
- },
- getlist: function () {
- // 初始化表格参数配置
- Table.api.init({
- extend: {
- list_url: 'stock/stockin/getlist',
- }
- });
- var table = $("#table");
- // 初始化表格
- table.bootstrapTable({
- url: $.fn.bootstrapTable.defaults.extend.list_url,
- pk: 'id',
- sortName: 'stockinlist.id',
- height: $(window).height() - 97,
- columns: [
- [
- { checkbox: true },
- {
- field: 'id',
- title: __('Id'),
- searchable: false,
- },
- { field: 'stockin.docnum', operate: "LIKE", title: '单据编号', sortable: true },
- { field: 'stockin.supplier.name', operate: "LIKE", title: '供应商' },
- { field: 'stockin.inboundtime', title: '入库日期', operate: 'RANGE', formatter: Table.api.formatter.datetime, datetimeFormat: 'YYYY-MM-DD', addclass: 'datetimerange' },
- { field: 'goods.volnum', title: '商品代码' },
- { field: 'goods.goodsname', operate: "LIKE", title: '商品名称', operate: 'LIKE' },
- { field: 'goods.productmodel', title: '商品型号', searchable: false },
- { field: 'goods.measureunit', title: '单位', searchable: false },
- { field: 'inboundprice', title: '单桶重量(kg)', searchable: false },
- { field: 'stockinnums', title: '入库数', searchable: false },
- { field: 'amount', title: '总重量(kg)' },
- ]
- ]
- });
- // 为表格绑定事件
- Table.api.bindevent(table);
- },
- look: function () {
- Vue.use(ELEMENT);
- var vm = new Vue({
- el: "#app",
- data: function () {
- return {
- row: { stock_supplier_id: "", remark: "", inboundtime: "", totalamount: 0.00 },
- supplierlist: [],
- selectedgoodsdata: {
- table: { height: ($(window).height() - 355) + "px" },
- list: [],
- },
- commiturl: "",
- }
- },
- computed: {
- goodslist: function () { return JSON.stringify(this.selectedgoodsdata.list) },
- },
- created() {
- this.loadstockininfo()
- },
- methods: {
- loadstockininfo() {
- let operatetype = Fast.api.query("operatetype")
- let that = this;
- $.ajax({
- url: 'stock/stockin/info',
- type: "POST",
- data: { id: Fast.api.query("ids") },
- async: false,
- success: function (res) {
- res.row.inboundtime = Moment(parseInt(res.row.inboundtime) * 1000).format("YYYY-MM-DD");
- if (operatetype == "audit") {
- if (res.row.audittime) {
- that.commiturl = 'stock/stockin/unaudit';
- $('#audit').html('反审核');
- } else {
- that.commiturl = 'stock/stockin/audit';
- $('#audit').html('审核');
- }
- } else if (operatetype == "settle") {
- if (res.row.settletime) {
- that.commiturl = 'stock/stockin/unsettle';
- $('#audit').html('反结算');
- } else {
- that.commiturl = 'stock/stockin/settle';
- $('#audit').html('结算');
- }
- }
- that.row = res.row;
- that.selectedgoodsdata.list = res.goodslist;
- },
- error: function (res) {
- Toastr.error("加载失败!")
- }
- })
- },
- }
- })
- // 提交事件
- $(document).on('click', '#audit', function (e) {
- e.preventDefault();
- var url = $("#c-commiturl").val();
- Layer.confirm(
- __('确认提交?'), { icon: 3, title: __('Warning'), offset: 200, shadeClose: true },
- function (index) {
- $('#form').attr('action', url);
- $('#form').submit();
- Layer.close(index);
- }
- );
- });
- Form.api.bindevent($("form[role=form]"));
- },
- add: function () {
- Vue.use(ELEMENT);
- var vm = new Vue({
- el: "#app",
- data: function () {
- return {
- searchvalue: "",
- row: { stock_supplier_id: "", remark: "", inboundtime: new Date(), totalamount: 0.00 },
- curgood: { stock_goods_id: "", volnum: "", goodsname: "", productmodel: "", measureunit: "件", inboundprice: "", stockinnums: 0, stockingoodsremark: "", amount: "", barcode: "" },
- defaultgood: { stock_goods_id: "", volnum: "", goodsname: "", productmodel: "", measureunit: "件", inboundprice: "", stockinnums: 0, stockingoodsremark: "", amount: "" },
- supplierlist: [],
- goodsdata: {
- table: { height: ($(window).height() - 490) + "px" },
- list: [],
- pagenation: {
- currentpage: 1,
- pagesize: 10,
- total: 0
- }
- },
- selectedgoodsdata: {
- table: { height: ($(window).height() - 355) + "px" },
- list: [],
- },
- deselectedgoodslist: [],
- rules: {
- inboundprice: [
- { required: true, type: 'string', trigger: 'blur', message: '金额不能为空' },
- { pattern: /(^[1-9]([0-9]+)?(\.[0-9]{1,2})?$)|(^(0){1}$)|(^[0-9]\.[0-9]([0-9])?$)/, message: '请输入正确额格式,可保留两位小数' }
- ],
- stockinnums: [
- { required: true, message: '入库数量不能为空' },
- { type: 'number', message: '入库数量必须为数字值' }
- ],
- }
- }
- },
- computed: {
- main: function () { return JSON.stringify(this.row) },
- goodslist: function () { return JSON.stringify(this.selectedgoodsdata.list) }
- },
- created() {
- this.loadgoodslist()
- this.loadsupplierlist()
- },
- methods: {
- loadsupplierlist() {
- let that = this;
- $.ajax({
- url: 'stock/supplier/index',
- data: {},
- success: function (res) {
- that.supplierlist = res.rows;
- },
- error: function (res) {
- Toastr.error("加载失败!")
- }
- })
- },
- loadgoodslist() {
- let that = this;
- $.ajax({
- url: 'stock/goods/getlist',
- data: { sort: 'goods.id', order: 'desc', offset: this.goodsdata.pagenation.pagesize * (this.goodsdata.pagenation.currentpage - 1), limit: this.goodsdata.pagenation.pagesize, searchvalue: this.searchvalue },
- success: function (res) {
- that.goodsdata.list = res.rows;
- that.goodsdata.pagenation.total = res.total;
- },
- error: function (res) {
- Toastr.error("加载失败!")
- }
- })
- },
- handleSizeChange(val) {
- this.goodsdata.pagenation.pagesize = val;
- this.loadgoodslist();
- },
- handleCurrentChange(val) {
- this.goodsdata.pagenation.currentpage = val;
- this.loadgoodslist();
- },
- debounce(fn, delay) {
- let timeout = null;
- delay = delay || 500;
- return function (e) {
- let args = arguments;
- let that = this;
- clearTimeout(timeout);
- timeout = setTimeout(function () {
- fn.apply(that, args);
- }, delay);
- };
- },
- barcodeinputenter() {
- let that=this;
- if (this.curgood.barcode == "") {
- Fast.api.msg("请输入商品条码并按回车键!")
- } else {
- Fast.api.ajax({
- url: "stock/goods/getgoodsbybarcodeorid",
- data: { barcode: this.curgood.barcode }
- }, function (data) {
- if (data !== null) {
- that.curgood.stock_goods_id = data.id;
- that.curgood.volnum = data.volnum;
- that.curgood.goodsname = data.goodsname;
- that.curgood.productmodel = data.productmodel;
- that.curgood.measureunit = data.measureunit;
- that.curgood.inboundprice = data.univalence;
- that.curgood.barcode = data.barcode;
- that.curgood.stockinnums = 1;
- that.curgood.stockingoodsremark = "";
- that.curgood.amount = data.univalence;
- }
- })
- }
- },
- onSearchvalueChange() {
- this.debounce(this.loadgoodslist, 1000)();
- },
- selectonegood(currentrow) {
- this.curgood.stock_goods_id = currentrow.id;
- this.curgood.volnum = currentrow.volnum;
- this.curgood.goodsname = currentrow.goodsname;
- this.curgood.productmodel = currentrow.productmodel;
- this.curgood.measureunit = currentrow.measureunit;
- this.curgood.inboundprice = currentrow.univalence;
- this.curgood.barcode = currentrow.barcode;
- this.curgood.stockinnums = 1;
- this.curgood.stockingoodsremark = "";
- this.curgood.amount = currentrow.univalence;
- },
- addtolist() {
- let that = this;
- let hasadded = false;
- if (this.curgood.stock_goods_id != "") {
- this.selectedgoodsdata.list.forEach(item => {
- if (item.stock_goods_id == that.curgood.stock_goods_id) {
- Fast.api.msg("该商品已添加,请勿重复添加!")
- hasadded = true;
- }
- });
- if (!hasadded) {
- let good = JSON.parse(JSON.stringify(this.curgood));
- this.selectedgoodsdata.list.unshift(good);
- this.curgood = JSON.parse(JSON.stringify(this.defaultgood));
- this.row.totalamount = this.accAdd(this.row.totalamount, good.amount);
- }
- } else {
- Fast.api.msg("请选择入库商品!")
- }
- },
- reset() {
- this.curgood = JSON.parse(JSON.stringify(this.defaultgood));
- },
- getcurgoodamount() {
- this.curgood.amount = this.accMul(this.curgood.stockinnums, this.curgood.inboundprice);
- },
- accMul(arg1, arg2) {
- var m = 0, s1 = arg1.toString(), s2 = arg2.toString();
- try {
- m += s1.split(".")[1].length
- } catch (e) {
- }
- try {
- m += s2.split(".")[1].length
- } catch (e) {
- }
- return Number(s1.replace(".", "")) * Number(s2.replace(".", "")) / Math.pow(10, m)
- },
- accAdd(arg1, arg2) {
- var r1, r2, m;
- try {
- r1 = arg1.toString().split(".")[1].length
- } catch (e) {
- r1 = 0
- }
- try {
- r2 = arg2.toString().split(".")[1].length
- } catch (e) {
- r2 = 0
- }
- m = Math.pow(10, Math.max(r1, r2))
- return (arg1 * m + arg2 * m) / m
- },
- accSub(arg1, arg2) {
- var r1, r2, m, n;
- try {
- r1 = arg1.toString().split(".")[1].length;
- } catch (e) {
- r1 = 0;
- }
- try {
- r2 = arg2.toString().split(".")[1].length;
- } catch (e) {
- r2 = 0;
- }
- m = Math.pow(10, Math.max(r1, r2));
- //last modify by deeka
- //动态控制精度长度
- n = (r1 >= r2) ? r1 : r2;
- return ((arg1 * m - arg2 * m) / m).toFixed(n);
- },
- deleteselected(row) {
- this.selectedgoodsdata.list = this.selectedgoodsdata.list.filter(item => {
- return item != row;
- });
- this.row.totalamount = this.accSub(this.row.totalamount, row.amount);
- }
- }
- })
- Form.api.bindevent($("form[role=form]"), "", "", function () {
- let main = JSON.parse($("#c-main").val());
- let goodslist = JSON.parse($("#c-goodslist").val());
- if (main.stock_supplier_id == "") {
- Toastr.error("请选择供应商");
- return false;
- } else if (goodslist.length < 1) {
- Toastr.error("请添加入库商品");
- return false;
- }
- });
- },
- edit: function () {
- Vue.use(ELEMENT);
- var vm = new Vue({
- el: "#app",
- data: function () {
- return {
- searchvalue: "",
- row: { stock_supplier_id: "", remark: "", inboundtime: "", totalamount: 0.00 },
- curgood: { stock_goods_id: "", volnum: "", goodsname: "", productmodel: "", measureunit: "件", inboundprice: "", stockinnums: 0, stockingoodsremark: "", amount: "", barcode: "" },
- defaultgood: { stock_goods_id: "", volnum: "", goodsname: "", productmodel: "", measureunit: "件", inboundprice: "", stockinnums: 0, stockingoodsremark: "", amount: "" },
- supplierlist: [],
- goodsdata: {
- table: { height: ($(window).height() - 490) + "px" },
- list: [],
- pagenation: {
- currentpage: 1,
- pagesize: 10,
- total: 0
- }
- },
- selectedgoodsdata: {
- table: { height: ($(window).height() - 355) + "px" },
- list: [],
- },
- deselectedgoodslist: [],
- rules: {
- inboundprice: [
- { required: true, type: 'string', trigger: 'blur', message: '金额不能为空' },
- { pattern: /(^[1-9]([0-9]+)?(\.[0-9]{1,2})?$)|(^(0){1}$)|(^[0-9]\.[0-9]([0-9])?$)/, message: '请输入正确额格式,可保留两位小数' }
- ],
- stockinnums: [
- { required: true, message: '入库数量不能为空' },
- { type: 'number', message: '入库数量必须为数字值' }
- ],
- }
- }
- },
- computed: {
- main: function () { return JSON.stringify(this.row) },
- goodslist: function () { return JSON.stringify(this.selectedgoodsdata.list) },
- deletedgoodslist: function () { return JSON.stringify(this.deselectedgoodslist) }
- },
- created() {
- this.loadgoodslist()
- this.loadsupplierlist()
- this.loadstockininfo()
- },
- methods: {
- loadstockininfo() {
- let that = this;
- $.ajax({
- url: 'stock/stockin/info',
- type: "POST",
- data: { id: Fast.api.query("ids") },
- success: function (res) {
- res.row.inboundtime = Moment(parseInt(res.row.inboundtime) * 1000).format("YYYY-MM-DD");
- console.log(res.row);
- that.row = res.row;
- that.selectedgoodsdata.list = res.goodslist;
- },
- error: function (res) {
- Toastr.error("加载失败!")
- }
- })
- },
- loadsupplierlist() {
- let that = this;
- $.ajax({
- url: 'stock/supplier/index',
- data: {},
- success: function (res) {
- that.supplierlist = res.rows;
- },
- error: function (res) {
- Toastr.error("加载失败!")
- }
- })
- },
- loadgoodslist() {
- let that = this;
- $.ajax({
- url: 'stock/goods/getlist',
- data: { sort: 'goods.id', order: 'desc', offset: this.goodsdata.pagenation.pagesize * (this.goodsdata.pagenation.currentpage - 1), limit: this.goodsdata.pagenation.pagesize, searchvalue: this.searchvalue },
- success: function (res) {
- that.goodsdata.list = res.rows;
- that.goodsdata.pagenation.total = res.total;
- },
- error: function (res) {
- Toastr.error("加载失败!")
- }
- })
- },
- handleSizeChange(val) {
- this.goodsdata.pagenation.pagesize = val;
- this.loadgoodslist();
- },
- handleCurrentChange(val) {
- this.goodsdata.pagenation.currentpage = val;
- this.loadgoodslist();
- },
- debounce(fn, delay) {
- let timeout = null;
- delay = delay || 500;
- return function (e) {
- let args = arguments;
- let that = this;
- clearTimeout(timeout);
- timeout = setTimeout(function () {
- fn.apply(that, args);
- }, delay);
- };
- },
- barcodeinputenter() {
- let that=this;
- if (this.curgood.barcode == "") {
- Fast.api.msg("请输入商品条码并按回车键!")
- } else {
- Fast.api.ajax({
- url: "stock/goods/getgoodsbybarcodeorid",
- data: { barcode: this.curgood.barcode }
- }, function (data) {
- if (data !== null) {
- that.curgood.stock_goods_id = data.id;
- that.curgood.volnum = data.volnum;
- that.curgood.goodsname = data.goodsname;
- that.curgood.productmodel = data.productmodel;
- that.curgood.measureunit = data.measureunit;
- that.curgood.inboundprice = data.univalence;
- that.curgood.barcode = data.barcode;
- that.curgood.stockinnums = 1;
- that.curgood.stockingoodsremark = "";
- that.curgood.amount = data.univalence;
- }
- })
- }
- },
- onSearchvalueChange() {
- this.debounce(this.loadgoodslist, 1000)();
- },
- selectonegood(currentrow) {
- this.curgood.stock_goods_id = currentrow.id;
- this.curgood.volnum = currentrow.volnum;
- this.curgood.goodsname = currentrow.goodsname;
- this.curgood.productmodel = currentrow.productmodel;
- this.curgood.measureunit = currentrow.measureunit;
- this.curgood.inboundprice = currentrow.univalence;
- this.curgood.barcode = currentrow.barcode;
- this.curgood.stockinnums = 1;
- this.curgood.stockingoodsremark = "";
- this.curgood.amount = currentrow.univalence;
- },
- addtolist() {
- let that = this;
- let hasadded = false;
- if (this.curgood.stock_goods_id != "") {
- this.selectedgoodsdata.list.forEach(item => {
- if (item.stock_goods_id == that.curgood.stock_goods_id) {
- Fast.api.msg("该商品已添加,请勿重复添加!")
- hasadded = true;
- }
- });
- if (!hasadded) {
- let good = JSON.parse(JSON.stringify(this.curgood));
- this.selectedgoodsdata.list.unshift(good);
- this.curgood = JSON.parse(JSON.stringify(this.defaultgood));
- this.row.totalamount = this.accAdd(this.row.totalamount, good.amount);
- }
- } else {
- Fast.api.msg("请选择入库商品!")
- }
- },
- reset() {
- this.curgood = JSON.parse(JSON.stringify(this.defaultgood));
- },
- getcurgoodamount() {
- this.curgood.amount = this.accMul(this.curgood.stockinnums, this.curgood.inboundprice);
- },
- accMul(arg1, arg2) {
- var m = 0, s1 = arg1.toString(), s2 = arg2.toString();
- try {
- m += s1.split(".")[1].length
- } catch (e) {
- }
- try {
- m += s2.split(".")[1].length
- } catch (e) {
- }
- return Number(s1.replace(".", "")) * Number(s2.replace(".", "")) / Math.pow(10, m)
- },
- accAdd(arg1, arg2) {
- var r1, r2, m;
- try {
- r1 = arg1.toString().split(".")[1].length
- } catch (e) {
- r1 = 0
- }
- try {
- r2 = arg2.toString().split(".")[1].length
- } catch (e) {
- r2 = 0
- }
- m = Math.pow(10, Math.max(r1, r2))
- return (arg1 * m + arg2 * m) / m
- },
- accSub(arg1, arg2) {
- var r1, r2, m, n;
- try {
- r1 = arg1.toString().split(".")[1].length;
- } catch (e) {
- r1 = 0;
- }
- try {
- r2 = arg2.toString().split(".")[1].length;
- } catch (e) {
- r2 = 0;
- }
- m = Math.pow(10, Math.max(r1, r2));
- //last modify by deeka
- //动态控制精度长度
- n = (r1 >= r2) ? r1 : r2;
- return ((arg1 * m - arg2 * m) / m).toFixed(n);
- },
- deleteselected(row) {
- if (row.id) {
- this.deselectedgoodslist.unshift(row.id);
- }
- this.selectedgoodsdata.list = this.selectedgoodsdata.list.filter(item => {
- return item != row;
- });
- this.row.totalamount = this.accSub(this.row.totalamount, row.amount);
- }
- }
- })
- Form.api.bindevent($("form[role=form]"), "", "", function () {
- let main = JSON.parse($("#c-main").val());
- let goodslist = JSON.parse($("#c-goodslist").val());
- if (main.stock_supplier_id == "") {
- Toastr.error("请选择供应商");
- return false;
- } else if (goodslist.length < 1) {
- Toastr.error("请添加入库商品");
- return false;
- }
- });
- },
- printer: function () {
- $.ajax({
- type: "POST",
- url: Fast.api.fixurl('stock/stockin/info'),
- data: { "id": Fast.api.query("id") },
- async: true, //或false,是否异步
- timeout: 5000, //超时时间
- dataType: 'json', //返回的数据格式:json/xml/html/script/jsonp/text
- success: function (data) {
- madehtml(data);
- }
- });
- function madehtml(data) {
- var h = "<div id=\"top\" class=\"page\" ><div style=\"text-align: center;font-size:22px;line-height:38px\" >入库单</div>" +
- "<table style=\"width:100%;\">" +
- " <tr>" +
- " <td width=\"40%\"></td>" +
- "<td width=\"25%\"></td>" +
- "<td width=\"12%\" tdata=\"pageNO\" format=\"##\" style=\"text-align:right;\">第##页</td>" +
- "<td width=\"13%\" tdata=\"pageCount\" format=\"##\" style=\"text-align:right;\"> 共##页</td>" +
- " </tr>" +
- "<tr>" +
- "<td >供应商:" + data.row.supplier.name + "</td>" +
- "<td>日期:" + Moment(Number( data.row.inboundtime) * 1000).format("YYYY-MM-DD") + "</td>" +
- "<td colspan=\"2\" style=\"text-align:right;\">编号:" + data.row.docnum + "</td>" +
- "</tr>" +
- "</table>" +
- "</div>" +
- "<div id=\"maintable\"><table border=\"1\" style=\"width:100%;\">" +
- "<thead><tr align=\"center\">" +
- "<th width=\"5%\" style=\"text-align:center;\"><div style=\"line-height:20px;\">序号</th>" +
- "<th width=\"10%\" style=\"text-align:center;\"><div style=\"line-height:20px;\">商品</br>代码</th>" +
- "<th width=\"20%\" style=\"text-align:center;\"><div style=\"line-height:20px;\">商品</br>名称</th>" +
- "<th width=\"10%\" style=\"text-align:center;\"><div style=\"line-height:20px;\">规格</br>型号</th>" +
- "<th width=\"8%\" style=\"text-align:center;\"><div style=\"line-height:20px;\">单位</th>" +
- "<th width=\"6%\" style=\"text-align:center;\"><div style=\"line-height:20px;\">数量</th>" +
- "<th width=\"10%\" style=\"text-align:center;\"><div style=\"line-height:20px;\">重量(kg)</th>" +
- "<th width=\"12%\" style=\"text-align:center;\"><div style=\"line-height:20px;\">总重量(kg)</th>" +
- "<th width=\"20%\" style=\"text-align:center;\"><div style=\"line-height:20px;\">备注</th>" +
- "</tr></thead> ";
- for (var i = 0; i < data.goodslist.length; i++) {
- h += maderow(data.goodslist[i], i)
- }
- h += "<tfoot> <tr><td tindex=\"8\" tdata=\"SubSum\" format=\"UpperMoney\" colspan=\"5\" ><div style=\"line-height:25px;text-align: left;\">本页小计:</td>" +
- "<td align=\"center\" tdata=\"SubSum\" format=\"#,##\">###</td>" +
- "<td></td>" +
- "<td align=\"center\" tdata=\"SubSum\" format=\"#,##0.00\">###</td>" +
- "<td></td>" +
- "</tr>" +
- "<tr><td colspan=\"5\" tindex=\"8\" tdata=\"AllSum\" format=\"UpperMoney\" ><div style=\"line-height:25px;text-align: left;\">合 计: </td>" +
- "<td align=\"center\" tdata=\"AllSum\" format=\"#,##\">###</td>" +
- "<td></td>" +
- "<td align=\"center\" tdata=\"AllSum\" format=\"#,##0.00\">###</td>" +
- "<td></td>" +
- "</tr>" +
- " </tfoot></table>" +
- "</div>" +
- "<div id=\"foot\"><table style=\"width:100%;\">" +
- "<tr >" +
- "<td width=\"30%\"><div style=\"line-height:30px;\">负责人:</td>" +
- "<td width=\"30%\"><div style=\"line-height:30px;\">经办人:</td>" +
- "<td width=\"40%\"><div style=\"line-height:30px;\">库管员:</td>" +
- "</tr>" +
- "<tr>" +
- "</tr>" +
- "</table></div>";
- $('.printContent').append(h);
- }
- function maderow(row, currow) {
- var h = " <tr align=\"center\">\n" +
- " <td >" + (currow + 1) + "</td>\n" +
- " <td >" + row.volnum + "</td>\n" +
- " <td >" + row.goodsname + "</td>\n" +
- " <td >" + row.productmodel + "</td>\n" +
- " <td >" + row.measureunit + "</td>\n" +
- " <td >" + row.stockinnums + "</td>\n" +
- " <td >" + row.inboundprice + "</td>\n" +
- " <td >" + row.amount + "</td>\n" +
- " <td >" + row.stockingoodsremark + "</td>\n" +
- " </tr>"
- return h;
- }
- require(['lodop'], function (lodop) {
- $(".btn-print").click(function () {
- var LODOP = getLodop();
- if (typeof (LODOP) != "undefined") {
- 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>"
- var strStyle2 = "<style>div{font-family:'思源黑体 CN Medium'} table{font-family:'思源黑体 CN Medium','times'}</style>";
- LODOP.ADD_PRINT_TABLE("30mm", "5%", "90%", "70mm", strStyle + document.getElementById("maintable").innerHTML);
- LODOP.SET_PRINT_STYLEA(0, "Vorient", 3);
- LODOP.ADD_PRINT_HTM("2mm", "5%", "90%", "25mm",strStyle2+ document.getElementById("top").innerHTML);
- LODOP.SET_PRINT_STYLEA(0, "ItemType", 1);
- LODOP.ADD_PRINT_HTM("120mm", "5%", "90%", "25mm", strStyle2+document.getElementById("foot").innerHTML);
- LODOP.SET_PRINT_STYLEA(0, "LinkedItem", 4);
- LODOP.SET_PRINT_STYLEA(0, "FontSize", 12);
- LODOP.SET_PRINT_STYLEA(0, "FontColor", "#FF0000");
- LODOP.SET_PRINT_STYLEA(0, "Alignment", 2);
- LODOP.SET_PRINT_STYLEA(0, "ItemType", 1);
- LODOP.SET_PRINT_STYLEA(0, "Horient", 3);
- LODOP.SET_PRINT_PAGESIZE(2, 0, 0, "A5")
- LODOP.PREVIEW();
- }
- });
- });
- },
- api: {
- formatter: {
- audit: function (value, row, index) {
- var colorArr = { normal: 'success', hidden: 'grey', deleted: 'danger', locked: 'info' };
- // 如果字段列有定义custom
- var newValue = value == null ? '未审核' : '已审核';
- var color = value == null ? 'danger' : 'primary';
- var html = '<span class="text-' + color + '"><i class="fa fa-circle"></i> ' + __(newValue) + '</span>';
- return html;
- },
- settle: function (value, row, index) {
- var colorArr = { normal: 'success', hidden: 'grey', deleted: 'danger', locked: 'info' };
- // 如果字段列有定义custom
- var newValue = value == null ? '未结算' : '已结算';
- var color = value == null ? 'danger' : 'primary';
- var html = '<span class="text-' + color + '"><i class="fa fa-circle"></i> ' + __(newValue) + '</span>';
- return html;
- },
- },
- bindevent: function () {
- }
- }
- };
- return Controller;
- });
|