// components/buycar/buycar.js const axios = require('../../api/index') let http = require('../../utils/request') let loading = false Component({ /** * 组件的属性列表 */ properties: { }, /** * 组件的初始数据 */ data: { // 轮播 banner_img: [], // 人气数据 sentiment_list: [], // 获取列表 key: '', currentPage: 1, pageSize:5, list_total: 0, // 筛选 condition_list: [{ name: '分类', id: 0 }, { name: '品牌', id: 0 }, { name: '年限', id: 0 }, ], is_scrool_top: false, autoLoad: false, // 筛选的第几个 condition_idx: null, // 分类列表 classification_list: [], classification_idx: 0, classification_id: 0, // 品牌列表 brand_code:'',//品牌 brand_list: [], brand_idx: 0, brand_id: 0, // 年限列表 years_list: [], time_idx: 0, time_id: 0, // 商品列表 showlist: [], have_data: true, triggered: false, refresh: true, }, lifetimes: { created() { this.getEquipmentCategory(); this.getEquipmentBrand(); this.getyearsList(); this.get_list(); this.getSentiment(); this.getBanner(); }, attached: function () { // this.getSysdata() }, detached: function () { // 在组件实例被从页面节点树移除时执行 }, }, /** * 组件的方法列表 */ methods: { // 点击轮播 click_banner(e){ console.log(e.currentTarget.dataset.data) var data=(e.currentTarget.dataset.data) if(data.type==1){ console.log('电话') console.log(data.phone) wx.makePhoneCall({ phoneNumber: data.phone, }) }else if(data.type==2){ console.log('链接') let token = wx.getStorageSync('token') if (!token) { wx.navigateTo({ url: '/pages/login/login?isred=1', }) return } wx.navigateTo({ url:data.pageUrl, }) }else{ return } }, getSentiment() { var sentiment_list = wx.getStorageSync('sentiment') console.log(sentiment_list) if (!sentiment_list) { http.xhr({ url: 'api/v1/register/newusers' }).then(res => { console.log(res) var sentiment_list = res.data this.setData({ sentiment_list }) }).catch(err => { console.log(err) }) } else { setTimeout(() => { this.setData({ sentiment_list }) }, 0) } }, // 获取轮播 getBanner() { var banner_img = wx.getStorageSync('banner') if (!banner_img) { http.xhr({ url: 'api/v1/banners' }).then(res => { var banner_img = res.data this.setData({ banner_img }) }) } else { setTimeout(() => { this.setData({ banner_img }) }, 0) } }, // 获取分类列表 getEquipmentCategory() { var that = this axios.getEquipmentCategory().then(res => { console.log(res) var list = res.data list.unshift({ name: '全部分类', id: 0 }) wx.setStorage({ key: 'classification', data: res.data }) that.setData({ classification_list: res.data, }) }).catch(err => { console.log(err) }) }, // 获取品牌列表 getEquipmentBrand() { var that = this axios.getEquipmentBrand().then(res => { console.log(res) var list = res.data list.unshift({ name: '全部品牌', id: 0 }) wx.setStorage({ key: 'brand', data: res.data }) that.setData({ brand_list: res.data, }) }).catch(err => { console.log(err) }) // 根据分类查询品牌 // if(this.data.brand_code==''){ // axios.getEquipmentBrand().then(res => { // console.log(res) // var list = res.data // list.unshift({ // name: '全部品牌', // id: 0 // }) // wx.setStorage({ // key: 'brand', // data: res.data // }) // that.setData({ // brand_list: res.data, // }) // }).catch(err => { // console.log(err) // }) // }else{ // axios.getgetbrand_list(this.data.brand_code).then(res => { // console.log(res) // var list = res.data // list.unshift({ // name: '全部品牌', // id: 0 // }) // // wx.setStorage({ // // key: 'brand', // // data: res.data // // }) // that.setData({ // brand_list: res.data, // }) // }).catch(err => { // console.log(err) // }) // } }, // 获取品牌列表 getyearsList() { var that = this axios.getyearsList().then(res => { console.log(res) var list = res.data list.unshift({ name: '全部年限', id: 0 }) wx.setStorage({ key: 'years', data: res.data }) that.setData({ years_list: res.data, }) }).catch(err => { console.log(err) }) }, // 获取设备列表click_banner get_list() { var data = { key: this.data.key, categoryId: this.data.classification_id, brandId: this.data.brand_id, yearId: this.data.time_id, currentPage: this.data.currentPage, pageSize: this.data.pageSize } axios.getEquipmentSearch(data).then(res => { console.log(res) var list_total = res.data.total if(this.data.currentPage==1){ var list=res.data.list }else{ var list = [...this.data.showlist, ...res.data.list] } this.setData({ showlist: list, list_total, refresh: false, triggered: false }) }).catch(err => { console.log(err) }) // getEquipmentSearch }, // 重置 reset() { var condition_list = [{ name: '分类', id: 0 }, { name: '品牌', id: 0 }, { name: '年限', id: 0 }, ] this.setData({ classification_idx: 0, classification_id: 0, time_idx: 0, time_id: 0, brand_idx: 0, brand_id: 0, condition_list, key: '', currentPage: 1, pageSize: 5, }, () => { this.get_list() }) }, // 上拉刷新 onScrolltolower() { let { list_total, showlist } = this.data; if (list_total == showlist.length) return this.setData({ currentPage: this.data.currentPage + 1, }, () => { this.get_list() }) }, // 下拉加载 onRefresh() { this.setData({ condition_idx: null, currentPage: 1, refresh: true, showlist: [] }, () => { this.get_list() }) // this.get_list() // setTimeout(()=>{ // this.setData({ // triggered:false // }) // },1000) }, // 点击蒙版 隐藏 menus_btn() { this.setData({ condition_idx: null }) }, // 点击筛选 condition_btn(e) { let condition_idx = e.currentTarget.dataset.idx; if (condition_idx == this.data.condition_idx) { this.setData({ autoLoad: true, condition_idx: null, }) } else { this.setData({ condition_idx: e.currentTarget.dataset.idx, autoLoad: true, }) } }, // 分类项点击 classification_btn(e) { console.log(e) let idx = e.currentTarget.dataset.idx; let id = e.currentTarget.dataset.id; let { condition_idx, condition_list } = this.data condition_list[condition_idx].name = this.data.classification_list[idx].name let brand_code=e.currentTarget.dataset.code||'' this.setData({ brand_code, classification_idx: idx, classification_id: id, autoLoad: false, condition_idx: null, condition_list, currentPage: 1, refresh: true, // showlist:[] },()=>{ this.get_list() this.getEquipmentBrand() }); }, // 品牌项点击 brand_btn(e) { let idx = e.currentTarget.dataset.idx; let id = e.currentTarget.dataset.id; let { condition_idx, condition_list } = this.data condition_list[condition_idx].name = this.data.brand_list[idx].name this.setData({ brand_idx: idx, brand_id: id, autoLoad: false, condition_idx: null, condition_list, // showlist:[] currentPage: 1, refresh: true, },()=>{ this.get_list() }); }, // 年限项点击 time_btn(e) { let idx = e.currentTarget.dataset.idx; let id = e.currentTarget.dataset.id; let { condition_idx, condition_list } = this.data condition_list[condition_idx].name = this.data.years_list[idx].name this.setData({ time_idx: idx, time_id: id, autoLoad: false, condition_idx: null, condition_list, // showlist:[] currentPage: 1, refresh: true, },()=>{ this.get_list() }); }, // 滑动触发判断筛选 nobindscroll(e) { this.setData({ condition_idx: null }) if (e.detail.scrollTop >= 220) { this.setData({ is_scrool_top: true }) } if (e.detail.scrollTop < 220) { this.setData({ is_scrool_top: false }) } if (this.data.condition_idx == null) { return } // this.setData({ // condition_idx: null // }) }, bindshare(e) { // console.log(e) this.triggerEvent('bindshare', { item: e.detail.item }) } } })