// packageD/energy/powerStore/powerStore.js
const app = getApp();
Page({
  /**
   * 页面的初始数据
   */
  data: {
    shop_address: "",
    phone: "",
    shop_name: "",
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.getdata();
  },
  shop_name(e) {
    let val = e.detail.value;
    this.setData({
      shop_name: val,
    });
  },
  phone(e) {
    let val = e.detail.value;
    this.setData({
      phone: val,
    });
  },
  shop_address(e) {
    let val = e.detail.value;
    this.setData({
      shop_address: val,
    });
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {},

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

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

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

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

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

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {},
  submit() {
    let json = {
      shop_name: this.data.shop_name,
      phone: this.data.phone,
      shop_address: this.data.shop_address,
    };
    let urlStr = app.getNetAddresss(
      "plugin.energy-cabin.frontend.dealer-terminal.store-dealer"
    );
    app._getNetWork({
      url: urlStr,
      data: json,
      success: function (resdata) {
        var res = resdata.data;
        if (res.result == 1) {
          console.log(res);
          wx.showToast({
            title: "提交成功",
            icon: "none",
            duration: 1000,
            success: function (e) {
              setTimeout(() => {
                wx.navigateBack({
                  delta: 1,
                });
              }, 1500);
            },
          });
        } else {
          wx.showToast({
            title: res.msg,
            icon: "none",
            duration: 1000,
          });
        }
      },
      fail: function (res) {
        console.log(res);
      },
    });
  },
  getdata() {
    wx.showLoading({
      title: "加载中",
    });
    let urlStr = app.getNetAddresss(
      "plugin.energy-cabin.frontend.dealer-terminal.get-shop-info"
    );
    let that = this;
    app._getNetWork({
      url: urlStr,
      success: function (resdata) {
        wx.hideLoading({
          success: (res) => {},
        });
        var res = resdata.data;
        if (res.result == 1) {
          console.log(res);
          if (res.data) {
            that.setData({
              shop_name: res.data.shop_name,
              phone: res.data.phone,
              shop_address: res.data.shop_address,
            });
          }
        }
      },
      fail: function (res) {
        console.log(res);
        wx.hideLoading({
          success: (res) => {},
        });
      },
    });
  },
});
