setup.ts 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369
  1. import { getPayCurrencyTypeEnumList } from "@/common/constants/enumsList";
  2. import { getGoodsUnitEnumItemName } from "@/common/constants/enumsName";
  3. import { commonResultInfo, getRequestResultInfo } from "@/common/methods/request";
  4. import { validateCommon } from "@/common/setup/validate";
  5. import { QueryCustomInfo } from "@/services/go/ermcp/customInfo";
  6. import { QueryCustomInfoType } from "@/services/go/ermcp/customInfo/interface";
  7. import { GetDeliveryGoodsDetail } from "@/services/go/ermcp/goodsInfo";
  8. import { orderContract, spotContractStatus } from "@/services/proto/spotcontract";
  9. import { GldErmcpSpotContractOperateReq, SpotContractOperateReq } from "@/services/proto/spotcontract/interface";
  10. import { ContractStateSign, GldContractStateSign } from "@/views/information/spot-contract/setup";
  11. import { message } from "ant-design-vue";
  12. import { RuleObject } from "ant-design-vue/lib/form/interface";
  13. import Long from 'long';
  14. import moment, { Moment } from "moment";
  15. import { reactive, ref, Ref, UnwrapRef } from "vue";
  16. import { FormState } from './interface';
  17. import { Ermcp3DeliveryGoodsDetail, Brand, Wrstandard, Goods } from '@/services/go/ermcp/goodsInfo/interface/deliverygoodsdetail'
  18. /**
  19. * 合同操作相关 针对操作类型 1: 保存草稿 2: 提交申请 3: 删除成功 4:审核通过
  20. * @param reqs GldErmcpSpotContractOperateReq
  21. * @param loading
  22. * @returns
  23. */
  24. export function orderContractControl(reqs: GldErmcpSpotContractOperateReq, loading: Ref<boolean>): Promise<string> {
  25. //处理 合同id
  26. if (reqs.SpotContractID) {
  27. reqs.SpotContractID = Long.fromString(reqs.SpotContractID)
  28. }
  29. // loading 效果
  30. loading.value = true
  31. // 获取提示信息
  32. const sign = getRequestResultInfo(GldContractStateSign, reqs.OperateType) // 接口请求后的返回提示 这里统一进行管理
  33. // 接口调用
  34. const result = orderContract(reqs)
  35. // 接口调用结果处理,提示成功或者失败信息,并关闭loading效果
  36. return commonResultInfo(result, sign, loading)
  37. }
  38. /**
  39. * 修改合同类型 针对操作类型 4:审核拒绝 6:正常完结 5:撤销
  40. * @param reqs
  41. * @param loading
  42. * @returns
  43. */
  44. export function orderContractOperateControl(reqs: SpotContractOperateReq, loading: Ref<boolean>): Promise<string> {
  45. //处理 合同id
  46. if (reqs.SpotContractID) {
  47. reqs.SpotContractID = Long.fromString(reqs.SpotContractID)
  48. }
  49. // loading 效果
  50. loading.value = true
  51. // 获取提示信息
  52. const sign = getRequestResultInfo(ContractStateSign, reqs.OperateType) // 接口请求后的返回提示 这里统一进行管理
  53. // 接口调用
  54. const result = spotContractStatus(reqs)
  55. // 接口调用结果处理,提示成功或者失败信息,并关闭loading效果
  56. return commonResultInfo(result, sign, loading)
  57. }
  58. /**
  59. * 新增和修改的表单数据
  60. * @returns
  61. */
  62. export function handleFromState(contractType: number) {
  63. function initFormData() {
  64. return {
  65. ContractNo: '', // 现货合同编号
  66. ContractType: contractType, // int32 现货合同类型-1:采购-1:销售
  67. BizType: 1, // uint32 业务类型 - 1:套保 2:套利
  68. BuyUserID: undefined, // uint64 采购方ID
  69. SellUserID: undefined,// uint64 客户ID
  70. ContractAttachment: '',// bytes 合同附件
  71. DeliveryGoodsID: undefined, // 现货品种ID
  72. WrStandardID: undefined, // uint64 现货商品ID
  73. SpotGoodsBrandID: undefined, // uint64 现货品牌ID
  74. ConvertFactor: undefined,// double 标仓系数
  75. SpotGoodsDesc: '', // string 商品型号
  76. PriceType: 1, // uint32 定价类型-1:一口价2:点价3:暂定价
  77. Qty: '', // double 数量
  78. Price: '',// double 价格暂定价[1:一口价、3:暂定价]
  79. Amount: null, // double 金额[1:一口价、3:暂定价]
  80. DeliveryStartDate: '', // string 交收期(开始)
  81. DeliveryEndDate: '', // string 交收期(结束)
  82. ContractMargin: null, // double 合同保证金
  83. SaleUserID: undefined, // uint64 业务员ID
  84. MerUserID: undefined, // uint64 跟单员ID
  85. AccountID: undefined, // uint64 期货账户ID
  86. PointDesc: '', // string 点价备注
  87. CurrencyID: undefined, // 结算币种ID
  88. GoodsID: undefined, // uint64 点价合约ID-0:为现货,其它为期货商品合约ID[2:点价3:暂定价]
  89. PriceMove: null,// double 升贴水[2:点价3:暂定价]
  90. StartDate: '', // 点价开始时间
  91. EndDate: '', // 点价结束时间
  92. TradeUserID: undefined, // 交易员ID
  93. SpotContractID: '0',//现货合同ID
  94. SubjectID: undefined,// 交易主体ID
  95. }
  96. }
  97. const formState: UnwrapRef<FormState> = reactive(initFormData())
  98. // 业务类型
  99. const businessType = [
  100. { key: 1, value: '套保' },
  101. { key: 2, value: '套利' },
  102. ];
  103. return { formState, businessType, initFormData }
  104. }
  105. /**
  106. * 表单新增和修改验证规则
  107. */
  108. export function handleFormRule(formState: UnwrapRef<FormState>) {
  109. // 验证合同类型
  110. async function v_ContractType(rule: RuleObject, value: number) {
  111. return validateCommon(value, '请选择合同类型')
  112. }
  113. // 验证业务类型
  114. // async function v_BizType(rule: RuleObject, value: number) {
  115. // return validateCommon(value, '请选择业务类型')
  116. // }
  117. // 验证业务类型
  118. async function v_BuyUser(rule: RuleObject, value: number) {
  119. return validateCommon(value, '请选择采购方')
  120. }
  121. // 验证业务类型
  122. async function v_SellUser(rule: RuleObject, value: number) {
  123. return validateCommon(value, '请选择销售方')
  124. }
  125. // 验证现货品种
  126. async function v_DeliveryGoods(rule: RuleObject, value: number) {
  127. return validateCommon(value, '请选择现货品种')
  128. }
  129. // 验证品类
  130. async function v_WrStandard(rule: RuleObject, value: number) {
  131. const errorInfo = formState.DeliveryGoodsID ? '请选择商品' : '请先选择现货品种'
  132. return validateCommon(value, errorInfo)
  133. }
  134. // 验证品牌
  135. async function v_SpotGoodsBrand(rule: RuleObject, value: number) {
  136. const errorInfo = formState.DeliveryGoodsID ? '请选择品牌' : '请先选择现货品种'
  137. return validateCommon(value, errorInfo)
  138. }
  139. // 验证定价类型
  140. async function v_PriceType(rule: RuleObject, value: number) {
  141. return validateCommon(value, '请选择定价类型')
  142. }
  143. // 验证结算币种
  144. async function v_Currency(rule: RuleObject, value: number) {
  145. return validateCommon(value, '请选择结算币种')
  146. }
  147. // 验证点价合约
  148. async function v_Goods(rule: RuleObject, value: number) {
  149. return validateCommon(value, '请选择点价合约')
  150. }
  151. // 验证业务员
  152. async function v_SaleUserID(rule: RuleObject, value: number) {
  153. return validateCommon(value, '请选择业务员')
  154. }
  155. // 验证交易用户
  156. async function v_TradeUserID(rule: RuleObject, value: number) {
  157. return validateCommon(value, '请选择交易用户')
  158. }
  159. // 验证交易主体
  160. async function v_SubjectID(rule: RuleObject, value: number) {
  161. return validateCommon(value, '请选择主体')
  162. }
  163. const rules = {
  164. ContractNo: [{ required: true, message: '请输入合同编号', trigger: 'blur' }],
  165. ContractType: [{ required: true, validator: v_ContractType, trigger: 'change' }],
  166. // BizType: [{ required: true, validator: v_BizType, trigger: 'change' }],
  167. BuyUserID: [{ required: true, validator: v_BuyUser, trigger: 'change' }],
  168. SellUserID: [{ required: true, validator: v_SellUser, trigger: 'change' }],
  169. DeliveryGoodsID: [{ required: true, validator: v_DeliveryGoods, trigger: 'change' }],
  170. WrStandardID: [{ required: true, validator: v_WrStandard, trigger: 'blur' }],
  171. SpotGoodsBrandID: [{ required: true, validator: v_SpotGoodsBrand, trigger: 'blur' }],
  172. GoodsID: [{ required: true, validator: v_Goods, trigger: 'blur' }],
  173. // ConvertFactor: [{ required: true, message: '请选择品类', trigger: 'blur' }],
  174. SpotGoodsDesc: [{ required: true, message: '请输入商品规格', trigger: 'blur' }],
  175. PriceType: [{ required: true, validator: v_PriceType, trigger: 'blur' }],
  176. CurrencyID: [{ required: true, validator: v_Currency, trigger: 'blur' }],
  177. Qty: [{ required: true, message: '请输入数量', trigger: 'blur' }],
  178. Price: [{ required: true, message: '请输入价格', trigger: 'blur' }],
  179. PriceMove: [{ required: true, message: '请输入升贴水', trigger: 'blur', type: 'number' }],
  180. SaleUserID: [{ required: true, validator: v_SaleUserID, trigger: 'change' }],
  181. TradeUserID: [{ required: true, validator: v_TradeUserID, trigger: 'change' }],
  182. SubjectID: [{ required: true, validator: v_SubjectID, trigger: 'change' }],
  183. };
  184. return { rules }
  185. }
  186. /**
  187. * 合同类型
  188. */
  189. export function handleContract(formState: UnwrapRef<FormState>) {
  190. // 合同类型
  191. const contractType = [
  192. { key: 1, value: '采购' },
  193. { key: -1, value: '销售' },
  194. ];
  195. const isSell = ref<boolean>(formState.ContractType === -1) // true => 销售 false => 采购
  196. /**
  197. * 合同类型变更
  198. */
  199. function contractChange(value: number) {
  200. if (value === 1) {
  201. isSell.value = false
  202. formState.SellUserID = undefined;
  203. } else {
  204. isSell.value = true
  205. formState.BuyUserID = undefined
  206. }
  207. }
  208. const customList = ref<QueryCustomInfoType[]>([])
  209. function queryCustomList() {
  210. QueryCustomInfo(3)
  211. .then((res) => {
  212. customList.value = res.filter(e => (e.status === 4))
  213. console.log('客户资料', customList);
  214. })
  215. .catch((err) => {
  216. message.error(err);
  217. })
  218. }
  219. return { contractType, isSell, contractChange, customList, queryCustomList }
  220. }
  221. /**
  222. * 处理现货商品
  223. */
  224. export function handleDeliveryGoods(formState: UnwrapRef<FormState>) {
  225. // 现货品种列表
  226. const deliveryGoodsList = ref<Ermcp3DeliveryGoodsDetail[]>([]);
  227. const request = GetDeliveryGoodsDetail().then((res) => {
  228. deliveryGoodsList.value = res.filter((item) => item.isvalid);
  229. }).catch(err => {
  230. message.error(err);
  231. })
  232. // 品牌列表
  233. const barandList = ref<Brand[]>([])
  234. // 现货商品列表
  235. const wrstandardList = ref<Wrstandard[]>([])
  236. // 商品合约列表
  237. const goodsList = ref<Goods[]>([]);
  238. // 切换现货商品
  239. async function deliveryGoodsChange(value: number | undefined) {
  240. await request;
  241. const deliveryGoods = deliveryGoodsList.value.find((e) => e.deliverygoodsid === value);
  242. if (deliveryGoods) {
  243. barandList.value = deliveryGoods.bdlst.filter((e_1) => e_1.isvalid); // 显示有效记录
  244. wrstandardList.value = deliveryGoods.wdlst;
  245. } else {
  246. barandList.value = [];
  247. wrstandardList.value = [];
  248. }
  249. goodsList.value = [];
  250. formState.GoodsID = undefined;
  251. formState.WrStandardID = undefined;
  252. formState.SpotGoodsBrandID = undefined;
  253. formState.ConvertFactor = undefined;
  254. }
  255. const numberUnit = ref<string>('')
  256. // 选择现货商品
  257. async function wrStandardChange(value: number) {
  258. formState.GoodsID = undefined;
  259. await request;
  260. const wrstandard = wrstandardList.value.find((e) => e.wrstandardid === value);
  261. if (wrstandard) {
  262. // 单位
  263. numberUnit.value = getGoodsUnitEnumItemName(wrstandard.unitid);
  264. goodsList.value = [];
  265. wrstandard.mglst.forEach((middlegoods) => {
  266. // 期货品种列表
  267. middlegoods.GPLST.forEach((item) => {
  268. goodsList.value.push(...item.GDLST);
  269. });
  270. });
  271. }
  272. }
  273. return {
  274. deliveryGoodsList,
  275. barandList,
  276. wrstandardList,
  277. goodsList,
  278. numberUnit,
  279. wrStandardChange,
  280. deliveryGoodsChange
  281. }
  282. }
  283. /**
  284. * 价格信息
  285. */
  286. export function handlePrice(formState: UnwrapRef<FormState>) {
  287. // 定价类型
  288. const priceType = [
  289. { key: 1, value: '一口价' },
  290. { key: 2, value: '点价' },
  291. { key: 3, value: '暂定价' },
  292. ];
  293. // 币种
  294. const payCurrency = getPayCurrencyTypeEnumList()
  295. console.log('payCurrency', payCurrency);
  296. // 目前写死,获取枚举信息里面没有 单位名称,后期进行优化
  297. const payCurrencyUnit = ref<string>('元')
  298. // 切换币种
  299. function parCurrencyChange(value: number) {
  300. const obj = payCurrency.find(e => e.enumitemname === value)
  301. console.log('切换币种', obj);
  302. // payCurrencyUnit.value = obj?.enumdicname
  303. }
  304. return { priceType, payCurrency, payCurrencyUnit, parCurrencyChange }
  305. }
  306. /**
  307. * 处理日期
  308. */
  309. export function handleDate() {
  310. // 交收期
  311. const deliveryDate = ref<Moment[]>([])
  312. // 点价期
  313. const priceDate = ref<Moment[]>([]);
  314. function disabledDate(current: Moment) {
  315. // Can not select days before today and today
  316. return current && current < moment().endOf('day');
  317. }
  318. return { deliveryDate, priceDate, disabledDate }
  319. }
  320. /**
  321. * 处理金额
  322. */
  323. export function handleAmout(formState: UnwrapRef<FormState>) {
  324. function getAmout() {
  325. const { Price, Qty, PriceMove } = formState
  326. formState.Amount = (Price && Qty && PriceMove) ? (Number(Price) + Number(PriceMove)) * Number(Qty) : 0
  327. }
  328. return { getAmout }
  329. }