var e = getApp(),
  a = e.globalData.setting,
  os = a,
  t = e.request,
  d = e.globalData;
Page({

  /**
   * 页面的初始数据
   */
  data: {
    url: a.url,
    iurl: a.imghost,
    tment_details: [], //预约详情
    number: "", //订单号
    arrangeTime: "", //预约年月日
    day: "", //判断是上午还是下午
    states: 3, //3为取消预约
  },
  //取消预约
  cancel_tment: function(e) {
    var th = this;
    var my_confirm = th.selectComponent("#my_confirm"); //组件的id
    my_confirm.open(
      "确定取消？",
      "取消",
      "确定",
      function() {
        my_confirm.open_cancel(0);
      },
      function() {
        var index = e.currentTarget.dataset.index;
        var states = th.data.states;
        var tment_details = th.data.tment_details;
        var number = th.data.number;
        var json = {
          "number": number,
          "storeId": a.stoid,
          "states": states
        };
        var data = JSON.stringify(json);
        var url = th.data.url + "/api/weshop/marketing/reservation/reservation/update"; //预约接口地址
        getApp().request.promisePut(url, {
          data: json,is_json:1,is_normal:1
        }).then(res => {
            my_confirm.open_cancel(0);
            if (res.data.code == 0) {
              getApp().my_warnning("取消成功", 1, th);
              var start = 'tment_details[' + 0 + '].State';
                th.setData({
                  [start]: 3
                })     
            } else {
              getApp().my_warnning(res.data.msg, 0, th);
            }

        })
      }
    );

  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    var th = this;
    th.setData({
      number: options.number
    })

    var user=getApp().globalData.userInfo;
    if(!user){
        getApp().goto("/packageE/pages/togoin/togoin");
    }

  },
  //查询美容师详情
  query_bea: function() {
    var th = this;
    var number = th.data.number;
    var url = "/api/weshop/marketing/reservation/reservation/page";
    getApp().request.promiseGet(url, {
      data: {
        storeId: a.stoid,
        userId: d.user_id,
        number: number
      }
    }).then(res => {
      wx.hideLoading();
      if (res.data.code == 0) {
        var data = res.data.data.pageData;
        var arrangeTime = data[0].ArrangeTime.substring(0, 11);
        var day = data[0].ArrangeTime.substring(11, 16);
        th.setData({
          tment_details: data,
          arrangeTime: arrangeTime,
          day: day
        })

      } else {
        getApp().my_warnning(res.data.msg, 0, th);
      }
    })
  },
  //显示核销码
  code_show: function(e) {
    var th = this;
    //--获取成功的时候--
    var no = e.currentTarget.dataset.order_sn;
    var qc_com = th.selectComponent("#qc_com"); //组件的id
    var obj = {
      val: no,
      content: "请将二维码展示给核销员，使用更快捷"
    };
    qc_com.open(obj)
  },
  //跳到首页
  goto: function(e) {
    var th = this;
    wx.navigateTo({
      url: '/pages/index/index/index',
    })
  },
  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function() {

    var user=getApp().globalData.userInfo;
    if(user){
        var th = this;
        th.query_bea();
    }

  },
  //关闭导航
  close: function () {
    var th = this;
    var nav_b = th.selectComponent("#nav_b"); //组件的id
    nav_b.close_box();
  }
})