Component({
  mixins: [],
  data: {
    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: '',
      });
    }

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

  },
  methods: {


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


  },
});
