mykehu.js 5.0 KB
// pages/mykehu/mykehu.js
const app=getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    kehulist:[],
    page:1,
    morenkehu:'',
    showmoren:true,
    letter: ["A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z","#"],
    cityListId:'',
    scrollHeight:"",
    len:''
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    
  },

  //获取默认客户
  getmorenkehu(){
    console.log(7654321)
    let that = this;
    let url = 'user/getCustomerList';
    let param = {
      page: 1,
      is_default: 1
    }

    app.post(url, param, 'get').then((res) => {
      console.log(res);

      this.setData({
        morenkehu:res[0]
      })

      console.log(res.length)

      if(res.length==0){
        that.setData({
          showmoren:false
        })
      }else{
        that.setData({
          showmoren:true
        })
      }

    }).catch((err) => {


    })
  },

  //获取客户列表
  getkehulist(){
    let that = this;
    let url = 'user/getCustomerList';
    let param={
      page:this.data.page,
      is_default:0
    }

    app.post(url, param, 'get').then((res) => {
      console.log(res);
      this.setData({
        kehulist:this.data.kehulist.concat(res)
      })
      

      let len = this.data.kehulist.length;
      console.log(len)
      len = len * 120+100;
      this.setData({
        len: len
      })

    }).catch((err) => {


    })
  },

  //编辑客户
  editkehu(e){
    let id=e.currentTarget.dataset.id;
    wx.navigateTo({
      url: '/pages/addkehu/addkehu?editype='+1+'&id='+id,
    })
  },
  //删除客户
  delkehu(e){
    console.log(e)
    let that = this;
    let id=e.currentTarget.dataset.id
    
    let url = 'user/delCustomer';
    let param = {
      customer_id: id,
     
    }

    app.post(url, param, 'get').then((res) => {
      console.log(res);
      wx.showToast({
        title: '删除客户成功',
        icon:"none"
      })

      

      setTimeout(function(){
        that.setData({
          page: 1,
          kehulist: []

        })
        that.getkehulist();
        that.getmorenkehu();
      },1500)
      
      

    }).catch((err) => {


    })

  },

  //选择默认地址
  select(e){
    let item = e.currentTarget.dataset.item;
    console.log(item)

    let pages = getCurrentPages();

    // let currPage = pages[pages.length - 1]; //当前页面
    let prevPage = pages[pages.length - 2]; //上一个页面

   

    //直接调用上一个页面的setData()方法,把数据存到上一个页面中去
    prevPage.setData({
      morenaddress:item,
      prepage:1
    });
   
    wx.navigateBack({
      checked:true
    })

  },


  //添加新客户
  addkehu(){
    wx.navigateTo({
      url: '/pages/addkehu/addkehu',
    })
  },


  letterTap(e) {
    console.log(e)
    const Item = e.currentTarget.dataset.item;
    console.log('000888',Item)
    // this.setData({
    //     cityListId: Item
    //   });



    // let scrollHeight = wx.getSystemInfoSync().windowHeight;
    // this.setData({
    //    scrollHeight: scrollHeight
    // })

    // var query = wx.createSelectorQuery();

    // var that = this;
    // query.select('.city_left').boundingClientRect(function (rect) {
    //    console.log('66666',rect)

    // }).exec();


    //滚动到某一位置
    // var me = this;
    // var query = wx.createSelectorQuery().in(me);
    // query.selectViewport().scrollOffset()
    // query.select("#comment").boundingClientRect();
    // query.exec(function (res) {
    //   console.log(res);
    //   var miss = res[0].scrollTop + res[1].top - 10;
    //   wx.pageScrollTo({
    //     scrollTop: miss,
    //     duration: 300
    //   });

    // });


    if (Item == '#') {
      this.setData({
        scrollHeight: this.data.len
      });

      
    } else {
      this.setData({
        cityListId: Item
      });
    }
    console.log('909090', this.data.scrollHeight)
   
    console.log('77777', Item)

    console.log("..............." + this.data.cityListId);
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    //获取默认客户
    this.getmorenkehu();
    this.setData({
      kehulist:[],
      page:1
    })

    this.getkehulist();
    
  },

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

  },

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

  },

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

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
  console.log(348843849)
    let newpage=this.data.page;
    newpage++;
    this.setData({
      page:newpage
    })

    this.getkehulist()

  },

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

  }
})