<template>
  <div>
    <div class="box">
      <div class="title flex">
        <div>
          <!-- 展示模块 -->
          {{ $t('common.l6') }}
        </div>
        <div class="tip">
          <!-- 可拖拽排序 -->
          {{ $t('common.l7') }}
        </div>
      </div>
      <div class="drag-box">
        <draggable class="list" ghost-class="ghost" v-model="tabList" animation="300">
          <div class="drag-item flex" v-for="(item, index) in tabList" :key="item.code">
            <div class="left" :class="{active: activeName == item.code}">{{ tabName[item.title] || item.title }}</div>
            <div class="right flex">
              <img class="drag-icon" src="/img/product/drag.png"/>
              <img class="del-icon" v-if="tabList.length > 1" @touchend="deleteTab(index)" src="/img/product/del.png"/>
            </div>
          </div>
        </draggable>
      </div>
    </div>
    <div class="box1" v-if="hideList.length">
      <div class="title flex">
        <div>
          <!-- 隐藏模块 -->
          {{ $t('common.l8') }}
        </div>
        <div class="tip">
          <!-- 点击显示 -->
          {{ $t('common.l9') }}
        </div>
      </div>
      <div class="hide-box flex">
        <div class="hide-item" @touchend="addTab(index)" v-for="(item, index) in hideList" :key="item.code">
          <i class="el-icon-plus"></i> {{ tabName[item.title] || item.title }}
        </div>
      </div>
    </div>
    <div class="btn-box">
      <div class="btn" @click="submit">
        <!-- 完成 -->
        {{ $t('common.l10') }}
      </div>
    </div>
  </div>
</template>
<script>
import draggable from 'vuedraggable'
import { getStorage, setStorage } from '@/utils/localStorage'
import { deepCopy } from "@/utils/index";
export default {
  props: ['activeName', 'list', 'tabName'],
  components: {
    draggable,
  },
  data () {
    return {
      tabList: [],
      hideList: []
    }
  },
  created () {
    var list = getStorage('optionShowTab')
    if (list) {
      this.tabList = list
    } else {
      this.tabList = deepCopy(this.list)
    }
    var list1 = getStorage('optionHideTab')
    if (list1) {
      this.hideList = list1
    }
  },
  methods: {
    submit() {
      setStorage('optionShowTab', this.tabList)
      setStorage('optionHideTab', this.hideList)
      this.$emit('back', this.tabList)
    },
    deleteTab(index) {
      var list = this.tabList.splice(index, 1)
      this.hideList.push(list[0])
    },
    addTab(index) {
      var list = this.hideList.splice(index, 1)
      this.tabList.push(list[0])
    }
  }
}
</script>
<style lang="less" scoped>
.title {
  font-size: 14px;
  color: #000000;
  column-gap: 3px;
  .tip {
    font-size: 10px;
    color: #9F9F9F;
  }
}
.box {
  padding: 0 28px 15px;
  .close {
    display: block;
    cursor: pointer;
    margin-bottom: 18px;
    width: 11px;
  }
}
.drag-box {
  .drag-item {
    justify-content: space-between;
    margin-top: 15px;
    -moz-user-select: none;
    -webkit-user-select: none;
    -ms-user-select: none;
    user-select: none;
  }
  .left {
    min-width: 71px;
    line-height: 26px;
    background-color: #F5F5F5;
    border-radius: 2px;
    text-align: center;
    font-size: 13px;
    padding: 0 6px;
    color: #4A4A4A;
    &.active {
      background-color: #4A4A4A;
      color: #fff;
    }
  }
  .right {
    column-gap: 20px;
  }
  .drag-icon {
    width: 14px;
  }
  .del-icon {
    cursor: pointer;
    width: 11px;
  }
}
.box1 {
  padding: 20px 28px 0;
  border-top: 1px solid #F2F2F2;
  .title {
    margin-bottom: 15px;
  }
}
.hide-box {
  column-gap: 16px;
  row-gap: 8px;
  flex-wrap: wrap;
  .hide-item {
    line-height: 26px;
    background-color: #F5F5F5;
    cursor: pointer;
    min-width: 71px;
    text-align: center;
    color: #4A4A4A;
    font-size: 13px;
    padding: 0 6px;
    border-radius: 2px;
  }
}
.btn-box {
  padding: 24px 28px 0;
  .btn {
    cursor: pointer;
    border-radius: 6px;
    text-align: center;
    line-height: 44px;
    font-size: 16px;
    color: #fff;
    background-color: var(--color-);
  }
}
</style>