| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369 |
- import { getPayCurrencyTypeEnumList } from "@/common/constants/enumsList";
- import { getGoodsUnitEnumItemName } from "@/common/constants/enumsName";
- import { commonResultInfo, getRequestResultInfo } from "@/common/methods/request";
- import { validateCommon } from "@/common/setup/validate";
- import { QueryCustomInfo } from "@/services/go/ermcp/customInfo";
- import { QueryCustomInfoType } from "@/services/go/ermcp/customInfo/interface";
- import { GetDeliveryGoodsDetail } from "@/services/go/ermcp/goodsInfo";
- import { orderContract, spotContractStatus } from "@/services/proto/spotcontract";
- import { GldErmcpSpotContractOperateReq, SpotContractOperateReq } from "@/services/proto/spotcontract/interface";
- import { ContractStateSign, GldContractStateSign } from "@/views/information/spot-contract/setup";
- import { message } from "ant-design-vue";
- import { RuleObject } from "ant-design-vue/lib/form/interface";
- import Long from 'long';
- import moment, { Moment } from "moment";
- import { reactive, ref, Ref, UnwrapRef } from "vue";
- import { FormState } from './interface';
- import { Ermcp3DeliveryGoodsDetail, Brand, Wrstandard, Goods } from '@/services/go/ermcp/goodsInfo/interface/deliverygoodsdetail'
- /**
- * 合同操作相关 针对操作类型 1: 保存草稿 2: 提交申请 3: 删除成功 4:审核通过
- * @param reqs GldErmcpSpotContractOperateReq
- * @param loading
- * @returns
- */
- export function orderContractControl(reqs: GldErmcpSpotContractOperateReq, loading: Ref<boolean>): Promise<string> {
- //处理 合同id
- if (reqs.SpotContractID) {
- reqs.SpotContractID = Long.fromString(reqs.SpotContractID)
- }
- // loading 效果
- loading.value = true
- // 获取提示信息
- const sign = getRequestResultInfo(GldContractStateSign, reqs.OperateType) // 接口请求后的返回提示 这里统一进行管理
- // 接口调用
- const result = orderContract(reqs)
- // 接口调用结果处理,提示成功或者失败信息,并关闭loading效果
- return commonResultInfo(result, sign, loading)
- }
- /**
- * 修改合同类型 针对操作类型 4:审核拒绝 6:正常完结 5:撤销
- * @param reqs
- * @param loading
- * @returns
- */
- export function orderContractOperateControl(reqs: SpotContractOperateReq, loading: Ref<boolean>): Promise<string> {
- //处理 合同id
- if (reqs.SpotContractID) {
- reqs.SpotContractID = Long.fromString(reqs.SpotContractID)
- }
- // loading 效果
- loading.value = true
- // 获取提示信息
- const sign = getRequestResultInfo(ContractStateSign, reqs.OperateType) // 接口请求后的返回提示 这里统一进行管理
- // 接口调用
- const result = spotContractStatus(reqs)
- // 接口调用结果处理,提示成功或者失败信息,并关闭loading效果
- return commonResultInfo(result, sign, loading)
- }
- /**
- * 新增和修改的表单数据
- * @returns
- */
- export function handleFromState(contractType: number) {
- function initFormData() {
- return {
- ContractNo: '', // 现货合同编号
- ContractType: contractType, // int32 现货合同类型-1:采购-1:销售
- BizType: 1, // uint32 业务类型 - 1:套保 2:套利
- BuyUserID: undefined, // uint64 采购方ID
- SellUserID: undefined,// uint64 客户ID
- ContractAttachment: '',// bytes 合同附件
- DeliveryGoodsID: undefined, // 现货品种ID
- WrStandardID: undefined, // uint64 现货商品ID
- SpotGoodsBrandID: undefined, // uint64 现货品牌ID
- ConvertFactor: undefined,// double 标仓系数
- SpotGoodsDesc: '', // string 商品型号
- PriceType: 1, // uint32 定价类型-1:一口价2:点价3:暂定价
- Qty: '', // double 数量
- Price: '',// double 价格暂定价[1:一口价、3:暂定价]
- Amount: null, // double 金额[1:一口价、3:暂定价]
- DeliveryStartDate: '', // string 交收期(开始)
- DeliveryEndDate: '', // string 交收期(结束)
- ContractMargin: null, // double 合同保证金
- SaleUserID: undefined, // uint64 业务员ID
- MerUserID: undefined, // uint64 跟单员ID
- AccountID: undefined, // uint64 期货账户ID
- PointDesc: '', // string 点价备注
- CurrencyID: undefined, // 结算币种ID
- GoodsID: undefined, // uint64 点价合约ID-0:为现货,其它为期货商品合约ID[2:点价3:暂定价]
- PriceMove: null,// double 升贴水[2:点价3:暂定价]
- StartDate: '', // 点价开始时间
- EndDate: '', // 点价结束时间
- TradeUserID: undefined, // 交易员ID
- SpotContractID: '0',//现货合同ID
- SubjectID: undefined,// 交易主体ID
- }
- }
- const formState: UnwrapRef<FormState> = reactive(initFormData())
- // 业务类型
- const businessType = [
- { key: 1, value: '套保' },
- { key: 2, value: '套利' },
- ];
- return { formState, businessType, initFormData }
- }
- /**
- * 表单新增和修改验证规则
- */
- export function handleFormRule(formState: UnwrapRef<FormState>) {
- // 验证合同类型
- async function v_ContractType(rule: RuleObject, value: number) {
- return validateCommon(value, '请选择合同类型')
- }
- // 验证业务类型
- // async function v_BizType(rule: RuleObject, value: number) {
- // return validateCommon(value, '请选择业务类型')
- // }
- // 验证业务类型
- async function v_BuyUser(rule: RuleObject, value: number) {
- return validateCommon(value, '请选择采购方')
- }
- // 验证业务类型
- async function v_SellUser(rule: RuleObject, value: number) {
- return validateCommon(value, '请选择销售方')
- }
- // 验证现货品种
- async function v_DeliveryGoods(rule: RuleObject, value: number) {
- return validateCommon(value, '请选择现货品种')
- }
- // 验证品类
- async function v_WrStandard(rule: RuleObject, value: number) {
- const errorInfo = formState.DeliveryGoodsID ? '请选择商品' : '请先选择现货品种'
- return validateCommon(value, errorInfo)
- }
- // 验证品牌
- async function v_SpotGoodsBrand(rule: RuleObject, value: number) {
- const errorInfo = formState.DeliveryGoodsID ? '请选择品牌' : '请先选择现货品种'
- return validateCommon(value, errorInfo)
- }
- // 验证定价类型
- async function v_PriceType(rule: RuleObject, value: number) {
- return validateCommon(value, '请选择定价类型')
- }
- // 验证结算币种
- async function v_Currency(rule: RuleObject, value: number) {
- return validateCommon(value, '请选择结算币种')
- }
- // 验证点价合约
- async function v_Goods(rule: RuleObject, value: number) {
- return validateCommon(value, '请选择点价合约')
- }
- // 验证业务员
- async function v_SaleUserID(rule: RuleObject, value: number) {
- return validateCommon(value, '请选择业务员')
- }
- // 验证交易用户
- async function v_TradeUserID(rule: RuleObject, value: number) {
- return validateCommon(value, '请选择交易用户')
- }
- // 验证交易主体
- async function v_SubjectID(rule: RuleObject, value: number) {
- return validateCommon(value, '请选择主体')
- }
- const rules = {
- ContractNo: [{ required: true, message: '请输入合同编号', trigger: 'blur' }],
- ContractType: [{ required: true, validator: v_ContractType, trigger: 'change' }],
- // BizType: [{ required: true, validator: v_BizType, trigger: 'change' }],
- BuyUserID: [{ required: true, validator: v_BuyUser, trigger: 'change' }],
- SellUserID: [{ required: true, validator: v_SellUser, trigger: 'change' }],
- DeliveryGoodsID: [{ required: true, validator: v_DeliveryGoods, trigger: 'change' }],
- WrStandardID: [{ required: true, validator: v_WrStandard, trigger: 'blur' }],
- SpotGoodsBrandID: [{ required: true, validator: v_SpotGoodsBrand, trigger: 'blur' }],
- GoodsID: [{ required: true, validator: v_Goods, trigger: 'blur' }],
- // ConvertFactor: [{ required: true, message: '请选择品类', trigger: 'blur' }],
- SpotGoodsDesc: [{ required: true, message: '请输入商品规格', trigger: 'blur' }],
- PriceType: [{ required: true, validator: v_PriceType, trigger: 'blur' }],
- CurrencyID: [{ required: true, validator: v_Currency, trigger: 'blur' }],
- Qty: [{ required: true, message: '请输入数量', trigger: 'blur' }],
- Price: [{ required: true, message: '请输入价格', trigger: 'blur' }],
- PriceMove: [{ required: true, message: '请输入升贴水', trigger: 'blur', type: 'number' }],
- SaleUserID: [{ required: true, validator: v_SaleUserID, trigger: 'change' }],
- TradeUserID: [{ required: true, validator: v_TradeUserID, trigger: 'change' }],
- SubjectID: [{ required: true, validator: v_SubjectID, trigger: 'change' }],
- };
- return { rules }
- }
- /**
- * 合同类型
- */
- export function handleContract(formState: UnwrapRef<FormState>) {
- // 合同类型
- const contractType = [
- { key: 1, value: '采购' },
- { key: -1, value: '销售' },
- ];
- const isSell = ref<boolean>(formState.ContractType === -1) // true => 销售 false => 采购
- /**
- * 合同类型变更
- */
- function contractChange(value: number) {
- if (value === 1) {
- isSell.value = false
- formState.SellUserID = undefined;
- } else {
- isSell.value = true
- formState.BuyUserID = undefined
- }
- }
- const customList = ref<QueryCustomInfoType[]>([])
- function queryCustomList() {
- QueryCustomInfo(3)
- .then((res) => {
- customList.value = res.filter(e => (e.status === 4))
- console.log('客户资料', customList);
- })
- .catch((err) => {
- message.error(err);
- })
- }
- return { contractType, isSell, contractChange, customList, queryCustomList }
- }
- /**
- * 处理现货商品
- */
- export function handleDeliveryGoods(formState: UnwrapRef<FormState>) {
- // 现货品种列表
- const deliveryGoodsList = ref<Ermcp3DeliveryGoodsDetail[]>([]);
- const request = GetDeliveryGoodsDetail().then((res) => {
- deliveryGoodsList.value = res.filter((item) => item.isvalid);
- }).catch(err => {
- message.error(err);
- })
- // 品牌列表
- const barandList = ref<Brand[]>([])
- // 现货商品列表
- const wrstandardList = ref<Wrstandard[]>([])
- // 商品合约列表
- const goodsList = ref<Goods[]>([]);
- // 切换现货商品
- async function deliveryGoodsChange(value: number | undefined) {
- await request;
- const deliveryGoods = deliveryGoodsList.value.find((e) => e.deliverygoodsid === value);
- if (deliveryGoods) {
- barandList.value = deliveryGoods.bdlst.filter((e_1) => e_1.isvalid); // 显示有效记录
- wrstandardList.value = deliveryGoods.wdlst;
- } else {
- barandList.value = [];
- wrstandardList.value = [];
- }
- goodsList.value = [];
- formState.GoodsID = undefined;
- formState.WrStandardID = undefined;
- formState.SpotGoodsBrandID = undefined;
- formState.ConvertFactor = undefined;
- }
- const numberUnit = ref<string>('')
- // 选择现货商品
- async function wrStandardChange(value: number) {
- formState.GoodsID = undefined;
- await request;
- const wrstandard = wrstandardList.value.find((e) => e.wrstandardid === value);
- if (wrstandard) {
- // 单位
- numberUnit.value = getGoodsUnitEnumItemName(wrstandard.unitid);
- goodsList.value = [];
- wrstandard.mglst.forEach((middlegoods) => {
- // 期货品种列表
- middlegoods.GPLST.forEach((item) => {
- goodsList.value.push(...item.GDLST);
- });
- });
- }
- }
- return {
- deliveryGoodsList,
- barandList,
- wrstandardList,
- goodsList,
- numberUnit,
- wrStandardChange,
- deliveryGoodsChange
- }
- }
- /**
- * 价格信息
- */
- export function handlePrice(formState: UnwrapRef<FormState>) {
- // 定价类型
- const priceType = [
- { key: 1, value: '一口价' },
- { key: 2, value: '点价' },
- { key: 3, value: '暂定价' },
- ];
- // 币种
- const payCurrency = getPayCurrencyTypeEnumList()
- console.log('payCurrency', payCurrency);
- // 目前写死,获取枚举信息里面没有 单位名称,后期进行优化
- const payCurrencyUnit = ref<string>('元')
- // 切换币种
- function parCurrencyChange(value: number) {
- const obj = payCurrency.find(e => e.enumitemname === value)
- console.log('切换币种', obj);
- // payCurrencyUnit.value = obj?.enumdicname
- }
- return { priceType, payCurrency, payCurrencyUnit, parCurrencyChange }
- }
- /**
- * 处理日期
- */
- export function handleDate() {
- // 交收期
- const deliveryDate = ref<Moment[]>([])
- // 点价期
- const priceDate = ref<Moment[]>([]);
- function disabledDate(current: Moment) {
- // Can not select days before today and today
- return current && current < moment().endOf('day');
- }
- return { deliveryDate, priceDate, disabledDate }
- }
- /**
- * 处理金额
- */
- export function handleAmout(formState: UnwrapRef<FormState>) {
- function getAmout() {
- const { Price, Qty, PriceMove } = formState
- formState.Amount = (Price && Qty && PriceMove) ? (Number(Price) + Number(PriceMove)) * Number(Qty) : 0
- }
- return { getAmout }
- }
|