<template>
  <div>
    <el-popover placement="top" popper-class="change-store-popper" trigger="hover">
      <span class="change-store-btn" slot="reference">
        切换商户
        <i class="iconfont-hb3 iconxiajiantou change-store-icon"></i>
      </span>
      <div class="change-store">
        <div class="store-item actived">
          <div>
            <div class="store-name">金华达摩</div>
            <div class="default-store-tag">默认商户</div>
          </div>
          <i class="el-icon-check checked"></i>
        </div>
        <div class="store-item">
          <div class="store-name">达摩演示</div>
        </div>
        <div class="store-item">
          <div class="store-name">金华达摩代理商</div>
        </div>
        <div class="change-default-store">
          <div class="change-default-store-btn" @click="onShow">更改默认商户</div>
        </div>
      </div>
    </el-popover>
    <el-dialog :visible.sync="changeStore.show" title="更改默认商户" width="600px" @closed="onClosed">
      <div class="change-store-title">选择商户</div>
      <el-select class="change-store-selector" v-show="changeStore.selectShow">
        <el-option label="金华达摩" value="1"></el-option>
      </el-select>
      <div slot="footer">
        <el-button @click="changeStore.show = false">取消</el-button>
        <el-button type="primary" :loading="changeStore.loading" @click="onSave">确定</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
// 获取商户列表
// 切换商户
// 更改默认商户
import { getRequest } from '@/api/api.js';
export default {
  name: 'ChangeStore',
  data() {
    return {
      changeStore: {
        show: false,
        selectShow: false,
        loading: false
      }
    };
  },
  created() {
    // this.getStoreList();
  },
  methods: {
    getStoreList() {
      getRequest('/haoban-manage3-web/login-wx-enterprise-list', { requestProject: 'haoban-manage-web' }).then(resp => {
        console.log(resp);
      });
    },
    onShow() {
      this.changeStore.show = true;
      this.changeStore.selectShow = false;
      setTimeout(() => {
        this.changeStore.selectShow = true;
      }, 300);
    },
    // onClosed() {},
    onSave() {
      this.changeStore.loading = true;
      setTimeout(() => {
        this.changeStore.loading = false;
      }, 1000);
    }
  }
};
</script>

<style lang="scss" scoped>
.change-store-btn {
  display: flex;
  justify-content: center;
  align-items: center;
  margin-right: 15px;
  padding: 9px;
  font-size: 16px;
  font-weight: 500;
  color: #303133;
  border-radius: 4px;
  cursor: pointer;
  .change-store-icon {
    display: inline-block;
    margin-left: 5px;
    transition: 0.3s;
  }
  &:hover {
    background: #f2f3f5;
    .change-store-icon {
      transform: rotateZ(180deg);
    }
  }
}
.change-store-title {
  margin-bottom: 10px;
  font-size: 14px;
  font-weight: 400;
  color: #303133;
  line-height: 20px;
}
.change-store-selector {
  width: 100%;
}
</style>
<style lang="scss">
.change-store-popper {
  padding: 7px 0 0 !important;
  width: 200px;
  box-sizing: border-box;
  .change-store {
    .store-item {
      display: flex;
      justify-content: space-between;
      align-items: center;
      padding: 7px 12px;
      + .store-item {
        margin-top: 4px;
      }
      &.actived {
        background: #f7f8fa;
        .store-name {
          color: #2f54eb;
          font-weight: 500;
        }
        .checked {
          color: #2f54eb;
        }
      }
      &:hover {
        background: #f7f8fa;
      }
      .store-name {
        font-size: 14px;
        font-weight: 400;
        color: #303133;
        line-height: 20px;
      }
      .default-store-tag {
        height: 18px;
        text-align: center;
        line-height: 18px;
        font-size: 12px;
        font-weight: 400;
        color: #2f54eb;
        background: #dee3fc;
        border-radius: 2px;
      }
    }
    .change-default-store {
      margin-top: 7px;
      padding: 0 12px;
      .change-default-store-btn {
        width: 100%;
        height: 36px;
        font-size: 14px;
        font-weight: 400;
        color: #2f54eb;
        line-height: 36px;
        border-top: 1px solid #e4e7ed;
        cursor: pointer;
      }
    }
  }
}
</style>
