<template>
  <div class="carousel-config">
    <div class="config-header">设置</div>
    <widgetFormitem>
      分组名称是否展示
      <el-switch slot="right" v-model="currentSub.show" />
    </widgetFormitem>
    <div class="confit-item">
      <div class="config-title">
        分组名称
      </div>
      <div class="config-setting">
        <el-input
          v-model="currentSub.groupName"
          placeholder="分组名称"
          class="full-input"
        />
      </div>
    </div>
    <div class="confit-item">
      <div class="config-title">
        排列方式
      </div>
      <div class="config-setting">
        <el-select
          v-model="currentSub.arrangement"
          placeholder="请选择"
          class="full-input"
        >
          <el-option
            v-for="link in arrangementList"
            :key="link.value"
            :label="link.label"
            :value="link.value"
          />
        </el-select>
      </div>
    </div>
    <div class="confit-item">
      <div class="config-title">
        <div class="left">展示数量</div>
        <span>{{ currentSub.quantity }}</span>
      </div>
      <div class="config-setting">
        <el-slider v-model="currentSub.quantity" :max="20" input-size="mini" />
      </div>
    </div>
    <widgetFormitem>
      卖点
      <el-switch slot="right" v-model="currentSub.sellingPoint" />
    </widgetFormitem>
    <widgetFormitem>
      原价
      <el-switch slot="right" v-model="currentSub.originalPrice" />
    </widgetFormitem>
    <widgetFormitem>
      售价
      <el-switch slot="right" v-model="currentSub.sellingPrice" />
    </widgetFormitem>
    <widgetFormitem>
      按钮
      <el-switch slot="right" v-model="currentSub.button" />
    </widgetFormitem>
    <div class="config-header">内容</div>
    <div class="config-item">
      <div class="config-setting">
        <div class="collapse-list">
          <div v-if="currentSub.categoryList.length" class="collapse-item">
            <div class="collapse-item-header">
              <div class="title">商品来源</div>
              <div class="right">
                <i
                  class="el-icon-delete"
                  @click="delectItem(currentSub.categoryList, 0)"
                ></i>
              </div>
            </div>
            <div class="collapse-item-content">
              <div
                v-for="(category, index2) in currentSub.categoryList"
                :key="index2"
                class="class-item"
              >
                <div class="left">
                  类别
                </div>
                <div class="content  text-overflow">
                  {{ category.categoryName }}
                </div>
              </div>
            </div>
          </div>
        </div>
      </div>
    </div>
    <a
      v-if="!currentSub.categoryList.length"
      class="add-widget"
      href="javascript:;"
      @click="addGategory"
    >
      <i class="el-icon-plus"></i>
      添加类别
    </a>
    <goods-class
      ref="edit"
      :dialog-visible="dialog1.isVisible"
      :type="dialog1.type"
      @close="close1"
      @success="success1"
    />
  </div>
</template>

<script>
import { mapState, mapMutations } from 'vuex'
import widgetFormitem from '../components/widgetFormitem'
import GoodsClass from '@/components/applet/GoodsClass'
export default {
  components: {
    widgetFormitem,
    GoodsClass
  },
  data() {
    return {
      arrangementList: [
        {
          value: 1,
          label: '网格'
        },
        {
          value: 2,
          label: '列表'
        }
      ],
      carouselList: [],
      value: '',
      Slidervalue1: 100,
      dialog1: {
        type: 'add',
        isVisible: false
      }
    }
  },
  computed: {
    ...mapState('creationCamp', [
      'currentComponentKeyCode',
      'currentComponentConfig'
    ]),
    currentSub() {
      return this.currentComponentConfig
    }
  },
  watch: {
    currentSub: {
      handler: function handler() {
        this.setComponentConfig({
          keyCode: this.currentComponentKeyCode,
          content: this.currentSub
        })
      },
      deep: true
    }
  },
  methods: {
    ...mapMutations('creationCamp', ['setComponentConfig']),
    addGategory() {
      this.dialog1.isVisible = true
    },
    success1(obj) {
      this.currentSub.categoryList = [obj]
    },
    close1() {
      this.dialog1.isVisible = false
    },
    delectItem(list, index) {
      list.splice(index, 1)
    }
  }
}
</script>

<style lang="less" scoped>
.collapse-item-header {
  display: flex;
  align-items: center;
  padding: 0 12px;
  .title {
    flex: 1;
  }
}

.class-item {
  display: flex;
  align-items: center;
  height: 36px;
  padding: 0 12px;
  margin-bottom: 10px;
  border: 1px solid #eee;
  font-size: 12px;
  .left {
    color: #409eff;
  }
  .content {
    flex: 1;
    margin: 0 8px;
  }
}
</style>
