calculation.html 13.4 KB

    <!DOCTYPE html>
    <html lang="en">

    <head>
        <meta charset="UTF-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <title>数量计算</title>
        <script src="https://code.jquery.com/jquery-3.0.0.min.js"></script>
        <script src="https://unpkg.com/axios/dist/axios.min.js"></script>
        <script src="https://cdn.jsdelivr.net/npm/vue@2.6.14"></script>
        <!-- 引入样式 -->
        <link rel="stylesheet" href="https://unpkg.com/element-ui/lib/theme-chalk/index.css">
        <!-- 引入组件库 -->
        <script src="https://unpkg.com/element-ui/lib/index.js"></script>
    </head>

    <body>
        <div class="box">
            <img src="./images/logo.png" class="logo-img">
            <div class="line"></div>
            <div class="content">
                <div class="co-type" style="justify-content:space-between">
                    <div class="type-se">
                        <div class="typeTitle">设备类型</div>
                        <el-select style="width:200px" v-model="type" clearable placeholder="请选择类型" @change="toQuery">
                            <el-option v-for="item in typeOptions" :key="item.boxName" :label="item.boxName"
                                :value="item.boxName">
                            </el-option>
                        </el-select>
                    </div>
                    <div>设备高度:{{ boxHeight }} mm</div>
                </div>
                <div class="both-btn">
                    <el-select style="width:200px" v-model="sizeValue" clearable placeholder="请选择直径"
                        @change="toQuerySize">
                        <el-option v-for="item in sizeOptions" :key="item.id" :label="item.name" :value="item.id">
                        </el-option>
                    </el-select>
                    <el-select style="width:200px" v-model="thickValue" clearable placeholder="请选择厚度" @change="toQuery">
                        <el-option v-for="item in thickOptions" :key="item.id" :label="item.name" :value="item.id">
                        </el-option>
                    </el-select>
                    <div>
                        <el-button size="small" round style="background-color:#00558C" @click="handleAdd()">添加
                        </el-button>
                    </div>

                </div>
                <el-table ref="table" :header-cell-style="{ color: '#FFF', background: '#1C4D84' }" :data="reelNameList"
                    style="width:45%">
                    <template slot="empty">
                        <span style="color: #969799">暂无数据</span>
                    </template>
                    <el-table-column prop="size" align="center" label="直径"></el-table-column>
                    <el-table-column prop="thick" align="center" label="厚度"></el-table-column>
                    <el-table-column label="需求数" align="center" width="180">
                        <template slot-scope="scope">
                            <el-input placeholder="请输入需求数量" v-model="scope.row.amount" min="1" clearable type="number">
                            </el-input>
                        </template>
                    </el-table-column>
                    <el-table-column label="操作" align="center">
                        <template slot-scope="scope">
                            <el-button type="danger" icon="el-icon-delete" size="mini"
                                @click="onDelete(scope.$index, scope.row)">
                            </el-button>
                        </template>
                    </el-table-column>
                </el-table>
                <div class="btn">
                    <el-button size="small" round style="background-color:#00558C" @click="handleCalculation()">计算
                    </el-button>
                </div>
                <!-- 计算结果 -->
                <div class="co-result">
                    <div class="co-title">计算结果</div>
                    <div class="co-type">
                        <div>设备类型:{{ boxName }}</div>
                        <div style="margin-left: 10px;">数量:{{ boxCount }}台</div>
                    </div>
                    <el-table :header-cell-style="{ color: '#000000', background: '#DDDDDD' }" :data="resultData"
                        :cell-style="cellStyle" style="width: 100%">
                        <el-table-column label="尺寸" align="center" prop="w,h">
                            <template slot-scope="scope">
                                {{ scope.row.w }} x {{ scope.row.h }}
                            </template>
                        </el-table-column>
                        <el-table-column prop="needNum" label="需求数" align="center">
                        </el-table-column>
                        <el-table-column prop="capacity" label="容量" align="center">
                        </el-table-column>


                    </el-table>
                </div>

            </div>
        </div>
        <!-- 底部 -->
        <div class="bottom-part">
            <div class="con-bottom bottom-line">上海挚锦科技有限公司</div>
            <div class="con-bottom" style="background-color:#00558C"></div>
        </div>

    </body>
    <script>
        new Vue({
        el: '.box', //el用于指定当前Vue实例为哪个容器服务,值通常为选择器字符串。
        data: {
            boxHeight: '',//显示高度
            type: '',
            typeOptions: [],//料架类型
            resSizeMap: [],//接口返回的原始尺寸数组
            sizeOptions: [],//尺寸下拉框
            sizeValue: '',
            thickValue: '',
            thickOptions: [],//厚度下拉框
            reelNameList: [],
            resultData: [],
            boxName: '',
            boxCount: '',//台数
        },
        mounted() {
            this.getList()
        },
        methods: {
            // 获取表格数据
            getList() {
                axios.get('/box/baseData', {
                })
                    .then(res => {
                        this.typeOptions = res.data.data.boxDataList

                        this.resSizeMap = res.data.data.reelSizeMap
                        const resArr = Object.keys(res.data.data.reelSizeMap);//获取到对象中key值
                        resArr.sort((a, b) => a - b)
                        this.sizeOptions = resArr.map(item => {
                            return {
                                name: item,
                                id: item,
                            }
                        })

                        console.log(resArr, 'data');

                    })
                    .catch(function (error) {
                        console.log(error);
                    });
            },
            // 下拉框选择事件
            toQuery() {
                let that = this
                console.log(that.type)
                for (let i = 0; i < that.typeOptions.length; i++) {
                    if (that.type == that.typeOptions[i].boxName) {
                        that.boxHeight = that.typeOptions[i].boxHeight
                    }
                }

            },
            // 尺寸下拉框change事件
            toQuerySize() {
                console.log(this.sizeValue, this.resSizeMap, 'size')
                for (var key in this.resSizeMap) {
                    if (key == this.sizeValue) {
                        console.log(this.resSizeMap[key])
                        this.thickOptions = this.resSizeMap[key].map(item => {
                            return {
                                name: item,
                                id: item,
                            }
                        })
                    }
                }
                console.log(this.thickOptions)
            },
            // 添加
            handleAdd() {
                let that = this
                if (that.reelNameList.length > 0) {
                    let exist = false;//判断是否存在
                    that.reelNameList.map(item => {
                        if (item.size == that.sizeValue && item.thick == that.thickValue) {
                            exist = true;
                            that.$message({
                                message: '已经存在了~',
                                type: 'error'
                            });
                        }
                    })
                    if (!exist) {
                        that.reelNameList.push({ size: this.sizeValue, thick: this.thickValue })
                    }
                } else {
                    console.log('数组小于0')
                    that.reelNameList.push({ size: that.sizeValue, thick: that.thickValue })
                }
            },
            // 删除
            onDelete(index, row) {
                this.reelNameList.splice(index, 1)
            },
            // 计算 按钮点击事件
            handleCalculation() {
                let that = this
                let newArr = {};
                this.reelNameList.map(itm => {
                    if(itm.amount){
                        newArr[itm.size + ' ' + 'x' + ' ' + itm.thick] = itm.amount
                    }
                })
                console.log(newArr, 'newArr')
                if (!this.type) {
                    that.$message({
                        message: '请选择设备类型',
                        type: 'error'
                    });
                    return
                }
                var arr = Object.keys(newArr)//判断对象是否为空
                if (arr.length == 0) {
                    that.$message({
                        message: '请填写必要数量',
                        type: 'error'
                    });
                    return
                }
                let query = {
                    boxName: this.type
                }
                let data = Object.assign(query, newArr)
                axios
                    .post('/box/capacity',
                        data
                        // data:JSON.stringify(Object.assign(query, newArr))
                    )
                    .then(function (res) {

                        if (res.data.code === 0) {
                            console.log(res.data.data.capacityItems)
                            that.boxName = res.data.data.boxName
                            that.boxCount = res.data.data.boxCount
                            that.resultData = res.data.data.capacityItems

                        } else {
                            that.$message({
                                message: res.data.msg,
                                type: 'error'
                            });
                        }


                    })
                    .catch(function (error) {
                        console.log(error);
                    });
            },

            //设置指定行、列、具体单元格颜色
            cellStyle({ row, column, rowIndex, columnIndex }) {
                if (rowIndex === 0) { //指定坐标rowIndex :行,columnIndex :列
                    return 'background:#F6F4F4'
                } else {
                    return ''
                }

            }
        }
    })

    </script>
    <style scoped>
    * {
        padding: 0;
        margin: 0;
    }
    
    .box {
        margin: 22px 59px 22px 64px
    }
    
    .logo-img {
        width: 98px;
        height: 40px;
        margin-bottom: 11px;
    }
    
    .line {
        border: thin solid #BABABA;
    }
    
    .content {
        margin-top: 42px;
        display: flex;
        flex-direction: column;
        align-items: center;
        margin-bottom: 150px;
    }
    
    .co-type {
        width: 45%;
        display: flex;
        align-items: center;
        margin-bottom: 25px;
    }
    
    .typeTitle {
        margin-right: 20px;
        font-family: Noto Sans SC;
        font-size: 14px;
        font-weight: 400;
    
    }
    
    .type-se {
        display: flex;
        align-items: center
    }
    
    .both-btn {
        margin-bottom: 25px;
        width: 45%;
        display: flex;
        justify-content: space-between
    }
    
    .el-button {
        background: #1C4D84;
        border: 1px solid #1C4D84 !important;
        color: #ffffff !important;
        border-radius: 4px;
    }
    
    .el-button--small.is-round {
        padding: 9px 35px !important;
    }
    
    .el-button.is-round {
        border-radius: 10px !important;
    }
    
    .btn {
        width: 45%;
        margin: 27px 0px;
        display: flex;
        justify-content: flex-end;
    }
    
    .co-result {
        width: 45%;
        color: rgb(0, 0, 0);
        font-family: Noto Sans SC;
        font-size: 14px;
        font-weight: 400;
    }
    
    .co-title {
        margin-bottom: 9px;
    
    }
    
    .bottom-part {
        position: fixed;
        bottom: 0;
        width: 100%;
        margin-top: 47px;
        z-index: 99;
    }
    
    .bottom-line {
        background-color: #1A6698;
    }
    
    .con-bottom {
        height: 40px;
        color: #02D1AE;
        text-align: center;
        font-size: 14px;
        line-height: 40px;
    }
    
    .el-button:hover {
        color: #ffffff !important;
        border-color: #1A6698 !important;
        background-color: #1A6698 !important;
    }
    </style>

    </html>