setup.ts 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354
  1. import { validateCommon } from '@/common/setup/validate';
  2. import APP from "@/services";
  3. import { getItemEnum } from '@/services/bus/allEnum';
  4. import { QueryCustomInfo } from '@/services/go/ermcp/customInfo';
  5. import { QueryCustomInfoType } from '@/services/go/ermcp/customInfo/interface';
  6. import { QueryDeliveryGoods, QueryDeliveryGoodsDetail } from '@/services/go/ermcp/goodsInfo';
  7. import { Ermcp3Brand, Ermcp3Wrstandard, ErmcpDeliveryGoodsRsp } from '@/services/go/ermcp/goodsInfo/interface';
  8. import {
  9. GldErmcpSpotContractOperateReq,
  10. GldSpotContractInfo
  11. } from "@/services/proto/spotcontract/interface";
  12. import { orderContractControl } from "@/views/information/spot-contract/components/setup";
  13. import { message } from 'ant-design-vue';
  14. import { RuleObject } from 'ant-design-vue/lib/form/interface';
  15. import moment, { Moment } from 'moment';
  16. import { reactive, Ref, ref, UnwrapRef } from 'vue';
  17. import { FormState } from "./interface";
  18. export function handleFromState() {
  19. const formState: UnwrapRef<FormState> = reactive({
  20. ContractNo: '', // 现货合同编号
  21. ContractType: 1, // int32 现货合同类型-1:采购-1:销售
  22. BizType: 1, // uint32 业务类型 - 1:套保 2:套利
  23. BuyUserID: 0, // uint64 采购方ID
  24. SellUserID: 0,// uint64 客户ID
  25. ContractAttachment: new Uint8Array(),// bytes 合同附件
  26. DeliveryGoodsID: undefined, // 现货品种ID
  27. WrStandardID: undefined, // uint64 现货商品ID
  28. SpotGoodsBrandID: undefined, // uint64 现货品牌ID
  29. ConvertFactor: undefined,// double 标仓系数
  30. SpotGoodsDesc: '', // string 商品型号
  31. PriceType: 1, // uint32 定价类型-1:一口价2:点价3:暂定价
  32. Qty: null, // double 数量
  33. Price: null,// double 价格暂定价[1:一口价、3:暂定价]
  34. Amount: null, // double 金额[1:一口价、3:暂定价]
  35. DeliveryStartDate: '', // string 交收期(开始)
  36. DeliveryEndDate: '', // string 交收期(结束)
  37. ContractMargin: null, // double 合同保证金
  38. SaleUserID: undefined, // uint64 业务员ID
  39. MerUserID: undefined, // uint64 跟单员ID
  40. AccountID: undefined, // uint64 期货账户ID
  41. Remark: '', // string 合同备注
  42. CurrencyID: undefined, // 结算币种ID
  43. GoodsID: undefined, // uint64 点价合约ID-0:为现货,其它为期货商品合约ID[2:点价3:暂定价]
  44. PriceMove: null,// double 升贴水[2:点价3:暂定价]
  45. StartDate: '', // 点价开始时间
  46. EndDate: '', // 点价结束时间
  47. TradeUserID: undefined, // 交易员ID
  48. })
  49. // 业务类型
  50. const businessType = [
  51. { key: 1, value: '套保' },
  52. { key: 2, value: '套利' },
  53. ];
  54. // 验证合同类型
  55. async function v_ContractType(rule: RuleObject, value: number) {
  56. return validateCommon(value, '请选择合同类型')
  57. }
  58. // 验证业务类型
  59. // async function v_BizType(rule: RuleObject, value: number) {
  60. // return validateCommon(value, '请选择业务类型')
  61. // }
  62. // 验证业务类型
  63. async function v_BuyUser(rule: RuleObject, value: number) {
  64. return validateCommon(value, '请选择采购方')
  65. }
  66. // 验证业务类型
  67. async function v_SellUser(rule: RuleObject, value: number) {
  68. return validateCommon(value, '请选择销售方')
  69. }
  70. // 验证现货品种
  71. async function v_DeliveryGoods(rule: RuleObject, value: number) {
  72. return validateCommon(value, '请选择现货品种')
  73. }
  74. // 验证品类
  75. async function v_WrStandard(rule: RuleObject, value: number) {
  76. const errorInfo = formState.DeliveryGoodsID ? '请选择品类' : '请先选择现货品种'
  77. return validateCommon(value, errorInfo)
  78. }
  79. // 验证品牌
  80. async function v_SpotGoodsBrand(rule: RuleObject, value: number) {
  81. const errorInfo = formState.DeliveryGoodsID ? '请选择品牌' : '请先选择现货品种'
  82. return validateCommon(value, errorInfo)
  83. }
  84. // 验证定价类型
  85. async function v_PriceType(rule: RuleObject, value: number) {
  86. return validateCommon(value, '请选择定价类型')
  87. }
  88. // 验证结算币种
  89. async function v_Currency(rule: RuleObject, value: number) {
  90. return validateCommon(value, '请选择结算币种')
  91. }
  92. // 验证点价合约
  93. async function v_Goods(rule: RuleObject, value: number) {
  94. return validateCommon(value, '请选择点价合约')
  95. }
  96. const rules = {
  97. ContractNo: [{ required: true, message: '请输入合同编号', trigger: 'blur' }],
  98. ContractType: [{ required: true, validator: v_ContractType, trigger: 'change' }],
  99. // BizType: [{ required: true, validator: v_BizType, trigger: 'change' }],
  100. BuyUserID: [{ required: true, validator: v_BuyUser, trigger: 'change' }],
  101. SellUserID: [{ required: true, validator: v_SellUser, trigger: 'change' }],
  102. DeliveryGoodsID: [{ required: true, validator: v_DeliveryGoods, trigger: 'change' }],
  103. WrStandardID: [{ required: true, validator: v_WrStandard, trigger: 'blur' }],
  104. SpotGoodsBrandID: [{ required: true, validator: v_SpotGoodsBrand, trigger: 'blur' }],
  105. GoodsID: [{ required: true, validator: v_Goods, trigger: 'blur' }],
  106. // ConvertFactor: [{ required: true, message: '请选择品类', trigger: 'blur' }],
  107. SpotGoodsDesc: [{ required: true, message: '请输入商品规格', trigger: 'blur' }],
  108. PriceType: [{ required: true, validator: v_PriceType, trigger: 'blur' }],
  109. CurrencyID: [{ required: true, validator: v_Currency, trigger: 'blur' }],
  110. Qty: [{ required: true, message: '请输入数量', trigger: 'blur' }],
  111. Price: [{ required: true, message: '请输入价格', trigger: 'blur' }],
  112. PriceMove: [{ required: true, message: '请输入升贴水', trigger: 'blur' }],
  113. };
  114. return { formState, businessType, rules }
  115. }
  116. /**
  117. * 新增现货合同 表单提交
  118. */
  119. export function addContractReq() {
  120. /**
  121. * @param form 表单信息
  122. * @Param type 1: 保存草稿 2: 提交申请
  123. */
  124. function sendReq(form: FormState, loading: Ref<boolean>, OperateType: 1 | 2): Promise<string> {
  125. loading.value = true
  126. const info: GldSpotContractInfo = {
  127. UserID: APP.get('userAccount').memberuserid,// 机构ID
  128. ProductType: 1, // 产品类型 产品类型-1:标准仓单2:等标3:非标
  129. ContractNo: form.ContractNo, // 现货合同编号
  130. ContractType: form.ContractType, // 现货合同类型-1:采购-1:销售
  131. BuyUserID: form.BuyUserID, // 采购方ID
  132. SellUserID: form.SellUserID,// 客户ID
  133. DeliveryGoodsID: form.DeliveryGoodsID as number,// 现货品种ID
  134. WrStandardID: form.WrStandardID as number,// 品类ID
  135. SpotGoodsBrandID: form.SpotGoodsBrandID as number,// 品牌ID
  136. ConvertFactor: form.ConvertFactor as number, // 标仓系数
  137. SpotGoodsDesc: form.SpotGoodsDesc, // 商品规格
  138. PriceType: form.PriceType,// 定价类型
  139. CurrencyID: form.CurrencyID as number,// 结算币种
  140. Qty: Number(form.Qty as number), // 数量
  141. Price: Number(form.Price as number), // 价格
  142. TradeDate: moment().format("YYYYMMDD"),// 交易日
  143. SignDate: moment().format("YYYY-MM-DD HH:mm:ss"), // 签订日期
  144. // 以上必填
  145. // 以下选填
  146. BizType: form.BizType, // 业务类型 - 1:套保 2:套利
  147. Remark: form.Remark, // 合同备注
  148. // ContractAttachment: , // 合同附件
  149. ContractMargin: form.ContractMargin ? Number(form.ContractMargin) : 0, // 合同保证金
  150. Amount: [1, 3].includes(form.PriceType) ? Number(form.Price) * Number(form.Qty) : 0, // 金额
  151. PriceMove: Number(form.PriceMove as number), // 升贴水
  152. StartDate: form.StartDate, // 点价开始时间
  153. EndDate: form.EndDate, // 点价结束时间
  154. DeliveryStartDate: form.DeliveryStartDate,// 交收期开始
  155. DeliveryEndDate: form.DeliveryEndDate, // 交收期结束
  156. GoodsID: form.GoodsID as number, // 点价合约ID-0:为现货,其它为期货商品合约ID[2:点价3:暂定价]
  157. MerUserID: form.MerUserID || 0, // 跟单员ID
  158. TradeUserID: form.TradeUserID || 0, // 交易员ID
  159. SaleUserID: form.SaleUserID || 0,// 业务员id
  160. }
  161. const params: GldErmcpSpotContractOperateReq = {
  162. SpotContractID: '0',
  163. OperateType,
  164. Remark: '',
  165. Info: info,
  166. }
  167. console.log('prams', params);
  168. return orderContractControl(params, loading)
  169. .then(res => {
  170. return Promise.resolve(res);
  171. })
  172. .catch(err => {
  173. return Promise.reject(err);
  174. })
  175. }
  176. return { sendReq }
  177. }
  178. /**
  179. * 合同类型
  180. */
  181. export function handleContract() {
  182. // 合同类型
  183. const contractType = [
  184. { key: 1, value: '采购' },
  185. { key: -1, value: '销售' },
  186. ];
  187. const isSell = ref<boolean>(false) // true => 销售 false => 采购
  188. /**
  189. * 合同类型变更
  190. */
  191. function contractChange(value: number) {
  192. isSell.value = value === 1 ? false : true;
  193. }
  194. const customList = ref<QueryCustomInfoType[]>([])
  195. function queryCustomList() {
  196. QueryCustomInfo(3)
  197. .then((res) => {
  198. customList.value = res
  199. console.log('客户资料', customList);
  200. })
  201. .catch((err) => {
  202. message.error(err);
  203. })
  204. }
  205. return { contractType, isSell, contractChange, customList, queryCustomList }
  206. }
  207. /**
  208. * 处理现货商品
  209. */
  210. export function handleDeliveryGoods(formState: UnwrapRef<FormState>) {
  211. // 现货品种
  212. const deliveryGoodsList = ref<ErmcpDeliveryGoodsRsp[]>([])
  213. // 品牌
  214. const gblist = ref<Ermcp3Brand[]>([])
  215. // 品类列表
  216. const gmlist = ref<Ermcp3Wrstandard[]>([])
  217. // 查询现货商品
  218. function getDeliveryGoods() {
  219. QueryDeliveryGoods({}).then(res => {
  220. console.log('查询现货商品', res);
  221. deliveryGoodsList.value = res;
  222. }).catch(err => {
  223. message.error(err)
  224. })
  225. }
  226. // 切换现货商品
  227. function deliveryGoodsChange(value: number | undefined) {
  228. if (value !== undefined) {
  229. getDeliveryGoodsDetail(value)
  230. } else {
  231. gblist.value.length = 0
  232. gmlist.value.length = 0
  233. }
  234. }
  235. // 查询现货商品详情
  236. function getDeliveryGoodsDetail(deliverygoodsid: number) {
  237. QueryDeliveryGoodsDetail(deliverygoodsid).then(res => {
  238. if (res.length) {
  239. gblist.value = res[0].gblist
  240. gmlist.value = res[0].gmlist
  241. }
  242. console.log('查询品类', res);
  243. }).catch(err => {
  244. message.error(err)
  245. })
  246. }
  247. const numberUnit = ref<string>('')
  248. // 品类变更
  249. function WrStandardChange(value: number) {
  250. const obj = gmlist.value.find((e) => e.wrstandardid === value);
  251. if (obj) {
  252. //标仓系数
  253. formState.ConvertFactor = obj.convertfactor;
  254. // 单位
  255. const unitInfo = getItemEnum('goodsunit').find(e => e.enumitemname === obj.unitid)
  256. if (unitInfo) {
  257. numberUnit.value = unitInfo.enumdicname
  258. }
  259. }
  260. }
  261. return {
  262. deliveryGoodsList,
  263. gblist,
  264. gmlist,
  265. numberUnit,
  266. WrStandardChange,
  267. getDeliveryGoods,
  268. getDeliveryGoodsDetail,
  269. deliveryGoodsChange
  270. }
  271. }
  272. /**
  273. * 价格信息
  274. */
  275. export function handlePrice(formState: UnwrapRef<FormState>) {
  276. // 定价类型
  277. const priceType = [
  278. { key: 1, value: '一口价' },
  279. { key: 2, value: '点价' },
  280. { key: 3, value: '暂定价' },
  281. ];
  282. // 币种
  283. const payCurrency = getItemEnum('paycurrency')
  284. console.log('payCurrency', payCurrency);
  285. // 目前写死,获取枚举信息里面没有 单位名称,后期进行优化
  286. const payCurrencyUnit = ref<string>('元')
  287. // 切换币种
  288. function parCurrencyChange(value: number) {
  289. const obj = payCurrency.find(e => e.enumdicid === value)
  290. console.log('切换币种', obj);
  291. // payCurrencyUnit.value = obj?.enumdicname
  292. }
  293. return { priceType, payCurrency, payCurrencyUnit, parCurrencyChange }
  294. }
  295. /**
  296. * 处理日期
  297. */
  298. export function handleDate() {
  299. // 交收期
  300. const deliveryDate = ref<Moment[]>([])
  301. // 点价期
  302. const priceDate = ref<Moment[]>([]);
  303. function disabledDate(current: Moment) {
  304. // Can not select days before today and today
  305. return current && current < moment().endOf('day');
  306. }
  307. return { deliveryDate, priceDate, disabledDate }
  308. }
  309. /**
  310. * 处理金额
  311. */
  312. export function handleAmout(formState: UnwrapRef<FormState>) {
  313. function getAmout() {
  314. const { Price, Qty } = formState
  315. formState.Amount = (Price && Qty) ? Price * Qty : 0
  316. }
  317. return { getAmout }
  318. }