"use strict"; //器材信息 angular.module('app.business') .controller("jsglCtrl", function($scope, $http, $state, $rootScope, jsglService, warehouseService, $stateParams, APP_CONFIG) { // 获取列表数据 $scope.jslx = $stateParams.jslx; $scope.ywlx = $stateParams.ywlx; if ($scope.jslx == "0" && $scope.ywlx == '1') { $scope.top_title = "入库结算列表"; } else if ($scope.jslx == "1" && $scope.ywlx == '1') { $scope.top_title = "出库结算列表"; } else { $scope.top_title = "散粮入库结算列表"; } $scope.pageInfo = {pageNum : 1, pageSize : 10}; $scope.search = {houseId:null, wareId: null, ywlx: $scope.ywlx}; $scope.loadData = function() { jsglService.getPageInfo($scope.pageInfo.pageNum, $scope.pageInfo.pageSize, $stateParams.jslx, $scope.search).then(function(data){ $scope.pageInfo = data; },function(data){ console.log(data); }); } $scope.loadData(); $scope.loadWare = function(houseId) { //按照单位获取单位下的仓房信息 if (null == houseId) { $scope.warehouseList = null; } else { var orgId = $rootScope.orgInfo.orgId; warehouseService.getStorehouse(orgId, houseId, "0").then(function(data){ $scope.warehouseList = data.wareList; //下拉列表数据 },function (data) { console.log(data); }); } } // 翻页 $scope.goPage = function(pageNum) { $scope.pageInfo.pageNum = pageNum; $scope.loadData(); } /** * 新增、查看、修改 * jslx: 0是入库,1是出库 */ $scope.edit = function(id, butType) { if ($scope.ywlx == "0") { $state.go('app.business.rkjs-sl-list.edit',{id:id, butType:butType, jslx: $stateParams.jslx}); } else { $state.go('app.business.rkjslist.edit',{id:id, butType:butType, jslx: $stateParams.jslx}); } } //删除 $scope.remove = function(id) { if (!confirm("确定要删除吗?")) { return; } jsglService.remove(id).then(function(data){ $scope.loadData(); },function(data){ console.log(data); }); } }) .controller("jsglEditCtrl", function($scope, $http, $filter, $state, $rootScope, $stateParams, $uibModal, APP_CONFIG, jsglService, warehouseService, customerService, commonUtilService) { var id = $stateParams.id; var butType = $stateParams.butType; $scope.jslx = $stateParams.jslx; if ($scope.jslx == "0") { $scope.top_title = "入库结算详情"; $scope.sectionHide = true; } else if ($scope.jslx == "1") { $scope.top_title = "出库结算详情"; $scope.sectionHide = false; // 非必填 $scope.isNotHide = true; } var isNotEdit = false;//大多数文本框 var isEdit = false;//少数要控制的文本框 $scope.jsgl = {}; // 获取列表数据 $scope.loadData = function() { jsglService.findBykey($stateParams.id).then(function(data){ $scope.jsgl = data; $scope.jsgl.orgId = $rootScope.orgInfo.orgId; $scope.loadWare($scope.jsgl.houseId); $scope.remarksChange(); if ("" != id) { if (butType != "show") { $scope.jsgl.commitPeople = $rootScope.userInfo.realName; // 提交人 $scope.jsgl.commitTime = $filter('date')(new Date(), "yyyy-MM-dd HH:mm:ss");// 提交时间 } } },function(data){ console.log(data); }); } $scope.loadWare = function(houseId) { //按照单位获取单位下的仓房信息 var orgId = $rootScope.orgInfo.orgId; warehouseService.getStorehouse(orgId, houseId, "0").then(function(data){ $scope.warehouseList = data.wareList; //下拉列表数据 },function (data) { console.log(data); }); } if ("" != id) { if (butType == "show") {//查看 $scope.isNotEdit = true; $scope.isEdit = true; } else { $scope.isEdit = true; } $scope.loadData(); } else { $scope.jsgl.bcjssj = $filter('date')(new Date(), "yyyy-MM-dd HH:mm:ss"); $scope.jsgl.fkdw = $rootScope.orgInfo.orgName; $scope.jsgl.orgId = $rootScope.orgInfo.orgId; $scope.jsgl.jslx = $scope.jslx; $scope.jsgl.fpzt = "1"; //发票状态默认1正常 $scope.jsgl.bcjsfs = "1"; //付款方式默认1转账 $scope.jsgl.ywlx = "1"; //业务类型是非散粮类型 $scope.jsgl.commitPeople = $rootScope.userInfo.realName; // 提交人 $scope.jsgl.commitTime = $filter('date')(new Date(), "yyyy-MM-dd HH:mm:ss");// 提交时间 } $scope.getReceiveContract = function() { var params = []; if ($scope.jslx == "0") {//入库 params.htlx = "0"; // 非字段条件-业务特殊需求(剩余数量为“0”的合同不展示在列表中) params.surplus = "0"; } else if ($scope.jslx == "1") {//出库 params.htlx = "1"; params.surplus = "1"; } else { alert("系统异常,请联系管理员!"); return; } var uibModalInstance = $uibModal.open({ size:'lg', templateUrl: 'app/business/deliveryStorageNotice/views/receiveContract-list-modal.html', controller: 'receiveContractListModalCtrl', resolve: { // items是一个回调函数 items: function () { // 这个值会被模态框的控制器获取到 return params; } } }); uibModalInstance.result.then(function (result) { if (result != null) { // 获取明细信息. $scope.jsgl.htid = result.id; $scope.jsgl.htbh = result.htbh; $scope.jsgl.htzsl = result.htzsl; $scope.jsgl.yjssl = result.yjssl; $scope.jsgl.houseId = result.houseId; $scope.jsgl.warehouseId = result.warehouseId; if (result.warehouseId != null) { $scope.loadWare(result.houseId); } $scope.jsgl.lypz = result.lypz; $scope.jsgl.mxpz = result.mxpz; $scope.jsgl.lyxz = result.lyxz; $scope.jsgl.bcjsdj = result.htdj; $scope.getCustomer(result.khid); } }, function (reason) { console.log(reason); }); } /** * 获取客户信息 * @param khid 客户ID */ $scope.getCustomer = function(khid) { customerService.loadDataById(khid).then(function(data){ $scope.jsgl.customerId = data.id; // 收付款人赋值客户姓名. $scope.jsgl.sfkr = data.name; //开户行名称 $scope.jsgl.khhmc = data.bankName; //开户行号 $scope.jsgl.khhh = data.khhh; //银行账号 $scope.jsgl.yhzh = data.accountNumber; //收付款人身份证号赋值社会信用代码 $scope.jsgl.skrsfzh = data.socialCreditCode; //付款单位 $scope.jsgl.fkdw = $rootScope.orgInfo.orgName; }, function (data) { console.log(data); }); }; $scope.calculate = function() { var bcjssl = $scope.jsgl.bcjssl; var bcjsdj = $scope.jsgl.bcjsdj; var re = /^([0-9]+.[0-9]{3})[0-9]*/; if(bcjssl !== undefined && bcjssl !== "" && bcjssl != null) { bcjssl = bcjssl.toString().replace(re,"$1"); bcjssl = parseFloat(bcjssl); $scope.jsgl.bcjssl = bcjssl; } else { return; } if(bcjsdj !== undefined && bcjsdj !== "" && bcjsdj != null) { bcjsdj = bcjsdj.toString().replace(re,"$1"); bcjsdj = parseFloat(bcjsdj); $scope.jsgl.bcjsdj = bcjsdj; } else { return; } /** * */ var bcjsje = $scope.jsgl.bcjssl * 1000 * $scope.jsgl.bcjsdj * 1000 / 1000000; //将v四舍五入,且保留n位小数 $scope.jsgl.bcjsje = commonUtilService.getMath_N(bcjsje, 2); // 备注必填效验 $scope.remarksChange(); }; // 备注必填效验 $scope.remarksChange = function() { // 本次结算单价,本次结算金额 if ($scope.jsgl.bcjsdj==='0' || $scope.jsgl.bcjsje==='0' || $scope.jsgl.bcjsje==='0.00') { // 备注必填 $('#remarks').attr("required", "false"); $scope.isNotHide = false; } else { // 非必填 $("#remarks").removeAttr("required"); $scope.isNotHide = true; } }; // 返回. $scope.retList = function () { if ($rootScope.previousState_name != '') { $rootScope.back(); } else { if ($scope.jslx=="0") { $state.go('app.business.rkjslist'); } else if ($scope.jslx=="1") { $state.go('app.business.ckjslist'); } } } var validator = $("#jsgl-form").validate(); //保存(0:保存,1:提交) $scope.save = function(czlx) { $scope.jsgl.dataStatus = czlx; var fp_s = $scope.jsgl.fpStart; var fp_e = $scope.jsgl.fpEnd; var fps = $scope.jsgl.fps; var bcjsje_check = $scope.jsgl.bcjsje; if (bcjsje_check!=0 || bcjsje_check!=0.00) { if (fp_s == null && fp_e == null && fps == null) { alert("连续发票号和不连续发票号至少要录入一种,不能都为空值!"); return; } else { if ((fp_s == null && fp_e != null) || (fp_s != null && fp_e == null)) { alert("连续发票号码不能只录入起始值或只录入终止值!"); return; } } } if ($scope.jsgl.yhzh == null) { alert("请补全对应客户档案信息!"); return; } if (validator.form()) { //本次结算时间 $("input[name='bcjssj']").each(function(j,item){ if(item.value != '' && item.value != null && typeof item.value != 'undefined'){ $scope.jsgl.bcjssj = $filter('date')(item.value, "yyyy-MM-dd HH:mm:ss"); } }); jsglService.saveData($scope.jsgl).then(function(data){ if (data.status == "200") { alert("操作成功!"); } else { alert("操作失败!"); } if ($scope.jslx=="0") { $state.go('app.business.rkjslist'); } else if ($scope.jslx=="1") { $state.go('app.business.ckjslist'); } },function(data){ console.log(data); }); } } }) .controller("jsglSlEditCtrl", function($scope, $http, $filter, $state, $rootScope, $stateParams, $uibModal, APP_CONFIG, jsglService, warehouseService, customerService, commonUtilService ) { var id = $stateParams.id; var butType = $stateParams.butType; $scope.jslx = $stateParams.jslx; if ($scope.jslx == "0") { $scope.top_title = "入库结算详情"; } else if ($scope.jslx == "1") { $scope.top_title = "出库结算详情"; } var isNotEdit = false;//大多数文本框 var isEdit = false;//少数要控制的文本框 $scope.jsgl = {}; // 获取列表数据 $scope.loadData = function() { jsglService.findBykey($stateParams.id).then(function(data){ $scope.jsgl = data; $scope.jsgl.orgId = $rootScope.orgInfo.orgId; $scope.sfkr_list = $scope.jsgl.khxxlist; $scope.loadWare($scope.jsgl.houseId); if ("" != id) { if (butType != "show") { $scope.jsgl.commitPeople = $rootScope.userInfo.realName; // 提交人 $scope.jsgl.commitTime = $filter('date')(new Date(), "yyyy-MM-dd HH:mm:ss");// 提交时间 } } },function(data){ console.log(data); }); } $scope.loadWare = function(houseId) { //按照单位获取单位下的仓房信息 var orgId = $rootScope.orgInfo.orgId; warehouseService.getStorehouse(orgId, houseId, "0").then(function(data){ $scope.warehouseList = data.wareList; //下拉列表数据 },function (data) { console.log(data); }); } if ("" != id) { if (butType == "show") {//查看 $scope.isNotEdit = true; $scope.isEdit = true; } else { $scope.isEdit = true; } $scope.loadData(); } else { $scope.jsgl.bcjssj = $filter('date')(new Date(), "yyyy-MM-dd HH:mm:ss"); $scope.jsgl.fkdw = $rootScope.orgInfo.orgName; $scope.jsgl.orgId = $rootScope.orgInfo.orgId; $scope.jsgl.jslx = $scope.jslx; $scope.jsgl.fpzt = "1"; //发票状态默认1正常 $scope.jsgl.bcjsfs = "1"; //付款方式默认1转账 $scope.jsgl.ywlx = "0"; //业务类型是散粮类型 $scope.jsgl.commitPeople = $rootScope.userInfo.realName; // 提交人 $scope.jsgl.commitTime = $filter('date')(new Date(), "yyyy-MM-dd HH:mm:ss");// 提交时间 } //获取储备粮外面的自建通知单列表 $scope.getDeliveryStorageNotice = function() { var params = []; if ($scope.jslx == "0") {//入库 params.billType = "1";//查询入库类型的通知单 } else if ($scope.jslx == "1") {//出库 params.billType = "3"; } else { alert("系统异常,请联系管理员!"); return; } params.orgId = $scope.jsgl.orgId; var uibModalInstance = $uibModal.open({ size:'lg', templateUrl: 'app/business/jsgl/views/tzd-zj-model.html', controller: 'tzdZjCtrl', resolve: { // items是一个回调函数 items: function () { // 这个值会被模态框的控制器获取到 return params; } } }); uibModalInstance.result.then(function (result) { if (result != null) { // 获取明细信息. $scope.jsgl.htid = result.id; $scope.jsgl.htbh = result.billNumber; $scope.jsgl.htzsl = parseInt(result.shipingCount); $scope.jsgl.yjssl = result.yjssl; $scope.jsgl.houseId = result.houseId; $scope.jsgl.warehouseId = result.warehouseId; if (result.warehouseId != null) { $scope.loadWare(result.houseId); } $scope.jsgl.lypz = result.lypz; $scope.jsgl.mxpz = result.mxpz; $scope.jsgl.lyxz = result.lyxz; $scope.jsgl.bcjsdj = result.dj; //$scope.getCustomer(result.khid); } }, function (result) { console.log(result); }); } // 选择收款人信息. $scope.getSkrData = function(id) { if ($scope.jsgl.htbh != null) { var params = []; params.tzdbh = $scope.jsgl.htbh; //通知单编号 var uibModalInstance = $uibModal.open({ size:'lg', templateUrl: 'app/business/jsgl/views/crkjl-model-list.html', controller: 'selectCyrDataModalCtrl', resolve: { // items是一个回调函数 items: function () { // 这个值会被模态框的控制器获取到 return params; } } }); uibModalInstance.result.then(function (result) { if (result != null) { $scope.sfkr_list = result; $scope.jsgl.khxxlist = result; $scope.jsgl.khxxlist.forEach(obj => { delete obj.bizno; delete obj.checked; }); //计算本次结算数量 var bcjssl = 0; bcjssl = $scope.sfkr_list.reduce((sum, slkhxx) => sum + slkhxx.crksl, 0); $scope.jsgl.bcjssl = bcjssl/1000; $scope.calculate();//计算本次结算金额 } // 关闭模态框时刷新页面数据 }, function (reason) { console.log(reason); }); } } $.validator.addMethod("checkKhhh",function(value,element, params) { var checkNumber = /(^[0-9]{1,12}$)/g; return this.optional(element)||(checkNumber.test(value)); },"请输入正确的开户行号"); $.validator.addMethod("checkSfzhm",function(value,element, params) { var checkNumber = /(^\d{18}$)|(^\d{17}(\d|X)$)/g; return this.optional(element)||(checkNumber.test(value)); },"请输入正确的身份证号码,且不能重复!"); $.validator.addMethod("checkYhzh",function(value,element, params) { var checkNumber = /^[0-9]{1,30}$/g; return this.optional(element)||(checkNumber.test(value)); },"请输入正确的银行账号!"); //散粮客户信息保存 $scope.saveKhxx = function(ite) { if (ite.sfkr != null && ite.skrsfzh != null && ite.sfkr != undefined && ite.skrsfzh != undefined) { var obj = {}; obj.khmc = ite.sfkr; obj.sfzhm = ite.skrsfzh; obj.khhmc = ite.khhmc; obj.yhhbdm = ite.yhhbdm; obj.khhh = ite.khhh; obj.yhzh = ite.yhzh; jsglService.saveOrUpdateSlkhxx(obj).then(function(data){ if (data.status == "200") { alert("操作成功!"); } else { alert("操作失败!"); } },function(data){ console.log(data); }); } else { alert("收款人和身份证号不能为空"); } } //点击收款人或身份证号码带出散粮客户信息 $scope.checkSlKhxx = function(ite) { if (ite.sfkr != null && ite.skrsfzh != null && ite.sfkr != undefined && ite.skrsfzh != undefined) { jsglService.queryStorageSlkhxx(ite.sfkr, ite.skrsfzh).then(function(data){ if (data.status == "200") { var slkhxx = data.msg; ite.khhmc = slkhxx.khhmc; ite.yhhbdm = slkhxx.yhhbdm; ite.khhh = slkhxx.khhh; ite.yhzh = slkhxx.yhzh; } },function(data){ console.log(data); }); } } /** * 计算本次结算金额 = 本次结算数量 * 本次结算单价 * 保留两位小数 */ $scope.calculate = function() { var bcjssl = $scope.jsgl.bcjssl; var bcjsdj = $scope.jsgl.bcjsdj; var re = /^([0-9]+.[0-9]{3})[0-9]*/; if(bcjssl !== undefined && bcjssl !== "" && bcjssl != null) { bcjssl = bcjssl.toString().replace(re,"$1"); bcjssl = parseFloat(bcjssl); $scope.jsgl.bcjssl = bcjssl; } else { return; } if(bcjsdj !== undefined && bcjsdj !== "" && bcjsdj != null) { bcjsdj = bcjsdj.toString().replace(re,"$1"); bcjsdj = parseFloat(bcjsdj); $scope.jsgl.bcjsdj = bcjsdj; } else { return; } /** * */ var bcjsje = $scope.jsgl.bcjssl * 1000 * $scope.jsgl.bcjsdj * 1000 / 1000000; $scope.jsgl.bcjsje = commonUtilService.getMath(bcjsje); } // 返回. $scope.retList = function () { if ($rootScope.previousState_name != '') { $rootScope.back(); } else { $state.go('app.business.rkjs-sl-list'); } } //保存(0:保存,1:提交) $scope.save = function(czlx) { $scope.jsgl.dataStatus = czlx; $scope.isCustomerEdit = $scope.jsgl.bcjsfs=='0'?false:true; if (null === $scope.jsgl.khxxlist || $scope.jsgl.khxxlist == undefined) { alert("至少要有一条客户信息!"); return; } let sfkr = $scope.jsgl.khxxlist.filter(item => !item.sfkr); let skrsfzh = $scope.jsgl.khxxlist.filter(item => !item.skrsfzh); let khhmc = $scope.jsgl.khxxlist.filter(item => !item.khhmc); let yhzh = $scope.jsgl.khxxlist.filter(item => !item.yhzh); if ($scope.isCustomerEdit) {//转账 if (sfkr.length != 0 || skrsfzh.length != 0 || khhmc.length != 0 || yhzh.length != 0) { alert("收款人、身份证号、开户行名称、银行账号不能为空!"); return; } } else { if (sfkr.length != 0 || skrsfzh.length != 0) { alert("收款人、身份证号不能为空!"); return; } } var validator = $("#jsgl-sl-form").validate(); if (validator.form()) { //本次结算时间 $("input[name='bcjssj']").each(function(j,item){ if(item.value != '' && item.value != null && typeof item.value != 'undefined'){ $scope.jsgl.bcjssj = $filter('date')(item.value, "yyyy-MM-dd HH:mm:ss"); } }); jsglService.saveData($scope.jsgl).then(function(data){ if (data.status == "200") { alert("操作成功!"); } else { alert("操作失败!"); } $state.go('app.business.rkjs-sl-list'); },function(data){ console.log(data); }); } }; }) .controller("selectCyrDataModalCtrl", function($scope, $uibModalInstance, $filter, $http, $uibModal, $rootScope, jsglService, APP_CONFIG, items) { $scope.search = {tzdbh: items.tzdbh, cph: null, startTime: null, endTime: null}; // 获取列表数据 $scope.loadData = function() { var startTime = $("#startTime").val(); var endTime = $("#endTime").val(); $scope.search.startTime = startTime; $scope.search.endTime = endTime; jsglService.queryCrkywData($scope.search).then(function(data) { $scope.list = data; }).catch(function(data) { if (data.status == 601) { // session失效,关闭模态框. $uibModalInstance.close(); } }); } $scope.loadData(); //勾选或取消勾选一条数据 $scope.selectData = function(index, obj) { $scope.list[index].checked = obj.checked; if (!obj.checked) { $scope.checkeds = false; } } // 关闭模态窗口 $scope.cancel = function() { $uibModalInstance.close(); } // 选择后点下一步. $scope.closeModal = function() { var arr = $scope.list.filter(item => item.checked); //检索被选中的数据 $uibModalInstance.close(arr); } });