inventory.vue 13.1 KB
Newer Older
张锡奇's avatar
张锡奇 committed
1 2 3
<style lang="less">
    @import url('../../../styles/common.less');
    #tiipChartInventory{
张锡奇's avatar
张锡奇 committed
4
        min-height:100%;
张锡奇's avatar
张锡奇 committed
5 6
        display:flex;
        flex-direction: column;
godwithdh's avatar
godwithdh committed
7
        background: #DCE9FE;
张锡奇's avatar
张锡奇 committed
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
        
        .Head{
            height:30px;
            line-height: 30px;
            background: #09F;
            text-align: center;
            color: #fff;
            font-weight: bold;
            margin-top:8px;
            width:100px;
            border-top-right-radius: 20px;
            border-bottom-right-radius: 20px;
        }
        .CONTENT{
            display:flex;flex-wrap:wrap;padding:8px;
            .iCard{
张锡奇's avatar
张锡奇 committed
24 25
                width:100%;
                // width:calc(50% - 4px);
张锡奇's avatar
张锡奇 committed
26 27 28 29 30
                margin:0;
                margin-bottom:8px;
                text-align: center;
                line-height:30px;
                .warehouse{
张锡奇's avatar
张锡奇 committed
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
                    background: linear-gradient(90deg,#8470FF, #2d8cf0, #00B2EE);
                    color:white;
                    border-bottom:1px solid #ddd;
                }
                .TITLE{
                    display: flex;
                    background: #f2f2f2;
                    >span{
                        flex:1;
                    }
                }
                .unit{
                    .ITEM{
                        display: flex;
                        >span{
                            flex:1;
                        }
                    }
张锡奇's avatar
张锡奇 committed
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
                }
            }
        }
        .vertical{
            flex-grow: 1;
            height:1px;
            margin-bottom: 7px;
        }
        .cross{
            height:auto;
        }
    }
</style>

<template>
    <div id="tiipChartInventory">
        <div>
            <div class="Head">金额</div>
            <div class="iCard" ref="chart">
                <canvas id="myChart" width="400" height="260" style="width:100%;height:240px;"></canvas>
            </div>
        </div>
        <div>
            <div class="Head">数量</div>
            <div class="CONTENT">
张锡奇's avatar
张锡奇 committed
74 75 76 77
                <div class="iCard" v-for="(item,index) in chartData" :key="index" @click="routerToWarehouseDetail(item)">
                    <div class="warehouse" :style="{'color':'white'}">{{item.sStoreName}}</div>
                    <div class="TITLE">
                        <span>总数量</span>
张锡奇's avatar
张锡奇 committed
78 79
                        <span>总匹数</span>
                        <span>单位</span>
张锡奇's avatar
张锡奇 committed
80 81 82 83
                    </div>
                    <div class="unit" v-for="(v,i) in item.child" :key="i">
                        <div class="ITEM">
                            <span style="color:#8a8a8a;">{{Number(v.nQty).toLocaleString()}}</span>
张锡奇's avatar
张锡奇 committed
84 85
                            <span style="color:#8a8a8a;">{{Number(v.nStockPieceQty).toLocaleString()}}</span>
                            <span>{{v.sUnit}}</span>
张锡奇's avatar
张锡奇 committed
86 87
                        </div>
                    </div>
张锡奇's avatar
张锡奇 committed
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 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161
                </div>
            </div>
            
        </div>
        <div v-if="false">
            <div class="Head">金额</div>
            <div :class="[direction == 'cross' ? 'cross' : 'vertical','iCard']">
                <customerTable :columns="columns" :list="list" :tableStyle="tableStyle"></customerTable>  
            </div>
        </div>
    </div>
</template>

<script>
import Util from '@/libs/util.js'
import { mapState } from 'vuex'
import customerTable from '@/components/Table'

const F2 = require('@antv/f2/lib/index')
require('@antv/f2/lib/interaction/pan')
require('@antv/f2/lib/interaction/pie-select'); // 引入饼图选中交互
const Gesture = require('@antv/f2/lib/plugin/gesture');

