<template>
    <!-- 新购工机具管理 -->
    <div class="app-container">
        <PageHeader
            v-if="isShowComponent !== 'Home'"
            :pageContent="pageContent"
            @goBack="goBack"
        />
        <component
            :is="isShowComponent"
            :isEdit="isEdit"
            :editTaskId="editTaskId"
            :queryTaskId="queryTaskId"
            :isView="isView"
            :codingTaskId="codingTaskId"
            @addTools="addTools"
            @editTools="editTools"
            @addToolsSuccess="addToolsSuccess"
            @queryTools="queryTools"
            @acceptTools="acceptTools"
            @codingTools="codingTools"
        />
    </div>
</template>

<script>
import PageHeader from '@/components/pageHeader'
import Home from './component/home.vue' // 主列表
import AddTools from './component/addTools.vue' // 新增机具 和 修改机具
import QueryTools from './component/queryTools.vue' // 查询机具 和 验收机具
import CodingTools from './component/codingTools.vue'
import CodingToolsCq from './component/codingTools-cq.vue'
export default {
    components: {
        Home,
        AddTools,
        QueryTools,
        CodingTools,
        CodingToolsCq,
        PageHeader,
    },
    data() {
        return {
            isShowComponent: 'Home',
            pageContent: '新增机具',
            isEdit: false,
            editTaskId: '',
            queryTaskId: '',
            isView: false,
            codingTaskId: '',
        }
    },
    methods: {
        /* 新增工机具 */
        addTools() {
            this.isEdit = false
            this.editTaskId = ''
            this.queryTaskId = ''
            this.pageContent = '新增机具'
            this.isShowComponent = 'AddTools'
        },
        /* 新增成功 */
        addToolsSuccess() {
            this.isShowComponent = 'Home'
        },
        /* 编辑工机具 */
        editTools(taskId) {
            this.isEdit = true
            this.pageContent = '编辑机具'
            this.editTaskId = taskId
            this.isShowComponent = 'AddTools'
        },
        /* 查询工机具 */
        queryTools(taskId) {
            this.isView = true
            this.pageContent = '详情信息'
            this.queryTaskId = taskId
            this.isShowComponent = 'QueryTools'
        },
        /* 验收工机具 */
        acceptTools(taskId) {
            this.isView = false
            this.pageContent = '机具验收'
            this.queryTaskId = taskId
            this.isShowComponent = 'QueryTools'
        },
        /* 编码管理 */
        codingTools(taskId) {
            this.pageContent = '编码管理'
            this.codingTaskId = taskId
            let comStr = ''
            process.env.VUE_APP_ENV === 'development-nw' ||
            process.env.VUE_APP_ENV === 'production-nw'
                ? (comStr = 'CodingTools')
                : (comStr = 'CodingToolsCq')
            this.isShowComponent = comStr
        },
        /* 返回按钮 */
        goBack() {
            this.isShowComponent = 'Home'
        },
    },
}
</script>
