Component({
  mixins: [],
  data: {
    showresult:"",
    result: "",
    scenes: 2,
    errMsg: ""
  },

  props: {

    //场景 1.输入商品码 2.会员 3.收款  4.退款
    scene: 1,
    //错误提示
    errMsg: ''
  },
  didMount() { },
  didUpdate() { },
  didUnmount() { },
  deriveDataFromProps(nextProps) {

    //弹窗消失的时候 result清空
    if (nextProps.scene == 0) {
      this.setData({
        result: '',
        errMsg: '',
        showresult:''
      });
    }

    this.setData({
      scenes: nextProps.scene,
    });

  },
  methods: {


    add7(e) {
      this.addInputContont("7")
    }, add8(e) {
      this.addInputContont("8")
    }, add9(e) {
      this.addInputContont("9")
    }, add4(e) {
      this.addInputContont("4")
    }, add5(e) {
      this.addInputContont("5")
    }, add6(e) {
      this.addInputContont("6")
    }, add1(e) {
      this.addInputContont("1")
    }, add2(e) {
      this.addInputContont("2")
    }, add3(e) {
      this.addInputContont("3")
    }, add0(e) {
      this.addInputContont("0")
    }, addpoint(e) {
      if (this.data.scenes == 3 || this.data.scenes == 4) {
         this.addInputContont(".")
      }
    }, delete(e) {
      if (this.data.result.length > 1) {
        let cur = this.data.result;
        cur = cur.substring(0, cur.length - 1)

        let shownewresult = cur
        if (cur.length > 13) {
          shownewresult = "..." + cur.substring(cur.length - 11, cur.length)
        }
        this.setData({ result: cur, showresult: shownewresult });
      } else {
        this.setData({ result: '',showresult:''});
      }
    }, finish(e) {
      this.setData({ errMsg: "" })
      if (this.data.scenes == 3 || this.data.scenes == 4) {
        //判断价格是否参数合法
        var priceReg = /(^[1-9]\d*(\.\d{1,2})?$)|(^0(\.\d{1,2})?$)/;
        if (!priceReg.test(this.data.result)) {
          //错误提示
          this.setData({ errMsg: "金额格式有误" })
          return
        }
      } else if (this.data.scenes == 2) {
        if (this.data.result == null || this.data.result.length != 11) {
          this.setData({ errMsg: "会员号格式有误" })
          return
        }
      }
      this.props.onKeyBordFinished(this.data.result);
    }, closeKeybord(e) {
      this.props.onKeyBordClose();
    },
 //处理输入的内容
  addInputContont(content){
     let newresult = this.data.result + content;
     let shownewresult = newresult
     if(newresult.length > 13){
        shownewresult = "..."+ newresult.substring(newresult.length - 11,newresult.length)
     }
     this.setData({ result: newresult,showresult:shownewresult});
  }

  },

 

});
