Tag.vue 5.68 KB
Newer Older
liuxin committed
1 2 3
<template>
<!-- mt报文 -->
  <div v-if="styleType == 'mtstyle'">
潘际乾 committed
4 5
    <c-row class="m-swf-message-content-item">
      <c-col :span="1">
liuxin committed
6
        <slot name="icon"></slot>
潘际乾 committed
7 8
      </c-col>
      <c-col :span="3" class="m-swf-message-content-tag">
liuxin committed
9 10 11 12 13 14 15 16
        <span v-if="pattern.status === 'M'" class="m-swf-message-content-star">*</span>
        <c-select v-model="pattern.tag" :clearable="false" size="small"
          v-if="pattern.letter && pattern.letter.length > 0" @change="handleTagChange">
          <el-option v-for="item in pattern.letter" :key="item" :label="item" :value="item"></el-option>
        </c-select>
        <span v-else>
          {{pattern.tag}}
        </span>
潘际乾 committed
17 18
      </c-col>
      <c-col :span="4" class="m-swf-message-content-label">
liuxin committed
19
        {{pattern.label}}
潘际乾 committed
20 21
      </c-col>
      <c-col :span="15">
liuxin committed
22 23
        <m-tag-content :tag="pattern.tag" :pattern="pattern" @validate="handleValidate" :seqlist="seqlist" :mty="mty">
        </m-tag-content>
潘际乾 committed
24 25
      </c-col>
      <c-col :span="1" class="m-swf-message-content-tno">
liuxin committed
26
        {{pattern.tno}}
潘际乾 committed
27 28
      </c-col>
    </c-row>
liuxin committed
29 30 31
  </div>
<!-- fmt 报文 -->
<div v-else-if="styleType == 'fmtstyle'">
潘际乾 committed
32 33
    <c-row class="m-swf-message-content-item">
      <c-col :span="1">
liuxin committed
34
        <slot name="icon"></slot>
潘际乾 committed
35 36
      </c-col>
      <c-col :span="3" class="m-swf-message-content-tag">
liuxin committed
37 38 39 40 41 42 43 44
        <span v-if="pattern.status === 'M'" class="m-swf-message-content-star">*</span>
        <c-select v-model="pattern.tag" :clearable="false" size="small"
          v-if="pattern.letter && pattern.letter.length > 0" @change="handleTagChange">
          <el-option v-for="item in pattern.letter" :key="item" :label="item" :value="item"></el-option>
        </c-select>
        <span v-else>
          {{pattern.tag}}
        </span>
潘际乾 committed
45 46
      </c-col>
      <c-col :span="19">
liuxin committed
47 48
        <m-tag-content :tag="pattern.tag" :pattern="pattern" @validate="handleValidate" :seqlist="seqlist" :mty="mty">
        </m-tag-content>
潘际乾 committed
49 50
      </c-col>
      <c-col :span="1" class="m-swf-message-content-tno">
liuxin committed
51
        {{pattern.tno}}
潘际乾 committed
52 53
      </c-col>
    </c-row>
liuxin committed
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203
  </div>
</template>
<script>
  import TagContent from './Tags/index.vue'
  import {
    TagV,
    isTagValueEmpty
  } from './TagValidater'

  export default {
    name: 'm-tag',
    components: {
      'm-tag-content': TagContent
    },
    props: {
      pattern: {
        type: Object,
        default: () => {}
      },
      mty: {
        type: String
      },
      seqlist: {
        type: Array,
        default: () => []
      },
      extra: {
        type: Object,
        default: () => {}
      }
    },
    data: function () {
      return {
        state: {
          tagValue: this.pattern.tagValue,
          isEmpty: this.isEmpty(this.pattern.tagValue)
        }
      }
    },
    mounted: function () {
      if (this.seqlist && !this.isEmpty(this.state.tagValue)) {
        let {
          countMap = {}
        } = this.extra
        for (let seqlbl of this.seqlist) {
          let key = seqlbl.seqlist
          if (!countMap[key])
            countMap[key] = 1
          else
            countMap[key]++
        }
        this.extra.countMap = countMap
      }
    },
    destroyed: function () {
      if (this.seqlist) {
        if (this.isEmpty(this.state.tagValue))
          return
        let {
          countMap
        } = this.extra
        if (!countMap)
          return
        for (let seqlbl of this.seqlist) {
          let key = seqlbl.seqlist
          if (countMap[key])
            countMap[key]--
        }
      }
    },
    computed: {
      styleType () {
        if (this.mty.indexOf('fmt19') !== -1 || this.mty == 'fmt985') {
          // fmt19X 和 fmt985 报文的样式
          return 'fmtstyle'
        } else {
          return 'mtstyle'
        }
      }
    },
    methods: {
      handleValidate: function () {
        console.log(JSON.stringify(this.pattern.tagValue))
        TagV("T" + this.pattern.tag,
          this.pattern.status,
          this.pattern.tagValue,
          this.pattern.tno,
          this.mty,
          this.seqlist,
          this.extra.countMap)
      },
      isEmpty: function (tagValue) {
        if (!tagValue)
          return true
        if (!tagValue.length || tagValue.length < 1)
          return true
        return isTagValueEmpty("T" + this.pattern.tag, tagValue)
      },
      handleTagChange: function () {
        if (this.pattern.copyTagFlag && this.pattern.copyTagFlag[this.pattern.tag + '-flag']) {
          this.pattern.tagFlag = this.pattern.copyTagFlag[this.pattern.tag + '-flag']
        } else {
          this.pattern.tagFlag = []
        }
        delete this.pattern.tagValue

        this.$nextTick(() => {
          if (this.pattern.tagValue && this.pattern.copyTagValue && this.pattern.copyTagValue[this.pattern.tag]) {
            for (let keyvalue in this.pattern.copyTagValue[this.pattern.tag][0]) {
              if (this.pattern.copyTagValue[this.pattern.tag][0][keyvalue]) {
                this.pattern.tagValue[0][keyvalue] = this.pattern.copyTagValue[this.pattern.tag][0][keyvalue]
              }
            }
            if (this.pattern.copyTagValue[this.pattern.tag][1]) {
              this.pattern.tagValue[1] = this.pattern.copyTagValue[this.pattern.tag][1]
            }
          }
        })
      }
    }
  }
</script>
<style>
  .m-swf-message-content-tag {
    position: relative;
    padding-left: 10px;
  }

  .m-swf-message-content-star {
    color: red;
    position: absolute;
    left: 0;
  }

  .m-swf-message-content-tag .el-select {
    width: 70%;
    display: inline-block;
  }

  .m-swf-message-content-label {
    font-size: 12px;
    text-align: center;
    padding-right: 10px;
  }

  .m-swf-message-content-tno {
    padding-left: 5px;
    font-size: 14px;
  }
</style>