chooseList.js 1.8 KB
import {
  request
} from "../../request/index.js";
// pages/chooseList/chooseList.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    pinData: [],
    selected: '',
    // 品牌|车系
    title: '',
    leftWrapH: 0
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    console.log(options)
    let listType = options.listType
    let brandId = options.brandId
    let that = this
    // 计算滚动区域长度
    wx.getSystemInfo({
      success: function (res) {
        that.setData({
          leftWrapH: res.windowHeight * 2
        })
      }
    })
    if (listType == 1) {
      this.setData({
        title: '品牌'
      })
      this.getData(listType)
    } else {
      this.setData({
        title: '车系'
      })
      this.getData2(listType,brandId)
    }
  },
  // 获取品牌
  getData(t) {
    request({
      url: '/api/h5/pinData' + t
    }).then((res) => {
      this.setData({
        pinData: res.data.data
      })
    })
  },
  // 获取车系
  getData2(t,b) {
    request({
      url: '/api/h5/pinData' + t,
      data:{
        id:b
      }
    }).then((res) => {
      this.setData({
        pinData: res.data.data
      })
    })
  },
  // 获取锚点
  point(e) {
    this.setData({
      selected: e.currentTarget.dataset.idx,
    })

  },
  //点击携带参数返回上页
  takeitback(e) {
    let name = e.currentTarget.dataset.name
    let id = e.currentTarget.dataset.id
    console.log(name, id)
    wx.setStorageSync('brand', name)
    wx.setStorageSync('brandId', id)
    wx.navigateBack({
      delta: 1,
    })
  },
  takeitback2(e){
    let name2 = e.currentTarget.dataset.name
    let id2 = e.currentTarget.dataset.id
    wx.setStorageSync('brand2', name2)
    wx.setStorageSync('brandId2', id2)
    wx.navigateBack({
      delta: 1,
    })
  }
  
})