<!-- 业务组件 BTCP签收码 -->
<template>
  <div class="component_BTCPSignCode">
    <van-field
      v-model="item.props[0].value"
      :name="item.label"
      :label="item.label"
      :required="item.props[0].required"
      :placeholder="item.label"
      :rules="[{ validator, message: `${item.props[0].value ? `仅支持输入数字、字母，短破折号（-）和下划线（_）` : `请输入${item.label}`}` }]"
    />
  </div>
</template>

<script>
import { Validator } from 'utils-cs'
export default {
  name: 'BTCPSignCode',
  props: {
    item: {
      type: Object,
      required: true,
      default () {
        return {}
      }
    }
  },
  watch: {
    'item.props': {
      handler () {
        this.item.componentFeedback[0].value = [{
          SignCode: this.item.props[0].value
        }]
      },
      deep: true,
      immediate: true
    }
  },
  created () {
  },
  methods: {
    validator (val) {
      if (val) {
        return Validator.isCode(val)
      } else {
        return false
      }
    }
  }
}
</script>
