// packageD/mycomponent/yz_wap/yz_wapmap.js
var app = getApp();
Component({
  addGlobalClass: true,
  /**
	 * 组件的属性列表
	 */
  properties: {
    showFrom: {
      type: Boolean,
      default: false
    },
  },
  pageLifetimes: {
    show: function () {},
  },
  observers: {
    'showFrom': function (flag) {
      if (flag == true) {
        this._getexplain();
        this._getMember();
      }
    },
  },
  /**
	 * 组件的初始数据
	 */
  data: {
    form: {
      member_name: "",
      member_card: ""
    },

    explain_title: "",
    explain_content: "",

    show1: false
  },

  /**
	 * 组件的方法列表
	 */
  methods: {
    closePopup() {
      this.triggerEvent('confirm', false);
    },
    _getexplain() {
      let that = this;
      let urlStr = app.getNetAddresss("from.div-from.explain");
      app._getNetWork({
        url: urlStr,
        success: (resdata) => {
          var res = resdata.data;
          if (res.result == 1) {
            that.setData({
              explain_title: res.data.explain_title,
              explain_content: res.data.explain_content
            });
          } else {
            wx.showToast({
              icon: 'none',
              title: res.msg,
              duration: 1500
            });
          }
        },
        fail: (res) => {
          console.log(res);
        }
      });
    },
    _getMember() {
      let that = this;
      let urlStr = app.getNetAddresss("from.div-from.getMemberInfo");
      app._getNetWork({
        url: urlStr,
        success: (resdata) => {
          var res = resdata.data;
          if (res.result == 1) {
            that.setData({
              'form.member_name': res.data.realname,
              'form.member_card': res.data.idcard
            });
          } else {
            wx.showToast({
              icon: 'none',
              title: res.msg,
              duration: 1500
            });
          }
        },
        fail: (res) => {
          console.log(res);
        }
      });
    },
    //真实姓名值绑定
    memberNameinp(e) {
      let val = e.detail.value;
      this.setData({
        'form.member_name': val
      });
    },
    //身份证号码值绑定
    membercardinp(e) {
      let val = e.detail.value;
      this.setData({
        'form.member_card': val
      });
    },
    saveInfo() {
      if (app._isTextEmpty(this.data.form.member_name)) {
        wx.showToast({
          title: '请填写姓名！',
          icon: 'none'
        });
        return;
      }
      if (app._isTextEmpty(this.data.form.member_card)) {
        wx.showToast({
          title: '请填写身份证号！',
          icon: 'none'
        });
        return;
      }

      let urlStr = app.getNetAddresss("from.div-from.updateMemberInfo");
      urlStr += '&member_name=' + this.data.form.member_name;
      urlStr += '&member_card=' + this.data.form.member_card;
      app._getNetWork({
        url: urlStr,
        success: (resdata) => {
          var res = resdata.data;
          if (res.result == 1) {
            let json = {
              name : this.data.form.member_name,
              card : this.data.form.member_card,
              status:false
            }
            this.triggerEvent('confirm', json);
          } else {
            wx.showToast({
              icon: 'none',
              title: res.msg,
              duration: 1500
            });
          }
        },
        fail: (res) => {
          console.log(res);
        }
      });
    },
  }
});