<template>
<div>
  <el-form-item v-bind:error="tagValue[2].s1">
    <el-input size="small" v-model="tagValue[0].s1" placeholder="Account" :maxlength="34" @blur="handleChange"
    :disabled="pattern.tagFlag && pattern.tagFlag.indexOf('s1') !== -1">
      <template slot="prepend">/</template>
    </el-input>
  </el-form-item>
  <el-form-item v-bind:error="tagValue[2].s2" :required="pattern.status=='M' || tagValue[1]?true:false">
    <c-input-format size="small" v-model="tagValue[0].s2" :maxRows="4" :maxCols="35"
    placeholder="Name and Address" @blur="handleChange" :disabled="pattern.tagFlag && pattern.tagFlag.indexOf('s2') !== -1">
    </c-input-format>
    <span class="m-tag-warning">请替换模板为正常内容</span>
  </el-form-item>  
</div>
</template>
<script>
export default {
  props: {
    tag: {
      type: String,
      default: ''
    },
    pattern: {
      type: Object,
      default: () => {}
    }
  },
  data: function () {
    return {
      tagValue: [{
        s1: '',
        s2: `1/(Name of Beneficiary Customer)
2/(Address Line)
3/(Country and Town)`
      },
      '',
      {
        s1: '',
        s2: ''
      }]
    }
  },
  created: function () {
    if (this.pattern.tagValue == undefined || JSON.stringify(this.pattern.tagValue) == '[{},null]') {
      this.pattern.tagValue = this.tagValue
    } else {
      this.tagValue = this.pattern.tagValue
    }
  },
  methods: {
    handleChange: function () {
      // 触发校验
      let obj = this.pattern.tagValue[0]
      let mval = ''
      if(obj.s1)
        mval = `${obj.s1}\r\n`
      if(obj.s2 )
        mval = `${mval}${obj.s2}`
      this.pattern.tagValue[1] = mval
      this.$emit('validate')
    }
  }
}
</script>
<style>
.m-tag-warning {
  font-size: 12px;
  color:orange;
}
</style>