// JavaScript source code
Forguncy.Page.ready(function () {
var priceColIndex = 7; // 单价
var countColIndex = 3; // 数量
var totalColIndex = 8; //金额
var unitsColIndex = 5; // 单价 包装数
var multipleColIndex = 6; // 数量 换算率
var isSettingValue = false;
var listview = Forguncy.Page.getListView("table1");
var updateCount = function (row) {
var total = listview.getValue(row, totalColIndex);
if (total == null) {
return false
}
var price = listview.getValue(row, priceColIndex);
if (price == null) {
return false
}
var count = total / price; //数量=金额/单价
isSettingValue = true;
listview.setValue(row, countColIndex, count);
isSettingValue = false;
return true;
}
var updatePrice = function (row) {
var total = listview.getValue(row, totalColIndex);
if (total == null) {
return false
}
var count = listview.getValue(row, countColIndex);
if (count == null) {
return false
}
var price = total / count; //单价=金额/数量
isSettingValue = true;
listview.setValue(row, priceColIndex, price);
isSettingValue = false;
return true;
}
var updateTotal = function (row) {
var price = listview.getValue(row, priceColIndex);
if (price == null) {
return false
}
var count = listview.getValue(row, countColIndex);
if (count == null) {
return false
}
var total = price * count; //金额=单价*数量
isSettingValue = true;
listview.setValue(row, totalColIndex, total);
isSettingValue = false;
return true;
}
listview.bind(Forguncy.ListViewEvents.ValueChanged, function (arg1, arg2) {
if (isSettingValue) {
return;
} //金额
var updateunits = function (row) {
var count = listview.getValue(row, countColIndex);
if (count == null) {
return false
}
var multiple = listview.getValue(row, multipleColIndex);
if (multiple == null) {
return false
}
var units = count / multiple; //包装数=数量/换算率
isSettingValue = true;
listview.setValue(row, unitsColIndex, units);
isSettingValue = false;
return true;
}
var updatecount = function (row) {
var units = listview.getValue(row, unitsColIndex);
if (units == null) {
return false
}
var multiple = listview.getValue(row, multipleColIndex);
if (multiple == null) {
return false
}
var count = units * multiple; //数量=包装数*换算率
isSettingValue = true;
listview.setValue(row, countColIndex, count);
isSettingValue = false;
return true;
}
var row = arg2.CellRanges[0].Row;
var col = arg2.CellRanges[0].Column;
if (row >= 0 && col >= 0) {
if (col === priceColIndex) {
if (!updateTotal(row)) {
updateCount(row);
}
}
else if (col === countColIndex) {
if (updateTotal(row)) {
updateunits(row);
}
}
else if (col === totalColIndex) {
if (!updatePrice(row)) {
updateCount(row);
}
}
else if (col === multipleColIndex) {
if (!updatecount(row)) {
updateunits(row);
}
}
else if (col === countColIndex) {
if (!updateunits(row)) {
updatemultiple(row);
}
}
else if (col === unitsColIndex) {
if (updatecount(row)) {
updateTotal(row);
}
}
}
});
}); |