<template>
  <div class="launch-flowable">
    <a-input-search
      enter-button
      style="width: 500px"
      class="px-5 pt-5"
      :placeholder="$t('PLACEENTER')"
      @search="(value) => queryData({ name: value })"
    />
    <a-collapse
      :active-key="activeKey"
      :bordered="false"
      expand-icon-position="right"
      class="collapse-header-divide"
    >
      <a-collapse-panel
        v-for="item in data"
        :key="item.categoryCode"
        :header="item.categoryName"
      >
        <a-list
          :grid="{ column: 8 }"
          :data-source="item.procdefBPOList"
          row-key="id"
        >
          <a-list-item slot="renderItem" slot-scope="e">
            <a-card class="flowable-item" @click.native="() => handleLaunch(e)">
              <div
                class="flowable-icon"
                :style="{
                  backgroundColor: color[Math.floor(Math.random() * (5 + 1))],
                }"
              >
                <svg-icon
                  v-if="e.icon"
                  :icon-class="e.icon"
                  style="font-size: 40px; margin-top: 0.0125em"
                />
                <Icon
                  v-else
                  type="icon-jichushuju06-gongchangjianmo"
                  :size="40"
                />
              </div>
              <span>
                {{ e.name }}
                {{ e.version }}
              </span>
            </a-card>
          </a-list-item>
        </a-list>
      </a-collapse-panel>
    </a-collapse>
  </div>
</template>

<script>
import { Icon } from "@mega-design/ui-vue";
import ApiConstant from "@/api/ApiConstant";

export default {
  components: {
    Icon,
  },
  data() {
    return {
      data: [],
      color: ["#005583", "#14CC8A", "#09B2EF", "#8B6FE6", "#F7A853", "#EE5253"],
      params: {
        name: "",
      },
    };
  },
  computed: {
    activeKey() {
      return this.data.map((item) => item.categoryCode).filter((item) => item);
    },
  },
  created() {
    this.queryData();
  },
  methods: {
    handleLaunch(item) {
      this.$router.push({
        path: "/flowable/launch/add",
        query: {
          id: item.id,
          deployId: item.deployId,
          type: "DEF",
          btnType: "todo",
        },
      });
    },
    queryData(params = {}) {
      this.$axios
        .get(
          `${ApiConstant.PREFIX_CORE}/api/flowable/definition/def-category-list`,
          {
            params: { ...params },
          }
        )
        .then((res) => {
          this.data = res.data.data;
        });
    },
  },
};
</script>

<style lang="less" scoped>
@import (optional, once) "@/theme";

.launch-flowable {
  .flowable-item {
    border-color: transparent;
    border-radius: 10%;
    cursor: pointer;
    text-align: center;
    &:hover {
      background-color: fade(@border-color-base, 30%);
    }
    /deep/.ant-card-body {
      display: flex;
      flex-direction: column;
      align-items: center;
    }
  }
  .flowable-icon {
    width: 82px;
    height: 82px;
    color: @white;
    text-align: center;
    line-height: 82px;
    border-radius: 20%;
    margin-bottom: 10px;
  }
}
</style>
