active.js 7.3 KB
// pages/active/active.js
const app = getApp();

Page({

  /**
   * 页面的初始数据
   */
  data: {
    page_Con: [],
    monIndex: 0,
    monthIndex: '',
    cityshowIndex: '',
    cityIndex: 0,
    topcityId: 0,
    dateIndex: 0,
    allIndex: 0,
    seachid: '',
    topCity: [],
    conCity: [],
    conMonth: [],
    conDate: ['全时段', '今天', '明天', '本周', '本月'],
    conWarp: ['全价格', '免费', '0-100', '100-300', '300-500', '500以上'],
    reveal: false,
    wxtary: ''
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {

  },
  //交流专区
  communitclub() {
    this.setData({
      reveal: true
    })

    let that = this;
    that.setData({
      reveal: true
    })

    var url = '/api/portal/Strategy/call';
    var params = {
      // token: wx.getStorageSync('token'),

    }
    app.post(url, params).then((res) => {
      console.log(res);
      that.setData({
        wxtary: res.secretary

      })



    }).catch((err) => {

    })

  },
  // 一键复制
  bindCopy: function() {
    let that = this;
    wx.setClipboardData({
      data: that.data.wxtary,
      success: function(res) {
        console.log("复制成功")

        setTimeout(function() {
          that.setData({
            reveal: false
          })
        }, 1500)
      }
    })
  },

  tapHide() {
    this.setData({
      reveal: false
    })
  },



  // 获取活动列表
  getActive: function() {
    let that = this;
    let url = "/api/portal/Activity/index";
    let params = {
      first: that.data.monthIndex,
      second: that.data.cityshowIndex,
      third: that.data.dateIndex,
      fourth: that.data.allIndex,
      keyword: that.data.seachid
    }
    app.post(url, params).then((res) => {
      console.log(res)
      // let stime = res.list;
      // for(var i=0; i<stime.length; i++){
      //   stime[i].start_time = that.toDate(stime[i].start_time);
      //   stime[i].end_time = that.toDate(stime[i].end_time);
      // }
      let newconMonth = res.score
      let newscore = {
        id: '',
        title: '全部'
      }
      newconMonth.unshift(newscore)
      that.setData({
        topCity: res.city,
        conMonth: newconMonth,
        page_Con: res.list
      })

      let kage = that.data.topCity[that.data.topcityId].son;
      let kagename = {
        id: "",
        name: '全部'
      }
      kage.unshift(kagename)
      that.setData({
        conCity: kage
      })
    }).catch((errMsg) => {})
  },
  // 幸福准妈下拉
  monthTap: function(e) {
    let that = this;
    that.setData({
      monIndex: e.detail.value,
      monthIndex: that.data.conMonth[e.detail.value].id,
      page_Con: []
    })
    that.getActive()
  },
  // 全城下拉
  cityTap: function(e) {
    let that = this;
    that.setData({
      cityIndex: e.detail.value,
      cityshowIndex: that.data.conCity[e.detail.value].id,
      page_Con: []
    })
    that.getActive()
  },
  // 全时段下拉
  dateTap: function(e) {
    this.setData({
      dateIndex: e.detail.value,
      page_Con: []
    })
    this.getActive()
  },
  // 全价格下拉
  allTap: function(e) {
    this.setData({
      allIndex: e.detail.value,
      page_Con: []
    })
    this.getActive()
  },
  // 获取搜索条件
  getSearch: function(e) {
    this.setData({
      seachid: e.detail.value,

    })
    if (e.detail.value == "" || e.detail.value == null) {
      this.getActive()
    }

  },
  // 点击搜索
  bindSearch: function(e) {
    this.setData({
      page_Con: []
    })
    this.getActive()
  },
  // 城市头部下拉切换
  bindPicker: function(e) {
    let that = this;
    this.setData({
      topcityId: e.detail.value
    })

    let cityname = that.data.topCity[e.detail.value].name;
    if (cityname == '北京市') {

      let newconCity = that.data.topCity[e.detail.value].son

      let kagename = {
        id: "",
        name: '全部'
      }
      newconCity.unshift(kagename)
      that.setData({
        conCity: newconCity
      })


    } else if (cityname == '上海市') {

      let newconCity = that.data.topCity[e.detail.value].son

      let kagename = {
        id: "",
        name: '全部'
      }
      newconCity.unshift(kagename)
      that.setData({
        conCity: newconCity
      })
      that.setData({
        conCity: newconCity
      })
    }
  },
  //时间戳转换时间
  toDate: function(number) {
    let n = number * 1000;
    let date = new Date(n);
    // let Y = date.getFullYear() + '年';
    let month = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1) + '月';
    let day = date.getDate() < 10 ? '0' + date.getDate() : date.getDate() + '日 ';
    let hour = date.getHours() < 10 ? '0' + date.getHours() + ':' : date.getHours() + ':';
    let minute = date.getMinutes() < 10 ? '0' + date.getMinutes() : date.getMinutes()

    return (month + day + hour + minute)
  },

  // 跳转到  月嫂攻略
  strateTap: function() {
    let token = wx.getStorageSync("token");
    if (token == '') {
      wx.showToast({
        title: '请先登录',
        icon: 'none'
      })
      setTimeout(function() {
        wx.navigateTo({
          url: '/pages/index/index',
        })
      }, 1000)
    } else {
      wx.navigateTo({
        url: '../cityWide/matronStrategy/matronStrategy',
      })
    }

  },
  // 跳转到 优选月嫂
  preponTap: function() {
    let token = wx.getStorageSync("token");
    if (token == '') {
      wx.showToast({
        title: '请先登录',
        icon: 'none'
      })
      setTimeout(function() {
        wx.navigateTo({
          url: '/pages/index/index',
        })
      }, 1000)
    } else {
      wx.navigateTo({
        url: '../cityWide/matronPrepon/matronPrepon',
      })
    }

  },
  // 跳转到 月子会所
  clubTap: function() {
    let token = wx.getStorageSync("token");
    if (token == '') {
      wx.showToast({
        title: '请先登录',
        icon: 'none'
      })
      setTimeout(function() {
        wx.navigateTo({
          url: '/pages/index/index',
        })
      }, 1000)
    } else {
      wx.navigateTo({
        url: '../cityWide/monthClub/monthClub',
      })
    }

  },
  // 跳转到 活动详情页
  bindDetail: function(e) {
    let token = wx.getStorageSync("token");
    if (token == '') {
      wx.showToast({
        title: '请先登录',
        icon: 'none'
      })
      setTimeout(function() {
        wx.navigateTo({
          url: '/pages/index/index',
        })
      }, 1000)
    } else {
      let activeid = e.currentTarget.dataset.activeid;
      wx.navigateTo({
        url: '../cityWide/monthDetail/monthDetail?activeid=' + activeid,
      })
    }

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function() {
    let that = this;
    that.getActive()
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function() {

  }
})