index.ts 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287
  1. import { shallowRef, reactive, computed } from 'vue'
  2. import { v4 } from 'uuid'
  3. import { useDataTable } from '@/hooks/datatable'
  4. import { getTableColumns } from '@/business/table'
  5. import { formatDecimal } from '@/filters'
  6. import { ClientType } from '@/constants/client'
  7. import { Market } from '@/constants/market'
  8. import { queryWarehouseInfo } from '@/services/api/warehouse'
  9. import { addZSGoods, queryDiamondList, queryDiamondDetails } from '@/services/api/goods'
  10. import { sessionData } from '@/stores'
  11. import {
  12. Category,
  13. getCategoryList,
  14. getCurrencyTypeList,
  15. getShapeTypeList,
  16. getColorTypeList,
  17. getCutTypeList,
  18. getClarityTypeList,
  19. getPolishTypeList,
  20. getSymmetryTypeList,
  21. getFluorescenceTypeList,
  22. getCurrencyTypeInfo,
  23. getCertTypeList,
  24. getCrystalTypeList,
  25. getStyleTypeList,
  26. getFancyColorType1List,
  27. getFancyColorType2List,
  28. getFancyColorType3List,
  29. } from '@/constants/diamond'
  30. // 钻石列表相关
  31. export function useDiamond() {
  32. const { UserID } = sessionData.getValue('loginInfo')
  33. const { dataList, total, pageIndex, pageSize, inputList, selectList, buttonList, getQueryParam } = useDataTable<Ermcp.MyWRPositionRsp>()
  34. const loading = shallowRef(false)
  35. const columns = getTableColumns('warehousingDiamond')
  36. selectList.value = [
  37. {
  38. label: '商品分类',
  39. key: 'zscategory',
  40. selectedValue: Category.Diamonds,
  41. options: getCategoryList(),
  42. },
  43. {
  44. label: '仓库',
  45. key: 'warehouseid',
  46. options: [],
  47. },
  48. ]
  49. inputList.value = [
  50. { label: '商品', keys: ['goodsno'] },
  51. ]
  52. const getDiamondList = () => {
  53. const param = getQueryParam()
  54. loading.value = true
  55. return queryDiamondList({
  56. data: {
  57. page: pageIndex.value,
  58. pagesize: pageSize.value,
  59. wruserid: UserID,
  60. zscategory: selectList.value[0].selectedValue as Ermcp.MyWRPositionRsp['zscategory'],
  61. zsallproperties: param.goodsno,
  62. warehouseid: param.warehouseid,
  63. },
  64. success: (res) => {
  65. total.value = res.total
  66. dataList.value = res.data
  67. },
  68. fail: () => {
  69. dataList.value = []
  70. },
  71. complete: () => {
  72. loading.value = false
  73. }
  74. })
  75. }
  76. const [reset, search] = buttonList.value
  77. reset.onClick = () => {
  78. selectList.value.forEach((e, i) => {
  79. if (i) {
  80. e.selectedValue = undefined
  81. }
  82. })
  83. inputList.value.forEach((e) => e.value = undefined)
  84. getDiamondList()
  85. }
  86. search.onClick = getDiamondList
  87. // 获取仓库列表
  88. queryWarehouseInfo({
  89. data: {
  90. userid: UserID,
  91. status: 1,
  92. isincludeexchange: true,
  93. },
  94. success: (res) => {
  95. const warehouse = selectList.value[1]
  96. res.data.forEach((e) => {
  97. warehouse.options.push({
  98. label: e.warehousename,
  99. value: e.autoid
  100. })
  101. })
  102. }
  103. })
  104. return {
  105. loading,
  106. dataList,
  107. total,
  108. pageIndex,
  109. pageSize,
  110. columns,
  111. inputList,
  112. selectList,
  113. buttonList,
  114. getDiamondList,
  115. }
  116. }
  117. // 钻石详情相关
  118. export function useDiamondDetails(goodsno: string) {
  119. const loading = shallowRef(false)
  120. const details = shallowRef<Ermcp.DiamondDetailsRsp>()
  121. const getDiamondDetails = () => {
  122. loading.value = true
  123. return queryDiamondDetails({
  124. data: {
  125. goodsno,
  126. },
  127. success: (res) => {
  128. details.value = res.data
  129. },
  130. complete: () => {
  131. loading.value = false
  132. }
  133. })
  134. }
  135. return {
  136. loading,
  137. details,
  138. getDiamondDetails
  139. }
  140. }
  141. // 钻石表单操作相关
  142. export function useDiamondForm(category: Category) {
  143. const { UserID, AccountIDs } = sessionData.getValue('loginInfo')
  144. const loading = shallowRef(false)
  145. const warehouseList = shallowRef<Ermcp.WarehouseInfoRsp[]>([]) // 仓库列表
  146. const performanceId = shallowRef<number>() // 选中的履约模板ID
  147. const shapeId = shallowRef<number>() // 选中的形状ID
  148. const formData = reactive<Partial<Proto.GZWRStandardExInfo>>({
  149. ZSCategory: category,
  150. })
  151. // 选中的枚举类型
  152. const selectedType = reactive({
  153. colorType: computed({
  154. get: () => [formData.ZSColorType1, formData.ZSColorType2],
  155. set: (val) => {
  156. formData.ZSColorType1 = val[0]
  157. formData.ZSColorType2 = val[1]
  158. }
  159. }),
  160. cutType: computed({
  161. get: () => [formData.ZSCutType1, formData.ZSCutType2],
  162. set: (val) => {
  163. formData.ZSCutType1 = val[0]
  164. formData.ZSCutType2 = val[1]
  165. }
  166. }),
  167. clarityType: computed({
  168. get: () => [formData.ZSClarityType1, formData.ZSClarityType2],
  169. set: (val) => {
  170. formData.ZSClarityType1 = val[0]
  171. formData.ZSClarityType2 = val[1]
  172. }
  173. }),
  174. polishType: computed({
  175. get: () => [formData.ZSPolishType1, formData.ZSPolishType2],
  176. set: (val) => {
  177. formData.ZSPolishType1 = val[0]
  178. formData.ZSPolishType2 = val[1]
  179. }
  180. }),
  181. symmetryType: computed({
  182. get: () => [formData.ZSSymmetryType1, formData.ZSSymmetryType2],
  183. set: (val) => {
  184. formData.ZSSymmetryType1 = val[0]
  185. formData.ZSSymmetryType2 = val[1]
  186. }
  187. }),
  188. fluorescenceType: computed({
  189. get: () => [formData.ZSFluorescenceType1, formData.ZSFluorescenceType2],
  190. set: (val) => {
  191. formData.ZSFluorescenceType1 = val[0]
  192. formData.ZSFluorescenceType2 = val[1]
  193. }
  194. }),
  195. })
  196. // 枚举类型列表
  197. const enums = {
  198. currencyTypeList: getCurrencyTypeList(),
  199. shapeTypeList: getShapeTypeList(),
  200. colorTypeList: getColorTypeList(),
  201. cutTypeList: getCutTypeList(),
  202. clarityTypeList: getClarityTypeList(),
  203. polishTypeList: getPolishTypeList(),
  204. symmetryTypeList: getSymmetryTypeList(),
  205. fluorescenceTypeList: getFluorescenceTypeList(),
  206. certTypeList: getCertTypeList(),
  207. crystalTypeList: getCrystalTypeList(),
  208. styleTypeList: getStyleTypeList(),
  209. fancyColorType1List: getFancyColorType1List(),
  210. fancyColorType2List: getFancyColorType2List(),
  211. fancyColorType3List: getFancyColorType3List(),
  212. }
  213. if (enums.currencyTypeList.length) {
  214. formData.ZSCurrencyType = enums.currencyTypeList[0].value
  215. }
  216. // 克拉单位
  217. const caratUnit = computed(() => {
  218. const { Price, Weight } = formData
  219. if (Price && Weight) {
  220. return formatDecimal(Price / Weight)
  221. }
  222. return '0.00'
  223. })
  224. // 货币信息
  225. const currencyInfo = computed(() => getCurrencyTypeInfo(formData.ZSCurrencyType ?? 0))
  226. const formSubmit = () => {
  227. loading.value = true
  228. return addZSGoods({
  229. data: {
  230. UserID,
  231. AccountID: AccountIDs[0],
  232. AddType: performanceId.value ? 2 : 1,
  233. MarketID: Market.GZ,
  234. OrderSrc: 2,
  235. ClientType: ClientType.Web,
  236. ClientSerialNo: v4(),
  237. GZ_WRStandardExInfo: formData,
  238. PerformanceTemplateID: performanceId.value,
  239. },
  240. complete: () => {
  241. loading.value = false
  242. }
  243. })
  244. }
  245. // 获取仓库列表
  246. queryWarehouseInfo({
  247. data: {
  248. userid: UserID,
  249. status: 1,
  250. isincludeexchange: true,
  251. },
  252. success: (res) => {
  253. warehouseList.value = res.data
  254. }
  255. })
  256. return {
  257. loading,
  258. formData,
  259. performanceId,
  260. shapeId,
  261. caratUnit,
  262. enums,
  263. selectedType,
  264. warehouseList,
  265. currencyInfo,
  266. formSubmit,
  267. }
  268. }