1. 基本功能 1. 基本功能
1.1. 数字控件小数位填充配置 1.1. 数字控件小数位填充配置
默认数字控件小数位会自动填充零,支持配置不自动补齐后面的精度位数。
1.2. 格式化表达式 1.2. 格式化表达式
若要实现界面显示的小数位数和数据库设置的不一致,则需配置格式化表达式,格式化表达式只针对数字控件。
2. 配置方法 2. 配置方法
2.1. 数字控件小数位填充配置 2.1. 数字控件小数位填充配置
- 项目管理–项目初始化–视图级配置菜单,新增【配置项类型】为是数字控件小数位填充零
(Y/N)
,【配置内容】为N。
- 设置完后点击保存,返回视图管理配置页面,勾选刚才新增的配置项,点击【批量提交】按钮。
- 重新生成代码。
2.2. 格式化表达式 2.2. 格式化表达式
配置
- 对象建模–业务对象–业务对象管理:编辑业务对象,点击【可视化布局】按钮,找到要配置格式化表达式的属性,在右边属性列表里面的格式化表达式里面填写表达式。格式为【number:格式化小数位数】,其中【number】代表的是数字控件中的千位分隔符。
代码
在html中生成了g-format
标签
<input id="testDengpp3101.itemLength" g-numeric="" allow-float="true" allow-negative="true" empty-zero="false" g-format="number:2" g-precision="3" rounding="true" zero-fill="true" max-length="19" integerpart-length="15" name="itemLength" class="input form-control" ng-model="testDengpp3101.itemLength" type="text" g-focus-select="" ng-disabled="testDengpp3101.testDengppId==null||$$isDeleted_=='Y'" />
3. 常用扩展 3. 常用扩展
3.1. 根据字段的值设置保留位数 3.1. 根据字段的值设置保留位数
- 数字控件根据某个或多个字段的值设置保留位数,常见场景例如:在油水加装业务中,不同的油种输入的数量的位数是不一样的,在输入的时候就需要控制其小数是否存在。
- 代码部分,参考如下
首先查询出所有的油种,然后根据油种判断是否保留小数
$scope.customOwConsumption2Init=function(){
$scope.scaleInstall="0";
$scope.scaleStorage="0";
$scope.scaleConsumption="0";
$scope.oilNames=[];
$scope.oilScales=[];
$scope.oilUnits=[];
$http.post($config.ctx+"/owConsumption2/getScaleLength",{}).success(function(data){
if(data.success!=undefined&&data.success==true){
var mapOilNameAndScale=data.mapOilNameAndScale;
if(mapOilNameAndScale!=null){
var oilName=mapOilNameAndScale.oilName; //油种名称
var oilScale=mapOilNameAndScale.oilScale; //保留位数
var oilUnit=mapOilNameAndScale.oilUnit //单位(规格)
$scope.oilNames=oilName;
$scope.oilScales=oilScale;
$scope.oilUnits=oilUnit;
}
}
});
};
然后在油水新增的时候选择哪个油种后,然后更具查询到的对应油种的保留位数来控制是否保留小数:
表格行选中事件绑定:
/**
* 设置保留位数
*/
$scope.setScale = function(type) {
var selectRow = {};
if (type == "lpOilWaterInstallation2") {
selectRow = $scope.lpOilWaterInstallation2;
} else if (type == "rptOilWaterStorage2") {
selectRow = $scope.rptOilWaterStorage2;
} else if (type == "evOilWaterConsumption2") {
selectRow = $scope.evOilWaterConsumption2;
}
var variety = selectRow.variety;
if (!variety) return;
//通过循环匹配出对应品种的保留为数情况
for (var i = 0; i & lt; $scope.oilNames.length; i++) {
var oilName = $scope.oilNames[i];
if (variety === oilName) {
var oilScale = $scope.oilScales[i];
if (type == "lpOilWaterInstallation2") {
$scope.scaleInstall = oilScale;
} else if (type == "rptOilWaterStorage2") {
$scope.scaleStorage = oilScale;
} else if (type == "evOilWaterConsumption2") {
$scope.scaleConsumption = oilScale;
}
}
}
}
表格中数字控件数据change事件:(标红的就是判断的依据)
$scope.controllValueMoreThanZero = function(type, ifTip) {
if (ifTip == undefined) ifTip = '1';
if (type == "quantity") {
var selectRow = $scope.lpOilWaterInstallation2SelectedRow;
var quantity = selectRow.quantity;
if (quantity & amp; & amp; quantity != "") {
if (Number(quantity) & lt; = 0) {
GillionMsg.alert("提示", "【数量】必须大于零!");
$scope.lpOilWaterInstallation2SelectedRow.quantity = 1;
return;
} else {
var quantityNew = Number(Number(quantity) % 1);
if ($scope.scaleInstall == "0") {
if (quantityNew & lt; 1 & amp; & amp; quantityNew & gt; 0) {
quantity = Math.round(quantity);
if (ifTip == "1") {
//GillionMsg.alert("提示","【润滑油类或水类】数量必须为整数!");
}
$scope.lpOilWaterInstallation2SelectedRow.quantity = quantity;
return;
}
}
}
}
} else if (type == "unitPrice") {
var selectRow = $scope.lpOilWaterInstallation2SelectedRow;
var unitPrice = selectRow.unitPrice;
if (unitPrice & amp; & amp; unitPrice != "") {
if (Number(unitPrice) & lt; = 0) {
GillionMsg.alert("提示", "【单价】必须大于零!");
$scope.lpOilWaterInstallation2SelectedRow.unitPrice = 1;
return;
}
}
} else if (type == "shipInventory") {
var selectRow = $scope.rptOilWaterStorage2SelectedRow;
var shipInventory = selectRow.shipInventory;
if (shipInventory & amp; & amp; shipInventory != "") {
if (Number(shipInventory) & lt; 0) {
GillionMsg.alert("提示", "【本次结存量】必须大于等于零!");
$scope.rptOilWaterStorage2SelectedRow.shipInventory = 0;
return;
} else {
shipInventoryNew = Number(Number(shipInventory) % 1);
if ($scope.scaleStorage == "0") {
if (shipInventoryNew & lt; 1 & amp; & amp; shipInventoryNew & gt; 0) {
shipInventory = Math.round(shipInventory);
var shipInventoryOld = selectRow.shipInventoryOld;
shipInventoryOld = Math.round(shipInventoryOld);
if (ifTip == "1") {
//GillionMsg.alert("提示","【润滑油类或水类】本次结存量必须为整数!");
}
$scope.rptOilWaterStorage2SelectedRow.shipInventory = shipInventory;
$scope.rptOilWaterStorage2SelectedRow.shipInventoryOld = shipInventoryOld;
return;
}
}
}
}
} else if (type == "shipInventoryOld") {
var selectRow = $scope.rptOilWaterStorage2SelectedRow;
var shipInventoryOld = selectRow.shipInventoryOld;
if (shipInventoryOld & amp; & amp; shipInventoryOld != "") {
if (Number(shipInventoryOld) & lt; 0) {
GillionMsg.alert("提示", "【上次结存量】必须大于等于零!");
$scope.rptOilWaterStorage2SelectedRow.shipInventoryOld = 0;
return;
} else {
shipInventoryOldNew = Number(Number(shipInventoryOld) % 1);
if ($scope.scaleStorage == "0") {
if (shipInventoryOldNew & lt; 1 & amp; & amp; shipInventoryOldNew & gt; 0) {
shipInventoryOld = Math.round(shipInventoryOld);
if (ifTip == "1") {
//GillionMsg.alert("提示","【润滑油类或水类】上次结存量必须为整数!");
}
$scope.rptOilWaterStorage2SelectedRow.shipInventoryOld = shipInventoryOld;
return;
}
}
}
}
} else if (type == "productionConsumption") {
var selectRow = $scope.evOilWaterConsumption2SelectedRow;
var productionConsumption = selectRow.productionConsumption;
if (productionConsumption & amp; & amp; productionConsumption != "") {
if (Number(productionConsumption) & lt; 0) {
GillionMsg.alert("提示", "【生产耗量】必须大于等于零!");
$scope.evOilWaterConsumption2SelectedRow.productionConsumption = 0;
return;
} else {
productionConsumptionNew = Number(Number(productionConsumption) % 1);
if ($scope.scaleConsumption == "0") {
if (productionConsumptionNew & lt; 1 & amp; & amp; productionConsumptionNew & gt; 0) {
productionConsumption = Math.round(productionConsumption);
var nonproductionConsumption = selectRow.nonproductionConsumption;
nonproductionConsumption = Math.round(nonproductionConsumption);
if (ifTip == "1") {
//GillionMsg.alert("提示","【润滑油类或水类】生产耗量必须为整数!");
}
$scope.evOilWaterConsumption2SelectedRow.productionConsumption = productionConsumption;
$scope.evOilWaterConsumption2SelectedRow.nonproductionConsumption = nonproductionConsumption;
return;
}
}
}
}
} else if (type == "nonProductionConsumption") {
var selectRow = $scope.evOilWaterConsumption2SelectedRow;
var nonproductionConsumption = selectRow.nonProductionConsumption;
if (nonproductionConsumption & amp; & amp; nonproductionConsumption != "") {
if (Number(nonproductionConsumption) & lt; 0) {
GillionMsg.alert("提示", "【非生产耗量】必须大于等于零!");
$scope.evOilWaterConsumption2SelectedRow.nonProductionConsumption = 0;
return;
} else {
nonproductionConsumptionNew = Number(Number(nonproductionConsumption) % 1);
if ($scope.scaleConsumption == "0") {
if (nonproductionConsumptionNew & lt; 1 & amp; & amp; nonproductionConsumptionNew & gt; 0) {
nonproductionConsumption = Math.round(nonproductionConsumption);
if (ifTip == "1") {
//GillionMsg.alert("提示","【润滑油类或水类】非生产耗量必须为整数!");
}
$scope.evOilWaterConsumption2SelectedRow.nonProductionConsumption = nonproductionConsumption;
return;
}
}
}
}
}
};