| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335 |
- import { validateCommon } from '@/common/setup/validate';
- import APP from "@/services";
- import { getItemEnum } from '@/services/bus/allEnum';
- import { QueryCustomInfo } from '@/services/go/ermcp/customInfo';
- import { QueryCustomInfoType } from '@/services/go/ermcp/customInfo/interface';
- import { QueryDeliveryGoods, QueryDeliveryGoodsDetail } from '@/services/go/ermcp/goodsInfo';
- import { Ermcp3Brand, Ermcp3Wrstandard, ErmcpDeliveryGoodsRsp } from '@/services/go/ermcp/goodsInfo/interface';
- import { GldSpotContractInfo } from "@/services/proto/spotcontract/interface";
- import { changeOrderContract } from "@/views/information/spot-contract/components/setup";
- import { message } from 'ant-design-vue';
- import { RuleObject } from 'ant-design-vue/lib/form/interface';
- import moment, { Moment } from 'moment';
- import { reactive, ref, UnwrapRef } from 'vue';
- import { FormState } from "./interface";
- export function handleFromState() {
- const formState: UnwrapRef<FormState> = reactive({
- ContractNo: '', // 现货合同编号
- ContractType: 1, // int32 现货合同类型-1:采购-1:销售
- BizType: 1, // uint32 业务类型 - 1:套保 2:套利
- BuyUserID: 0, // uint64 采购方ID
- SellUserID: 0,// uint64 客户ID
- ContractAttachment: new Uint8Array(),// bytes 合同附件
- DeliveryGoodsID: undefined, // 现货品种ID
- WrStandardID: undefined, // uint64 现货商品ID
- SpotGoodsBrandID: undefined, // uint64 现货品牌ID
- ConvertFactor: undefined,// double 标仓系数
- SpotGoodsDesc: '', // string 商品型号
- PriceType: 1, // uint32 定价类型-1:一口价2:点价3:暂定价
- Qty: null, // double 数量
- Price: null,// 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
- Remark: '', // string 合同备注
- CurrencyID: undefined, // 结算币种ID
- GoodsID: undefined, // uint64 点价合约ID-0:为现货,其它为期货商品合约ID[2:点价3:暂定价]
- PriceMove: null,// double 升贴水[2:点价3:暂定价]
- StartDate: '', // 点价开始时间
- EndDate: '', // 点价结束时间
- TradeUserID: 0, // 交易员ID
- })
- // 业务类型
- const businessType = [
- { key: 1, value: '套保' },
- { key: 2, value: '套利' },
- ];
- return { formState, businessType }
- }
- /**
- * 新增现货合同 表单提交
- */
- export function addContractReq() {
- const { loading, orderContractState } = changeOrderContract()
- /**
- * @param form 表单信息
- * @Param type 1: 保存草稿 2: 提交申请
- */
- function sendReq(form: FormState, type: number): Promise<string> {
- const info: GldSpotContractInfo = {
- UserID: APP.get('userAccount').memberuserid,// 机构ID
- ProductType: 1, // 产品类型 产品类型-1:标准仓单2:等标3:非标
- ContractNo: form.ContractNo, // 现货合同编号
- ContractType: form.ContractType, // 现货合同类型-1:采购-1:销售
- BuyUserID: form.BuyUserID, // 采购方ID
- SellUserID: form.SellUserID,// 客户ID
- DeliveryGoodsID: form.DeliveryGoodsID as number,// 现货品种ID
- WrStandardID: form.WrStandardID as number,// 品类ID
- SpotGoodsBrandID: form.SpotGoodsBrandID as number,// 品牌ID
- ConvertFactor: form.ConvertFactor as number, // 标仓系数
- SpotGoodsDesc: form.SpotGoodsDesc, // 商品规格
- PriceType: form.PriceType,// 定价类型
- CurrencyID: form.CurrencyID as number,// 结算币种
- Qty: Number(form.Qty as number), // 数量
- Price: Number(form.Price as number), // 价格
- TradeDate: moment().format("YYYYMMDD"),// 交易日
- SignDate: moment().format("YYYY-MM-DD HH:mm:ss"), // 签订日期
- // 以上必填
- // 以下选填
- BizType: form.BizType, // 业务类型 - 1:套保 2:套利
- Remark: form.Remark, // 合同备注
- // ContractAttachment: , // 合同附件
- ContractMargin: form.ContractMargin as number, // 合同保证金
- Amount: [1, 3].includes(form.PriceType) ? Number(form.Price) * Number(form.Qty) : 0, // 金额
- PriceMove: Number(form.PriceMove as number), // 升贴水
- StartDate: form.StartDate, // 点价开始时间
- EndDate: form.EndDate, // 点价结束时间
- DeliveryStartDate: form.DeliveryStartDate,// 交收期开始
- DeliveryEndDate: form.DeliveryEndDate, // 交收期结束
- GoodsID: form.GoodsID as number, // 点价合约ID-0:为现货,其它为期货商品合约ID[2:点价3:暂定价]
- // MerUserID: form.MerUserID, // 跟单员ID
- // TradeUserID: form.TradeUserID, // 交易员ID
- // SaleUserID: form.SaleUserID,// 业务员id
- }
- return orderContractState('0', type, info)
- .then(res => {
- return Promise.resolve(res);
- })
- .catch(err => {
- return Promise.reject(err);
- })
- }
- return { loading, sendReq }
- }
- /**
- * 合同类型
- */
- export function handleContract() {
- // 合同类型
- const contractType = [
- { key: 1, value: '采购' },
- { key: -1, value: '销售' },
- ];
- const isSell = ref<boolean>(false) // true => 销售 false => 采购
- /**
- * 合同类型变更
- */
- function contractChange(value: number) {
- isSell.value = value === 1 ? false : true;
- }
- const customList = ref<QueryCustomInfoType[]>([])
- function queryCustomList() {
- QueryCustomInfo(3)
- .then((res) => {
- customList.value = res
- console.log('客户资料', customList);
- })
- .catch((err) => {
- message.error(err);
- })
- }
- return { contractType, isSell, contractChange, customList, queryCustomList }
- }
- /**
- * 自定义表单验证方法
- */
- export function handlevalidate(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, '请选择点价合约')
- }
- return {
- v_ContractType, v_BizType, v_BuyUser, v_SellUser, v_DeliveryGoods, v_WrStandard,
- v_SpotGoodsBrand, v_PriceType, v_Currency, v_Goods
- }
- }
- /**
- * 处理现货商品
- */
- export function handleDeliveryGoods(formState: UnwrapRef<FormState>) {
- // 现货品种
- const deliveryGoodsList = ref<ErmcpDeliveryGoodsRsp[]>([])
- // 品牌
- const gblist = ref<Ermcp3Brand[]>([])
- // 品类列表
- const gmlist = ref<Ermcp3Wrstandard[]>([])
- // 查询现货商品
- function getDeliveryGoods() {
- QueryDeliveryGoods({}).then(res => {
- console.log('查询现货商品', res);
- deliveryGoodsList.value = res;
- }).catch(err => {
- message.error(err)
- })
- }
- // 切换现货商品
- function deliveryGoodsChange(value: number | undefined) {
- if (value !== undefined) {
- getDeliveryGoodsDetail(value)
- } else {
- gblist.value.length = 0
- gmlist.value.length = 0
- }
- }
- // 查询现货商品详情
- function getDeliveryGoodsDetail(deliverygoodsid: number) {
- QueryDeliveryGoodsDetail(deliverygoodsid).then(res => {
- if (res.length) {
- gblist.value = res[0].gblist
- gmlist.value = res[0].gmlist
- }
- console.log('查询品类', res);
- }).catch(err => {
- message.error(err)
- })
- }
- const numberUnit = ref<string>('')
- // 品类变更
- function WrStandardChange(value: number) {
- const obj = gmlist.value.find((e) => e.wrstandardid === value);
- if (obj) {
- //标仓系数
- formState.ConvertFactor = obj.convertfactor;
- // 单位
- const unitInfo = getItemEnum('goodsunit').find(e => e.enumitemname === obj.unitid)
- if (unitInfo) {
- numberUnit.value = unitInfo.enumdicname
- }
- }
- }
- return {
- deliveryGoodsList,
- gblist,
- gmlist,
- numberUnit,
- WrStandardChange,
- getDeliveryGoods,
- getDeliveryGoodsDetail,
- deliveryGoodsChange
- }
- }
- /**
- * 价格信息
- */
- export function handlePrice(formState: UnwrapRef<FormState>) {
- // 定价类型
- const priceType = [
- { key: 1, value: '一口价' },
- { key: 2, value: '点价' },
- { key: 3, value: '暂定价' },
- ];
- // 币种
- const payCurrency = getItemEnum('paycurrency')
- console.log('payCurrency', payCurrency);
- // 目前写死,获取枚举信息里面没有 单位名称,后期进行优化
- const payCurrencyUnit = ref<string>('元')
- // 切换币种
- function parCurrencyChange(value: number) {
- const obj = payCurrency.find(e => e.enumdicid === 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 } = formState
- formState.Amount = (Price && Qty) ? Price * Qty : 0
- }
- return { getAmout }
- }
|