马宇豪
2024-02-23 4cfbfd1b425f7b22b876ae6cae95c4fc29ae6bfb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
<template>
    <el-dialog
        :visible.sync="deliverDialog"
        :close-on-click-modal="false"
        width="50%"
        :append-to-body="true"
        :title=stockName
        center
        size="medium"
    >
        <div class="app-container">
            <div class="upTitle">
                请勾选或取消勾选允许使用该仓库的批发企业,您允许使用的企业可将货物入库到该仓库。
            </div>
            <div class="table_content">
                <el-checkbox-group v-model="authorityCorts" @change="changeData">
                    <el-checkbox v-for="item in companyList" :key="item.enterpriseId" :label="item.enterpriseId" :disabled="item.enterpriseAuthority == 1? true: false" border style="display: block">
                        {{item.enterpriseName}}
                    </el-checkbox>
                </el-checkbox-group>
            </div>
        </div>
        <span slot="footer" class="dialog-footer">
                <el-button @click="deliverDialog = false">取 消</el-button>
                <el-button type="primary" @click="handleSubmit()">提 交</el-button>
            </span>
    </el-dialog>
</template>
 
<script>
    import {computePageCount} from "@/utils";
    import {listStockhouseEnterpriseUserInfo,editEnterpriseUserAuthority} from "../../../api/warehouse";
 
    export default {
        name: "deliverUsage",
        components: {},
        data(){
            return{
                tableStatus: true,
                tableKey:'',
                stockName: '',
                listLoading:false,
                companyList:[],
                authorityCorts: [],
                deliverDialog:false,
                reserveId: null,
                storehouseId: null,
                submitForm: {
                    addEnterprises: [],
                    addStatus: false,
                    deleteEnterprises: [],
                    deleteStatus: false
                }
            }
        },
        created() {
            const t = this
        },
        methods:{
            open(data){
                this.submitForm = {
                    addEnterprises: [],
                    addStatus: false,
                    deleteEnterprises: [],
                    deleteStatus: false
                }
                this.reserveId = data.topId
                this.storehouseId = data.id
                listStockhouseEnterpriseUserInfo({id: data.id}).then((res)=>{
                    this.stockName = '仓库【'+ data.storehouseName + '】使用权分配'
                    if(res.data.code == 200){
                        this.companyList = res.data.result.enterpriseUserAuthorityInfo
                        this.authorityCorts = this.companyList.filter(item=>item.enterpriseAuthority == 1 || item.enterpriseAuthority == 2).map(i=>{return i.enterpriseId})
                    }else{
                        this.$message.warning(res.data.message)
                    }
                    this.deliverDialog = true
                }).catch(()=>{
                    this.$message.warning('数据获取失败')
                })
            },
            changeData(value){
                console.log(value,'val')
            },
            async handleSubmit(){
                const originList = this.companyList.filter(i=>i.enterpriseAuthority == 1 || i.enterpriseAuthority==2)
                const companyIds = originList.map(i=>i.enterpriseId)
                const addedElementsSet = new Set(this.authorityCorts.filter(element => !companyIds.includes(element)))
                const removedElementsSet = new Set(companyIds.filter(element => !this.authorityCorts.includes(element)))
                const addedElements = Array.from(addedElementsSet)
                const removedElements = Array.from(removedElementsSet)
                if(addedElements.length>0){
                    this.submitForm.addStatus = true
                    this.submitForm.addEnterprises = addedElements.map((i)=>{
                        return {
                            enterpriseId: i,
                            reserveId: this.reserveId,
                            storehouseId: this.storehouseId
                        }
                    })
                }
                if(removedElements.length>0){
                    this.submitForm.deleteStatus = true
                    for(let i of this.companyList){
                        if(removedElements.find(item=>item == i.enterpriseId)){
                            this.submitForm.deleteEnterprises.push({
                                id: i.id?i.id:null,
                                enterpriseId: i.enterpriseId,
                                reserveId: this.reserveId,
                                storehouseId: this.storehouseId
                            })
                        }
                    }
                }
                const res = await editEnterpriseUserAuthority(this.submitForm)
                if(res.data.code == 200){
                    this.$message.success('仓库使用权修改成功')
                }else{
                    this.$message.warning(res.data.message)
                }
                this.deliverDialog = false
                this.$emit('refresh')
            }
        }
    }
</script>
 
<style lang="scss" scoped>
    .upTitle{
        font-size: 16px;
        margin-bottom: 20px;
    }
    /deep/ .el-checkbox{
        width: 80%;
        margin-left: 0 !important;
        margin-right: 0 !important;
        margin-bottom: 10px !important;
    }
</style>