product-page.ts 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346
  1. import {
  2. getDyLiveList,
  3. getDyProductList,
  4. getJdProductList,
  5. getPddProductList,
  6. getSuProductList, getTaobaoProductList, getVipProductList,
  7. searchProductList
  8. } from "~/apis/product";
  9. import type {
  10. DyProductModel, IProductDetail,
  11. JdProductModel, SuNingProductModel,
  12. TaobaoProductDetailModel,
  13. TaobaoProductThirdPartyWaresModel, VipProductModel
  14. } from "~/apis/model/product.model";
  15. import {getDcProductList} from "~/apis/dacang";
  16. import type {DcProductModel} from "~/apis/model/dacang.model";
  17. import {encodeBase64} from "~/utils/http/helper";
  18. import {PLATFORM_NAME} from "~/apis/model/common.model";
  19. import {CDN_URL} from "~/config/app";
  20. interface TabItem {
  21. id: PLATFORM_NAME,
  22. text: string,
  23. iconPath: string,
  24. selectedIconPath: string
  25. }
  26. const tabList = <Array<TabItem>>[{
  27. id: PLATFORM_NAME.JD,
  28. text: '京东',
  29. iconPath: CDN_URL + '/static/assets/jingdong_x.png',
  30. selectedIconPath: CDN_URL + '/static/assets/jingdong_d.png',
  31. }, {
  32. id: PLATFORM_NAME.TB,
  33. text: '淘宝',
  34. iconPath: CDN_URL + '/static/assets/taobaoyanglao_x.png',
  35. selectedIconPath: CDN_URL + '/static/assets/taobaoyanglao_d.png',
  36. }, {
  37. id: PLATFORM_NAME.PDD,
  38. text: '拼多多',
  39. iconPath: CDN_URL + '/static/assets/pinduoduo_x.png',
  40. selectedIconPath: CDN_URL + '/static/assets/pinduoduo_d.png',
  41. }, {
  42. id: PLATFORM_NAME.DC,
  43. text: '大仓',
  44. iconPath: CDN_URL + '/static/assets/dacang_x_220914.png',
  45. selectedIconPath: CDN_URL + '/static/assets/dacang_d_220914.png',
  46. }, {
  47. id: PLATFORM_NAME.DY,
  48. text: '抖音',
  49. iconPath: CDN_URL + '/static/assets/douyin_x_230313.png',
  50. selectedIconPath: CDN_URL + '/static/assets/douyin_d_230313.png',
  51. }, {
  52. id: PLATFORM_NAME.VIP,
  53. text: '唯品会',
  54. iconPath: CDN_URL + '/static/assets/weipinhui_x.png',
  55. selectedIconPath: CDN_URL + '/static/assets/weipinhui_d.png',
  56. }, {
  57. id: PLATFORM_NAME.SU,
  58. text: '苏宁',
  59. iconPath: CDN_URL + '/static/assets/suningyigou_x.png',
  60. selectedIconPath: CDN_URL + '/static/assets/suningyigou_d.png',
  61. }]
  62. const state = reactive({
  63. currentTab: PLATFORM_NAME.JD
  64. })
  65. onLoad((options) => {
  66. const platform = options.platform
  67. if (platform) {
  68. state.currentTab = platform
  69. loadProductList(state.currentTab)
  70. }
  71. })
  72. const list = ref<Array<
  73. JdProductModel
  74. | DcProductModel
  75. | DyProductModel
  76. | SuNingProductModel
  77. | TaobaoProductThirdPartyWaresModel
  78. | VipProductModel
  79. | any
  80. >>()
  81. const dyLiveList = ref<Array<DyProductModel>>()
  82. export function loadProductList(platform: PLATFORM_NAME) {
  83. switch (platform) {
  84. case PLATFORM_NAME.JD: {
  85. getJdProductList({
  86. page: 1,
  87. limit: 10
  88. }).then(res => {
  89. list.value = res
  90. // res[0].
  91. // console.log(res)
  92. })
  93. break;
  94. }
  95. case PLATFORM_NAME.DC: {
  96. getDcProductList({
  97. page: 1,
  98. limit: 10,
  99. classify: '',
  100. keyword: ''
  101. }).then(res => {
  102. list.value = res
  103. })
  104. break;
  105. }
  106. case PLATFORM_NAME.DY: {
  107. getDyLiveList({
  108. page: 1,
  109. limit: 4,
  110. // keyword: ''
  111. }).then(res => {
  112. // console.log(res)
  113. // console.log(res.authorPic)
  114. })
  115. getDyLiveList({page: 1,limit: 4})
  116. .then(res => {
  117. // console.log(res)
  118. if (res) {
  119. dyLiveList.value = res
  120. }
  121. })
  122. getDyProductList({
  123. page: 1,
  124. limit: 10,
  125. }).then(res => {
  126. list.value = res
  127. })
  128. break;
  129. }
  130. case PLATFORM_NAME.PDD: {
  131. getPddProductList({
  132. page: 1,
  133. limit: 10
  134. }).then(res => {
  135. list.value = res
  136. })
  137. break;
  138. }
  139. case PLATFORM_NAME.SU: {
  140. getSuProductList({
  141. page: 1,
  142. limit: 10
  143. }).then(res => {
  144. list.value = res
  145. console.log(res)
  146. })
  147. break;
  148. }
  149. case PLATFORM_NAME.TB: {
  150. getTaobaoProductList({
  151. pageNum: '1',
  152. pageSize: '10'
  153. }).then(res => {
  154. list.value = res.thirdPartyWaresList
  155. })
  156. break;
  157. }
  158. case PLATFORM_NAME.VIP: {
  159. getVipProductList({
  160. page: 1,
  161. limit: 10
  162. }).then(res => {
  163. list.value = res
  164. })
  165. break;
  166. }
  167. default: {
  168. // getJdProductList({
  169. // page: 1,
  170. // limit: 10
  171. // }).then(res => {
  172. // list.value = res
  173. // })
  174. }
  175. }
  176. }
  177. export function handleCategoryItemClick(item: TabItem) {
  178. state.currentTab = item.id
  179. loadProductList(item.id)
  180. }
  181. export function handleProductItemClick(
  182. item:
  183. JdProductModel
  184. & DcProductModel
  185. & DyProductModel
  186. & SuNingProductModel
  187. & TaobaoProductThirdPartyWaresModel
  188. & VipProductModel
  189. ) {
  190. console.log(item)
  191. function navigateToDetail(params) {
  192. let otherDetailUrl = `/pages/store/product/other`
  193. return uni.navigateTo({
  194. url: `${otherDetailUrl}?params=${params}`
  195. })
  196. }
  197. // 大仓
  198. if (state.currentTab === PLATFORM_NAME.DC && item.type === '5') {
  199. uni.navigateTo({
  200. url: `/pages/store/product/detail?id=${item.product_id}`
  201. })
  202. }
  203. // 京东
  204. if (item.type === 6) {
  205. // productParams.id = item.skuId
  206. const productParams: Partial<IProductDetail> = {
  207. platform: item.type,
  208. id: item.skuId,
  209. title: item.name,
  210. featured: [item.thumb],
  211. allowance: item.commission,
  212. salePrice: item.lowestCouponPrice,
  213. price: item.price,
  214. coupon: {
  215. amount: item.coupon_money[0].discount,
  216. startTime: item.coupon_money[0].getStartTime,
  217. endTime: item.coupon_money[0].getEndTime
  218. },
  219. spreadUrl: item.coupon_link
  220. }
  221. return navigateToDetail(encodeBase64(productParams))
  222. }
  223. // 淘宝
  224. if (item.type === 5) {
  225. const productParams: Partial<IProductDetail> = {
  226. platform: item.type,
  227. id: item.id,
  228. title: item.name,
  229. featured: [item.thumb],
  230. allowance: item.commission,
  231. salePrice: item.price,
  232. // 原价
  233. price: item.market_price,
  234. coupon: {
  235. amount: item.coupon_money
  236. // amount: item.coupon_money[0].discount,
  237. // startTime: item.coupon_money[0].getStartTime,
  238. // endTime: item.coupon_money[0].getEndTime
  239. },
  240. spreadUrl: item.coupon_share_url
  241. }
  242. return navigateToDetail(encodeBase64(productParams))
  243. // uni.navigateTo({
  244. // url: `/pages/store/product/other?platform=${item.type}&id=${item.id}`
  245. // })
  246. }
  247. // 拼多多
  248. if (item.type === 1) {
  249. const productParams: Partial<IProductDetail> = {
  250. platform: item.type,
  251. id: item.id,
  252. title: item.name,
  253. featured: [item.thumb],
  254. allowance: item.commission,
  255. salePrice: item.price,
  256. // 原价
  257. price: item.market_price,
  258. coupon: {
  259. amount: item.coupon_money
  260. // amount: item.coupon_money[0].discount,
  261. // startTime: item.coupon_money[0].getStartTime,
  262. // endTime: item.coupon_money[0].getEndTime
  263. },
  264. // spreadUrl: item.coupon_share_url
  265. }
  266. return navigateToDetail(encodeBase64(productParams))
  267. // uni.navigateTo({
  268. // url: `/pages/store/product/other?platform=${item.type}&id=${item.id}&allowance=${item.commission}`
  269. // })
  270. }
  271. // 唯品会
  272. if (item.type === 2) {
  273. const productParams: Partial<IProductDetail> = {
  274. platform: item.type,
  275. id: item.id,
  276. title: item.name,
  277. featured: [item.thumb],
  278. allowance: item.commission,
  279. salePrice: item.price,
  280. // 原价
  281. price: item.market_price,
  282. // coupon: {
  283. // amount: item.coupon_money
  284. // },
  285. }
  286. return navigateToDetail(encodeBase64(productParams))
  287. }
  288. // 苏宁
  289. if (item.type === 3) {
  290. const productParams: Partial<IProductDetail> = {
  291. platform: item.type,
  292. id: item.id,
  293. title: item.name,
  294. featured: [item.thumb],
  295. allowance: item.commission,
  296. salePrice: item.price,
  297. // 原价
  298. price: item.market_price,
  299. // coupon: {
  300. // amount: item.coupon_money
  301. // },
  302. }
  303. return navigateToDetail(encodeBase64(productParams))
  304. //
  305. }
  306. // 抖音 9
  307. if (item.type === 9) {
  308. console.log(item)
  309. const productParams: Partial<IProductDetail> = {
  310. platform: item.type,
  311. id: item.id,
  312. title: item.name,
  313. featured: [item.thumb],
  314. allowance: item.commission,
  315. salePrice: item.price,
  316. // 原价
  317. price: item.market_price,
  318. // coupon: {
  319. // amount: item.coupon_money
  320. // },
  321. }
  322. return navigateToDetail(encodeBase64(productParams))
  323. }
  324. }
  325. export function handleLiveRecommendTitleClick() {
  326. uni.navigateTo({
  327. url: `/pages/store/product/dy-live`
  328. })
  329. }