index.js 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. import { fetchCouponDetail } from '../../../services/coupon/index';
  2. import { fetchGoodsList } from '../../../services/good/fetchGoods';
  3. import Toast from 'tdesign-miniprogram/toast/index';
  4. Page({
  5. data: {
  6. goods: [],
  7. detail: {},
  8. couponTypeDesc: '',
  9. showStoreInfoList: false,
  10. cartNum: 2,
  11. },
  12. id: '',
  13. onLoad(query) {
  14. const id = parseInt(query.id);
  15. this.id = id;
  16. this.getCouponDetail(id);
  17. this.getGoodsList(id);
  18. },
  19. getCouponDetail(id) {
  20. fetchCouponDetail(id).then(({ detail }) => {
  21. this.setData({ detail });
  22. if (detail.type === 2) {
  23. if (detail.base > 0) {
  24. this.setData({
  25. couponTypeDesc: `满${detail.base / 100}元${detail.value}折`,
  26. });
  27. } else {
  28. this.setData({ couponTypeDesc: `${detail.value}折` });
  29. }
  30. } else if (detail.type === 1) {
  31. if (detail.base > 0) {
  32. this.setData({
  33. couponTypeDesc: `满${detail.base / 100}元减${detail.value / 100}元`,
  34. });
  35. } else {
  36. this.setData({ couponTypeDesc: `减${detail.value / 100}元` });
  37. }
  38. }
  39. });
  40. },
  41. getGoodsList(id) {
  42. fetchGoodsList(id).then((goods) => {
  43. this.setData({ goods });
  44. });
  45. },
  46. openStoreList() {
  47. this.setData({
  48. showStoreInfoList: true,
  49. });
  50. },
  51. closeStoreList() {
  52. this.setData({
  53. showStoreInfoList: false,
  54. });
  55. },
  56. goodClickHandle(e) {
  57. const { index } = e.detail;
  58. const { spuId } = this.data.goods[index];
  59. wx.navigateTo({ url: `/pages/goods/details/index?spuId=${spuId}` });
  60. },
  61. cartClickHandle() {
  62. Toast({
  63. context: this,
  64. selector: '#t-toast',
  65. message: '点击加入购物车',
  66. });
  67. },
  68. });