1
lzhe
2024-06-03 a786409d7f6769f43c107159dd84faf4a2927a9a
src/views/console/basic-data/material-warehousing-data/material-storage.vue
@@ -1,19 +1,219 @@
<!--
 * @Date: 2024-05-07 22:46:30
 * @LastEditors: Sneed
 * @LastEditTime: 2024-05-07 22:46:44
 * @LastEditTime: 2024-05-11 20:53:42
 * @FilePath: /belleson-frontend/Users/mache/Documents/demo/cps-web/src/views/console/basic-data/material-warehousing-data/material-storage.vue
-->
<template>
    <div>
        物料存放
    </div>
    <el-main style="height: 100%;">
        <el-card shadow="never" style="height: 100%;" body-style="height: 100%">
            <el-containter>
                <el-header>
                    <import-table style="margin:0 8px" :exportUrl="exportUrl" :uploadUrl="uploadUrl"></import-table>
                </el-header>
                <el-main>
                    <el-container>
                        <el-aside width="200px" v-loading="showGrouploading">
                            <el-tree default-expand-all ref="group" node-key="id" :data="treeData" :props="props"
                                @node-click="nodeClick">
                                <template #default="{ node, data }">
                                    <span class="custom-tree-node">
                                        <span :class="data.isArea ? 'treedisabled' : ''">{{
                                            node.label }}</span>
                                    </span>
                                </template>
                            </el-tree>
                        </el-aside>
                        <el-container>
                            <el-main v-if="selectNode?.id">
                                <el-row>
                                    <el-col :span="4">
                                        库位编号: {{ selectNode.warehouseCode }}
                                    </el-col>
                                    <el-col :span="4">
                                        库位名称: {{ selectNode.warehouseName }}
                                    </el-col>
                                    <el-col :span="4">
                                        库位描述: {{ selectNode.remark }}
                                    </el-col>
                                </el-row>
                                <el-row style="margin-top: 10px;">
                                    <el-col>
                                        <el-button @click="table_add" type="primary"
                                            icon="el-icon-plus">添加物料</el-button>
                                    </el-col>
                                    <el-col style="margin-top: 10px;">
                                        <scTable ref="table" @selection-change="handleSelectionChange" row-key="id"
                                            border :params="params" :apiObj="apiObj" stripe @dataChange="dataChange">
                                            <!-- <el-table-column type="selection" width="55" /> -->
                                            <el-table-column prop="materialCode" label="物料编号" />
                                            <el-table-column prop="materialName" label="物料名称" />
                                            <el-table-column prop="standardModel" label="规格" />
                                            <el-table-column prop="unit" label="计量单位" />
                                            <el-table-column prop="typeName" label="物料类型" />
                                            <el-table-column prop="stuff" label="材质" />
                                            <el-table-column prop="property" label="物料属性">
                                                <template #default="scope">
                                                    {{ this.options.property.find(v => v.value ==
                                                        scope.row.property)?.label
                                                    }}
                                                </template>
                                            </el-table-column>
                                            <el-table-column prop="isMustCheckName" label="是否必检">
                                                <template #default="scope">
                                                    {{ scope.row.isMustCheck == 1 ? '是' : '否' }}
                                                </template>
                                            </el-table-column>
                                            <el-table-column prop="lowerLimit" label="额定库存" />
                                            <el-table-column prop="upperLimit" label="安全库存" />
                                            <el-table-column label="操作" fixed="right" align="left" width="160">
                                                <template #default="scope">
                                                    <el-button-group>
                                                        <el-popconfirm width="220" title="确定将选择的数据删除"
                                                            @confirm="table_del([scope.row], '0')">
                                                            <template #reference>
                                                                <el-button text type="primary"
                                                                    size="small">删除</el-button>
                                                            </template>
                                                        </el-popconfirm>
                                                    </el-button-group>
                                                </template>
                                            </el-table-column>
                                        </scTable>
                                    </el-col>
                                </el-row>
                            </el-main>
                            <el-main v-else>
                                <el-empty description="" />
                            </el-main>
                        </el-container>
                    </el-container>
                </el-main>
            </el-containter>
        </el-card>
        <el-dialog v-model="dialogVisible" title="添加" width="500">
            <el-select v-model="materialIds">
                <template #prefix>
                    物料编号
                </template>
                <el-option v-for="item in todoList" :key="item.value" :label="item.code" :value="item.id" />
            </el-select>
            <template #footer>
                <div class="dialog-footer">
                    <el-button type="primary" @click="add">
                        确定
                    </el-button>
                </div>
            </template>
        </el-dialog>
    </el-main>
</template>
<script>
import importTable from '@/layout/components/importTable.vue'
export default {
    components: {
        importTable,
    },
    watch: {
        selectNode(val) {
            this.params.wareId = val?.id
            this.$refs?.table?.reload()
        }
    },
    data() {
        return {
            options: {
            },
            props: {
                label: 'name',
                disabled: 'isArea'
            },
            exportUrl: '/api/blade-cps/material-storage/excel/template',
            uploadUrl: '/api/blade-cps/material-storage/excel/import',
            treeData: [],
            selectNode: {},
            apiObj: {
                get: async (data) => {
                    let params = {
                        ...data,
                        wareId: this.selectNode.id
                    }
                    return await this.$HTTP.post(`/api/blade-cps/material-storage/page`, {}, { params }).then(res => {
                        return res
                    })
                }
            },
            params: {
                wareId: ''
            },
            todoList: [],
            dialogVisible: false,
            materialIds: ''
        }
    },
    created() {
        this.init()
    },
    methods: {
        init() {
            this.$HTTP.get(`/api/blade-cps/tray-storage/tree`).then(res => {
                this.treeData = res.data
            })
            this.$HTTP.get(`/api/blade-cps/material-type/list`).then(res => {
                this.options.typeId = res.data.map(item => ({
                    label: item.name,
                    value: item.id
                }))
            })
            this.$HTTP.get(`/api/blade-system/dict/dictionary?code=material_property`).then(res => {
                this.options.property = res.data.map(item => ({
                    label: item.dictValue,
                    value: item.dictKey - 0
                }))
            })
        },
        nodeClick(node) {
            if (node.isArea) return
            this.queryInfo(node.id)
        },
        queryInfo(id) {
            this.$HTTP.get(`/api/blade-cps/warehouse-station/get/${id}`).then(res => {
                this.selectNode = res.data
            })
        },
        table_add() {
            this.$HTTP.get(`/api/blade-cps/material-storage/material/not-bind`).then(res => {
                if (res.data?.length > 0) {
                    this.todoList = res.data
                    this.dialogVisible = true
                } else {
                    this.$message.warning("暂无可添加物料")
                }
            })
        },
        add() {
            this.$HTTP.post(`/api/blade-cps/material-storage`, { warehouseStationId: this.selectNode.id, materialIds: [this.materialIds] }).then(res => {
                this.$message.success("操作成功")
                this.dialogVisible = false
                this.$refs.table.reload()
            })
        },
        table_del(ids) {
            this.$HTTP.delete(`/api/blade-cps/material-storage`, ids.map(v => v.id)).then(res => {
                this.$message.success("操作成功")
                this.$refs.table.reload()
            })
        }
    },
}
</script>
<style lang="scss" scoped></style>
<style lang="scss" scoped>
.treedisabled {
    color: #ccc;
}
</style>