<template>
<div v-if="mty == 'fmt100' || this.mty == 'fmt103'">
  <el-form-item label="B00" v-bind:error="tagValue[2].s1" :required="true"  label-position="left" label-width="80px">
    <c-date-picker size="small" v-model="tagValue[0].s1" placeholder="委托日期" format="yyyyMMdd" value-format="yyyyMMdd" style="width: 100%" @change="handleChange"></c-date-picker>
  </el-form-item>
  <el-form-item label="A30" v-bind:error="tagValue[2].s2" :required="true"  label-position="left" label-width="80px">
    <el-input size="small" v-model="tagValue[0].s2" placeholder="发起行行号" :maxlength="11" @blur="handleChange">
      <el-button slot="append" icon="el-icon-search" size="mini" @click="handleOpenDialog"></el-button>
    </el-input>
  </el-form-item>
  <el-form-item label="E26" v-bind:error="tagValue[2].s3" :required="true"  label-position="left" label-width="80px">
    <c-select size="small" v-model="tagValue[0].s3" placeholder="业务种类" @change="handleChange" style="width: 100%">
      <el-option v-for="item in busiType" :label="item.label" :value="item.value" :key="item.value"></el-option>
    </c-select>
  </el-form-item>
    <el-form-item label="G53" v-bind:error="tagValue[2].s4" :required="true"  label-position="left" label-width="80px">
    <c-select size="small" v-model="tagValue[0].s4" placeholder="汇款人账户性质" @change="handleChange" style="width: 100%">
      <el-option v-for="item in accType" :label="item.label" :value="item.value" :key="item.value"></el-option>
    </c-select>
  </el-form-item>
  <m-ybic :visible.sync="dialogVisible" @close="handleClose" @rowselect="handleRowSelect"></m-ybic>
</div>
<div v-else>
  <el-form-item v-bind:error="tagValue[2].s1">
    <c-input-format size="small" v-model="tagValue[0].s1" :maxRows="6" :maxCols="35" placeholder="Narrative"
    @blur="handleChange" :disabled="pattern.tagFlag && pattern.tagFlag.indexOf('s1') !== -1">
    </c-input-format>
  </el-form-item>
</div>
</template>
<script>
export default {
  props: {
    tag: {
      type: String,
      default: ''
    },
    mty: {
      type: String,
      default: ''
    },
    pattern: {
      type: Object,
      default: () => {}
    }
  },
  data: function () {
    if (this.mty == 'fmt100' || this.mty == 'fmt103') {
      return {
        dialogVisible: false,
        tagValue: [{
          s1: '',
          s2: '',
          s3: '',
          s4: ''
        },
        '',
        {
          s1: '',
          s2: '',
          s3: '',
          s4: ''
        }],
        busiType: [
          {label:"02-代理进出口",value:"02" },
          {label:"03-与特殊经济区企业资金往来",value:"03" },
          {label:"04-同一企业不同账户资金划转",value:"04" },
          {label:"05-归还国内贷款或转贷款",value:"05" },
          {label:"01-支付运保费",value:"01" },
          {label:"08-其他",value:"08" },
          {label:"06-贸易深加工结转业务",value:"06" },
          {label:"07-贸易融资业务",value:"07" },
        ],
        accType: [
          {label:"01-外币经常项目",value:"01" },
          {label:"02-外币资本项目",value:"02" },
          {label:"03-外币暂存账户",value:"03" },
        ]
      }
    } else {
      return {
        tagValue: [{
          s1: '',
        },
        '',
        {
          s1: '',
        }]
      }
    }
    
  },
  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 () {
      // 触发校验
      if (this.mty == 'fmt100' || this.mty == 'fmt103') {
        let obj = this.pattern.tagValue[0]
        let mval = ''
        if (obj.s1) {
          mval = mval + '/B00/' + obj.s1
        }
        if (obj.s2) {
          mval = (mval?mval+'\r\n': mval) + '/A30/' + obj.s2
        }
        if (obj.s3) {
          mval = (mval?mval+'\r\n': mval) + '/E26/' + obj.s3
        }
        if (obj.s4) {
          mval = (mval?mval+'\r\n': mval) + '/G53/' + obj.s4
        }
        this.pattern.tagValue[1] = mval
      } else {
        let obj = this.pattern.tagValue[0]
        let mval = ''
        mval = obj.s1
        this.pattern.tagValue[1] = mval 
      }
      this.$emit('validate')
    },
    handleOpenDialog: function () {
      this.dialogVisible = true
    },
    handleClose: function () {
      this.dialogVisible = false
    },
     handleRowSelect: function (row) {
      this.pattern.tagValue[0].s2 = row.BIC
      this.handleChange()
    }

  }
}
</script>