<!--
 * @Descripttion: 当前组件信息
 * @version: 1.0.0
 * @Author: 无尘
 * @Date: 2019-07-22 19:15:16
 * @LastEditors: 无尘
 * @LastEditTime: 2019-09-30 16:23:24
 -->
<template>
  <div class="api-body-content border-box">
    <div class="common-nav">
      <nav-bread :nav-path="navPath" />
    </div>
    <div class="api-body-main common-body-main border-box">
      <div class="api-main-content border-box">
        <el-input
          v-model="search"
          placeholder="请输入插件名称"
          prefix-icon="el-icon-search"
          clearable
          class="w-320"
          @keyup.enter.native="getList()"
          @clear="getList()" />
        <div
          v-loadingh="loading"
          class="list-content">
          <div
            v-for="(item, index) in list"
            :key="index"
            class="list-item">
            <div class="item-top">
              <span class="icon-content">
                <i
                  v-if="item.pluginType === 0"
                  class="iconfont iconahas" />
                <i
                  v-if="item.pluginType === 1"
                  class="iconfont iconkaifangpingtai" />
              </span>
              <div class="item-info">
                <h3>插件名称</h3>
                <p>{{ item.pluginName }}</p>
              </div>
            </div>
            <div class="item-bottom">
              <el-button
                type="text"
                @click="goEnvList(item)">
                选择环境进入<i class="iconfont iconjiantou-zuo" />
              </el-button>
            </div>
          </div>
        </div>
      </div>
    </div>
    <select-env
      v-if="showdialog"
      :plugin-id="pluginId"
      :plugin-type="pluginType"
      @closeDialog="closeDialog" />
  </div>
</template>
<script>
import navBread from '@/components/nav/nav-bread.vue';
import { getRequest } from '@/api/api';
import selectEnv from '@/components/plug/environment-list';
export default {
  name: 'PluginManage',
  components: {
    navBread,
    selectEnv
  },
  data() {
    return {
      // 面包屑参数
      navPath: [
        {
          name: '插件管理',
          path: ''
        }
      ],
      search: '',
      list: [],
      showdialog: false,
      pluginType: 0,
      pluginId: '',
      loading: false
    };
  },

  /* 接收数据 */
  mounted() {
    this.getList();
  },
  methods: {
    /**
     *  获取数据
     */
    getList() {
      let that = this;
      let params = {
        search: this.search
      };
      this.loading = true;
      getRequest('/gateway-manage/plugin/list', params)
        .then(res => {
          if (res.data.code == '0000') {
            if (res.data.result) {
              this.list = res.data.result;
            } else {
              this.list = [];
            }
            this.loading = false;
          } else {
            this.$message.error(res.data.message);
          }
        })
        .catch(function(error) {
          that.$message.error({
            duration: 1000,
            message: error.message
          });
        });
    },
    goEnvList(item) {
      this.showdialog = true;
      this.pluginId = item.pluginId;
      this.pluginType = item.pluginType;
    },
    closeDialog() {
      this.showdialog = false;
    }
  },
  watch: {
    $route: {
      handler: function(val, oldVal) {},
      // 深度观察监听
      deep: true
    }
  }
};
</script>

<style lang="less" scoped>
.w-320 {
  width: 320px;
}
.list-content {
  margin-top: 20px;
  font-size: 0;
  .list-item {
    display: inline-block;
    margin-right: 10px;
    width: 180px;
    height: 127px;
    background: rgba(255, 255, 255, 1);
    border-radius: 4px;
    border: 1px solid rgba(228, 231, 237, 1);
    &:hover {
      box-shadow: 0px 2px 7px 0px rgba(213, 213, 213, 0.5);
    }
    .item-top {
      margin-top: 20px;
      display: flex;
      .icon-content {
        display: inline-block;
        width: 42px;
        height: 42px;
        line-height: 42px;
        text-align: center;
        border-radius: 50%;
        background: #f0f2f5;
        margin-left: 10px;
        i {
          font-size: 21px;
          color: #606266;
        }
      }
      .item-info {
        margin-left: 15px;
        h3 {
          font-size: 12px;
          font-family: PingFang-SC;
          font-weight: 500;
          color: rgba(144, 147, 153, 1);
          line-height: 17px;
        }
        p {
          font-size: 16px;
          font-family: PingFangSC;
          font-weight: 600;
          color: rgba(48, 49, 51, 1);
          line-height: 22px;
        }
      }
    }
    .item-bottom {
      border-top: 1px solid #e4e7ed;
      margin-top: 23px;
      button {
        font-size: 14px;
        margin-left: 65px;
        margin-top: 10px;
        &.el-button--text:hover,
        &.el-button--text:focus {
          color: #2656d4;
        }
      }
    }
  }
}
</style>
