// packageE/appointment/technician/work_day/TechnicianWork.js
var app = getApp();
Page({
  /**
   * 页面的初始数据
   */
  data: {
    worker_id: "",
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    if (options.worker_id) {
      this.setData({
        worker_id: options.worker_id,
      });
    }
    this.getData();
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {},

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

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

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

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

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

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {},
  addTime(e) {
    let item = e.currentTarget.dataset.item;
    if (item) {
      wx.navigateTo({
        url:
          "/packageE/appointment/technician/work_day/TechnicianTime/TechnicianTime?worker_id=" +
          this.data.worker_id +
          "&item=" +
          JSON.stringify(item),
      });
    } else {
      wx.navigateTo({
        url:
          "/packageE/appointment/technician/work_day/TechnicianTime/TechnicianTime?worker_id=" +
          this.data.worker_id,
      });
    }
  },
  getTime(e) {
    console.log(e);
    let obj = e.currentTarget.dataset.item;
    let ind = e.currentTarget.dataset.ind;
    if (obj.show) {
      obj.show = false;
      this.data.store[ind] = obj;
      this.setData({
        store: this.data.store,
      });
      return;
    }
    var store_id = obj.id;
    var that = this;
    let urlStr = app.getNetAddresss(
      "plugin.appointment.frontend.appointment-service.get-by-worker"
    );
    app._getNetWork({
      url: urlStr,
      data: {
        store_id: store_id,
        worker_id: that.data.worker_id,
      },
      success: (resdata) => {
        var res = resdata.data;
        if (res.result == 1) {
          console.log(res);
          obj.show = true;
          obj.times = res.data;
          that.data.store[ind] = obj;
          that.setData({
            store: that.data.store,
          });
          console.log(that.data.store);
        } else {
          wx.showToast({
            title: res.msg,
            icon: "none",
          });
          console.log(res.msg);
        }
      },
    });
  },
  getData() {
    var that = this;
    let urlStr = app.getNetAddresss(
      "plugin.appointment.frontend.store.get-list-by-worker-uid"
    );
    app._getNetWork({
      url: urlStr,
      success: (resdata) => {
        var res = resdata.data;
        if (res.result == 1) {
          console.log(res);
          that.setData({
            store: res.data,
          });
          console.log(that.data.store);
        } else {
          wx.showToast({
            title: res.msg,
            icon: "none",
          });
          console.log(res.msg);
        }
      },
    });
  },
});
