<template>
  <!-- 新购工机具管理 -->
  <div class="app-container">
    <PageHeaderApply
      v-if="isShowComponent != 'Home'"
      :pageContent="pageContent"
      @goBack="goBack"
    />
    <keep-alive include="Home">
    <component
      ref="componentRef"
      :is="isShowComponent"
      :isEdit="isEdit"
      :editTaskId="editTaskId"
      :editId="editId"
      :queryTaskId="queryTaskId"
      :queryId="queryId"
      :isView="isView"
      :codingTaskId="codingTaskId"
      @addTools="addTools"
      @editTools="editTools"
      @addToolsSuccess="addToolsSuccess"
      @queryTools="queryTools"
    />
    </keep-alive>
  </div>
</template>

<script>
import PageHeaderApply from "@/components/pageHeaderApply";
import Home from "./component/homeApply.vue"; // 主列表
import AddTools from "./component/addToolsApply.vue"; // 发布
import QueryTools from "./component/queryToolsApply.vue"; // 查询机具
export default {
  name: "LeasePublish",
  components: {
    Home,
    PageHeaderApply,
    AddTools,
    QueryTools,
  },
  data() {
    return {
      isShowComponent: "Home",
      pageContent: "领用申请发布",
      isEdit: false,
      editTaskId: "",
      editId: "",
      queryId: "",
      queryTaskId: "",
      isView: false,
      codingTaskId: "",
    };
  },

  methods: {
    /* 发布 */
    addTools() {
      this.isEdit = false;
      this.editTaskId = "";
      this.queryTaskId = "";
      this.pageContent = "领用申请发布";
      this.isShowComponent = "AddTools";
    },
    /* 新增成功 */
    addToolsSuccess() {
      this.isShowComponent = "Home";
      this.$nextTick(() => {
        this.$refs.componentRef.resetQuery()
      })
    },
    /* 编辑工机具 */
    editTools(taskId, id) {
      this.isEdit = true;
      this.pageContent = "领料申请发布";
      this.editTaskId = taskId;
      this.editId = id;
      this.isShowComponent = "AddTools";
    },
    /* 查询工机具 */
    queryTools(taskId, id) {
      this.isView = true;
      this.pageContent = "详情信息";
      this.queryTaskId = taskId;
      this.queryId = id;
      this.isShowComponent = "QueryTools";
    },
    /* 返回按钮 */
    goBack() {
      this.isShowComponent = "Home";
    },
  },
};
</script>
