index.js 4.21 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
let app = getApp()
const { spokesmanApi, DFSImg, $themeToLink } = app;
const componentOptions = {
  // 组件选项
  options: {
    multipleSlots: true
  },
  behaviors: [],
  properties: {
    datas: {
      type: Object
    },
    scrollContent:{
      type:String,
      default:''
    },
  },
  // 组件数据
  data: {
    isPageHidden: false, // 页面是否处于隐藏状态
    query: {
      pageSize: 9999,
      pageNum: 1,
      productCategoryId: '',
张卓 committed
25
      // distributorHomepageId: '1',//分销商主页ID ,
26 27 28
      goodsNameOrCode: '',//商品名或编码 ,
      hotRecommendFlag: 1,//是否热门推荐(0:否,1:是) ,
    },
张卓 committed
29 30
    spokesmanInfo: {},
    parentSpokesmanHandImage: '11111111',
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90
    lists: [],
    isShow: ''
  },
  // 数据监听器
  observers: {
    scrollContent(scrollContent) {
      console.log(scrollContent,555555555)
    }
  },
  // 组件生命周期
  lifetimes: {
    created() {},
    ready() {
      // let $scrollContent = document.querySelector(this.scrollContent);
      // $scrollContent.on('scroll', e => {
      //   if($scrollContent.scrollTop() > 24) {
      //     this.setData({ isShow: "is_show" });
      //   }else {
      //     this.setData({ isShow: "" });
      //   }
      // });
      // console.log(this.data.scrollContent,555555555)
      this.init()
    },
    moved() {},
    detached() {}
  },
  attached() {
  },
  definitionFilter() {},
  onPageScroll() {
    // console.log(e,444444444444);
  },
  // 页面生命周期
  pageLifetimes: {
    // 页面被展示
    show() {
      const { isPageHidden } = this.data;

      // show事件发生前,页面不是处于隐藏状态时
      if (!isPageHidden) {
        return;
      }

      // 重新执行定时器等操作
    },
    // 页面被隐藏
    hide() {
      this.setData({
        isPageHidden: true
      });

      // 清除定时器等操作
    },
    // 页面尺寸变化时
    resize() {}
  },
  // 组件方法
  methods: {
    init() {
张卓 committed
91 92 93
      this.setData({ spokesmanInfo: app.fenxiaoModel.spokesmanInfo });
      this.spokesmanInfo = app.fenxiaoModel.spokesmanInfo;
      let parentSpokesmanHandImage = DFSImg(app.fenxiaoModel.spokesmanInfo.parentSpokesmanHandImage);
张卓 committed
94 95 96 97 98
      this.setData({parentSpokesmanHandImage: parentSpokesmanHandImage});
      let query = {
        ...this.data.query,
        distributorHomepageId: this.spokesmanInfo.distributorHomepage.id,
      }
张卓 committed
99
      console.log(query,555555777777)
张卓 committed
100 101
      app.fenxiaoModel.getDistributorHomepageGoodsList(query).then(res=>{
        if(res) {
102
          let lists = [];
张卓 committed
103
          let num = Math.ceil(res.length/3);
104 105 106
          for(let i = 0; i < num; i++) {
            lists.push(new Array());
          }
张卓 committed
107
          res.forEach((ele,index)=>{
108 109 110
            ele.terminalProductGoods.imgUrl = DFSImg(ele.terminalProductGoods.imgUrl)
            ele.terminalProductGoods.discountPrice = (ele.terminalProductGoods.discountPrice-0).toFixed(2)
            ele.terminalProductGoods.salePrice = (ele.terminalProductGoods.salePrice-0).toFixed(2)
111
            ele.terminalProductGoods.discountPriceToatal = (ele.terminalProductGoods.salePrice-ele.terminalProductGoods.discountPrice).toFixed(2)
112 113 114 115 116 117 118 119
            let flag = Math.ceil((index+1)/3)
            lists[flag-1].push(ele)
          })
          // this.data.lists = lists;
          this.setData({ lists: lists });
        }
      })
    },
侯体倬 committed
120
    toSpokesmanHomePage(e) {
121
      let linkVal = '/personalCenter/spokesmanCenter/mine/spokesmanHomePage?from=_goodsInfo'
侯体倬 committed
122
      app.trackCpn(e, this.data.datas.componentName)
123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143
      $themeToLink({
        type: 1,
        link:linkVal,
      });
    },
    getScroll(el) {
      // console.log(el.scrollTop,555555555,this.data.isShow)
      if(el.scrollTop > 24) {
        if(this.data.isShow == 'is_show') {
          return
        }
        this.setData({ isShow: "is_show" });
      }else {
        if(this.data.isShow) {
          this.setData({ isShow: "" });
        }
      }
    },
    toGoodsInfo(event) {
      const item = event.currentTarget.dataset.item;
      let linkVal = `/goods/${item.terminalProductGoods.productId}`
侯体倬 committed
144
      app.trackCpn(event, this.data.datas.componentName, item)
145 146 147 148 149 150 151 152 153 154 155
      $themeToLink({
        type: 1,
        link:linkVal,
      });
    }
  }
};

Component(componentOptions);