<template>
  <div class="elseif-content">
    <div class="add-perate-icon" @click.stop="addOperate" title="If...Then...">
      <img :src="icon" alt="" title="If...Then...">
      <img v-if="typeof(stageData.enable) != 'undefined' && stageData.enable === false" class="perate-enable" :src="enable" alt="" title="禁用">
    </div>
    <div class="row-content">
      <el-row class="mb-10">
        <b>Else if</b>
        (
        <expression exprText="条件" :exprType="exprTypep" :messageExpr="stageData.contentExpr" @confirm="handleExpression" />
        <span class="isrequired">*</span>
        )
      </el-row>
      <el-row class="mb-10">then (</el-row>
      <el-row class="mb-10">
        <flow-stage ref="flowStage" :list="stageData.subNodes" />
      </el-row>
      <el-row class="mb-10">)</el-row>
    </div>
  </div>
</template>

<script>
import icon from '@/assets/img/elseif.gif'
import enable from '@/assets/img/enable.gif'
import Expression from '../expression'
export default {
  name: 'IfThen',
  components: {
    Expression,
    FlowStage: () => import('../FlowStage')
  },
  data() {
    return {
      icon: icon,
      enable
    }
  },
  props: {
    index: {
      type: Number,
      default: 0
    },
    stageData: {
      type: Object,
      default() {
        return {}
      }
    },
    exprTypep: {
      type: Array,
      default() {
        return ['simple', 'jsonpath']
      }
    }
  },
  watch: {
    stageData: {
      handler: function(val) {
        if (!val.contentExpr) {
          this.$set(val, 'contentExpr', {})
        }
      },
      deep: true,
      immediate: true
    }
  },
  methods: {
    handleExpression(data) {
      this.$set(this.stageData.contentExpr, 'exprType', data.exprType)
      this.$set(this.stageData.contentExpr, 'valueExpr', data.valueExpr)
      if (data.valueExpr.indexOf(':=') !== -1) {
        this.stageData.contentExpr.logicalExpr = ':='
      }
      if (data.valueExpr.indexOf(':<') !== -1) {
        this.stageData.contentExpr.logicalExpr = ':<'
      }
      if (data.valueExpr.indexOf(':>') !== -1) {
        this.stageData.contentExpr.logicalExpr = ':>'
      }
      if (data.valueExpr.indexOf(':!=') !== -1) {
        this.stageData.contentExpr.logicalExpr = ':!='
      }
      if (data.valueExpr.indexOf(':ct') !== -1) {
        this.stageData.contentExpr.logicalExpr = ':ct'
      }
    },
    addOperate(e) {
      this.$emit('confirm', e, this.index)
    }
  }
}
</script>

<style lang="scss" scoped>
  .elseif-content {
    &:after {
      content: "";
      clear: both;
      display: block;
    }
  }
</style>
