myOrder.js 4.8 KB
// pages/person/myOrder/myOrder.js
const app=getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    orderTab: 0,
    orderlist:'',
    reveal:false,
    telshop:'',
    cancelorder:false,
    cancelorderid:''
  },

  //点击切换
  orderClick:function(e){
    var that = this;
    if (this.data.orderTab === e.target.dataset.current){
      return false;
    }else{
      that.setData({
        orderTab:e.target.dataset.current
      })

      that.getorderlist()
    }
  },
  //跳转到 订单详情页面
  order_Tap:function(e){
    console.log(e)
    let orderid = e.currentTarget.dataset.orderid;
    wx.navigateTo({
      url: '../myOrderDetail/myOrderDetail?orderid=' + orderid,
    })
  },
  //跳转到 评价页面
  evalute:function(e){
    let orderid=e.currentTarget.dataset.id
    wx.navigateTo({
      url: '../myComment/myComment?orderid=' + orderid
    })
  },


//订单完成
  finish(e){
    let that = this;
    let orderid = e.currentTarget.dataset.id;
    var url = '/api/portal/Mine/sureOver';
    var params = {
      token: wx.getStorageSync('token'),
      orderId: orderid

    }
    app.post(url, params).then((res) => {
      console.log(res);
      if(res.length==0){
        wx.showToast({
          title: '已完成',
          icon:'none'
        })
      }

      setTimeout(function(){
        that.getorderlist()
      },1000)


    }).catch((err) => {

    })
  },

  //寻找服务
  searchfu(){
    wx.switchTab({
      url:'../../partner/partner'
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
   
  },
  

  getorderlist(){
    let that = this;
    var url = '/api/portal/Mine/myOrder';
    var params = {
       token: wx.getStorageSync('token'),
      type: that.data.orderTab
      

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



    }).catch((err) => {

    })
  },

  //待付款订单去付款
  pay(e){
    let id=e.currentTarget.dataset.id;
    let that = this;
    var url = '/api/portal/Compare/pay';
    var params = {
      orderId: id
    }
    app.post(url, params).then((res) => {
      console.log(res);
      that.payment(res)



    }).catch((err) => {

    })
  },

  payment(res) {
    wx.requestPayment({
      timeStamp: res.timeStamp,
      nonceStr: res.nonceStr,
      package: res.package,
      signType: res.signType,
      paySign: res.paySign,
      success(res) {
        console.log(res)
        wx.navigateBack({
          checked: true
        })

        // if (res.errMsg == 'requestPayment:ok') {
        //   wx.switchTab({
        //     url: '../../order/order',
        //   })
        // }
      },
      fail(res) { }
    })
  },
  canceltbtn(){
    this.setData({
      cancelorder:false
    })
  },

  //取消订单
  cancelpay(e){
    let that = this;
    let id=e.currentTarget.dataset.id;
    console.log(id)
    that.setData({
      cancelorderid:id,
      cancelorder:true
    })
  },
  surebtn(){
    let that = this;
   
    var url = '/api/portal/Mine/cancel';
    var params = {
      token: wx.getStorageSync('token'),
      orderId: that.data.cancelorderid
    }

    app.post(url, params).then((res) => {
      console.log(res);
      if(res==''){
        wx.showToast({
          title: '取消成功',
          icon:"none"
        })

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



    }).catch((err) => {

    })
  },
  //显示商家电话
  showphone(e){
    console.log(e)
    this.setData({
      reveal: true
    })
    let orderid=e.currentTarget.dataset.id;
    var url = '/api/portal/Mine/compareTel';
    var params = {
      token: wx.getStorageSync('token'),
      orderId: orderid

    }
    app.post(url, params).then((res) => {
      console.log(res);

      this.setData({
        telshop: res
      })



    }).catch((err) => {

    })


  },
  //关闭商家电话
  close(){
    this.setData({
      reveal:false
    })
  },
  boda(){
    wx.makePhoneCall({
      phoneNumber: this.data.telshop //仅为示例,并非真实的电话号码
    })
  },

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

  },

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

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

  },

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

  },

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

  },

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

  },

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

  }
})