index.ts 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236
  1. import { shallowRef } from 'vue'
  2. import { useDataTable } from '@/hooks/datatable'
  3. import { queryTHJWrstandard, queryTHJWrstandardDetail, addUserFavoriteGoods, removeUserFavoriteGoods, queryTHJProduct, queryMarketRun, queryTHJTradeData, querySpotGoodsPrice } from '@/services/api/goods'
  4. import { useLoginStore } from '@/stores'
  5. // 采购列表
  6. export function useWrstandardList() {
  7. const { dataList, total, pageIndex, pageSize, pageCount } = useDataTable<Model.THJWrstandardRsp>()
  8. const loading = shallowRef(false)
  9. const getWrstandardList = async () => {
  10. loading.value = true
  11. await queryTHJWrstandard({
  12. data: {
  13. page: pageIndex.value,
  14. pagesize: pageSize.value,
  15. },
  16. success: (res) => {
  17. total.value = res.total
  18. dataList.value = res.data
  19. },
  20. complete: () => {
  21. loading.value = false
  22. }
  23. })
  24. return dataList.value
  25. }
  26. return {
  27. loading,
  28. dataList,
  29. total,
  30. pageIndex,
  31. pageSize,
  32. pageCount,
  33. getWrstandardList,
  34. }
  35. }
  36. // 采购详细
  37. export function useWrstandardDetails(wrstandardid: number) {
  38. const details = shallowRef<Partial<Model.THJWrstandardDetailRsp>>({})
  39. const getWrstandardDetails = () => {
  40. return queryTHJWrstandardDetail({
  41. data: {
  42. wrstandardid,
  43. },
  44. success: (res) => {
  45. details.value = res.data
  46. }
  47. })
  48. }
  49. return {
  50. details,
  51. getWrstandardDetails,
  52. }
  53. }
  54. // 添加用户商品收藏信息
  55. export function useAddUserFavoriteGoods(goodsid: number) {
  56. const { getUserId } = useLoginStore()
  57. const getAddUserFavoriteGoods = () => {
  58. return addUserFavoriteGoods({
  59. data: {
  60. userID: getUserId(),
  61. goodsID: goodsid
  62. },
  63. success: (res) => { console.log(res) }
  64. })
  65. }
  66. return { getAddUserFavoriteGoods }
  67. }
  68. // 移除用户商品收藏信息
  69. export function useRemoveUserFavoriteGoods(goodsid: number) {
  70. const { getUserId } = useLoginStore()
  71. const getRemoveUserFavoriteGoods = () => {
  72. return removeUserFavoriteGoods({
  73. data: {
  74. userID: getUserId(),
  75. goodsID: goodsid
  76. },
  77. success: (res) => { console.log(res) }
  78. })
  79. }
  80. return { getRemoveUserFavoriteGoods }
  81. }
  82. // 获取我的推广-交易数据
  83. export function useQueryTHJTradeDataList() {
  84. const { dataList, total, pageIndex, pageSize, pageCount } = useDataTable<Model.THJTradeDataRsp>()
  85. const loading = shallowRef(false)
  86. const { getUserId } = useLoginStore()
  87. const getQueryTHJTradeDataList = async (marketid: number) => {
  88. loading.value = true
  89. await queryTHJTradeData({
  90. data: {
  91. userid: getUserId(),
  92. marketid: marketid,
  93. page: pageIndex.value,
  94. pagesize: pageSize.value,
  95. },
  96. success: (res) => {
  97. total.value = res.total
  98. dataList.value = res.data
  99. },
  100. complete: () => {
  101. loading.value = false
  102. }
  103. })
  104. return dataList.value
  105. }
  106. return {
  107. loading,
  108. dataList,
  109. total,
  110. pageIndex,
  111. pageSize,
  112. pageCount,
  113. getQueryTHJTradeDataList,
  114. }
  115. }
  116. // 获取产品介绍列表
  117. export function useQueryTHJProductLists() {
  118. const { dataList, total, pageIndex, pageSize, pageCount } = useDataTable<Model.THJProductRsp>()
  119. const loading = shallowRef(false)
  120. const { getUserId } = useLoginStore()
  121. const active = shallowRef(0)
  122. const getQueryTHJProductLists = async () => {
  123. loading.value = true
  124. await queryTHJProduct({
  125. data: {
  126. userid: getUserId(),
  127. favoriteflag: active.value === 0,
  128. page: pageIndex.value,
  129. pagesize: pageSize.value,
  130. },
  131. success: (res) => {
  132. total.value = res.total
  133. dataList.value = res.data
  134. },
  135. complete: () => {
  136. loading.value = false
  137. }
  138. })
  139. return dataList.value
  140. }
  141. return {
  142. loading,
  143. dataList,
  144. active,
  145. total,
  146. pageIndex,
  147. pageSize,
  148. pageCount,
  149. getQueryTHJProductLists,
  150. }
  151. }
  152. // 获取现货行情
  153. export function useQuerySpotGoodsPriceLists() {
  154. const { dataList, total, pageIndex, pageSize, pageCount } = useDataTable<Model.SpotGoodsPriceRsp>()
  155. const loading = shallowRef(false)
  156. const getQuerySpotGoodsPriceLists = () => {
  157. loading.value = true
  158. return querySpotGoodsPrice({
  159. data: {
  160. page: pageIndex.value,
  161. pagesize: pageSize.value,
  162. },
  163. success: (res) => {
  164. total.value = res.total
  165. dataList.value = res.data
  166. },
  167. complete: () => {
  168. loading.value = false
  169. }
  170. })
  171. }
  172. return {
  173. loading,
  174. dataList,
  175. total,
  176. pageIndex,
  177. pageSize,
  178. pageCount,
  179. getQuerySpotGoodsPriceLists,
  180. }
  181. }
  182. // 查询市场运行信息
  183. export function useQueryMarketRunLists() {
  184. const { dataList, total, pageIndex, pageSize, pageCount } = useDataTable<Model.MarketRunRsp>()
  185. const loading = shallowRef(false)
  186. const getQueryMarketRunLists = (marketid?: number) => {
  187. loading.value = true
  188. return queryMarketRun({
  189. data: {
  190. marketID: marketid
  191. },
  192. success: (res) => {
  193. total.value = res.total
  194. dataList.value = res.data
  195. },
  196. complete: () => {
  197. loading.value = false
  198. }
  199. })
  200. }
  201. return {
  202. loading,
  203. dataList,
  204. total,
  205. pageIndex,
  206. pageSize,
  207. pageCount,
  208. getQueryMarketRunLists,
  209. }
  210. }