<template>
  <section class="dm-store">
    <el-select v-model="leftValue" placeholder="请选择" class="w200 inline-block">
      <el-option v-for="(v,i) in leftList" :key="i" :label="v.label" :value="v.value"></el-option>
    </el-select>
    <option-type v-if="storeType === 1" :uuid="newUuid"></option-type>
    <option-tags v-if="storeType === 2" :uuid="newUuid"></option-tags>
    <option-area v-if="storeType === 3" :uuid="newUuid"></option-area>
    <option-group v-if="storeType === 4" :uuid="newUuid"></option-group>
    <option-part v-if="leftValue === 5" :uuid="newUuid"></option-part>
  </section>
</template>

<script>
import qs from 'qs';
import uuidv1 from 'uuid/v1';
import { baseUrl } from './config';
import optionType from './options/option-type';
import optionArea from './options/option-area';
import optionTags from './options/option-tags';
import optionGroup from './options/option-group';
import optionPart from './options/option-part';

export default {
  name:'vue-gic-store-new',
  props:{
    uuid:{
      type:String,
      default:''
    }
  },
  components:{
    'option-type':optionType,
    'option-area':optionArea,
    'option-tags':optionTags,
    'option-group':optionGroup,
    'option-part':optionPart
  },
  data() {
    return {
      leftValue:0, // 一级选择值
      leftList:[ // 一级列表
        {label:'所有门店',value:0},
        {label:'门店类型',value:1},
        {label:'门店标签',value:2},
        {label:'门店区域',value:3},
        {label:'门店分组',value:4},
        {label:'部分门店',value:5}
      ],
      newUuid:uuidv1().replace(/-/g,'')  // 生成uuid
    }
  },
  created() {
    this.init();
  },
  methods:{
    // 获取配置项
    init() {
      this.newUuid = this.uuid || this.newUuid;
      if (!this.uuid) {
        this.$emit('update:uuid',this.newUuid);
      } else {
        let params = {
          key:this.newUuid,
          currentPage:1,
          pageSize:20
        }
        this.axios.post(baseUrl + '/api-plug/get-store-widget-config?requestProject=gic-web',qs.stringify(params)).then(res => {
          this.comList = res.data.result.config.result || [];
          this.leftValue = res.data.result.selectType || 0;
        }).catch(err => {
          console.log(err)
        })
      }
    }
  }
}
</script>

<style lang="scss">
@import url('./index.css');
</style>
