891 lines
40 KiB
JavaScript
891 lines
40 KiB
JavaScript
(function (vc) {
|
||
var DEFAULT_PAGE = 1;
|
||
var DEFAULT_ROWS = 10;
|
||
vc.extends({
|
||
data: {
|
||
ABANeedData: {},
|
||
pollingTimerId: null,
|
||
aba_pay_status: true,
|
||
payFeeOrderInfo: {
|
||
feeId: '',
|
||
thirdPayId:'',
|
||
feeName: '',
|
||
feeTypeCdName: '',
|
||
feeTypeCd: '',
|
||
primeRates: '',
|
||
primeRate: '',
|
||
endTime: '',
|
||
feeFlag: '',
|
||
feePrice: 0.00,
|
||
tempCycles: '',
|
||
cycles: '',
|
||
paymentCycles: [],
|
||
totalFeePrice: 0.00,
|
||
receivedAmount: '',
|
||
receivedAmountNumber: '',
|
||
communityId: vc.getCurrentCommunity().communityId,
|
||
payerObjName: '',
|
||
payerObjId: '',
|
||
payerObjType: '',
|
||
remark: '',
|
||
builtUpArea: 0.0,
|
||
squarePrice: 0.0,
|
||
additionalAmount: 0.0,
|
||
receiptId: '',
|
||
showEndTime: '',
|
||
accountList: [],
|
||
integralAmount: '',
|
||
cashAmount: '',
|
||
couponAmount: '',
|
||
selectDiscount: [],
|
||
totalDiscountMoney: 0.0,
|
||
scale: 1, // 编码映射-应收款取值标识
|
||
decimalPlace: 2,
|
||
receivedAmountSwitch: '',
|
||
createTime: vc.dateTimeFormat(new Date().getTime()),
|
||
accountAmount: 0.0, // 账户金额
|
||
viewAccountAmount: 0.0, // 账户金额
|
||
deductionAmount: 0.0, //抵扣金额
|
||
redepositAmount: 0.0, //转存金额
|
||
selectUserAccount: [], // 选中的账户
|
||
authCode: '',
|
||
orderId: '',
|
||
offlinePayFeeSwitch: '1',
|
||
flag: '',
|
||
custEndTime: '',
|
||
configId: '',
|
||
roomName: '',
|
||
sign: 1,
|
||
integralQuantity: 0,
|
||
customStartTime: '',
|
||
customEndTime: '',
|
||
ABAQRCode: ""
|
||
},
|
||
isLoadData: false
|
||
},
|
||
watch: {
|
||
'payFeeOrderInfo.receivedAmount': {
|
||
deep: true,
|
||
handler: function () {
|
||
//计算折扣金额和转存金额
|
||
$that._doComputeAccountRedepositDeduction();
|
||
}
|
||
}
|
||
},
|
||
_initMethod: function () {
|
||
$that.aba_pay_status = true;
|
||
$that.payFeeOrderInfo.feeId = vc.getParam('feeId');
|
||
$that._initCustEndDate();
|
||
$that.listAndComputeFeeInfo();
|
||
},
|
||
_initEvent: function () {
|
||
// 子组件折扣change事件
|
||
vc.on('payFeeOrder', 'changeDiscountPrice', function (_param) {
|
||
// 用未格式化的总金额减优惠金额
|
||
let _totalFeePrice = $that.payFeeOrderInfo.totalFeePrice;
|
||
if (_totalFeePrice < 0) {
|
||
return;
|
||
}
|
||
let _totalDiscountMoney = _param.totalDiscountMoney;
|
||
//如果应收小区 优惠金额 则不优惠
|
||
if (_totalFeePrice < _totalDiscountMoney) {
|
||
vc.toast("实收款不能为负数!")
|
||
}
|
||
$that.payFeeOrderInfo.selectDiscount = _param.selectDiscount;
|
||
$that.payFeeOrderInfo.totalDiscountMoney = _totalDiscountMoney;
|
||
// 该处js做减法后,会出现小数点后取不尽的bug,再次处理
|
||
let receivedAmount = _totalFeePrice - _totalDiscountMoney;
|
||
$that.payFeeOrderInfo.receivedAmount = $that._getFixedNum(receivedAmount);
|
||
});
|
||
// 用户账户组件事件
|
||
vc.on('payFeeOrder', 'changeUserAmountPrice', function (_param) {
|
||
$that.payFeeOrderInfo.selectUserAccount = _param.selectAccount;
|
||
$that.payFeeOrderInfo.accountAmount = _param.totalUserAmount;
|
||
$that.payFeeOrderInfo.accountList = _param.accountList;
|
||
$that.payFeeOrderInfo.integralAmount = _param.integralAmount;
|
||
$that.payFeeOrderInfo.cashAmount = _param.cashAmount;
|
||
$that.payFeeOrderInfo.couponAmount = _param.couponAmount;
|
||
$that._doComputeAccountRedepositDeduction();
|
||
});
|
||
// 账户预缴弹窗
|
||
vc.on('payFeeOrder', 'openAddModalWithParams', function (_param) {
|
||
_param.redepositAmount = $that.payFeeOrderInfo.redepositAmount;
|
||
_param.receivedAmount = $that.payFeeOrderInfo.receivedAmount;
|
||
vc.emit('prestoreAccount2', 'openAddModalWithParams', _param)
|
||
});
|
||
vc.on('payFeeOrder', 'initData', function (_param) {
|
||
// 重新赋值下拉列表
|
||
$that.payFeeOrderInfo.paymentCycles = [];
|
||
for (let _index = 1; _index < 7; _index++) {
|
||
$that.payFeeOrderInfo.paymentCycles.push(_index * _param.paymentCycle);
|
||
}
|
||
})
|
||
},
|
||
methods: {
|
||
popOverShowMsg1: function () {
|
||
$('.popover-show1').popover('show');
|
||
},
|
||
popOverHideMsg1: function () {
|
||
$('.popover-show1').popover('hide');
|
||
},
|
||
_initCustEndDate: function () {
|
||
vc.initDate('cust-endTime', function (_value) {
|
||
$that.payFeeOrderInfo.custEndTime = _value;
|
||
let start = Date.parse(new Date($that.payFeeOrderInfo.endTime))
|
||
let end = Date.parse(new Date($that.payFeeOrderInfo.custEndTime))
|
||
if (start - end >= 0) {
|
||
vc.toast("结束时间必须大于起始时间")
|
||
$that.payFeeOrderInfo.custEndTime = '';
|
||
return;
|
||
}
|
||
$that.listAndComputeFeeInfo(103)
|
||
});
|
||
vc.initDate('customStartTime', function (_value) {
|
||
$that.payFeeOrderInfo.customStartTime = _value;
|
||
let start = Date.parse(new Date($that.payFeeOrderInfo.endTime))
|
||
let end = Date.parse(new Date($that.payFeeOrderInfo.customStartTime))
|
||
if (start - end >= 0) {
|
||
vc.toast("缴费开始时间必须大于起始时间")
|
||
$that.payFeeOrderInfo.customStartTime = '';
|
||
return;
|
||
}
|
||
if ($that.payFeeOrderInfo.customEndTime) {
|
||
$that.listAndComputeFeeInfo(105)
|
||
}
|
||
});
|
||
vc.initDate('customEndTime', function (_value) {
|
||
$that.payFeeOrderInfo.customEndTime = _value;
|
||
let start = Date.parse(new Date($that.payFeeOrderInfo.customStartTime))
|
||
let end = Date.parse(new Date($that.payFeeOrderInfo.customEndTime))
|
||
if (start - end >= 0) {
|
||
vc.toast("缴费开始时间必须大于缴费结束时间")
|
||
$that.payFeeOrderInfo.customEndTime = '';
|
||
return;
|
||
}
|
||
if ($that.payFeeOrderInfo.customStartTime) {
|
||
$that.listAndComputeFeeInfo(105)
|
||
}
|
||
})
|
||
// 查询用户账户
|
||
vc.initDateTime('payFeeOrderCreateTime', function (_value) {
|
||
$that.payFeeOrderInfo.createTime = _value;
|
||
});
|
||
//与字典表支付方式关联
|
||
vc.getDict('pay_fee_detail', "prime_rate", function (_data) {
|
||
$that.payFeeOrderInfo.primeRates = _data;
|
||
});
|
||
vc.emit('payFeeUserAccount', 'computeFeeUserAmount', {
|
||
feeId: $that.payFeeOrderInfo.feeId,
|
||
});
|
||
},
|
||
/**
|
||
* 启动定时查询 ABA 支付状态
|
||
* @param {String} trainId - 支付交易 ID
|
||
* @param {Number} duration - 查询总时长(毫秒),默认 3 分钟
|
||
* @param {Number} interval - 查询间隔(毫秒),默认 3 秒
|
||
*/
|
||
_startABAPayPolling: function (trainId, duration = 3 * 60 * 1000, interval = 3000) {
|
||
let n_stat = $that
|
||
n_stat.payFeeOrderInfo.thirdPayId = trainId;
|
||
|
||
// 页面中间消息提示
|
||
function showMessage(message, duration = 20000) {
|
||
let msgBox = document.createElement("div");
|
||
msgBox.innerText = message;
|
||
|
||
Object.assign(msgBox.style, {
|
||
position: "fixed",
|
||
top: "50%",
|
||
left: "50%",
|
||
transform: "translate(-50%, -50%)",
|
||
background: "rgba(0,0,0,0.8)",
|
||
color: "#fff",
|
||
padding: "15px 25px",
|
||
borderRadius: "10px",
|
||
fontSize: "16px",
|
||
textAlign: "center",
|
||
zIndex: 9999,
|
||
opacity: "0",
|
||
transition: "opacity 0.5s"
|
||
});
|
||
|
||
document.body.appendChild(msgBox);
|
||
|
||
setTimeout(() => {
|
||
msgBox.style.opacity = "1";
|
||
}, 50);
|
||
|
||
setTimeout(() => {
|
||
msgBox.style.opacity = "0";
|
||
setTimeout(() => {
|
||
if (msgBox && msgBox.parentNode) {
|
||
msgBox.parentNode.removeChild(msgBox);
|
||
}
|
||
}, 500);
|
||
}, duration);
|
||
}
|
||
|
||
|
||
if (!trainId) {
|
||
console.error("trainId 不能为空");
|
||
return;
|
||
}
|
||
|
||
let startTime = new Date().getTime();
|
||
|
||
// 保存定时器 id,方便后续清理
|
||
let pollingTimer = setInterval(() => {
|
||
let now = new Date().getTime();
|
||
|
||
// 超时判断
|
||
if (now - startTime > duration) {
|
||
clearInterval(pollingTimer);
|
||
console.warn("支付状态查询超时,未完成支付");
|
||
return;
|
||
}
|
||
|
||
// 请求支付状态
|
||
vc.http.apiGet(
|
||
'/acct.abaPayStatus',
|
||
{params: {trainId: trainId}},
|
||
function (json, res) {
|
||
try {
|
||
let result = JSON.parse(json);
|
||
console.log("支付状态查询结果:", result);
|
||
|
||
// 这里假设接口直接返回 bool 值 { success: true/false }
|
||
if (result === true || result.success === true) {
|
||
console.log("支付成功 ✅,停止轮询");
|
||
clearInterval(pollingTimer);
|
||
// 其他页面中调用_payFee方法
|
||
// 可以传递参数,也可以不传递
|
||
vc.emit('payFeeOrderConfirm', 'callPayFee', {});
|
||
|
||
n_stat.aba_pay_status = true
|
||
// 页面提示 20 秒
|
||
showMessage("Payment succeeded ✅ order form " + trainId + " Completed", 5000);
|
||
|
||
// 可以在这里发事件通知ABAPaySuccess
|
||
vc.emit('payFeeOrder', '', {trainId: trainId});
|
||
}
|
||
} catch (e) {
|
||
console.error("解析支付状态响应失败:", e);
|
||
}
|
||
},
|
||
function (errInfo, error) {
|
||
console.error("支付状态请求失败:", errInfo);
|
||
// 请求失败也不中断,继续下次轮询
|
||
}
|
||
);
|
||
|
||
}, interval);
|
||
$that.pollingTimerId = pollingTimer;
|
||
},
|
||
_useUserAccountChange: function (e) {
|
||
if (e.target.checked) {
|
||
// 查询用户账户
|
||
vc.emit('payFeeUserAccount', 'computeFeeUserAmount', {
|
||
feeId: $that.payFeeOrderInfo.feeId,
|
||
});
|
||
} else {
|
||
// 隐藏用户账户
|
||
vc.emit('payFeeUserAccount', 'clear', {});
|
||
}
|
||
},
|
||
payFeeValidate: function () {
|
||
return vc.validate.validate({
|
||
payFeeOrderInfo: $that.payFeeOrderInfo
|
||
}, {
|
||
'payFeeOrderInfo.feeId': [
|
||
{
|
||
limit: "required",
|
||
param: "",
|
||
errInfo: "费用ID不能为空"
|
||
}
|
||
],
|
||
'payFeeOrderInfo.cycles': [
|
||
{
|
||
limit: "required",
|
||
param: "",
|
||
errInfo: "缴费周期不能为空"
|
||
}
|
||
],
|
||
'payFeeOrderInfo.primeRate': [
|
||
{
|
||
limit: "required",
|
||
param: "",
|
||
errInfo: vc.i18n('支付方式不能为空','payFeeOrder')
|
||
}
|
||
],
|
||
'payFeeOrderInfo.receivedAmount': [
|
||
{
|
||
limit: "required",
|
||
param: "",
|
||
errInfo: "实收金额不能为空"
|
||
},
|
||
{
|
||
limit: "money",
|
||
param: "",
|
||
errInfo: "实收金额不是有效的金额"
|
||
}
|
||
]
|
||
});
|
||
},
|
||
/**
|
||
* 查询 ABA 支付状态允许的查询时长(带 queryLifetime)
|
||
* @param {String} trainId - 支付交易 ID
|
||
* @param {Function} callback - 回调函数,返回 (trainId, duration),单位毫秒
|
||
*/
|
||
_getABAPayQueryLifetime: function (trainId, callback) {
|
||
if (!trainId) {
|
||
console.error("trainId 不能为空");
|
||
return;
|
||
}
|
||
|
||
vc.http.apiGet(
|
||
'/acct.abaPayStatus',
|
||
{params: {trainId: trainId, queryLifetime: true}},
|
||
function (json, res) {
|
||
try {
|
||
let result = JSON.parse(json);
|
||
console.log("首次查询结果:", result);
|
||
|
||
if (result && result) {
|
||
let duration = parseInt(result) * 60 * 1000; // 分钟转毫秒
|
||
console.log("允许查询时长(毫秒):", duration);
|
||
console.log("允许查询时长(分钟", result);
|
||
|
||
if (callback) {
|
||
callback(trainId, duration);
|
||
}
|
||
} else {
|
||
console.warn("未返回 queryLifetime,使用默认 3 分钟");
|
||
if (callback) {
|
||
callback(trainId, 3 * 60 * 1000);
|
||
}
|
||
}
|
||
} catch (e) {
|
||
console.error("解析 queryLifetime 响应失败:", e);
|
||
if (callback) {
|
||
callback(trainId, 3 * 60 * 1000);
|
||
}
|
||
}
|
||
},
|
||
function (errInfo, error) {
|
||
console.error("请求失败:", errInfo);
|
||
if (callback) {
|
||
callback(trainId, 3 * 60 * 1000);
|
||
}
|
||
}
|
||
);
|
||
},
|
||
/**
|
||
* 点击 “提交缴费”
|
||
*/
|
||
_openPayFee: function (_type) {
|
||
|
||
clearInterval($that.pollingTimerId);
|
||
// 周期不为空且不是自定义周期
|
||
if ($that.payFeeOrderInfo.tempCycles != "" && $that.payFeeOrderInfo.tempCycles != '-102') {
|
||
$that.payFeeOrderInfo.cycles = $that.payFeeOrderInfo.tempCycles;
|
||
}
|
||
// 一次性费用
|
||
if ($that.payFeeOrderInfo.feeFlag == '2006012') {
|
||
$that.payFeeOrderInfo.cycles = '1';
|
||
$that.payFeeOrderInfo.tempCycles = '1';
|
||
}
|
||
// 新增缴费周期必选项
|
||
if ($that.payFeeOrderInfo.tempCycles == "") {
|
||
vc.toast(vc.i18n('请选择缴费周期','payFeeOrder'));
|
||
return;
|
||
}
|
||
if (!$that.payFeeValidate()) {
|
||
vc.toast(vc.validate.errInfo);
|
||
return;
|
||
}
|
||
// 缴费周期为正整数时,显示缴费结束时间
|
||
if (!(/(^[1-9]\d*$)/.test($that.payFeeOrderInfo.cycles))) {
|
||
$that.payFeeOrderInfo.showEndTime = '';
|
||
} else {
|
||
$that.payFeeOrderInfo.showEndTime = vc.addMonth(new Date($that.payFeeOrderInfo.endTime), parseInt($that.payFeeOrderInfo.cycles));
|
||
}
|
||
if ($that.payFeeOrderInfo.selectUserAccount.length > 0 &&
|
||
$that.payFeeOrderInfo.accountAmount >= $that.payFeeOrderInfo.receivedAmount) {
|
||
$that.payFeeOrderInfo.flag = "";
|
||
}
|
||
if ($that.payFeeOrderInfo.selectUserAccount.length == 1) { //现金账户
|
||
$that.payFeeOrderInfo.integralAmount = "";
|
||
} else {
|
||
$that.payFeeOrderInfo.integralAmount = "";
|
||
$that.payFeeOrderInfo.cashAmount = "";
|
||
}
|
||
$that.payFeeOrderInfo.selectUserAccount.forEach(item => {
|
||
let number = 0.0;
|
||
let number2 = 0.0;
|
||
//现金账户
|
||
if ($that.payFeeOrderInfo.receivedAmount && $that.payFeeOrderInfo.flag != 'true' && parseFloat(item.amount) > parseFloat($that.payFeeOrderInfo.receivedAmount)) {
|
||
$that.payFeeOrderInfo.cashAmount = $that.payFeeOrderInfo.receivedAmount;
|
||
} else if ($that.payFeeOrderInfo.receivedAmountNumber != null && $that.payFeeOrderInfo.receivedAmountNumber != '' && parseFloat(item.amount) > parseFloat($that.payFeeOrderInfo.receivedAmountNumber)) {
|
||
$that.payFeeOrderInfo.cashAmount = $that.payFeeOrderInfo.receivedAmountNumber;
|
||
} else {
|
||
$that.payFeeOrderInfo.cashAmount = item.amount;
|
||
}
|
||
});
|
||
$that.payFeeOrderInfo.payType = _type;
|
||
|
||
if ($that.payFeeOrderInfo.primeRate == '9' && _type == "common") {
|
||
|
||
// if ($that.isLoadData) {
|
||
//页面没有标记数据是否更改的部分
|
||
// console.log("加载原本数据")
|
||
// vc.emit('payFeeOrderConfirm', 'openConfirm', $that.payFeeOrderInfo);
|
||
//
|
||
//
|
||
// return;
|
||
// }
|
||
|
||
// 第一个请求:加载数据
|
||
$that.__loadViewFeeData(
|
||
$that.payFeeOrderInfo.communityId,
|
||
$that.payFeeOrderInfo.feeId,
|
||
function (response, error) { // 回调函数:第一个请求完成后执行
|
||
if (error) {
|
||
console.error("加载失败", error);
|
||
return; // 如果失败,不再执行后续请求
|
||
}
|
||
|
||
console.log("ABA 需要的数据:", $that.ABANeedData);
|
||
|
||
// 假设这些变量已定义
|
||
const data = [
|
||
// {name: $that.ABANeedData.ownerPhone, quantity: 1, price: 1},
|
||
// {name: $that.payFeeOrderInfo.communityId, quantity: 0, price: 0},
|
||
// {name: $that.payFeeOrderInfo.payerObjName, quantity: 0, price: 0},
|
||
// {name: $that.ABANeedData.ownerId, quantity: 0, price: 0}
|
||
];
|
||
|
||
|
||
const custom =
|
||
{
|
||
f1: $that.payFeeOrderInfo.feeId
|
||
}
|
||
;
|
||
|
||
|
||
// 先序列化为JSON字符串
|
||
const jsonStr = JSON.stringify(data);
|
||
const customStr = JSON.stringify(custom);
|
||
|
||
// 再进行Base64编码
|
||
const base64Str = btoa(unescape(encodeURIComponent(jsonStr)));
|
||
const customBase64Str = btoa(unescape(encodeURIComponent(customStr)));
|
||
|
||
console.log(base64Str);
|
||
|
||
// 构建第二个请求的参数(此时ABANeedData已准备好)
|
||
const payParams = {
|
||
amount: $that.payFeeOrderInfo.receivedAmount,
|
||
shipping: "",
|
||
itemsJson: "",
|
||
firstname: $that.ABANeedData.ownerName,
|
||
lastname: "",
|
||
email: "",
|
||
phone: $that.payFeeOrderInfo.feeId,
|
||
type: "purchase",
|
||
paymentOption: "abapay_khqr",
|
||
currency: "USD",
|
||
returnParams: $that.payFeeOrderInfo.feeId,
|
||
googlePayToken: "",
|
||
customFields: customBase64Str
|
||
};
|
||
|
||
const config = {
|
||
params: payParams // 关键:参数需要放在 params 属性中
|
||
};
|
||
|
||
// 发送第二个请求
|
||
vc.http.apiGet(
|
||
'/acct.abaPayCreate', // URL
|
||
config, // 配置对象,包含 params 属性
|
||
function (json, res) { // 成功回调
|
||
let response = JSON.parse(json);
|
||
console.log('请求成功', response);
|
||
$that.aba_pay_status = false
|
||
|
||
|
||
// 处理成功逻辑,将qrImage赋值给目标变量
|
||
$that.payFeeOrderInfo.ABAQRCode = response.qrImage;
|
||
|
||
vc.emit('payFeeOrderConfirm', 'openConfirm', $that.payFeeOrderInfo);
|
||
vc.emit('payFeeOrderConfirm', 'check', {
|
||
preCheck: true
|
||
});
|
||
|
||
// todo 启动定时查询任务
|
||
console.log(response)
|
||
console.log(response.status)
|
||
$that.isLoadData = true
|
||
|
||
console.log("isLoadData赋值为 true")
|
||
|
||
|
||
// 启动定时查询,3分钟超时
|
||
|
||
// 第一次先查 queryLifetime
|
||
$that._getABAPayQueryLifetime(response.status.tran_id, function (trainId, duration) {
|
||
// 拿到查询时长后再启动定时轮询
|
||
$that._startABAPayPolling(trainId, duration);
|
||
});
|
||
|
||
|
||
},
|
||
function (errInfo, error) { // 错误回调
|
||
console.error('请求失败:', errInfo);
|
||
// 处理错误逻辑,例如:
|
||
// vc.toast('支付请求失败,请稍后重试');
|
||
}
|
||
);
|
||
}
|
||
);
|
||
|
||
|
||
} else {
|
||
$that.payFeeOrderInfo.ABAQRCode = null;
|
||
|
||
vc.emit('payFeeOrderConfirm', 'openConfirm', $that.payFeeOrderInfo);
|
||
}
|
||
|
||
|
||
}
|
||
,
|
||
__loadViewFeeData: function (communityId, feeId, callback) {
|
||
let param = {
|
||
params: {
|
||
page: 1,
|
||
row: 1,
|
||
communityId: communityId,
|
||
feeId: feeId
|
||
}
|
||
};
|
||
|
||
vc.http.apiGet('/fee.listFee', param,
|
||
function (json, res) {
|
||
let response = JSON.parse(json);
|
||
|
||
if (response && response.fees && response.fees.length > 0) {
|
||
let fee = response.fees[0];
|
||
if (fee.feeAttrs && fee.feeAttrs.length > 0) {
|
||
|
||
$that.ABANeedData.ownerId = fee.userId;
|
||
|
||
|
||
// 提取属性
|
||
fee.feeAttrs.forEach(attr => {
|
||
if (attr.specCdName === "业主名称") { // 业主名称
|
||
$that.ABANeedData.ownerName = attr.value;
|
||
} else if (attr.specCdName === "业主联系方式") { // 业主联系方式
|
||
$that.ABANeedData.ownerPhone = attr.value;
|
||
}
|
||
});
|
||
|
||
|
||
if (!$that.ABANeedData.ownerName || !$that.ABANeedData.ownerPhone) {
|
||
|
||
fee.feeAttrs.forEach(attr => {
|
||
if (attr.specCdName === "付费对象") { // 业主名称
|
||
$that.ABANeedData.ownerName = attr.value;
|
||
$that.ABANeedData.ownerPhone = attr.feeId;
|
||
}
|
||
});
|
||
|
||
|
||
}
|
||
|
||
}
|
||
} else {
|
||
console.log('未找到有效的费用数据');
|
||
}
|
||
|
||
if (callback) callback(response);
|
||
},
|
||
function (errInfo, error) {
|
||
console.error('请求失败:', errInfo);
|
||
if (callback) callback(null, error);
|
||
}
|
||
);
|
||
}
|
||
,
|
||
|
||
|
||
/**
|
||
* 下拉 change 事件
|
||
* @param {*} _cycles
|
||
*/
|
||
_changeMonth: function (_cycles) {
|
||
$that.payFeeOrderInfo.custEndTime = '';
|
||
if ('-102' == _cycles) {
|
||
$that.payFeeOrderInfo.totalFeePrice = 0.00;
|
||
$that.payFeeOrderInfo.receivedAmount = 0.00;
|
||
if ($that.payFeeOrderInfo.cycles) {
|
||
$that.listAndComputeFeeInfo($that.payFeeOrderInfo.cycles);
|
||
}
|
||
return;
|
||
} else if ('-101' == _cycles) {
|
||
$that.payFeeOrderInfo.cycles = "101";
|
||
return;
|
||
} else if ('-103' == _cycles) {
|
||
$that.payFeeOrderInfo.cycles = "103";
|
||
return;
|
||
} else if ('-105' == _cycles) {
|
||
$that.payFeeOrderInfo.cycles = "105";
|
||
return;
|
||
}
|
||
let _newCycles = _cycles;
|
||
if (_cycles == '') {
|
||
_newCycles = $that.payFeeOrderInfo.paymentCycles[0];
|
||
}
|
||
$that.listAndComputeFeeInfo(_newCycles);
|
||
}
|
||
,
|
||
/**
|
||
* 输入 自定义 缴费周期
|
||
* @param {*} _cycles
|
||
*/
|
||
changeCycle: function (_cycles) {
|
||
if (_cycles == '') {
|
||
return;
|
||
}
|
||
$that.listAndComputeFeeInfo(_cycles);
|
||
}
|
||
,
|
||
/**
|
||
* 格式化数字
|
||
*/
|
||
_getFixedNum: function (num) {
|
||
if ($that.payFeeOrderInfo.toFixedSign == 2) {
|
||
return $that._mathToFixed1(num);
|
||
} else if ($that.payFeeOrderInfo.toFixedSign == 3) {
|
||
return $that._mathCeil(num);
|
||
} else if ($that.payFeeOrderInfo.toFixedSign == 4) {
|
||
return $that._mathFloor(num);
|
||
} else if ($that.payFeeOrderInfo.toFixedSign == 5) {
|
||
return $that._mathRound(num);
|
||
} else {
|
||
return $that._mathToFixed2(num);
|
||
}
|
||
}
|
||
,
|
||
/**
|
||
* 向上取整
|
||
*/
|
||
_mathCeil: function (_price) {
|
||
return Math.ceil(_price);
|
||
}
|
||
,
|
||
/**
|
||
* 向下取整
|
||
*/
|
||
_mathFloor: function (_price) {
|
||
return Math.floor(_price);
|
||
}
|
||
,
|
||
/**
|
||
* 四首五入取整
|
||
*/
|
||
_mathRound: function (_price) {
|
||
return Math.round(_price);
|
||
}
|
||
,
|
||
/**
|
||
* 保留小数点后一位
|
||
*/
|
||
_mathToFixed1: function (_price) {
|
||
return parseFloat(_price).toFixed(1);
|
||
}
|
||
,
|
||
/**
|
||
* 保留小数点后两位
|
||
*/
|
||
_mathToFixed2: function (_price) {
|
||
return parseFloat(_price).toFixed(2);
|
||
}
|
||
,
|
||
listAndComputeFeeInfo: function (_cycles) {
|
||
if (!vc.notNull($that.payFeeOrderInfo.feeId)) {
|
||
return;
|
||
}
|
||
if (!_cycles) {
|
||
_cycles = 1;
|
||
}
|
||
|
||
let param = {
|
||
params: {
|
||
communityId: vc.getCurrentCommunity().communityId,
|
||
feeId: $that.payFeeOrderInfo.feeId,
|
||
page: 1,
|
||
row: 1,
|
||
cycle: _cycles
|
||
}
|
||
};
|
||
if (_cycles && _cycles == 103) {
|
||
let _custEndTime = vc.dateAdd($that.payFeeOrderInfo.custEndTime);
|
||
//前端选择会默认 少一天 所以 加上一天
|
||
param.params.custEndTime = _custEndTime;
|
||
}
|
||
if (_cycles && _cycles == 105) {
|
||
let _customEndTime = vc.dateAdd($that.payFeeOrderInfo.customEndTime);
|
||
//前端选择会默认 少一天 所以 加上一天
|
||
param.params.customEndTime = _customEndTime;
|
||
param.params.customStartTime = $that.payFeeOrderInfo.customStartTime
|
||
}
|
||
//发送get请求
|
||
vc.http.apiGet('/feeApi/listFeeObj',
|
||
param,
|
||
function (json, res) {
|
||
let listRoomData = JSON.parse(json);
|
||
if (listRoomData.data.hasOwnProperty('custEndTime')) {
|
||
delete listRoomData.data.custEndTime
|
||
}
|
||
if (listRoomData.data.hasOwnProperty('customEndTime')) {
|
||
delete listRoomData.data.customEndTime
|
||
}
|
||
vc.copyObject(listRoomData.data, $that.payFeeOrderInfo);
|
||
// 由于返回的键与档期那页面自定义的键不一致,单独赋值toFiexedSign
|
||
vc.emit('payFeeOrder', 'initData', listRoomData.data);
|
||
$that.payFeeOrderInfo.totalFeePrice = listRoomData.data.feeTotalPrice;
|
||
$that.payFeeOrderInfo.receivedAmount = listRoomData.data.feeTotalPrice;
|
||
let _deadlineTime = new Date(listRoomData.data.deadlineTime);
|
||
let _maxEndTime = new Date(listRoomData.data.maxEndTime);
|
||
if (_deadlineTime.getTime() > _maxEndTime.getTime()) {
|
||
vc.toast('超过最大计费结束时间,' + vc.dateSub(listRoomData.data.maxEndTime, listRoomData.data.feeFlag) + ",请用更小缴费周期或者自定义结束时间缴费");
|
||
return;
|
||
}
|
||
vc.emit('payFeeDiscount', 'computeFeeDiscount', {
|
||
feeId: $that.payFeeOrderInfo.feeId,
|
||
cycles: _cycles,
|
||
payerObjId: $that.payFeeOrderInfo.payerObjId,
|
||
payerObjType: $that.payFeeOrderInfo.payerObjType,
|
||
endTime: $that.payFeeOrderInfo.endTime,
|
||
custEndTime: $that.payFeeOrderInfo.custEndTime
|
||
});
|
||
vc.emit('payFeeCoupon', 'computeFeeCoupon', {
|
||
feeId: $that.payFeeOrderInfo.feeId,
|
||
cycles: _cycles,
|
||
payerObjId: $that.payFeeOrderInfo.payerObjId,
|
||
payerObjType: $that.payFeeOrderInfo.payerObjType,
|
||
endTime: $that.payFeeOrderInfo.endTime
|
||
});
|
||
vc.emit('payFeeDeposit', 'computeFeeDeposit', {
|
||
payerObjId: $that.payFeeOrderInfo.payerObjId,
|
||
payerObjType: $that.payFeeOrderInfo.payerObjType,
|
||
});
|
||
$that._listFeeIntegral(_cycles);
|
||
},
|
||
function (errInfo, error) {
|
||
console.log('请求失败处理');
|
||
}
|
||
);
|
||
}
|
||
,
|
||
/**
|
||
*
|
||
* accountAmount: 0.0, // 账户金额
|
||
deductionAmount: 0.0, //抵扣金额
|
||
redepositAmount: 0.0, //转存金额
|
||
* 使用用户钱包余额
|
||
*/
|
||
computeAccountRedepositDeduction: function () {
|
||
//计算折扣金额和转存金额
|
||
$that._doComputeAccountRedepositDeduction();
|
||
}
|
||
,
|
||
/**
|
||
* 如果选择使用用户余额,则更新应缴金额
|
||
*
|
||
* accountAmount: 0.0, // 账户金额
|
||
viewAccountAmount: 0.0, // 账户金额
|
||
deductionAmount: 0.0, //抵扣金额
|
||
needDeductionAmount: false,
|
||
redepositAmount: 0.0, //转存金额
|
||
*/
|
||
_doComputeAccountRedepositDeduction: function () {
|
||
let receivedAmount = $that.payFeeOrderInfo.receivedAmount; //实缴
|
||
//计算
|
||
let accountAmount = $that.payFeeOrderInfo.accountAmount;
|
||
let deductionAmount = 0.0; // 抵消金额
|
||
$that.payFeeOrderInfo.deductionAmount = deductionAmount;
|
||
let redepositAmount = 0.0; //转存金额
|
||
$that.payFeeOrderInfo.redepositAmount = redepositAmount;
|
||
let totalDiscountMoney = $that.payFeeOrderInfo.totalDiscountMoney; // 优惠金额
|
||
let totalFeePrice = $that.payFeeOrderInfo.totalFeePrice; //应缴
|
||
//将显示账户金额实际刷成 账户金额
|
||
$that.payFeeOrderInfo.viewAccountAmount = accountAmount;
|
||
//计算转存 ,转存 = 实缴 + 折扣优惠 - 应缴
|
||
redepositAmount = parseFloat(receivedAmount) + parseFloat(totalDiscountMoney) - parseFloat(totalFeePrice);
|
||
//转存
|
||
if (parseFloat(redepositAmount) > 0) {
|
||
$that.payFeeOrderInfo.redepositAmount = redepositAmount.toFixed(2); // 计算转存
|
||
$that.payFeeOrderInfo.viewAccountAmount = parseFloat($that.payFeeOrderInfo.viewAccountAmount) + parseFloat($that.payFeeOrderInfo.redepositAmount);
|
||
return;
|
||
}
|
||
// 计算抵消金额 应缴 - 折扣 - 实缴 = 抵消金额
|
||
deductionAmount = parseFloat(totalFeePrice) - parseFloat(totalDiscountMoney) - parseFloat(receivedAmount);
|
||
if (parseFloat(deductionAmount) > 0 && parseFloat(accountAmount) >= parseFloat(deductionAmount)) {
|
||
$that.payFeeOrderInfo.deductionAmount = deductionAmount.toFixed(2);
|
||
let viewAccountAmount = $that.payFeeOrderInfo.viewAccountAmount;
|
||
$that.payFeeOrderInfo.viewAccountAmount = parseFloat($that.payFeeOrderInfo.viewAccountAmount) - parseFloat($that.payFeeOrderInfo.deductionAmount);
|
||
if (parseFloat($that.payFeeOrderInfo.viewAccountAmount) < 0) { //账户小于0
|
||
$that.payFeeOrderInfo.viewAccountAmount = 0;
|
||
$that.payFeeOrderInfo.deductionAmount = viewAccountAmount;
|
||
}
|
||
}
|
||
}
|
||
,
|
||
_viewFeeConfig: function () {
|
||
vc.emit('viewFeeConfigData', 'showData', {
|
||
configId: $that.payFeeOrderInfo.configId
|
||
})
|
||
}
|
||
,
|
||
_viewFee: function () {
|
||
vc.emit('viewFeeData', 'showData', {
|
||
feeId: $that.payFeeOrderInfo.feeId
|
||
})
|
||
}
|
||
,
|
||
_viewRoomData: function () {
|
||
vc.emit('viewRoomData', 'showData', {
|
||
roomId: $that.payFeeOrderInfo.payerObjId
|
||
})
|
||
}
|
||
,
|
||
_listFeeIntegral: function (_cycles) {
|
||
let param = {
|
||
params: {
|
||
page: DEFAULT_PAGE,
|
||
row: DEFAULT_ROWS,
|
||
feeId: $that.payFeeOrderInfo.feeId,
|
||
communityId: $that.payFeeOrderInfo.communityId,
|
||
cycles: _cycles,
|
||
endTime: $that.payFeeOrderInfo.endTime,
|
||
amount: $that.payFeeOrderInfo.receivedAmount,
|
||
area: $that.payFeeOrderInfo.builtUpArea
|
||
}
|
||
};
|
||
//发送get请求
|
||
vc.http.apiGet('/integral.computePayFeeIntegral',
|
||
param,
|
||
function (json, res) {
|
||
let _payFeeCouponInfo = JSON.parse(json);
|
||
$that.payFeeOrderInfo.integralQuantity = _payFeeCouponInfo.data;
|
||
},
|
||
function (errInfo, error) {
|
||
console.log('请求失败处理');
|
||
}
|
||
);
|
||
}
|
||
}
|
||
})
|
||
;
|
||
})(window.vc);
|