const app = getApp()

Page({
  data: {
    oneVNParams: null,
    oneVNServiceCode: null
  },

  handleChange(e) {
    let { obj } = e.target.dataset;
    let value = e.detail.value;
    this.data[obj] = value;
  },
  saveCongfig() {
    try {
      app.data.oneVNParams = JSON.parse(this.data.oneVNParams);
    } catch (error) {
      my.showToast({
        type: 'fail',
        content: 'JSON格式有误',
        duration: 1500,
      });
      return;
    }
    app.data.oneVNServiceCode = this.data.oneVNServiceCode;
    my.showToast({
      type: 'success',
      content: '保存成功',
      duration: 1500,
    });
    my.navigateBack(1)
  },
  resetConfig() {
    app.data.oneVNParams = my.getStorageSync({key: "defaultOneVNParams"}).data;
    app.data.oneVNServiceCode = my.getStorageSync({key: "defaultOneVNServiceCode"}).data;
    this.update();
    my.showToast({
      type: 'success',
      content: '恢复成功',
      duration: 1500,
    });  
    my.navigateBack(1)
  },
  update() {
    this.setData({
      oneVNParams: JSON.stringify(app.data.oneVNParams),
      oneVNServiceCode: app.data.oneVNServiceCode
    })
  },
  onLoad() {
    this.update();
  },
});
