<template>
  <div id="weight-setting">
    <div class="setting-item">
      <Checkbox v-model="setting.isLinkDevice">
        连接称重设备
      </Checkbox>
      <Tooltip
        content=" 支持牧炫软件"
        placement="top"
        style="line-height: 12px"
      >
        <Icon
          type="md-alert"
          style="color:var(--primary-color);font-size: 18px;"
        />
      </Tooltip>
    </div>

    <div class="setting-item">
      <Checkbox v-model="setting.isAlert">
        未发货提醒
      </Checkbox>
    </div>

    <div class="setting-item">
      <Checkbox v-model="setting.isLimitRange">
        称重误差范围(千克) ±
      </Checkbox>
      <Input
        v-model="setting.weightRange"
        size="small"
        placeholder=""
        :regx="regxString"
        style="width: 100px"
        @input.native="onInputWeight"
      />
    </div>

    <div class="setting-item">
      <span style="margin-right: 8px;font-size: 12px;">自动提交时间(秒)</span> 
      <!-- 自动提交时间(秒s) -->
      <Input
        v-model="setting.submitTime"
        size="small"
        :regx="regxTime"
        placeholder=""
        style="width: 100px;"
      />
    </div>
  </div>
</template>

<script>
  export default {
    name: 'WeightSetting',

    props: {
      setting: {
        type: Object,
        default() {
          return {};
        }
      }
    },

    data() {
      return {
        regxString: /^[\+]?\d*?\.?\d{0,2}$/,
        regxTime: /^[\+]?\d*?\.?\d{0,0}$/,
      };
    },

    mounted() {

    },

    methods: {
      // 监听重量范围输入
      onInputWeight(e) {
        const value = e.target.value;
        if (value) {
          this.setting.isLimitRange = true;
        } else {
          this.setting.isLimitRange = false;
        }
        // if (!/^\d*\.?\d{0,2}$/.test(value) || value < 0) {
        //   e.preventDefault();
        //   e.target.value = value.replace(/[^\d.]/g, '');
        // } else {
        //   const parts = value.split('.');
        //   if (parts.length > 1 && parts[1].length > 2) {
        //     e.target.value = `${parts[0]}.${parts[1].slice(0, 2)}`;
        //   }
        // }
      },

      // 监听提交时间的输入
      // onInputTime(e) {
      // 只能输入正整数
      // const value = e.target.value;
      // if (!/^\d+$/.test(value)) {
      //   e.preventDefault();
      //   e.target.value = value.replace(/[^\d]/g, '');
      // }
      // }
    },
  };
</script>

<style lang="less" scoped>
#weight-setting {
  // border: 1px solid #e5e5e5;
  // position: absolute;
  // right: 20px;
  // top: 50px;
  padding: 10px;
  font-size: 16px;
  .setting-item {
    margin-bottom: 10px;
    &:last-child {
      display: flex;
      align-items: center;
      justify-content: space-between;
    }
  }
}
</style>
<style lang="less">
#weight-setting {
  .ark-tooltip-inner {
    line-height: 16px;
  }
}
</style>
