// mycomponent/payKeyboard/payKeyboard.js
const app = getApp();
Component({
  /**
   * 组件的属性列表
   */
  properties: {
    show:{
      value:false,
      type:Boolean
    },
    displaySetPass:{
      value:true,
      type:Boolean
    }
  },

  /**
   * 组件的初始数据
   */
  data: {
    passValueArr:[],
    restrict:'',
    nemberKeyboardShow:true
  },
  lifetimes:{
    attached(){

    },
    ready(){
    }
  },
  observers:{
    'show': function (news){
      if(news){
        this.checkCode();
      }
    }
  },
  /**
   * 组件的方法列表
   */
  methods: {
    gotoBalance(){
      this.triggerEvent("close");
      wx.navigateTo({
        url: '/packageA/member/balance_password/balance_password'
      });
    },
    handkeyboardinput(evt){
      let {value,type} = evt.detail;
      console.log(this.data.passValueArr);

      if(type=="number"){
        if(this.data.passValueArr.length<6)this.data.passValueArr.push(value);

        if(this.data.passValueArr.length>=6){
          this.triggerEvent("complete",this.data.passValueArr.join(''));
          this.setData({show:false,passValueArr:[]});
          return;
        }

      }else if(type=="deleteBtn"){
        this.data.passValueArr.pop();
      }
      this.setData({
        passValueArr:this.data.passValueArr
      });
    },
    setNemberKeyboardShow(){
      this.setData({nemberKeyboardShow:true});
    },
    closePayKeyboard(){
      this.setData({show:false});
      this.triggerEvent("close");
    },
    submit(){
      console.log(this.data.passValueArr);
      if (this.data.passValueArr.length <= 16 && this.data.passValueArr.length >= 8) {
        this.triggerEvent("complete",this.data.passValueArr);
        this.setData({show:false,passValueArr:''});
      }else{
        app.tips('请输入正确密码');
        this.triggerEvent("close");
        this.setData({show:false,passValueArr:''});
      }
    },
    tapinp(e){
      this.setData({
        passValueArr:e.detail
      });
    },
    checkCode(){
      if(this.data.restrict) {
        return;
      }
      wx.showLoading({
        title: '加载中',
      });
      let urlStr = app.getNetAddresss("payment.password.multiple");
      app._getNetWork({
        showToastIn: false,
        url: urlStr,
        success: (resdata)=> {
          var res = resdata.data;
          wx.hideLoading({
            success: (res) => {},
          });
          if (res.result == 1) {
            let rict;
            if(res.data){
              rict = 'more';
            }else{
              rict = 'once';
            }
            this.setData({
              restrict : rict
            });
          }else {
            this.setData({
              restrict : 'more'
            });
          }
        },
        fail: (res)=> {
          wx.hideLoading();
          this.setData({
            restrict : 'more'
          });
        },
      });
    },
  },
  ready: function() {

  },
});
