setup.ts 12 KB

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