<template>
  <div>
    <div class="widget-form-item" @click.stop="handleSelectWidget(index)">
      <!-- <div class="drag-widget" title="拖拽" v-if="selectWidget.key == element.key">
      <i class="icon-drag"></i>
    </div>
    <div class="widget-view-action" v-if="selectWidget.key == element.key">
      <i class="icon-trash" title="删除" @click.stop="handleWidgetDelete(index)"></i>
    </div>-->
      <el-steps :active="1" finish-status="success" align-center>
        <el-step
          v-for="(col, colIndex) in element.pageStepsArr"
          :key="colIndex"
          :title="col.name"
        ></el-step>
      </el-steps>
    </div>
  </div>
</template>
<script>
import { mapState, mapMutations } from 'vuex'
import Draggable from 'vuedraggable'
import WidgetFormItem from '@/components/form/WidgetFormItem.vue'

export default {
  name: 'widget-page-steps-layout',
  components: {Draggable, WidgetFormItem},
  props: ['element', 'index', 'data'],
  data() {
    return {
      activeName: 0,
      showIndex: 0,
    }
  },
  computed: {
    ...mapState('form', ['selectWidget']),
  },
  methods: {
    ...mapMutations({
      setSelectWidget: 'form/setSelectWidget', // 设置当前选中控件
    }),
    back() {
      this.showIndex -= 1
    },
    next() {
      this.showIndex += 1
    },
    handleCurrentChange(val) {
      this.showIndex = val - 1
    },
    handleMoveStart: function (evt) {
      // 新增控件时  将控件属性切断联系
      evt.item._underlying_vm_ = deepmerge({}, evt.item._underlying_vm_, {
        clone: true,
      })
      const key =
        Date.parse(new Date()) + '_' + Math.ceil(Math.random() * 99999)
      evt.item._underlying_vm_.key = key
    },
    handleSelectWidget(index) {
      this.setSelectWidget(this.data.list[index])
    },
    handleWidgetColAdd($event, row, colIndex) {
      const newIndex = $event.newIndex
      const oldIndex = $event.oldIndex
      const item = $event.item
      // 防止布局元素的嵌套拖拽
      if (item.className.indexOf('data-grid') >= 0) {
        // 如果是列表中拖拽的元素需要还原到原来位置
        item.tagName === 'DIV' &&
          this.data.list.splice(
            oldIndex,
            0,
            row.columns[colIndex].list[newIndex]
          )
        row.columns[colIndex].list.splice(newIndex, 1)
        return false
      }
      this.setSelectWidget(row.columns[colIndex].list[newIndex])
    },
    handleWidgetDelete(index) {
      if (this.data.list.length - 1 === index) {
        if (index === 0) {
          this.setSelectWidget({options: {validateType: ''}})
        } else {
          this.setSelectWidget(this.data.list[index - 1])
        }
      } else {
        this.setSelectWidget(this.data.list[index + 1])
      }

      this.$nextTick(() => {
        this.data.list.splice(index, 1)
      })
    },
  },
}
</script>
<style lang="scss" scoped>
@import '@/assets/css/form-editor.scss';

.widget-col {
  padding-bottom: 0;
  padding: 15px 5px;
}

.widget-col.active {
  outline: 1px solid $--form-design-active-color;
}

.el-col {
  min-height: 50px;
}

.widget-col-list {
  min-height: 50px;
  border: 1px solid $--form-design-active-color;
}

div.widget-view-action {
  border-color: $--form-design-active-color;
  border-radius: 15px;
}

div.widget-view-action i.icon-trash {
  margin: 0 10px;
}

div.drag-widget {
  border-color: $--form-design-active-color;
}

div.drag-widget i.icon-drag {
  color: $--form-design-active-color;
}
</style>