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

  /**
   * 页面的初始数据
   */
  data: {
    inurl: a.url, //接口网址
    iurl: a.imghost,
    url: "", //选择选择时间后返回的页面
    defimgurl: "/miniapp/images/yyservice/yyxmdefault.jpg",
    seekTime: "", //当前服务预约选择的时间
    time_list: [], //可预约时间
    name: "", //美容师姓名
    comment: "", //美容师评价
    aweeks: [], //七天的预约时间
    head_img: "", //美容师头像
    time: ["08:00", "09:00", "10:00", "11:00", "12:00", "13:00", "14:00", "15:00", "16:00", "17:00", "18:00", "19:00", "20:00", "21:00", "22:00"],
    time_index: "", //选择预约时间下标
    date_id: 0, //选择日期的id
    beautician_id: "", //美容师id
    itemId: "", //服务id
    number: "", //预约单号
    modify: 0, //是否是修改时间
    iscos: 0, //是否是从美容师列表过来的
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    var th = this;
    var beautician_id = options.BeauticianID;
    th.setData({
      url: options.url,
      beautician_id: beautician_id,
      itemId: options.itemId,
      iscos: options.iscos,
      modify: options.modify
    })
    
    if (options.number != "") {
      th.setData({
        number: options.number
      })
    }
    th.query_beatea();
    th.query_aweek();
  },
  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function() {

  },
  //图片失败,默认图片
  bind_bnerr1: function(e) {
    var _errImg = e.target.dataset.errorimg;
    var _Img = e.target.dataset.img;
    if (_Img != undefined) {
      var _errObj = {};
      _errObj[_errImg] = "/miniapp/images/no_cate_def.png";
      this.setData(_errObj) //注意这里的赋值方式,只是将数据列表中的此项图片路径值替换掉 ;
    }
  },
  //选择服务日期
  check_date: function(e) {
    var th = this;
    var id = e.currentTarget.dataset.dateid;
    var date_id = th.data.date_id;
    var seekTime = th.data.aweeks[id].time;
    if (id != date_id) {
      th.setData({
        date_id: id,
        seekTime: seekTime
      })
      th.query_date();
    }
  },
  //获取美容师信息
  query_beatea: function() {
    var th = this;
    var url = "/api/weshop/marketing/reservation/staff/get"; //接口路径
    var beautician_id = th.data.beautician_id;
    getApp().request.promiseGet(url, {
      data: {
        beauticianId: beautician_id,
        storeId: a.stoid,
      }
    }).then(res => {
      if (res.data.code == 0) {
        var data = res.data.data;
        th.setData({
          name: data.StaffName,
          comment: data.Remark1,
          head_img: data.PhotoUrl
        })
      } else {
        getApp().my_warnning(res.data.msg, 0, th);
      }
    })
  },
  //返回上个页面
  navigateBack: function() {
    var th = this;
    var modify = th.data.modify; //是否是更改时间
    var seekTime = th.data.seekTime; //选择的日期
    var time_list = th.data.time_list;
    var time_index = th.data.time_index;
    if (time_index == "") {
      getApp().my_warnning("请选择预约时间", 0, th);
      return false;
    }
    var date_id = th.data.date_id;
    var date = th.data.aweeks[date_id].time;
    var time = date + " " + time_list[time_index] + ":00";
    if (modify == 1) {
      var json = {
        "arrangeTime": time,
        "number": th.data.number,
        "remark": "更改时间",
        "states": 0,
        "storeId": a.stoid
      };
      var data = JSON.stringify(json);
      var url = th.data.inurl + "/api/weshop/marketing/reservation/reservation/update"; //预约接口地址
      wx.request({
        url: url,
        data: data,
        method: 'put',
        header: {
          'content-type': 'application/json'
        }, // 设置请求的 header
        success: function(res) {
          if (res.data.code == 0) {
            getApp().my_warnning(res.data.msg, 0, th);
            wx.navigateBack({
              //返回
              delta: 1
            })
          } else {
            getApp().my_warnning(res.data.msg, 0, th);
          }
        }
      })
    } else {
      var pages = getCurrentPages(); //当前页面
      var iscos = th.data.iscos;
      var prevPage = pages[pages.length - 2 - iscos]; //上一页面
      prevPage.setData({
        //直接给上一个页面赋值
        time: time,
      });
      wx.navigateBack({
        //返回
        delta: 2
      })
    }
  },
  //选择时间
  Selection_time: function(e) {
    var th = this;
    var index = e.currentTarget.dataset.index;
    var time_index = th.data.time_index;
    if (index == time_index) {
      return false;
    } else {
      th.setData({
        time_index: index
      })
    }
  },
  //查询七天预约时间
  query_aweek: function() {
    var th = this;
    var beautician_id = th.data.beautician_id; //美容师id
    var itemId = th.data.itemId; //项目id
    var url = "/api/weshop/marketing/reservation/staff/seven/time/list"; //接口地址
    getApp().request.promiseGet(url, {
      data: {
        beauticianId: beautician_id,
        serviceId: itemId,
        storeId: a.stoid,
      }
    }).then(res => {
      if (res.data.code == 0) {
        var data = res.data.data;
        var arr = [];
        for (var i in data) {
          var em = {
            "time": i,
            "val": data[i]
          };
          arr.push(em);
        }
        th.setData({
          aweeks: arr
        })
        th.query_date();
      } else {
        getApp().my_warnning(res.data.msg, 0, th);
      }
    })

  },

  query_date: function() {
    var th = this;
    var date_id = th.data.date_id; //日期下标
    var SeekTime = th.data.aweeks[date_id].time;
    var url = "/api/weshop/marketing/reservation/staff/time/list";
    getApp().request.promiseGet(url, {
      data: {
        beauticianId: th.data.beautician_id,
        serviceId: th.data.itemId,
        seekTime: SeekTime,
        storeId: a.stoid,
      }
    }).then(res => {
      if (res.data.code == 0) {
        var time_list = res.data.data;
        var time = th.data.time;
        var new_time = [];
        for (var i = 0; i < time.length; i++) {
          for (var ii = 0; ii < time_list.length; ii++) {
            if (time[i] == time_list[ii].GroupHour.substring(0, 5)) {
              new_time[i] = time_list[ii].GroupHour.substring(0, 5);
              break;
            } else {
              new_time[i] = "";
            }
          }
        }
        th.setData({
          time_list: new_time
        })
      } else {
        getApp().my_warnning(res.data.msg, 0, th);
      }
    })
  },
  //更改预约时间
  change_time: function() {
    var th = this;
    var seekTime = th.data.seekTime; //选择的日期
    var time_list = th.data.time_list;
    var time_index = th.data.time_index;
    var time = time_list[time_index];
    var number = th.data.number; //预约单号
    var json = {
      "arrangeTime": seekTime + " " + time,
      "number": number,
      "remark": "更改预约时间",
      "states": 0,
      "storeId": a.stoid
    };
    var data = JSON.stringify(json);
    var url = th.data.inurl + "/api/weshop/marketing/reservation/reservation/update"; //预约接口地址
    wx.request({
      url: url,
      data: data,
      method: 'put',
      header: {
        'content-type': 'application/json'
      }, // 设置请求的 header
      success: function(res) {
        if (res.data.code == 0) {
          getApp().my_warnning("更改成功", 0, th);
        } else {
          getApp().my_warnning(res.data.msg, 0, th);
        }
      }
    })
  },
  //预览头像
  previewImage: function(e) {
    var th = this;
    var current = e.currentTarget.dataset.src;
    wx.previewImage({
      current: current, // 当前显示图片的http链接  
      urls: [th.data.head_img] // 需要预览的图片http链接列表  
    })
  },
})