<template>
<div v-if="mty.indexOf('fmt') !== -1">
  <el-row :gutter="20">
    <el-col :span="12">
      <el-form-item v-bind:error="tagValue[2].s1" :required="pattern.status=='M' || tagValue[1]?true:false"
      label="原MT报文号" label-position="left" label-width="150px">
        <c-input size="small" v-model="tagValue[0].s1" placeholder="" :maxlength="3" style="width: 100%" @blur="handleChange" :disabled="pattern.tagFlag && pattern.tagFlag.indexOf('s1') !== -1"></c-input>
      </el-form-item>
    </el-col>
    <el-col :span="12">
      <el-form-item v-bind:error="tagValue[2].s2" :required="pattern.status=='M' || tagValue[1]?true:false"
      label="原委托日期" label-position="left" label-width="150px">
        <c-date-picker size="small" v-model="tagValue[0].s2" format="yyMMdd" value-format="yyMMdd" style="width: 100%" @change="handleChange" :disabled="pattern.tagFlag && pattern.tagFlag.indexOf('s2') !== -1"></c-date-picker>
      </el-form-item>
    </el-col>
  </el-row>
</div>
<div v-else>
  <el-row :gutter="20">
    <el-col :span="6">
      <el-form-item v-bind:error="tagValue[2].s1" :required="pattern.status=='M' || tagValue[1]?true:false">
        <c-input size="small" v-model="tagValue[0].s1" placeholder="MT Number" :maxlength="3" style="width: 100%" @blur="handleChange" :disabled="pattern.tagFlag && pattern.tagFlag.indexOf('s1') !== -1"></c-input>
      </el-form-item>
    </el-col>
    <el-col :span="6">
      <el-form-item v-bind:error="tagValue[2].s2" :required="pattern.status=='M' || tagValue[1]?true:false">
        <c-date-picker size="small" v-model="tagValue[0].s2" format="yyMMdd" value-format="yyMMdd" style="width: 100%" @change="handleChange" :disabled="pattern.tagFlag && pattern.tagFlag.indexOf('s2') !== -1"></c-date-picker>
      </el-form-item>
    </el-col>
    <el-col :span="6">
      <el-form-item v-bind:error="tagValue[2].s3" :required="!!(tagValue[0].s3 || tagValue[0].s4)">
        <c-input size="small" v-model="tagValue[0].s3" placeholder="4位固定长度数字" :maxlength="4" style="width: 100%" @blur="handleChange" :disabled="pattern.tagFlag && pattern.tagFlag.indexOf('s3') !== -1"></c-input>
      </el-form-item>
    </el-col>
    <el-col :span="6">
      <el-form-item v-bind:error="tagValue[2].s4" :required="!!(tagValue[0].s3 || tagValue[0].s4)">
        <c-input size="small" v-model="tagValue[0].s4" placeholder="6位固定长度数字" :maxlength="6" style="width: 100%" @blur="handleChange" :disabled="pattern.tagFlag && pattern.tagFlag.indexOf('s4') !== -1"></c-input>
      </el-form-item>
    </el-col>
  </el-row>
</div>
</template>
<script>
export default {
  props: {
    tag: {
      type: String,
      default: ''
    },
    mty: {
      type: String,
      default: ''
    },
    pattern: {
      type: Object,
      default: () => {}
    }
  },
  data: function () {
    return {
      tagValue: [{
        s1: '',
        s2: '',
        s3: '',
        s4: ''
      },
      '',
      {
        s1: '',
        s2: '',
        s3: '',
        s4: ''
      }],
    }
  },
  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 temp = "";
      if(obj.s3)
        temp ="\r\n" + obj.s3+obj.s4;
      let mval = `${obj.s1}\r\n${obj.s2}${temp}`.replace('/','')
      this.pattern.tagValue[1] = mval
      this.$emit('validate')
    }
  }
}
</script>