<template>
  <div class="module-cont">
    <div class="add-perate-icon" @click.stop="addPerate">
      <img :src="icon" alt="" title="分配">
      <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>分配</b>
        <expression
          :exprType="exprType"
          messageExprType="ContentExpr"
          :messageExpr="stageData.contentExpr"
          @confirm="handleExpression" />
        <span class="isrequired">*</span>
        至变量
        <el-input v-model="stageData.variable" class="ml-5 mr-5" style="width: 200px;"></el-input>
        <span class="isrequired">*</span>
      </el-row>
      <!-- <el-row>
        <b>操作：</b>
        <el-select
          v-model="stageData.binding"
          clearable
          placeholder="请选择"
          style="width: 100%;">
          <el-option v-for="item in ports" :key="item.name" :label="item.name" :value="item.name">
          </el-option>
        </el-select>
      </el-row> -->
    </div>
  </div>
</template>

<script>
import icon from '@/assets/img/assign.gif'
import enable from '@/assets/img/enable.gif'
import Expression from '../expression'
import { createNamespacedHelpers } from 'vuex'

const { mapGetters } = createNamespacedHelpers('app')
export default {
  name: 'Report',
  components: {
    Expression
  },
  data() {
    return {
      icon: icon,
      enable: enable,
      exprType: []
    }
  },
  props: {
    index: {
      type: Number,
      default: 0
    },
    stageData: {
      type: Object,
      default() {
        return {}
      }
    }
  },
  computed: {
    ...mapGetters(['payloadType'])
  },
  watch: {
    stageData: {
      handler: function(val) {
        if (!val.contentExpr) {
          this.$set(val, 'contentExpr', {})
        }
      },
      deep: true,
      immediate: true
    },
    payloadType: {
      handler: function(val) {
        this.exprType = val === 'xml' ? ['simple', 'xquery', 'jsonpath'] : val === 'json' ? ['simple', 'xquery', 'jsonpath'] : ['simple']
      },
      immediate: true
    }
  },
  methods: {
    handleExpression(data) {
      this.$set(this.stageData.contentExpr, 'exprType', data.exprType)
      this.$set(this.stageData.contentExpr, 'valueExpr', data.valueExpr)
      this.$set(this.stageData.contentExpr, 'resourcePath', data.resourcePath)
      this.$set(this.stageData.contentExpr, 'resourceId', data.resourceId)
      this.$set(this.stageData.contentExpr, 'objname', data.objname)
      this.$set(this.stageData.contentExpr, 'resourceType', data.resourceType)
    },
    addPerate(e) {
      this.$emit('confirm', e, '0', this.index)
    }
  },
  mounted() {
    if (!this.stageData.resourcePath) {
      if (this.stageData.contentExpr.resourcePath) {
        var names = this.stageData.contentExpr.resourcePath.split('/')
        this.$set(this.stageData.contentExpr, 'objname', names[names.length - 1])
      }
    }
  }
}
</script>

<style lang="scss" scoped>
</style>