export default {
    name: 'tiipChartInventory',
    data () {
        return {
            myChart:null,
            list:[],
            columns:[
                {
                    width:'50px',
                    name:'序号',
                    align:'center',
                    field:'iIden',
                },
                {
                    width:'100px',
                    name:'类别',
                    align:'center',
                    field:'sMaterialTypeName',
                },
                {
                    width:'100px',
                    name:'入库数量',
                    align:'center',
                    field:'nInQty',
                },
                {
                    width:'100px',
                    name:'仓库金额',
                    align:'center',
                    field:'nAmount'
                },
                {
                    width:'100px',
                    name:'库存数量',
                    align:'center',
                    field:'nStockQty'
                },
                {
                    width:'100px',
                    name:'物料编号',
                    align:'center',
                    field:'sSampleMaterialNo'
                },
            ],
            tableStyle:{
                theadBgColor:'rgba(223,238,253,1)',
                complexTrBgColor:'white',
                singleTrBgColor:'#eef4fe',
                theadTdBorder:false,
                tbodyTdBorder:false,
                tbodyHeight:'calc(100vh - 342px)',
张锡奇's avatar
张锡奇 committed
162
                tbodyTrBorderBottom:'1px solid #dbe9f8',
张锡奇's avatar
张锡奇 committed
163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186
                width:'550px'
            },
            chartData:[],
            direction:'vertical',
            sStoreNo:'',
            colorList:[ '#FE5D4D', '#3BA4FF', '#737DDE','#0000CD','#008B45','#FFF68F','#8B814C','#8B658B' ]
        }
    },
    computed:{
        ...mapState({
            userId:state => state.app.userId
        })
    },
    async mounted(){
        window.d = this;
        this.$store.dispatch('saveUserId',this.$route.params.userId);
        window.addEventListener("resize",()=>{
            setTimeout(()=>{
                this.renderResize();
                this.myChart.changeSize(this.$refs['chart'].offsetWidth); // 清除
                this.myChart.destroy();
                this.renderChart();
            })
        });
godwithdh's avatar
godwithdh committed
187 188 189 190 191 192
        
        this.$nextTick(async ()=>{
            this.renderResize();
            await this.getDetail();
            await this.renderChart();
        })
张锡奇's avatar
张锡奇 committed
193
    },
张锡奇's avatar
张锡奇 committed
194 195 196
    activated(){
        document.getElementsByClassName('content')[0].scrollTo(0,this.$store.state.kanban.kanban.inventory.scrollTop)
    },
张锡奇's avatar
张锡奇 committed
197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216
    methods:{
        renderResize() {
            // 判断横竖屏
            let width = document.documentElement.clientWidth;
            let height = document.documentElement.clientHeight;
            if(width > height) {
                this.direction = 'cross';
                this.tableStyle.tbodyHeight = '100%';
            }else{
                this.direction = 'vertical';
                this.tableStyle.tbodyHeight = 'calc(100vh - 342px)';
            }
            // 做页面适配
            // 注意:renderResize方法执行时虚拟dom尚未渲染挂载,如果要操作vue实例,最好在this.$nextTick()里进行。
        },
        renderChart () {
            let that = this;
            const data = this.chartData;
            const map = {};
            data.forEach(function(obj) {
张锡奇's avatar
张锡奇 committed
217
                map[obj.sStoreName] = Number(obj.nAllAmount||0).toLocaleString() + '元';
张锡奇's avatar
张锡奇 committed
218 219 220 221 222 223 224 225
            });
            this.myChart = new F2.Chart({
                id: 'myChart',
                pixelRatio: window.devicePixelRatio,
                padding: [ 20, 'auto' ],
                plugins: Gesture,
            });
            this.myChart.source(data, {
张锡奇's avatar
张锡奇 committed
226
                nAllAmount: {
张锡奇's avatar
张锡奇 committed
227 228 229 230 231 232 233 234 235 236 237 238 239 240
                    formatter: function formatter(val) {
                        return val + '元';
                    }
                }
            });
            this.myChart.tooltip(false)
            
            this.myChart.coord('polar', {
                transposed: true,
                innerRadius: 0.7,
                radius: 1
            });
            this.myChart.axis(false);
            this.myChart.interval()
张锡奇's avatar
张锡奇 committed
241
            .position('a*nAllAmount')
张锡奇's avatar
张锡奇 committed
242 243 244 245 246 247 248 249
            .color('sStoreName', this.colorList)
            .adjust('stack');

            const guide = this.myChart.guide().html({
                position: [ '50%', '50%' ],
                html: `
                    <div style="width: 250px;height: 40px;text-align: center;">
                        <div style="font-size: 12px">总计</div>
张锡奇's avatar
张锡奇 committed
250
                        <div style="font-size: 12px">${(this.chartData.reduce((x,y)=>{return x = x+y.nAllAmount},0)).toFixed(2)}万</div>
张锡奇's avatar
张锡奇 committed
251 252 253
                    </div>
                `
            });
张锡奇's avatar
张锡奇 committed
254 255 256 257 258 259 260 261 262 263 264 265
            this.myChart.pluginGesture({
                gesture: {
                    press(data, event) {
                        guide.html = `<div style="width: 250px;height: 40px;text-align: center;">
                            <div style="font-size: 12px">总计</div>
                            <div style="font-size: 12px">${(that.chartData.reduce((x,y)=>{return x = x+y.nAllAmount},0)).toFixed(2)}万</div>
                            </div>
                        `
                        guide.repaint();
                    }
                }
            })
张锡奇's avatar
张锡奇 committed
266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288
            this.myChart.interaction('pie-select',{
                startEvent: 'tap',
                cancelable:true,
                animate: {
                    duration: 300,
                    delay: 0, // 动画延迟执行的时间
                    easing: 'bounceOut' // 动画的缓动函数
                },
                onEnd:async function(e){
                    if(!e.hasOwnProperty('data')){
                        // guide.html = `<div style="width: 250px;height: 40px;text-align: center;">
                        //     <div style="font-size: 12px">总计</div>
                        //     <div style="font-size: 12px">${(that.chartData.reduce((x,y)=>{return x = x+y.nAmount},0)).toFixed(2)}</div>
                        //     </div>
                        // `
                        // guide.repaint();
                        return false;
                    }
                    if(that.sStoreNo != e.data.sStoreNo){
                        that.sStoreNo = e.data.sStoreNo;
                        guide.html = `
                            <div style="width: 250px;height: 40px;text-align: center;">
                                <div style="font-size: 12px">${e.data.sStoreName}</div>
张锡奇's avatar
张锡奇 committed
289
                                <div style="font-size: 12px">${((e.data.nAllAmount / (that.chartData.reduce((x,y)=>{return x = x+y.nAllAmount},0))) * 100).toFixed(2)}%</div>
张锡奇's avatar
张锡奇 committed
290 291 292 293 294
                            </div>
                        `
                    }else{
                        guide.html = `<div style="width: 250px;height: 40px;text-align: center;">
                            <div style="font-size: 12px">总计</div>
张锡奇's avatar
张锡奇 committed
295
                            <div style="font-size: 12px">${(that.chartData.reduce((x,y)=>{return x = x+y.nAllAmount},0)).toFixed(2)}万</div>
张锡奇's avatar
张锡奇 committed
296 297 298 299 300 301 302 303 304 305 306
                            </div>
                        `
                        that.sStoreNo = '';
                    }
                    guide.repaint();
                    // await that.getDetail(that.sStoreNo);
                }
            });

            this.myChart.legend({
                clickable:true,
张锡奇's avatar
张锡奇 committed
307
                position: 'left',
张锡奇's avatar
张锡奇 committed
308 309 310 311 312 313 314 315 316
                itemFormatter: function itemFormatter(val) {
                    return val + '(' + map[val] + ')';
                },
                onClick: ev => {
                    let data = that.chartData.filter(x=>x.sStoreName == ev.clickedItem._attrs.dataValue);
                    if(data.length > 0){
                        guide.html = `
                            <div style="width: 250px;height: 40px;text-align: center;">
                                <div style="font-size: 12px">${data[0].sStoreName}</div>
张锡奇's avatar
张锡奇 committed
317
                                <div style="font-size: 12px">${((data[0].nAllAmount / (that.chartData.reduce((x,y)=>{return x = x+y.nAllAmount},0))) * 100).toFixed(2)}%</div>
张锡奇's avatar
张锡奇 committed
318 319 320 321 322 323 324 325 326 327 328 329 330
                            </div>
                        `
                        guide.repaint();
                    }
                    
                }
            });
            
            this.myChart.render();
        },
        async getDetail(sStoreNo){
            let data = {};
            !!sStoreNo && (data.sStoreNo = sStoreNo);
张锡奇's avatar
张锡奇 committed
331 332 333 334 335 336 337
            let res = await this.request('getBoss',{
                data:[
                    {key:'url',value:'Inventory situation'},
                ],
                params:{},
            },'加载中',{})
            if(res && res.length > 0) this.chartData = res;
张锡奇's avatar
张锡奇 committed
338 339 340
            this.chartData.map((x,y)=>{
                x.a = '1';
            })
张锡奇's avatar
张锡奇 committed
341 342 343 344
            this.chartData = this.chartData.filter(x=>x.nAllAmount != 0);
            // if(res.hasOwnProperty('set2')) this.list = res.set2;
        },
        routerToWarehouseDetail(item){
张锡奇's avatar
张锡奇 committed
345 346 347 348 349 350 351
            this.$store.dispatch('saveKanban',{
                type:'inventory',
                item:{
                    scrollTop:document.getElementsByClassName('content')[0].scrollTop
                }
            });

张锡奇's avatar
张锡奇 committed
352 353
            this.$store.dispatch('saveWarehouseDetail',item);
            this.$router.push({name:'tiipChartWarehouseDetail'});
张锡奇's avatar
张锡奇 committed
354 355 356 357 358 359 360 361
        }
    },
    components:{
        customerTable
    },
}
</script>