listing.ts 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437
  1. import { shallowRef, reactive } from 'vue'
  2. import { v4 } from 'uuid'
  3. import { ClientType } from '@/constants/client'
  4. import { useDataTable } from '@/hooks/datatable'
  5. import { Market } from '@/constants/market'
  6. import { queryDiamondList } from '@/services/api/goods'
  7. import { zsBuyOrderListing, zsSellOrderListing } from '@/services/api/order'
  8. import { sessionData } from '@/stores'
  9. import {
  10. Category,
  11. getCategoryList,
  12. getCurrencyTypeList,
  13. getShapeTypeList,
  14. getColorTypeList,
  15. getCutTypeList,
  16. getClarityTypeList,
  17. getPolishTypeList,
  18. getSymmetryTypeList,
  19. getFluorescenceTypeList,
  20. getCrystalTypeList,
  21. getFancyColorType1List,
  22. getStyleTypeList,
  23. } from '@/constants/diamond'
  24. import moment from 'moment'
  25. import Long from 'long'
  26. /**
  27. * 求购大厅挂牌
  28. * @returns
  29. */
  30. export function useBuyOrderListing() {
  31. const { UserID, AccountIDs } = sessionData.getValue('loginInfo')
  32. const loading = shallowRef(false)
  33. const performanceId = shallowRef<number>() // 选中的履约模板ID
  34. const currencyId = shallowRef<number>() // 选中的货币类型ID
  35. const formData = reactive<Proto.GZBuyOrderDetailExInfo>({
  36. UserID,
  37. AccountID: AccountIDs[0],
  38. ZSCategory: Category.Diamonds,
  39. ZSCurrencyType: [],
  40. ZSShapeType: [],
  41. ZSColorType: [],
  42. ZSClarityType: [],
  43. ZSCutType: [],
  44. ZSSymmetryType: [],
  45. ZSPolishType: [],
  46. ZSFluorescenceType: [],
  47. Size: [],
  48. ZSCrystalType: [],
  49. Origin: '',
  50. ZSStyleType: [],
  51. ZSCZColor1Type: [],
  52. })
  53. const enums = {
  54. categoryList: getCategoryList(),
  55. currencyTypeList: getCurrencyTypeList(),
  56. shapeTypeList: getShapeTypeList(),
  57. colorTypeList: getColorTypeList(),
  58. cutTypeList: getCutTypeList(),
  59. clarityTypeList: getClarityTypeList(),
  60. polishTypeList: getPolishTypeList(),
  61. symmetryTypeList: getSymmetryTypeList(),
  62. fluorescenceTypeList: getFluorescenceTypeList(),
  63. crystalTypeList: getCrystalTypeList(),
  64. fancyColorType1List: getFancyColorType1List(),
  65. styleTypeList: getStyleTypeList(),
  66. }
  67. const formSubmit = () => {
  68. loading.value = true
  69. if (formData.Size.some((val) => !val)) {
  70. formData.Size = []
  71. }
  72. return zsBuyOrderListing({
  73. data: {
  74. Header: {
  75. AccountID: AccountIDs[0],
  76. },
  77. UserID,
  78. AccountID: AccountIDs[0],
  79. MarketID: Market.GZ,
  80. OrderSrc: 2,
  81. ClientType: ClientType.Web,
  82. ClientSerialNo: v4(),
  83. PerformanceTemplateID: performanceId.value,
  84. GZ_BuyOrderDetailExInfo: formData
  85. },
  86. complete: () => {
  87. loading.value = false
  88. }
  89. })
  90. }
  91. return {
  92. loading,
  93. performanceId,
  94. currencyId,
  95. formData,
  96. enums,
  97. formSubmit,
  98. }
  99. }
  100. /**
  101. * 出售大厅挂牌
  102. * @returns
  103. */
  104. export function useSellOrderListing() {
  105. const { dataList } = useDataTable<Ermcp.MyWRPositionRsp>()
  106. const { UserID, AccountIDs } = sessionData.getValue('loginInfo')
  107. const submitLoading = shallowRef(false)
  108. const tableLoading = shallowRef(false)
  109. const columns = shallowRef<Ermcp.TableColumn[]>([])
  110. const categoryList = getCategoryList() // 分类列表
  111. const selectedCategoryId = shallowRef(Category.Diamonds)
  112. const formData = reactive<Proto.ZSSellOrderListingReq>({
  113. Header: {
  114. AccountID: AccountIDs[0],
  115. },
  116. UserID,
  117. AccountID: AccountIDs[0],
  118. WRStandardID: 0,
  119. OrderQty: 0,
  120. LadingBillID: Long.fromNumber(0),
  121. SubNum: 0,
  122. TimevalidType: 4, // 4:一直有效
  123. OrderSrc: 2,
  124. ClientSerialNo: '',
  125. ClientOrderTime: '',
  126. ClientType: ClientType.Web,
  127. MarketID: Market.GZ,
  128. })
  129. // 获取商品列表
  130. const getDiamondList = () => {
  131. dataList.value = []
  132. formData.WRStandardID = 0
  133. tableLoading.value = true
  134. queryDiamondList({
  135. data: {
  136. wruserid: UserID,
  137. zscategory: selectedCategoryId.value,
  138. },
  139. success: (res) => {
  140. dataList.value = res.data.filter((e) => e.ftotalqty - e.ffreezeqty > 0)
  141. },
  142. complete: () => {
  143. tableLoading.value = false
  144. }
  145. })
  146. }
  147. // 切换商品分类
  148. const categoryChange = () => {
  149. switch (selectedCategoryId.value) {
  150. case Category.Diamonds: {
  151. columns.value = [
  152. {
  153. prop: 'goodsno',
  154. label: '商品编号',
  155. show: true,
  156. },
  157. {
  158. prop: 'price',
  159. label: '总价',
  160. show: true,
  161. },
  162. {
  163. prop: 'weight',
  164. label: '总重量',
  165. show: true,
  166. },
  167. {
  168. prop: 'weightavg',
  169. label: '平均单颗重量',
  170. show: true,
  171. },
  172. {
  173. prop: 'priceper',
  174. label: '克拉单位',
  175. show: true,
  176. },
  177. {
  178. prop: 'ftotalqty',
  179. label: '库存重量',
  180. show: true,
  181. },
  182. {
  183. prop: 'remainqty',
  184. label: '剩余重量',
  185. show: true,
  186. },
  187. {
  188. prop: 'zsshapetypedisplay',
  189. label: '形状',
  190. show: true,
  191. width: 200,
  192. },
  193. {
  194. prop: 'zscolortype',
  195. label: '颜色',
  196. show: true,
  197. },
  198. {
  199. prop: 'zsclaritytype',
  200. label: '净度',
  201. show: true,
  202. }
  203. ]
  204. break
  205. }
  206. case Category.Diamond: {
  207. columns.value = [
  208. {
  209. prop: 'goodsno',
  210. label: '商品编号',
  211. show: true,
  212. },
  213. {
  214. prop: 'price',
  215. label: '价格',
  216. show: true,
  217. },
  218. {
  219. prop: 'weight',
  220. label: '克拉重量',
  221. show: true,
  222. },
  223. {
  224. prop: 'priceper',
  225. label: '克拉单位',
  226. show: true,
  227. },
  228. {
  229. prop: 'zsshapetypedisplay',
  230. label: '形状',
  231. width: 200,
  232. show: true,
  233. },
  234. {
  235. prop: 'zscolortype1display',
  236. label: '颜色',
  237. show: true,
  238. },
  239. {
  240. prop: 'zsclaritytype1display',
  241. label: '净度',
  242. show: true,
  243. }
  244. ]
  245. break
  246. }
  247. case Category.Rough: {
  248. columns.value = [
  249. {
  250. prop: 'goodsno',
  251. label: '商品编号',
  252. show: true,
  253. },
  254. {
  255. prop: 'price',
  256. label: '总价',
  257. show: true,
  258. },
  259. {
  260. prop: 'weight',
  261. label: '总重量',
  262. show: true,
  263. },
  264. {
  265. prop: 'weightavg',
  266. label: '平均单颗重量',
  267. show: true,
  268. },
  269. {
  270. prop: 'priceper',
  271. label: '克拉单位',
  272. show: true,
  273. },
  274. {
  275. prop: 'ftotalqty',
  276. label: '库存重量',
  277. show: true,
  278. },
  279. {
  280. prop: 'remainqty',
  281. label: '剩余重量',
  282. show: true,
  283. },
  284. {
  285. prop: 'zscrystaltypedisplay',
  286. label: '晶型',
  287. width: 200,
  288. show: true,
  289. },
  290. {
  291. prop: 'zscolortype',
  292. label: '颜色',
  293. show: true,
  294. },
  295. {
  296. prop: 'zsclaritytype',
  297. label: '净度',
  298. show: true,
  299. }
  300. ]
  301. break
  302. }
  303. case Category.Jewelry: {
  304. columns.value = [
  305. {
  306. prop: 'goodsno',
  307. label: '商品编号',
  308. show: true,
  309. },
  310. {
  311. prop: 'price',
  312. label: '价格',
  313. show: true,
  314. },
  315. {
  316. prop: 'weight',
  317. label: '主石重量',
  318. show: true,
  319. },
  320. {
  321. prop: 'priceper',
  322. label: '克拉单位',
  323. show: true,
  324. },
  325. {
  326. prop: 'zsstyletypedisplay',
  327. label: '款式',
  328. width: 200,
  329. show: true,
  330. },
  331. {
  332. prop: 'zsstyletypedisplay',
  333. label: '主石形状',
  334. width: 200,
  335. show: true,
  336. },
  337. {
  338. prop: 'zsclaritytype1display',
  339. label: '主石净度',
  340. show: true,
  341. },
  342. {
  343. prop: 'zscuttype1display',
  344. label: '主石切工',
  345. show: true,
  346. },
  347. {
  348. prop: 'zssymmetrytype1display',
  349. label: '主石对称度',
  350. show: true,
  351. }
  352. ]
  353. break
  354. }
  355. case Category.Fancy: {
  356. columns.value = [
  357. {
  358. prop: 'goodsno',
  359. label: '商品编号',
  360. show: true,
  361. },
  362. {
  363. prop: 'price',
  364. label: '价格',
  365. show: true,
  366. },
  367. {
  368. prop: 'weight',
  369. label: '克拉重量',
  370. show: true,
  371. },
  372. {
  373. prop: 'priceper',
  374. label: '克拉单位',
  375. show: true,
  376. },
  377. {
  378. prop: 'zsshapetypedisplay',
  379. label: '形状',
  380. width: 200,
  381. show: true,
  382. },
  383. {
  384. prop: 'zsczcolortype',
  385. label: '颜色',
  386. width: 200,
  387. show: true,
  388. },
  389. {
  390. prop: 'zsclaritytype1display',
  391. label: '净度',
  392. show: true,
  393. }
  394. ]
  395. break
  396. }
  397. }
  398. getDiamondList()
  399. }
  400. const formSubmit = () => {
  401. submitLoading.value = true
  402. return zsSellOrderListing({
  403. data: {
  404. ...formData,
  405. ClientSerialNo: v4(),
  406. ClientOrderTime: moment().format('YYYY-MM-DD HH:mm:ss')
  407. },
  408. complete: () => {
  409. submitLoading.value = false
  410. }
  411. })
  412. }
  413. // 初始化
  414. categoryChange()
  415. return {
  416. submitLoading,
  417. tableLoading,
  418. formData,
  419. dataList,
  420. columns,
  421. categoryList,
  422. selectedCategoryId,
  423. categoryChange,
  424. formSubmit,
  425. }
  426. }