123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241 |
- // newsShop/pages/patternMenu/patternMenu.js
- let app = getApp();
- let host = app.globalData.servsers; // 请求的url
- Page({
- /**
- * 页面的初始数据
- */
- data: {
- host:host,
- isSelect: "1", //默认全部
- dataStateArray: [
- {
- state: '1',
- label: "营销礼赠",
- },
- {
- state: '2',
- label: "商务送礼",
- },
- {
- state: '3',
- label: "员工/福利",
- }
- ],
- filterArray: [
- // { name: '1', value: '0~499元' },
- // { name: '2', value: '500~999元' },
- // { name: '3', value: '1000~1999元' },
- // { name: '4', value: '2000元以上' },
- ],
- requestState:true, //检测请求状态是否结束了
- filterStatic: false,
- isNew: true,
- isMin: true,
- goodsList:[],
- page:1, //默认是第一页
- limit:20, //一页20条数据
- maxPrice:null,//最大价格
- minPrice:null,//最低价格
- priceSort: null, //价格排序,默认降序
- timeSort: null, //价时间排序,默认降序
- requestState:true, //默认是可以向下请求的
- loginStatic: false, //登陆状态,默认为false
- },
- /**
- * 生命周期函数--监听页面加载
- */
- onLoad: function (options) {
-
- },
- /**
- * 生命周期函数--监听页面初次渲染完成
- */
- onReady: function () {
- },
- /**
- * 生命周期函数--监听页面显示
- */
- onShow: function () {
- let that = this;
- that.getGiftNavTab(that)
- that.setData({
- goodsList:[],
- page:1,
- })
- if (wx.getStorageSync('channelIdObj').channelId) {
- that.setData({
- loginStatic: true,
- })
- }
- },
- /**
- * 生命周期函数--监听页面隐藏
- */
- onHide: function () {
- },
- /**
- * 生命周期函数--监听页面卸载
- */
- onUnload: function () {
- },
- /**
- * 页面相关事件处理函数--监听用户下拉动作
- */
- onPullDownRefresh: function () {
- let that = this;
- if (that.data.requestState){
- that.setData({
- page:that.data.page + 1
- })
- that.getGiftList(that)
- }
- },
- /**
- * 页面上拉触底事件的处理函数
- */
- onReachBottom: function () {
- },
- /**
- * 用户点击右上角分享
- */
- onShareAppMessage: function () {
- },
- tab(e){ // 头部tab切换
- let that = this;
- that.setData({
- isSelect: e.currentTarget.dataset.id,
- goodsList:[],
- page:1,
- requestState: true,
- })
- that.getGiftList(that)
- },
- timeSortTap(){ // 时间筛选
- let that = this;
- that.setData({
- timeSort: that.data.timeSort === null ? 'asc' : that.data.timeSort === 'asc' ? 'desc' : 'asc',
- goodsList: [],
- page: 1,
- requestState: true,
- })
- that.getGiftList(that)
- },
- priceSortTap() { // 价格筛选
- let that = this;
- that.setData({
- priceSort: that.data.priceSort === null ? 'asc' : that.data.priceSort === 'asc' ? 'desc' : 'asc',
- goodsList: [],
- page: 1,
- requestState: true,
- })
- that.getGiftList(that)
- },
- priceMaxMinTap(){ // 价格区间筛选
- let that = this;
- that.setData({
- filterStatic: true
- })
- },
- close(){
- let that = this;
- that.setData({
- filterStatic: false
- })
- },
- blurPriceMin(e){
- // event.detail = {value: value}
- let that = this;
- that.setData({
- minPrice: e.detail.value,
- page: 1,
- requestState:true,
- goodsList: [],
- })
- that.getGiftList(that)
- },
- blurPriceMax(e){
- let that = this;
- that.setData({
- maxPrice:e.detail.value,
- page:1,
- requestState: true,
- goodsList:[],
- })
- that.getGiftList(that)
- },
- getGiftNavTab(that){
- wx.request({
- url: host + '/classifyapi/classifyTwoAll',
- method: 'get',
- data: {
- classifyHigher:'3060'
- },
- success(res){
- console.log(res,"res")
- that.setData({
- dataStateArray:res.data.rows,
- isSelect:res.data.rows[0].id
- })
- that.getGiftList(that)
- }
- })
- },
- getGiftList(that){
- let data = {
- channelId: 5, // 渠道id,现在为5,一件选礼为5
- classId: that.data.isSelect,
- limit: that.data.limit, // 一页20条数据
- offset: that.data.page, //当前页数
- channelId: wx.getStorageSync('channelIdObj').channelId ? wx.getStorageSync('channelIdObj').channelId : ""
- }
- if (that.data.priceSort) {
- data.priceSort = that.data.priceSort
- }
- if (that.data.timeSort) {
- data.timeSort = that.data.timeSort
- }
- if (that.data.maxPrice){
- data.maxPrice = that.data.maxPrice
- }
- if (that.data.minPrice) {
- data.minPrice = that.data.minPrice
- }
- wx.request({
- url: host +'/commodityapi/queryCommodityByClass',
- method:'get',
- data:data,
- success(res){
- let dataArray = that.data.goodsList;
- res.data.rows.forEach(el=>{
- el.logo = el.commodity_logo.split(",")
- })
- dataArray.push(...res.data.rows)
- that.setData({
- goodsList: dataArray,
- requestState: res.data.rows.length == that.data.limit
- })
- }
- })
- },
- toGoodsDetail(e){ // 进入商品详情页
- let that = this, id = e.currentTarget.dataset.id;
- wx.navigateTo({
- url: '/pages/buy/buy?com_id='+id,
- })
- }
- })
|