350 lines
11 KiB
JavaScript
350 lines
11 KiB
JavaScript
var winloss = 0; // 已实现盈亏
|
||
var netFund = 0; // 初保账户
|
||
var vmFund = 0; // 追保账户
|
||
var transferOutMoney = 0; // 转出金额
|
||
const cardInputMgr = (new function () {
|
||
|
||
var _inited = 0, _inputFlag = 0;
|
||
|
||
if (page.changeBeforeConfirm) {
|
||
_inputFlag = page.IsBankOnlyDropDown ? 1 : page.OpenBankCard && !page.OpenBankId ? 4 : 3;
|
||
}
|
||
|
||
var self = this;
|
||
|
||
function __init() {
|
||
|
||
if (_inputFlag) {
|
||
let $html = $('<div>').html($('#cardInputTpl').html());
|
||
let html = $html.children(_inputFlag === 4 ? '.input' : '.select').html();
|
||
$('.card-input-wrap').html(html.trim());
|
||
}
|
||
|
||
self.updateOptions();
|
||
}
|
||
|
||
this.init = function () {
|
||
__init();
|
||
_inited = 1;
|
||
};
|
||
|
||
this.updateOptions = function () {
|
||
|
||
if (!(_inputFlag & 1)) return;
|
||
|
||
let clientId = $("#ClientId").val();
|
||
let direction = $("#Direction").val();
|
||
$('#OpenBankId').html("");
|
||
clientId && main.post("/client/GetValidBankCard", { ClientId: clientId, Direction: direction }, { waitMe: false }).done(function (resp) {
|
||
let html = resp.obj.reduce((s, cur) => {
|
||
return s += `<option value="${cur.id}" data-bank="${cur.Bank}" data-Use="${cur.Use}">${cur.Card}</option>`;
|
||
}, "");
|
||
$('#OpenBankId').html(html).val(page.OpenBankId);
|
||
$('#OpenBankUser').html("");
|
||
});
|
||
};
|
||
|
||
this.onBankIdChange = function () {
|
||
if (_inited && _inputFlag && _inputFlag < 4) {
|
||
let $s = $("#OpenBankId").find(":selected");
|
||
$("#OpenBankCard").val($s.text() || '');
|
||
$("#OpenBank").val($s.data("bank") || '');
|
||
$("#OpenBankUser").html($s.data("use") || '');
|
||
}
|
||
};
|
||
|
||
this.changeInputType = function (forceSelect) {
|
||
|
||
if (!_inited || forceSelect && _inputFlag < 4) return;
|
||
|
||
if (_inputFlag === 4) {
|
||
_inputFlag = 3;
|
||
__init();
|
||
}
|
||
else if (_inputFlag === 3) {
|
||
_inputFlag = 4;
|
||
__init();
|
||
}
|
||
};
|
||
|
||
this.toggle = function (blShow) {
|
||
$('.card-input-wrap').closest('.form-group').toggle(blShow);
|
||
};
|
||
|
||
this.checkSubmit = function () {
|
||
if ($("#Direction").val() === "出金") {
|
||
if (_inputFlag === 4) {
|
||
return $("#OpenBankCard").val() || main.message("请填写银行卡号!");
|
||
} else if (_inputFlag) {
|
||
return $("#OpenBankId").val() || main.message("请选择银行卡号!");
|
||
}
|
||
}
|
||
return true;
|
||
};
|
||
});
|
||
|
||
const moneyInputMgr = (new function () {
|
||
|
||
var _moneyEle, _moneyStrEle;
|
||
|
||
//转换成财务计数
|
||
function cc(s) {
|
||
if (/[^0-9.]/.test(s)) {
|
||
main.message("金额不能小于0");
|
||
return "";
|
||
}
|
||
s = s.replace(/^(\d*)$/, "$1.");
|
||
s = (s + "00").replace(/(\d*\.\d\d)\d*/, "$1");
|
||
s = s.replace(".", ",");
|
||
var re = /(\d)(\d{3},)/;
|
||
while (re.test(s))
|
||
s = s.replace(re, "$1,$2");
|
||
s = s.replace(/,(\d\d)$/, ".$1");
|
||
|
||
return s.replace(/^\./, "0.")
|
||
};
|
||
|
||
//转换为大写金额
|
||
function toAmountMoney(n) {
|
||
|
||
var unit = "千百拾亿千百拾万千百拾元角分", str = "";
|
||
var p = n.indexOf('.');
|
||
if (p < 0) {
|
||
n += '00';
|
||
} else {
|
||
n = _.trimStart(n.substring(0, p) + n.substr(p + 1, 2).padEnd(2, '0'), '0')
|
||
}
|
||
unit = unit.substr(unit.length - n.length);
|
||
for (var i = 0; i < n.length; i++)
|
||
str += '零壹贰叁肆伍陆柒捌玖'.charAt(n.charAt(i)) + unit.charAt(i);
|
||
return str.replace(/零(千|百|拾|角)/g, "零").replace(/(零)+/g, "零").replace(/零(万|亿|元)/g, "$1").replace(/(亿)万|壹(拾)/g, "$1$2").replace(/^元零?|零分/g, "").replace(/元$/g, "元");
|
||
}
|
||
|
||
function changeForm(s) {
|
||
let arr = s.split(",");
|
||
let newArr = toAmountMoney(arr.join(""));
|
||
$("#MoneyStr").next().html(newArr);
|
||
$("#MoneyStr").val(arr.join(""));
|
||
};
|
||
|
||
this.onInput = function () {
|
||
changeForm(_moneyEle.value = _moneyStrEle.value || '');
|
||
};
|
||
|
||
this.onChange = function () {
|
||
_moneyStrEle.value = cc(_moneyStrEle.value)
|
||
};
|
||
|
||
this.onFocus = function () {
|
||
var moneyStr = $("#MoneyStr").val().replace(/,/g, "");
|
||
$("#MoneyStr").val(moneyStr);
|
||
};
|
||
|
||
this.init = function () {
|
||
_moneyEle = document.getElementById('Money');
|
||
_moneyStrEle = document.getElementById('MoneyStr');
|
||
FastVue.numberInput(_moneyStrEle);
|
||
changeForm(_moneyEle.value);
|
||
};
|
||
});
|
||
|
||
const currencyInputMgr = (new function () {
|
||
|
||
this.updateOptions = function () {
|
||
|
||
let happenDate = $("#HappenDate").val();
|
||
|
||
main.post("/Currency/getCurrencyList?happenDate=" + happenDate).done(function (resp) {
|
||
let html = resp.obj.reduce((s, cur) => {
|
||
return s += `<option value="${cur.Value}">${cur.Text}</option>`;
|
||
}, "");
|
||
$('#CurrencyCode').html(html);
|
||
|
||
$('#CurrencyCode').val(page.currencyCode);
|
||
});
|
||
};
|
||
|
||
});
|
||
|
||
|
||
//------
|
||
function checkSubmitData() {
|
||
|
||
if (!$("#ClientId").val()) {
|
||
return main.message("请选择出入金客户!");
|
||
}
|
||
|
||
if (!$("#HappenDate").val()) {
|
||
return main.message("请设置出入金时间!");
|
||
}
|
||
|
||
if (!$("#Money").val()) {
|
||
return main.message("请设置出入金金额!");
|
||
}
|
||
else {
|
||
$("#Money").val($("#Money").val().replace(',', ''));
|
||
}
|
||
let direction = $("#Direction").val();
|
||
if (direction==="划转") {
|
||
var transfer_out_account = $("#TransferOutAccount").val();
|
||
var transfer_in_account = $("#TransferInAccount").val();
|
||
if (transfer_out_account === transfer_in_account) {
|
||
return main.message("转出科目与转入科目不能相同!");
|
||
}
|
||
var money = parseFloat($("#Money").val());
|
||
if (money <=0) {
|
||
return main.message("转出金额必须大于0!");
|
||
}
|
||
}
|
||
return cardInputMgr.checkSubmit();
|
||
}
|
||
|
||
function saveentryexit() {
|
||
if (!checkSubmitData()) return false;
|
||
//var openBankId= $("#OpenBankId").val();
|
||
//if (!openBankId) {
|
||
// $("#OpenBankCard").val("");
|
||
//}
|
||
var data = $("#entryexitEditForm").serialize();
|
||
var eventTarget = $(event.target).prop('disabled', true);
|
||
main.post("/entryexit/entryexitEditJson", data).done(function (res) {
|
||
window.location.href = "/entryexit/entryexitview?enid=" + res.obj.EncryptId;
|
||
layer.closeMe('reloadentryexit');
|
||
}).always(function () {
|
||
eventTarget.prop('disabled', false);
|
||
});
|
||
}
|
||
|
||
function setDirection(isInit) {
|
||
|
||
!isInit && cardInputMgr.changeInputType(true);
|
||
let direction = $("#Direction").val();
|
||
$(".changeInputBtn").toggleClass("hide", ["出金", "应付"].includes(direction));
|
||
if (direction === "入金") {
|
||
$("#cash_type_container").show(); // 显示资金类型
|
||
} else {
|
||
$("#cash_type_container").hide(); // 隐藏资金类型
|
||
}
|
||
if (direction === "划转") {
|
||
$("#transfer_out_container").show();
|
||
$("#transfer_in_container").show();
|
||
$("#transferAll").show();
|
||
} else {
|
||
$("#transfer_out_container").hide();
|
||
$("#transfer_in_container").hide();
|
||
$("#transferAll").hide();
|
||
}
|
||
cardInputMgr.toggle(["入金", "出金"].includes(direction));
|
||
|
||
cardInputMgr.updateOptions();
|
||
}
|
||
|
||
// 全部转出
|
||
function transferAll() {
|
||
$("#MoneyStr").val(transferOutMoney);
|
||
moneyInputMgr.onInput();
|
||
}
|
||
function setClientCash() {
|
||
var clientId = $("#ClientId").val();
|
||
if (!clientId) {
|
||
return;
|
||
}
|
||
main.post("/entryexit/GetClientCash?ClientId=" + clientId).done(function (res) {
|
||
if (res) {
|
||
$("#ClientCashCNY").val(res.CNY);
|
||
$("#ClientCashUSD").val(res.USD);
|
||
}
|
||
});
|
||
main.post("/trade_span/GetClientLatestBalance", { clientId: clientId }).done(function (data) {
|
||
winloss = numFormart(data.WinLoss);
|
||
netFund = numFormart(data.NetFund);
|
||
vmFund = numFormart(data.VmFundSum);
|
||
setTransferMoney();
|
||
});
|
||
}
|
||
function setTransferMoney() {
|
||
var clientId = $("#ClientId").val();
|
||
if (!clientId) {
|
||
return;
|
||
}
|
||
var transfer_out_account = $("#TransferOutAccount").val();
|
||
var transfer_in_account = $("#TransferInAccount").val();
|
||
if (transfer_out_account === "初保账户") {
|
||
transferOutMoney = netFund;
|
||
$("#transfer_out_account_money").text("余额:" + netFund);
|
||
}
|
||
else if (transfer_out_account === "追保账户") {
|
||
transferOutMoney = vmFund;
|
||
$("#transfer_out_account_money").text("余额:" + vmFund);
|
||
} else {
|
||
transferOutMoney = winloss;
|
||
$("#transfer_out_account_money").text("余额:" + winloss);
|
||
}
|
||
if (transfer_in_account === "初保账户") {
|
||
$("#transfer_in_account_money").text("余额:" + netFund);
|
||
}
|
||
else if (transfer_in_account === "追保账户") {
|
||
$("#transfer_in_account_money").text("余额:" + vmFund);
|
||
} else {
|
||
$("#transfer_in_account_money").text("余额:" + winloss);
|
||
}
|
||
}
|
||
function numFormart(num) {
|
||
num = num || 0;
|
||
var result = numeral(num).format("0,0.00") === "NaN" ? "0.00" : numeral(num).format("0,0.00");
|
||
if (result === "-0.00") {
|
||
result = "0.00";
|
||
}
|
||
return result;
|
||
}
|
||
$(function () {
|
||
|
||
cardInputMgr.init();
|
||
currencyInputMgr.updateOptions();
|
||
|
||
var width = 152;
|
||
for (var i = 0; i < page.clients.length; i++) {
|
||
let ele = document.createElement('span')
|
||
ele.innerText = page.clients[i].Name;
|
||
ele.style.fontSize = '14px';
|
||
document.documentElement.append(ele);
|
||
var charLength = ele.offsetWidth + 28;//滚动条
|
||
document.documentElement.removeChild(ele);
|
||
if (charLength > width) {
|
||
width = charLength
|
||
}
|
||
}
|
||
if (page.changeBeforeConfirm) {
|
||
let autoClient = FastVue.autocomplete(document.getElementById('ClientId'), {
|
||
lookup: page.clients, nameField: 'Name', valueField: 'id', searchField: ['Name', 'PinYin'], width: width,
|
||
onSelect(data) {
|
||
cardInputMgr.updateOptions();
|
||
$('#ClientName').val(data.Name);
|
||
$('#ClientId_auto').attr('title', data.Name);
|
||
setClientCash();
|
||
}
|
||
});
|
||
autoClient.setData(page.client);
|
||
setClientCash();
|
||
}
|
||
|
||
const fp = flatpickr(".form_datetime", {
|
||
enableTime: true, dateFormat: "Y-m-d H:i",
|
||
allowInput: true, time_24hr: true,
|
||
onChange: function (dateObject, dateString) {
|
||
currencyInputMgr.updateOptions();
|
||
}
|
||
});
|
||
|
||
setDirection(1);
|
||
|
||
moneyInputMgr.init();
|
||
|
||
if (!page.changeBeforeConfirm) {
|
||
if (!page.isChangeAfterConfirm) {
|
||
$("#MoneyStr").prop("disabled", true);
|
||
}
|
||
$("#HappenDate").prop("disabled", true);
|
||
}
|
||
});
|