Files
zszq-trs/YLErpWeb/wwwroot/Scripts/app/swaptrade/SwapflowList.js
T
张名锐 5b7f17727d refactor(swaptrade): 优化互换交易中的数量和金额格式化功能
- 引入UnderlyingInstrumentType字段用于精确控制格式化规则
- 添加quantityPrecision配置支持不同产品类型的数量精度设置
- 实现formatAmount和formatQuantity方法提供统一格式化接口
- 更新视图模板使用新的格式化方法替代直接数据绑定
- 重构swapPricePrecisionHelper.js支持按产品类型定制格式化规则
- 移除废弃的inputFormatTradeAmount等旧格式化配置
- 添加千分位分组显示功能提升数字可读性
2026-08-06 12:41:30 +08:00

1246 lines
43 KiB
JavaScript

//window.otcformat.options.disableGrouping = true;
const inputFormatTradePrice = Object.freeze({ precision: otcformat.trading.tradeSinglePrice.precision, negative: true, append: '' });
const inputFormatSwapDeliveryPrice = Object.freeze({ precision: 9, negative: true, append: '' });
const inputFormatSwapAmount = swapPricePrecision.getCommonInputFormat('amount', { negative: true, append: '' });
const formatSwapAmount = value => swapPricePrecision.formatCommon('amount', value);
const formatSwapQuantity = function (value, options, rowObject) {
const row = rowObject || {};
const instrumentType = row.UnderlyingInstrumentType
|| row.InstrumentType
|| (row.position && row.position.UnderlyingInstrumentType)
|| '';
return swapPricePrecision.formatCommon('quantity', value, instrumentType);
};
const inputFormatMarginRate = Object.freeze({ precision: otcformat.trading.marginRateP.precision, append: '%' });
var clients = ylotc.clients;
const consUnderlyingFlag = (function () {
let unSelFlag = tradeHelper.UnderlyingSelectFlag;
return unSelFlag.UseForTrading | unSelFlag.IncludeMatured | unSelFlag.UsePinYinFilter | unSelFlag.IncludeBasket | unSelFlag.IncludeSynthetic | unSelFlag.CheckLaunch;
}());
const inputFormatDouble2 = Object.freeze({ precision: 2, append: '' });
const consClients = ylotc.clients;
let autoClient;
let progressBar;
// 流水簿记交互
function CombookingHub() {
// 创建SignalR连接并连接到服务器上的Hub
var bookconnection = new signalR.HubConnectionBuilder()
.withUrl('/swapflow/combookinghub')
.withAutomaticReconnect()
.build();
bookconnection.start()
.then(function () {
$("#combookingBtn").click(function () {
var flowIds = main.GetGridIds(jQuery('#listGrid'));
var tradeDate = $("#tradeDate").val();
var req = {
flowIds: flowIds,
tradeDate: tradeDate
}
bookconnection.invoke('StartProcessing', JSON.stringify(req))
layer.open({
type: 1,
area: ['400px', '120px'],
content: $('#combookingMsg'),
});
});
}).catch(function (error) {
console.error(error);
});;
// 监听服务器发送的消息。
bookconnection.on('ReceiveMessage', function (msg) {
$('#msg').text(msg);
});
// 监听服务器发送的消息。
bookconnection.on('WarnMessage', function (msg) {
main.message(msg);
});
// 监听服务器发送的异常消息。
bookconnection.on('ExceptionMessage', function (msg) {
$('#msg').text(msg);
getList();
});//main.message("sdf")
// 监听服务器发送的完成消息。
bookconnection.on('ProcessCompleted', function (msg) {
$('#msg').text(msg);
getList();
});
// 监听连接关闭,启动重连
bookconnection.onclose(async (error) => {
console.log("连接断开");
// 等待3秒后尝试重新连接
setTimeout(async () => {
try {
await bookconnection.start();
console.log("已重新连接");
} catch (err) {
console.error("重新连接失败: ", err);
}
}, 3000); // 3秒
});
}
// 流水重置交互
function ResetHub() {
// 创建SignalR连接并连接到服务器上的Hub
var connection = new signalR.HubConnectionBuilder()
.withUrl('/swapflow/resethub')
.withAutomaticReconnect()
.build();
connection.start()
.then(function () {
$("#resetBtn").click(function () {
var tradeDate = $("#tradeDate").val();
var req = {
clientId: $("#SearchClientId").val(),
tradeDate: tradeDate,
underlyingCode: $("#UnderlyingCode").val()
}
req.underlyingCode = req.underlyingCode == "---" ? null : req.underlyingCode;
let client = req.clientId ? consClients.find(x => x.id == req.clientId) : null;
var str = "</br>清算日期:" + tradeDate + "</br>客户名称:" + (client == null ? "不限" : client.Name) + "</br>标的代码:" + (req.underlyingCode == null || req.underlyingCode =="" ? "不限" : req.underlyingCode);
main.confirm("此操作将重新合成当前清算日期簿记,是否继续?" + str, function () {
connection.invoke('StartProcessing', JSON.stringify(req))
showProgressBar();
});
});
}).catch(function (error) {
console.error(error);
});;
// 监听服务器发送的消息。
connection.on('UpdateProgress', function (msg) {
$('.layui-progress-bar').css('width', msg + '%');
$('.layui-progress-text').text(msg + '%');
});
// 监听服务器发送的异常消息。
connection.on('ExceptionMessage', function (msg) {
layer.close(progressBar);
main.alert(msg);
getList();
});
// 监听服务器发送的完成消息。
connection.on('ProcessCompleted', function () {
layer.close(progressBar);
getList();
});
// 监听连接关闭,启动重连
connection.onclose(async (error) => {
console.log("连接断开");
// 等待3秒后尝试重新连接
setTimeout(async () => {
try {
await connection.start();
console.log("已重新连接");
} catch (err) {
console.error("重新连接失败: ", err);
}
}, 3000); // 3秒
});
}
//标的选择组件
const vueUnderlying = function () {
return {
props: ['value', 'index'],
data() {
return { autoUnderlying: null };
},
mounted() {
var selFlag = tradeHelper.UnderlyingSelectFlag;
autoUnderlying = tradeHelper.UnderlyingAutoComplete(this.$el, { SelectFlag: selFlag.UsePinYinFilter | selFlag.UseForTrading | selFlag.IncludeSynthetic | selFlag.IncludeMatured | selFlag.IncludeBasket | selFlag.CheckLaunch, BlackLimit: 2, });
autoUnderlying.onSelect(this.onchange);
this.value && autoUnderlying.selectByCode(this.value);
},
methods: {
onchange(data) {
data.index = this.index;
if (this.value !== data.Code) {
this.$emit('change', data);
this.$emit('input', data.Code);
}
}
},
destroyed() {
autoUnderlying && autoUnderlying.dispose();
},
template: '<input type="text" v-model="value" />'
};
};
var PostData = {};
$(function () {
$(".datepicker").change(function () {
var dateVal = $(this).val();
if (!dateVal) return;
dateVal = dateVal.replace(/\D/g, '').padStart(4, '0');
switch (dateVal.length) {
case 4:
dateVal = new Date().getFullYear() + dateVal; break;
case 6:
dateVal = '20' + dateVal; break;
case 8: break;
default:
dateVal = dateVal.length > 8 ? dateVal.substring(0, 8) : ''; break;
}
if (dateVal) {
dateVal = moment(dateVal).format('YYYY-MM-DD');
!/^\d+/.test(dateVal) && (dateVal = '');
}
$(this).datepicker("setDate", dateVal);
});
function keyEnter(event) {
try {
var e = event ? event : (window.event ? window.event : null);
if (e.keyCode === 13) {
getList(true);
}
} catch (e) {
//
}
}
document.onkeydown = keyEnter;
let underlyingCtrl = new tradeHelper.UnderlyingSelectCtrl('#UnderlyingCode', { UseCodeAsId: true }).setFlag(tradeHelper.UnderlyingSelectFlag.OtcTrade);
let autoClientNumber_0 = FastVue.autocomplete(document.getElementById('SearchClientId'), {
nameField: 'Name', valueField: 'id', searchField: ['Number', 'Name'], lookup: clients
});
CombookingHub();
ResetHub();
});
function getColModelGridStep1() {
var col = [
{
name: 'id',
hidden: true,
optionHide: true
},
{
name: 'OccurTime',
hidden: true,
optionHide: true
}, {
name: '',
label: '操作',
align: 'center',
width: 140,
formatter: showToolName
}, {
name: 'OptTime',
label: '交易时间',
width: 160,
align: 'center',
formatter: 'datetime'
}, {
name: 'SettleDate',
label: '清算日期',
width: 160,
align: 'center',
formatter: 'date'
}, {
name: 'FundAccount',
label: '资金账号',
width: 160,
align: 'center',
hidden: true,
}
, {
name: 'SwapTradeNo',
label: '互换交易编号',
width: 160,
align: 'center',
hidden: true,
}, {
name: 'ClientName',
label: '交易对手方',
width: 90,
align: 'center'
}, {
name: 'BsType',
label: '买卖方向',
width: 70,
align: 'center',
formatter: function (cellValue, options, rowObject) {
if (cellValue == 1) {
return "买入";
} else if (cellValue == 2) {
return "卖出";
}
return "";
}
}, {
name: 'UnderlyingCode',
label: '标的代码',
width: 150,
align: 'center'
}, {
name: 'TradingQty',
label: '成交数量/张数',
width: 160,
align: 'center',
formatter: formatSwapQuantity
}, {
name: 'TradingAmount',
label: '成交金额(元)',
width: 210,
align: 'center',
formatter: formatSwapAmount
}, {
name: 'TradingFee',
label: '交易费用',
width: 90,
align: 'center',
formatter: formatSwapAmount
}, {
name: 'TradingAmountAvg',
label: '成交全价',
width: 210,
align: 'center',
formatter: otcformat.trading.umprice
}, {
name: 'TradingAmountFeeAvg',
label: '成交全价(含费)',
width: 90,
align: 'center',
formatter: otcformat.trading.umprice
}, {
name: 'ytm',
label: '成交收益率',
width: 90,
align: 'center',
formatter: otcformat.trading.marginRateP
}, {
name: 'TradingAmountNet',
label: '成交净价',
width: 90,
align: 'center',
formatter: otcformat.trading.umprice
}, {
name: 'TradingAmountNetFee',
label: '成交净价(含费)',
width: 90,
align: 'center',
formatter: otcformat.trading.umprice
}, {
name: 'ContractSize',
label: '乘数',
width: 90,
align: 'center',
formatter: otcformat.trading.notional
}, {
name: 'limit_alert_remark',
label: '预警通过说明',
width: 190,
align: 'center',
}
];
return col;
}
function getColModelGridStep2() {
var col = [
{
name: 'id',
hidden: true,
optionHide: true
}, {
name: 'OccurTime',
label: '交易时间',
width: 90,
align: 'center',
formatter: 'date'
}, {
name: 'FundAccount',
label: '资金账号',
width: 160,
align: 'center'
}
, {
name: 'SwapTradeNo',
label: '互换交易编号',
width: 160,
align: 'center'
}, {
name: 'BsType',
label: '买卖方向',
width: 70,
align: 'center',
formatter: function (cellValue, options, rowObject) {
if (cellValue == 1) {
return "买入";
} else if (cellValue == 2) {
return "卖出";
}
return "";
}
}, {
name: 'UnderlyingCode',
label: '标的代码',
width: 150,
align: 'center'
}, {
name: 'TradingQty',
label: '成交数量/张数',
width: 90,
align: 'center',
formatter: formatSwapQuantity
}, {
name: 'TradingAmount',
label: '成交金额(元)',
width: 90,
align: 'center',
formatter: formatSwapAmount
}, {
name: 'TradingAmountAvg',
label: '成交均价',
width: 90,
align: 'center',
formatter: otcformat.trading.umprice
}
, {
name: 'TradingFee',
label: '交易费用',
width: 90,
align: 'center',
formatter: formatSwapAmount
}, {
name: 'TradingAmountFeeAvg',
label: '含费均价',
width: 90,
align: 'center',
formatter: otcformat.trading.umprice
}, {
name: 'ContractSize',
label: '乘数',
width: 90,
align: 'center',
formatter: otcformat.trading.notional
}, {
name: '',
label: '操作',
align: 'center',
width: 140,
formatter: showToolName2
}
];
return col;
}
function getColModelGridStep3() {
var col = [
{
name: 'id',
hidden: true,
optionHide: true
}, {
name: 'EventDate',
label: '事件日期',
align: 'center',
width: 90,
formatter: 'date'
}, {
name: 'UnwindDate',
label: '开仓/平仓日期',
align: 'center',
width: 90,
formatter: 'date'
}, {
name: 'SwapTradeNo',
label: '互换交易编号',
width: 150,
align: 'center'
}, {
name: 'SwapPositionIdPadding',
label: '持仓编码',
align: 'center'
}, {
name: 'EventType',
label: '事件类型',
align: 'center',
formatter: function (cellValue, options, rowObject) {
if (cellValue == 1) {
return "开仓";
} else if (cellValue == 2) {
return "平仓";
}
return "";
}
}, {
name: 'EventReason',
label: '事件原因',
align: 'center'
}, {
name: 'PayDirection',
label: '收支方向',
align: 'center',
formatter: function (cellValue, options, rowObject) {
if (cellValue == 1) {
return "收取";
} else if (cellValue == 2) {
return "支付";
}
return "";
}
}, {
name: 'PositionType',
label: '标的多空',
align: 'center',
formatter: function (cellValue, options, rowObject) {
if (cellValue == 1) {
return "多";
} else if (cellValue == 2) {
return "空";
}
return "";
}
}, {
name: 'UnderlyingCode',
label: '标的代码',
width: 150,
align: 'center'
}, {
name: 'MatuirityDate',
label: '到期日',
width: 90,
align: 'center',
formatter: 'date'
}, {
name: 'TradingAmountAvg',
label: '成交全价',
width: 90,
align: 'center',
formatter: otcformat.trading.umprice
}, {
name: 'TradingAmountFeeAvg',
label: '成交全价(含费)',
width: 90,
align: 'center',
formatter: otcformat.trading.umprice
}, {
name: 'TradingAmountNetAvg',
label: '成交净价',
width: 90,
align: 'center',
formatter: otcformat.trading.umprice
}, {
name: 'TradingAmountNetFeeAvg',
label: '成交净价(含费)',
width: 90,
align: 'center',
formatter: otcformat.trading.umprice
}, {
name: 'Quantity',
label: '成交数量/张数',
width: 160,
align: 'center',
formatter: formatSwapQuantity
}, {
name: 'TradingAmount',
label: '成交金额(元)',
width: 160,
align: 'center',
formatter: formatSwapAmount
}, {
name: 'ContractSize',
label: '乘数',
width: 90,
align: 'center',
formatter: otcformat.trading.notional
}
, {
name: 'TradingFee',
label: '交易费用佣金',
width: 160,
align: 'center',
formatter: formatSwapAmount
}, {
name: 'TradingFeePending',
label: '待结算交易费用佣金',
width: 160,
align: 'center',
formatter: formatSwapAmount
}, {
name: 'DividendPending',
label: '待结算分红收益',
width: 160,
align: 'center',
formatter: formatSwapAmount
}, {
name: 'MarkClosePnl',
label: '浮动端平仓盈亏·浮动',
width: 160,
align: 'center',
formatter: formatSwapAmount
}, {
name: 'DividendIn',
label: '浮动端平仓盈亏·分红',
width: 160,
align: 'center',
formatter: formatSwapAmount
}
];
return col;
}
function getColModelGridStep4() {
var col = [
{
name: 'position.id',
hidden: true,
optionHide: true
}, {
name: 'TradeDate',
label: '交易日期',
width: 90,
align: 'center',
formatter: 'date'
}
, {
name: 'ClientName',
label: '对手方',
width: 150,
align: 'center'
}, {
name: 'SwapTradeNo',
label: '互换交易编码',
width: 150,
align: 'center'
}, {
name: 'position.PositionIdPadding',
label: '持仓编码',
align: 'center'
}, {
name: 'StructureType',
label: '互换类型',
align: 'center'
}, {
name: 'position.PosiDirection',
label: '收支方向',
align: 'center',
formatter: function (cellValue, options, rowObject) {
if (cellValue == 1) {
return "收取";
} else if (cellValue == 2) {
return "支付";
}
return "";
}
}, {
name: 'position.PositionType',
label: '标的多空',
align: 'center',
formatter: function (cellValue, options, rowObject) {
if (cellValue == 1) {
return "多";
} else if (cellValue == 2) {
return "空";
}
return "";
}
}, {
name: 'position.UnderlyingCode',
label: '标的代码',
width: 90,
align: 'center'
}, {
name: 'position.ContractSize',
label: '乘数',
width: 90,
align: 'center',
formatter: otcformat.trading.notional
}, {
name: 'position.PosiNetPrice',
label: '期初价格',
width: 160,
align: 'center',
formatter: otcformat.trading.umprice
}, {
name: 'position.PosiGrossPrice',
label: '期初价格不含费',
width: 160,
align: 'center',
formatter: otcformat.trading.umprice
}, {
name: 'position.PosiNetNoFeePrice',
label: '成交净价不含费',
width: 160,
align: 'center',
formatter: otcformat.trading.umprice
}, {
name: 'position.PosiNetFeePrice',
label: '成交净价含费',
width: 160,
align: 'center',
formatter: otcformat.trading.umprice
}, {
name: 'position.PosiQuantity',
label: '名义数量',
width: 160,
align: 'center',
formatter: formatSwapQuantity
}, {
name: 'position.PosiNotionalValue',
label: '名义本金',
width: 160,
align: 'center',
formatter: formatSwapAmount
}
, {
name: 'position.PosiTradingFee',
label: '交易费用佣金',
width: 160,
align: 'center',
formatter: formatSwapAmount
}, {
name: 'position.PosiTradingFeePending',
label: '待实现交易费用佣金',
width: 160,
align: 'center',
formatter: formatSwapAmount
}, {
name: 'position.PosiStartDate',
label: '起始日期',
width: 90,
align: 'center',
formatter: 'date'
}, {
name: 'position.PosiMatuirityDate',
label: '到期日',
width: 90,
align: 'center',
formatter: 'date'
}
];
return col;
}
function intiGrid(step) {
if (vue) {
vue.setStep(step);
}
var multiselect = false;
var colModelGrid = getColModelGridStep1();
if (step == 2) {
colModelGrid = getColModelGridStep2();
multiselect = false;
}
else if (step == 3) {
colModelGrid = getColModelGridStep3();
multiselect = false;
}
else if (step == 4) {
colModelGrid = getColModelGridStep4();
multiselect = false;
}
PostData.Step = step;
PostData.TradeDate = $("#tradeDate").val();
$("#listGrid").GridUnload();
grid = jQuery('#listGrid').jqGrid({
cmTemplate: {
width: 120,
align: 'center',
sortable: false
},
url: "/swapTrade2/SwapflowQuery",
datatype: 'json',
multiselect: multiselect,
shrinkToFit: false,
autoScroll: true,
height: 'auto',
width: '96%',
autowidth: false,
shrinkToFit: false,
viewrecords: true,
jsonReader: { repeatitems: false },
caption: '',
mtype: 'POST',
postData: PostData,
colModel: colModelGrid,
pager: jQuery('#pagerGrid'),
pagerpos: 'left',
rowNum: 20,
rowList: [20, 30, 50, 200, 10000],
footerrow: false,
loadComplete: gridComplete,
onPaging: onJqgridPaging,
}).trigger("reloadGrid");
if (step == 3) {
$("#listGrid").jqGrid('setGroupHeaders', {
useColSpanStyle: true, // 没有表头的列是否与表头列位置的空单元格合并
groupHeaders: [{
startColumnName: "PayDirection", //开始列
numberOfColumns: 15, //合并几列
titleText: "浮动收益",//合并后父列名
}
//, {
//startColumnName: "swap_Position.Direction", //开始列
//numberOfColumns: 4, //合并几列
//titleText: "利息收益",//合并后父列名
//}
]
});
}
else if (step == 4) {
$("#listGrid").jqGrid('setGroupHeaders', {
useColSpanStyle: true, // 没有表头的列是否与表头列位置的空单元格合并
groupHeaders: [{
startColumnName: "position.PosiDirection", //开始列
numberOfColumns: 14, //合并几列
titleText: "浮动收益",//合并后父列名
}]
});
}
}
function showToolName(cellValue, options, rowObject) {
var html = "";
var canEdit = page.canEdit == true ? "" : "disabled";
var canDelete = page.canDelete == true ? "" : "disabled";
html =
"<input type=\"button\" class=\"wentiEdit\" title='修改' onclick=\"vue.editSwapflow('{0}',1)\" value=\"修改\" {1}/>"
.template(rowObject.EncryptId, canEdit);
html = html + "<input type=\"button\" class=\"wentiEdit\" title='删除' onclick=\"vue.deleteSwapflow('{0}',1)\" value=\"删除\" {1}/>"
.template(rowObject.EncryptId, canDelete);
return html;
}
function showToolName2(cellValue, options, rowObject) {
var html = "";
var canEdit = page.canEdit == true ? "" : "disabled";
var canDelete = page.canDelete == true ? "" : "disabled";
html =
"<input type=\"button\" class=\"wentiEdit\" title='修改' onclick=\"vue.editSwapflow('{0}',2)\" value=\"修改\" {1}/>"
.template(rowObject.EncryptId, canEdit);
html = html + "<input type=\"button\" class=\"wentiEdit\" title='删除' onclick=\"vue.deleteSwapflow('{0}',2)\" value=\"删除\" {1}/>"
.template(rowObject.EncryptId, canDelete);
return html;
}
function gridComplete() {
$(window).off('resize.jqGrid');
$(window).on('resize.jqGrid', function () {
$("#listGrid").jqGrid('setGridWidth', $('#tableContent').width() - 2);
});
$("#listGrid").jqGrid('setGridWidth', $('#tableContent').width() - 2);
$("#gbox_listGrid").css("margin-left","0");
}
function getList(isSearchclick) {
var listGrid = $('#listGrid');
listGrid.appendPostData({ TradeDateStart: $("#DateFromTradeDate").val() });
listGrid.appendPostData({ TradeDateEnd: $("#DateToTradeDate").val() });
listGrid.appendPostData({ TradeNumber: $("#TradeNumber").val() });
listGrid.appendPostData({ FundAccount: $("#FundAccount").val() });
var underlyingCode = $("#UnderlyingCode").val();
underlyingCode = underlyingCode == "---" ? null : underlyingCode;
listGrid.appendPostData({ UnderlyingCode: underlyingCode });
listGrid.appendPostData({ ClientId: $("#SearchClientId").val() });
listGrid.appendPostData({ TradeDate: $("#tradeDate").val() });
if (typeof isSearchclick !== "undefined" && isSearchclick) {
//点击搜索时默认第一页
listGrid.jqGrid('setGridParam',
{
page: 1
});
}
listGrid.trigger('reloadGrid');
}
function showProgressBar() {
$('.layui-progress-bar').css('width', '0%');
$('.layui-progress-text').text('0%');
// 创建进度条弹窗
progressBar = layer.open({
type: 1,
title: false,
closeBtn: 0,
btn: false,
area: ['400px', '100px'],
content: $('#progressBar'),
});
}
function refreshData() {
main.post("/swaptrade2/GenerateSwapTradeFromDb?tradeDate=" + $("#tradeDate").val() + "&reset=true").done(function (resp) {
intiGrid(vue.step)
});
}
function gotoLastStep() {
vue.setStep(4);
$("#steps").step("goto", vue.step);
intiGrid(vue.step)
}
var _reloadData = "";
var vue = new Vue({
el: "#flowBook",
data: {
swapflow: {
id: 0,
OccurTime: "",
FundAccount: "",
SwapTradeNo: "",
BsType: 1,
UnderlyingCode: "",
UnderlyingInstrumentType: "",
TradingQty: 0,
TradingAmount: 0,
TradingFee: 0,
TradingAmountAvg: 0,
TradingAmountFeeAvg: 0,
ContractSize: 0,
ClientId: null,
ytm: 0,
TradingAmountNet: 0,
ClientName: "",
UnderlyingName: "",
TradingAmountNetFee:0,
},
step: 1,
tradeDate: "",
UnderlyingCode: "",
ClientId: null,
isAddOrEditFRData: false,
isShowWarning: true,
isFromArtifical: false,
FRData: {
oldValue: null,
value: "",
id: "",
date: ""
},
},
mounted: function () {
autoClient = FastVue.autocomplete(document.getElementById('ClientId'), {
nameField: 'Name', valueField: 'id', searchField: ['Name', 'PinYin'],
lookup: consClients, onSelect: function (rep) {
vue.changeClient(rep);
}
});
this.getCurrentDate();
this.initStep(this.step);
//intiGrid(this.step)
this.refreshTradeFlow(false);
this.FRData.date = this.getToday()
this.getFRData();
},
computed: {
maxTradeDate() {
var now = this.getCurrentDate();
return now;
},
frTips() {
return `${this.FRData.date}无FR007,请补充。`;
}
},
methods: {
initStep(index) {
$("#steps").step({
stepNames: ['①成交流水导入', '②成交流水汇总', '③开平仓流水事件', '④合成持仓'],
initStep: index,
isClick: true,
clickFunc: intiGrid
})
},
refreshTradeFlow(reset) {
var thisObj = this;
main.post("/swaptrade2/GenerateSwapTradeFromDb?tradeDate=" + $("#tradeDate").val() + "&reset=" + reset).done(function (resp) {
intiGrid(thisObj.step)
});
},
getToday() {
const today = new Date();
const year = today.getFullYear();
const month = today.getMonth() + 1; // getMonth() 返回的月份是从 0 开始的
const day = today.getDate();
// 如果需要格式化为 YYYY-MM-DD 字符串
const formattedToday = `${year}-${month.toString().padStart(2, '0')}-${day.toString().padStart(2, '0')}`;
return formattedToday
},
getFRData() {
const thisObj = this;
main.post(`/swapTrade2/SearchTodayWhetherFRData?dateTime=${this.FRData.date}`).done(function (resp) {
if (resp.UnderlyingCode) { // 如果这天有fr007获取值和id,隐藏警告
thisObj.FRData.value = (resp.ReferencePrice * 100).toFixed(swapPricePrecision.getCommonPrecision('rate'));
thisObj.FRData.oldValue = (resp.ReferencePrice * 100).toFixed(swapPricePrecision.getCommonPrecision('rate'));
thisObj.FRData.id = resp.id;
thisObj.isShowWarning = false
thisObj.isFromArtifical = resp.DataSource === "人工"
} else {
thisObj.FRData.value = "";
thisObj.FRData.id = "";
thisObj.isShowWarning = true;
thisObj.isFromArtifical = true;// 如果没有fr007,fr007来源默认设置为人工,用于新增
}
});
},
editFRData() {
this.isAddOrEditFRData = true
this.isShowWarning = false
},
cancelEditFRData() {
this.FRData.value = "";
this.isAddOrEditFRData = false
const today = this.getToday();
if (this.FRData.date !== today) {
this.isShowWarning = true;
} else {
this.isShowWarning = false
}
},
commitFRData() {
if (this.FRData.value) {
const value = Number(this.FRData.value)
if (!Number.isNaN(value)) {
// 用字符串四舍五入
const price = main.toNumber(value / 100, 6);
// 新增时不传id
const url = this.FRData.date ? `/swapTrade2/AddOrUpdateFRData?dateTime=${this.FRData.date}&price=${price}` : `/swapTrade2/AddOrUpdateFRData?price=${price}`
const thisObj = this;
main.post(url).done(function (resp) {
if (resp) {
thisObj.isAddOrEditFRData = false
thisObj.getFRData()
}
});
}
} else if (this.isShowWarning) { // 当日无fr007不做改动
this.isAddOrEditFRData = false
this.getFRData()
} else if (this.FRData.id) { // 当日有fr007删除fr007
const thisObj = this;
main.post(`/swapTrade2/DeleteFRData?id=${thisObj.FRData.id}`).done(function (resp) {
if (resp) {
thisObj.isAddOrEditFRData = false
thisObj.getFRData()
}
});
} else {
this.isAddOrEditFRData = false
this.isShowWarning = true;
}
},
deleteFRData() {
if (this.FRData.id) {
this.FRData.value = this.FRData.oldValue
this.isAddOrEditFRData = false
} else {
this.cancelEditFRData()
}
},
setStep(st) {
this.step = st;
},
getCurrentDate() {
this.tradeDate = page.valueDate; //将1970/08/08转化成1970-08-08
return this.tradeDate;
},
getQuantityInputFormat() {
return swapPricePrecision.getCommonInputFormat(
'quantity',
{ append: '' },
this.swapflow.UnderlyingInstrumentType);
},
addNew() {
this.tradeDate = page.valueDate;
this.initSwapFlow();
autoClient.setData(null);
$("#flowAssetBookModal").modal('show');
},
initSwapFlow() {
this.swapflow = {
id: 0,
TaskId: 1,
OccurTime: this.tradeDate,
FundAccount: "",
SwapTradeNo: "",
BsType: 1,
UnderlyingCode: "",
UnderlyingInstrumentType: "",
TradingQty: 0,
TradingAmount: 0,
TradingFee: 0,
TradingAmountAvg: 0,
TradingAmountFeeAvg: 0,
ContractSize: 0,
ClientId: null,
ytm: 0,
TradingAmountNet: 0,
ClientName: "",
UnderlyingName: "",
TradingAmountNetFee: 0,
SettleDate: page.afterDate,
};
autoClient.setData(null);
},
showImportSwapflow() {
layer.open({
type: 1,
area: ['60%', '60%'],
fixed: false, //不固定
maxmin: true,
content: $("#importSwapFlow"),
end: function () {
getList();
}
});
},
//导入
importSwapflow() {
let fileName = $("#openFile").val();
if (!fileName) {
return main.alert("请选择要导入的文件!");
}
let index = fileName.lastIndexOf(".");
let fileEx = index > 0 ? fileName.substr(index).toLowerCase() : '';
if (fileEx !== '.xlsx') {
return main.alert("只能上传.xlsx类型的文件!");
}
function success(data) {
if (data.success) {
_reloadData = 'reloadData';
main.alert(!data.totalNum ? '导入成功!' : "共 {0} 条数据,导入成功 {1} 条数据!".template(data.totalNum, data.successNum));
} else {
main.alert("导入失败:" + data.msg);
}
}
var url = "/swapTrade2/ImportSwapflow";//区分导入,了结导入
main.confirm("确定导入?", UploadFile.bind(null, { inputId: 'openFile', url: url, success: success }));
},
//汇总
summaryStep(skip) {
var thisObj = this;
if (skip != true) {
main.confirm("确定汇总?", function () {
main.post("/swaptrade2/SwapFlowMerge?tradeDate=" + $("#tradeDate").val()).done(function (resp) {
thisObj.step = thisObj.step + 1;
$("#steps").step("next");
intiGrid(thisObj.step)
});
});
}
},
unwindStep() {
var thisObj = this;
main.confirm("确定执行开平仓事件?", function () {
main.post("/swaptrade2/SwapFlowEvent?tradeDate=" + $("#tradeDate").val()).done(function (resp) {
thisObj.step = thisObj.step + 1;
$("#steps").step("next");
intiGrid(thisObj.step)
});
});
},
composeUnwindStep() {
var thisObj = this;
main.confirm("确定合成持仓?", function () {
main.post("/swaptrade2/SwapFlowEventCompose?tradeDate=" + $("#tradeDate").val()).done(function (resp) {
thisObj.step = thisObj.step + 1;
$("#steps").step("next");
intiGrid(thisObj.step)
});
});
},
editSwapflow(id, st) {
this.initSwapFlow();
var thisObj = this;
main.post("/swaptrade2/GetSwapflow?enid=" + id + "&step=" + st).done(function (resp) {
var item = resp;
thisObj.swapflow.id = item.id;
thisObj.swapflow.TaskId = item.TaskId;
thisObj.swapflow.OccurTime = moment(item.OccurTime).format('YYYY-MM-DD');
thisObj.swapflow.FundAccount = item.FundAccount;
thisObj.swapflow.SwapTradeId = item.SwapTradeId;
thisObj.swapflow.SwapTradeNo = item.SwapTradeNo;
thisObj.swapflow.BsType = item.BsType;
thisObj.swapflow.UnderlyingCode = item.UnderlyingCode;
thisObj.swapflow.UnderlyingInstrumentType = item.UnderlyingInstrumentType || item.InstrumentType || "";
thisObj.swapflow.TradingQty = item.TradingQty;
thisObj.swapflow.TradingAmount = item.TradingAmount;
thisObj.swapflow.TradingFee = item.TradingFee;
thisObj.swapflow.ContractSize = item.ContractSize;
thisObj.swapflow.TradingAmountAvg = item.TradingAmountAvg;
thisObj.swapflow.TradingAmountFeeAvg = item.TradingAmountFeeAvg;
thisObj.swapflow.ClientId = item.ClientId;
thisObj.swapflow.ytm = item.ytm;
thisObj.swapflow.TradingAmountNet = item.TradingAmountNet;
thisObj.swapflow.ClientName = item.ClientName;
thisObj.swapflow.UnderlyingName = item.UnderlyingName;
thisObj.swapflow.TradingAmountNetFee = item.TradingAmountNetFee;
if (item.SettleDate) {
thisObj.swapflow.SettleDate = moment(item.SettleDate).format('YYYY-MM-DD');
}
let clientId = item.ClientId;
let client = clientId ? consClients.find(x => x.id === clientId) : null;
if (client != null) {
autoClient.setData(client);
}
$("#flowAssetBookModal").modal('show');
}).fail(function () {
});
},
setUnderlyingCode(data) {
this.swapflow.ContractSize = data.ContractSize;
this.swapflow.UnderlyingName = data.Name;
this.swapflow.UnderlyingInstrumentType = data.InstrumentType || data.UnderlyingInstrumentType || "";
},
changeClient: function (client) {
this.swapflow.ClientId = client.id;
this.swapflow.ClientName = client.Name;
},
//变更标的单价
changeSpotPrice() {
this.swapflow.TradingAmount = main.toNumber(this.swapflow.TradingAmountAvg * this.swapflow.TradingQty * this.swapflow.ContractSize, 2);
},
deleteSwapflow(id, st) {
main.confirm("确定要删除吗?", function () {
main.post("/swaptrade2/DeleteSwapflow?enid=" + id + "&step=" + st).done(function (resp) {
getList();
})
});
},
saveSwapflow() {
var thisObj = this;
if (thisObj.swapflow.OccurTime == "" || thisObj.swapflow.OccurTime == null) {
return main.alert("请选择交易时间");
}
//if (thisObj.swapflow.FundAccount == "" || thisObj.swapflow.FundAccount == null) {
// return main.alert("请填写资金账号");
//}
if (thisObj.swapflow.ClientId ==0 || thisObj.swapflow.ClientId == null) {
return main.alert("请选择交易对手方");
}
if (thisObj.swapflow.UnderlyingCode == "" || thisObj.swapflow.UnderlyingCode == null) {
return main.alert("请选择标的");
}
if (thisObj.swapflow.TradingQty == "" || thisObj.swapflow.TradingQty == null || thisObj.swapflow.TradingQty <= 0) {
return main.alert("成交数量必须大于0");
}
if (thisObj.swapflow.SettleDate == "" || thisObj.swapflow.SettleDate == null) {
return main.alert("请选择清算日期");
}
if (thisObj.swapflow.SettleDate < thisObj.swapflow.OccurTime) {
return main.alert("清算日期不能小于交易时间");
}
thisObj.postSwapflow();
},
postSwapflow() {
var thisObj = this;
thisObj.swapflow.TradingAmountAvg = _.round(Number(thisObj.swapflow.TradingAmountAvg), 9);
main.post("/swaptrade2/SaveSwapflow", { req: thisObj.swapflow, step: thisObj.step }).done(function (resp) {
if (resp.success) {
getList();
$("#flowAssetBookModal").modal('hide');
}
})
},
getSwapTradeNo() {
var thisObj = this;
main.post("/swaptrade2/GetCapitalAccountByFoundAccount?foundAccount=" + thisObj.swapflow.FundAccount).done(function (resp) {
var item = resp;
thisObj.swapflow.SwapTradeNo = item != null ? item.SwapTradeNo : "";
})
}
},
components: {
'vue-datepicker': FastVue.vueDatePicker(),
'vue-number-input': FastVue.vueNumberInput(),
'vue-underlying': vueUnderlying()
}
});
window.reloadData = getList();