<template>
    <fullscreen :fullscreen.sync="fullscreen" class="container">
        <div class="container-box">
            <toolList @iconCli='iconCli' :tooltit='tooltit'></toolList>
            <div class="search">
                <mySearch :searchList="searchList" @searchInfo="searchInfo"></mySearch>
            </div>
            <div class="tabbox">
                <el-table height="calc(100% - 40px)" class="com-table" ref="multipleTable" :data="tableData"
                    tooltip-effect="dark" size="small" border style="width: 100%" >
                    <el-table-column prop="cityName" label="地市" align="center" width="120">
                    </el-table-column>
                    <el-table-column label="预算使用进度" align="center">
                        <el-table-column prop="budgetMoney" label="预算金额(万元)" width="150">
                            <template slot-scope="scope">
                                <el-input v-if="scope.row.cityName != '全省'" :disabled="companyFlag != 0" v-model="scope.row.budgetMoney" @change="changeRow(scope.row)"></el-input>
                                <span v-if="scope.row.cityName == '全省'" style="padding-left: 10px;">{{scope.row.budgetMoney}}</span>
                            </template>
                        </el-table-column>
                        <el-table-column prop="useMoney" label="已用金额(万元)" width="120">
                        </el-table-column>
                        <el-table-column prop="useProcess" label="使用进度" width="120">
                        </el-table-column>
                        <el-table-column prop="surplusMoney" label="剩余金额(万元)" width="120">
                        </el-table-column>
                    </el-table-column>
                    <el-table-column label="当月使用金额(万元)" align="center">
                        <el-table-column prop="month1" label="一月" width="150">
                            <template slot-scope="scope">
                                <el-input v-if="scope.row.cityName != '全省'" v-model="scope.row.month1" @change="changeRow(scope.row)"></el-input>
                                <span v-if="scope.row.cityName == '全省'" style="padding-left: 10px;">{{scope.row.month1}}</span>
                            </template>
                        </el-table-column>
                        <el-table-column prop="month1" label="二月" width="150">
                            <template slot-scope="scope">
                                <el-input v-if="scope.row.cityName != '全省'" v-model="scope.row.month2" @change="changeRow(scope.row)"></el-input>
                            <span v-if="scope.row.cityName == '全省'" style="padding-left: 10px;">{{scope.row.month2}}</span>
                            </template>
                        </el-table-column>
                        <el-table-column prop="month1" label="三月" width="150">
                            <template slot-scope="scope">
                                <span v-if="scope.row.cityName == '全省'" style="padding-left: 10px;">{{scope.row.month3}}</span>
                                <el-input v-if="scope.row.cityName != '全省'" v-model="scope.row.month3" @change="changeRow(scope.row)"></el-input>
                            </template>
                        </el-table-column>
                        <el-table-column prop="month1" label="四月" width="150">
                            <template slot-scope="scope">
                                <span v-if="scope.row.cityName == '全省'" style="padding-left: 10px;">{{scope.row.month4}}</span>
                                <el-input v-if="scope.row.cityName != '全省'" v-model="scope.row.month4" @change="changeRow(scope.row)"></el-input>
                            </template>
                        </el-table-column>
                        <el-table-column prop="month1" label="五月" width="150">
                            <template slot-scope="scope">
                                <span v-if="scope.row.cityName == '全省'" style="padding-left: 10px;">{{scope.row.month5}}</span>
                                <el-input v-if="scope.row.cityName != '全省'" v-model="scope.row.month5" @change="changeRow(scope.row)"></el-input>
                            </template>
                        </el-table-column>
                        <el-table-column prop="month1" label="六月" width="150">
                            <template slot-scope="scope">
                                <span v-if="scope.row.cityName == '全省'" style="padding-left: 10px;">{{scope.row.month6}}</span>
                                <el-input v-if="scope.row.cityName != '全省'" v-model="scope.row.month6" @change="changeRow(scope.row)"></el-input>
                            </template>
                        </el-table-column>
                        <el-table-column prop="month1" label="七月" width="150">
                            <template slot-scope="scope">
                                <span v-if="scope.row.cityName == '全省'" style="padding-left: 10px;">{{scope.row.month7}}</span>
                                <el-input v-if="scope.row.cityName != '全省'" v-model="scope.row.month7" @change="changeRow(scope.row)"></el-input>
                            </template>
                        </el-table-column>
                        <el-table-column prop="month1" label="八月" width="150">
                            <template slot-scope="scope">
                                <span v-if="scope.row.cityName == '全省'" style="padding-left: 10px;">{{scope.row.month8}}</span>
                                <el-input v-if="scope.row.cityName != '全省'" v-model="scope.row.month8" @change="changeRow(scope.row)"></el-input>
                            </template>
                        </el-table-column>
                        <el-table-column prop="month1" label="九月" width="150">
                            <template slot-scope="scope">
                                <span v-if="scope.row.cityName == '全省'" style="padding-left: 10px;">{{scope.row.month9}}</span>
                                <el-input v-if="scope.row.cityName != '全省'" v-model="scope.row.month9" @change="changeRow(scope.row)"></el-input>
                            </template>
                        </el-table-column>
                        <el-table-column prop="month1" label="十月" width="150">
                            <template slot-scope="scope">
                                <span v-if="scope.row.cityName == '全省'" style="padding-left: 10px;">{{scope.row.month10}}</span>
                                <el-input v-if="scope.row.cityName != '全省'" v-model="scope.row.month10" @change="changeRow(scope.row)"></el-input>
                            </template>
                        </el-table-column>
                        <el-table-column prop="month1" label="十一月" width="150">
                            <template slot-scope="scope">
                                <span v-if="scope.row.cityName == '全省'" style="padding-left: 10px;">{{scope.row.month11}}</span>
                                <el-input v-if="scope.row.cityName != '全省'" v-model="scope.row.month11" @change="changeRow(scope.row)"></el-input>
                            </template>
                        </el-table-column>
                        <el-table-column prop="month1" label="十二月" width="150">
                            <template slot-scope="scope">
                                <span v-if="scope.row.cityName == '全省'" style="padding-left: 10px;">{{scope.row.month12}}</span>
                                <el-input v-if="scope.row.cityName != '全省'" v-model="scope.row.month12" @change="changeRow(scope.row)"></el-input>
                            </template>
                        </el-table-column>

                    </el-table-column>

                </el-table>
                <!-- <el-pagination class="pageBox" @current-change="currchange" layout="prev, pager, next" background
                    :total="total">
                </el-pagination> -->
            </div>
        </div>
    </fullscreen>

</template>
<script>
    import mySearch from "../../../components/search.vue";
    import myMessage from "../../../components/myMessage.vue"
    import toolList from '../../../components/toolList'

    export default {
        components: {
            mySearch,
            myMessage,
            toolList
        },
        data() {
            return {
                searchList: [{
                    type: 'year',
                    tit: '年份标识',
                    value: '',
                    width: '98%'
                }],
                tooltit: '预算管理',
                fullscreen: false,
                total: 0,
                pageSize: 1,
                tableData: [{}],
                dialogStatus: false,
                disableStatus: false,
                titname: '',
                infolist: {

                },
                userInfo: {},
                params: {},
                centerDialogVisible: false,
                messTit: '',
                delid: '',
                loading: false,
                loadinged: false,
                companyFlag:'',
                region:'',
            }
        },
        methods: {
            changeRow(v) {
                v.month1 = (v.month1*1).toFixed(6);
                v.month2 = (v.month2*1).toFixed(6);
                v.month3 = (v.month3*1).toFixed(6);
                v.month4 = (v.month4*1).toFixed(6);
                v.month5 = (v.month5*1).toFixed(6);
                v.month6 = (v.month6*1).toFixed(6);
                v.month7 = (v.month7*1).toFixed(6);
                v.month8 = (v.month8*1).toFixed(6);
                v.month9 = (v.month9*1).toFixed(6);
                v.month10 = (v.month10*1).toFixed(6);
                v.month11 = (v.month11*1).toFixed(6);
                v.month12 = (v.month12*1).toFixed(6);
                v.month1 = parseFloat(v.month1);
                v.month2 = parseFloat(v.month2);
                v.month3 = parseFloat(v.month3);
                v.month4 = parseFloat(v.month4);
                v.month5 = parseFloat(v.month5);
                v.month6 = parseFloat(v.month6);
                v.month7 = parseFloat(v.month7);
                v.month8 = parseFloat(v.month8);
                v.month9 = parseFloat(v.month9);
                v.month10 = parseFloat(v.month10);
                v.month11 = parseFloat(v.month11);
                v.month12 = parseFloat(v.month12);
                v.useMoney = v.month1 * 1 + v.month2 * 1 + v.month3 * 1 + v.month4 * 1 + v.month5 * 1 + v.month6 * 1 + v
                    .month7 * 1 + v.month8 * 1 + v.month9 * 1 + v.month10 * 1 + v.month11 * 1 + v.month12 * 1;
                v.useMoney = (v.useMoney*1).toFixed(6);
                v.useMoney = parseFloat(v.useMoney);
                v.budgetMoney = (v.budgetMoney*1).toFixed(6);
                v.budgetMoney = parseFloat(v.budgetMoney);
                if (v.budgetMoney*1 < v.useMoney*1) {
                    this.$message({
                    	message: '预算金额须大于使用金额',
                    	type: 'error'
                    });
                    this.getList(this.params, this.pageSize);
                    return
                }
                v.useProcess = (v.useMoney/v.budgetMoney*100).toFixed(2) +'%';
                v.surplusMoney = (v.budgetMoney-v.useMoney).toFixed(6);
                v.surplusMoney = parseFloat(v.surplusMoney);

                this.$http({
                    url: "/market/cStoreOutBudget/update",
                    method: "post",
                    headers: {
                        "Content-Type": "application/json",
                    },
                    data: v,
                }).then((res) => {
                    this.getList(this.params, this.pageSize);
                });
            },
            //搜索数据
            searchInfo(v) {
                this.params = {};
                v[0] ? this.params.year = this.$formatDate(v[0], "YYYY") : '';
                this.getList(this.params, this.pageSize);
            },
            //获取列表
            getList(v, n) {
                this.pageSize = n;
                let _this = this;
                this.loading = true;
                this.$http({
                    url: "/market/cStoreOutBudget/queryList",
                    method: "post",
                    headers: {
                        "Content-Type": "application/json",
                        "page": '{"pageNo":"' + n + '","pageSize":"10"}'
                    },
                    data: v,
                }).then((res) => {
                    this.tableData = res.data;
                    this.total = res.data.totalRecord;
                    this.loading = false;
                    if(this.tableData[0].cityName == '全省'){
                        this.tableData[0].budgetMoney = 0;
                        this.tableData[0].month1 = 0;
                        this.tableData[0].month2 = 0;
                        this.tableData[0].month3 = 0;
                        this.tableData[0].month4 = 0;
                        this.tableData[0].month5 = 0;
                        this.tableData[0].month6 = 0;
                        this.tableData[0].month7 = 0;
                        this.tableData[0].month8 = 0;
                        this.tableData[0].month9 = 0;
                        this.tableData[0].month10 = 0;
                        this.tableData[0].month11 = 0;
                        this.tableData[0].month12 = 0;
                        this.tableData[0].useMoney = 0;
                        for (let i = 1; i < this.tableData.length; i++) {
                            this.tableData[0].budgetMoney = this.tableData[i].budgetMoney*1 + this.tableData[0].budgetMoney*1;
                            this.tableData[0].budgetMoney = (this.tableData[0].budgetMoney*1).toFixed(6);
                            this.tableData[0].budgetMoney = parseFloat(this.tableData[0].budgetMoney);
                    
                            this.tableData[0].month1 = this.tableData[i].month1*1 + this.tableData[0].month1*1;
                            this.tableData[0].month1 = (this.tableData[0].month1*1).toFixed(6);
                            this.tableData[0].month1 = parseFloat(this.tableData[0].month1);
                    
                            this.tableData[0].month2 = this.tableData[i].month2*1 + this.tableData[0].month2*1;
                            this.tableData[0].month2 = (this.tableData[0].month2*1).toFixed(6);
                            this.tableData[0].month2 = parseFloat(this.tableData[0].month2);
                    
                            this.tableData[0].month3 = this.tableData[i].month3*1 + this.tableData[0].month3*1;
                            this.tableData[0].month3 = (this.tableData[0].month3*1).toFixed(6);
                            this.tableData[0].month3 = parseFloat(this.tableData[0].month3);
                    
                            this.tableData[0].month4 = this.tableData[i].month4*1 + this.tableData[0].month4*1;
                            this.tableData[0].month4 = (this.tableData[0].month4*1).toFixed(6);
                            this.tableData[0].month4 = parseFloat(this.tableData[0].month4);
                    
                            this.tableData[0].month5 = this.tableData[i].month5*1 + this.tableData[0].month5*1;
                            this.tableData[0].month5 = (this.tableData[0].month5*1).toFixed(6);
                            this.tableData[0].month5 = parseFloat(this.tableData[0].month5);
                    
                            this.tableData[0].month6 = this.tableData[i].month6*1 + this.tableData[0].month6*1;
                            this.tableData[0].month6 = (this.tableData[0].month6*1).toFixed(6);
                            this.tableData[0].month6 = parseFloat(this.tableData[0].month6);
                    
                            this.tableData[0].month7 = this.tableData[i].month7*1 + this.tableData[0].month7*1;
                            this.tableData[0].month7 = (this.tableData[0].month7*1).toFixed(6);
                            this.tableData[0].month7 = parseFloat(this.tableData[0].month7);
                    
                            this.tableData[0].month8 = this.tableData[i].month8*1 + this.tableData[0].month8*1;
                            this.tableData[0].month8 = (this.tableData[0].month8*1).toFixed(6);
                            this.tableData[0].month8 = parseFloat(this.tableData[0].month8);
                    
                            this.tableData[0].month9 = this.tableData[i].month9*1 + this.tableData[0].month9*1;
                            this.tableData[0].month9 = (this.tableData[0].month9*1).toFixed(6);
                            this.tableData[0].month9 = parseFloat(this.tableData[0].month9);
                    
                            this.tableData[0].month10 = this.tableData[i].month10*1 + this.tableData[0].month10*1;
                            this.tableData[0].month10 = (this.tableData[0].month10*1).toFixed(6);
                            this.tableData[0].month10 = parseFloat(this.tableData[0].month10);
                    
                            this.tableData[0].month11 = this.tableData[i].month11*1 + this.tableData[0].month11*1;
                            this.tableData[0].month11 = (this.tableData[0].month11*1).toFixed(6);
                            this.tableData[0].month11 = parseFloat(this.tableData[0].month11);
                    
                            this.tableData[0].month12 = this.tableData[i].month12*1 + this.tableData[0].month12*1;
                            this.tableData[0].month12 = (this.tableData[0].month12*1).toFixed(6);
                            this.tableData[0].month12 = parseFloat(this.tableData[0].month12);
                    
                            this.tableData[0].useMoney = this.tableData[i].useMoney*1 + this.tableData[0].useMoney*1;
                            this.tableData[0].useMoney = (this.tableData[0].useMoney*1).toFixed(6);
                            this.tableData[0].useMoney = parseFloat(this.tableData[0].useMoney);
                    
                            this.tableData[0].useProcess = (this.tableData[0].useMoney/this.tableData[0].budgetMoney*100).toFixed(2) +'%';
                            this.tableData[0].surplusMoney = (this.tableData[0].budgetMoney-this.tableData[0].useMoney).toFixed(6);
                            this.tableData[0].surplusMoney = parseFloat(this.tableData[0].surplusMoney);
                        }
                    }
                });
            },
            // 分页
            currchange(v) {
                this.pageSize = v;
                this.getList(this.params, this.pageSize);
            },
            setabList(n, p) {
                let params = {
                    children: "",
                    name: n,
                    rountPath: p,
                    target: "_self",
                };
                for (let i = 0; i < this.$store.state.tabList.length; i++) {
                    if (this.$store.state.tabList[i].name === params.name) {
                        this.$store.state.tabList[i] = params;
                    }
                }
                let set = new Set([...this.$store.state.tabList, params]);
                set.add(params);
                this.$store.commit("setDefaultActive", params.rountPath);
                this.$store.commit("setTabList", Array.from(set));
            },
            //申请
            dialogCheck(v, n) {
                let id = n.woNo + ',' + v;
                this.$router.push({
                    path: "/stageSeatcheck?id=" + id,
                    query: {
                        id: id
                    }
                });
                this.setabList("台席管理详情", "/stageSeatcheck?id=" + id);
            },
            //功能栏
            iconCli(v) {
                if (v === 1) {
                    this.getList(this.params, this.pageSize);
                }
                if (v === 2) {
                    this.fullscreen = !this.fullscreen
                }
            },
            getUser() {
                this.userInfo = JSON.parse(window.sessionStorage.userInfo);
                this.$http({
                    url: "/sysmgr/csysuserinfo/queryUserInfoByLoginNo",
                    method: "post",
                    headers: {
                        "Content-Type": "application/json",
                    },
                    data: {},
                }).then((res) => {
                    this.companyFlag = res.data.companyFlag;
                    this.region = res.data.groupName.split("/")[1];
                });
            },
        },
        mounted() {
            let time = this.$formatDate(new Date(), "YYYY");
            this.params.year = time;
            this.searchList[0].value = time;
            this.getList({
                year: time
            }, 1);
            this.getUser();
        },
        created() {

        }
    }
</script>
<style scoped lang="scss">
    .onetab {
        margin-bottom: 20px;
        padding: 0 20px;
    }

    .titbox {
        div {
            float: right;

            i {
                font-size: 22px;
                margin-left: 20px;
                cursor: pointer;
            }
        }
    }

    .tabbox {
        margin-top: 15px;
    }

    .pageBox {
        text-align: right;
        margin-top: 10px;
    }

    .info-line {
        width: 100%;
        display: block;
        padding-left: 20px;

        div {
            width: 50%;
            display: inline-block;
        }

        span {
            width: 80px;
            display: inline-block;
            text-align: left;

            i {
                color: red;
                display: inline-block;
                padding-right: 5px;
            }
        }

        .el-select,
        .el-input {
            width: calc(100% - 100px);
        }
    }

    .online {
        width: 100%;

        .el-select {
            width: calc(100% - 100px);
        }

        span {
            vertical-align: top;
        }

        .el-textarea {
            width: calc(100% - 80px);
        }

        .tree {
            width: calc(50% - 60px);
            display: inline-block;
            margin-right: 20px;
            height: 300px;
            overflow-y: scroll;

            p {
                overflow: hidden;
                display: flex;
                justify-content: space-between;
            }

            .p-btn {
                width: 50px !important;
                cursor: pointer;
                color: #0074DA;
            }

            span {
                display: inline-block;
                width: calc(100% - 100px);
            }

            .el-icon-error {
                float: right;
                font-size: 20px;
                margin-top: 9px;
                cursor: pointer;
            }
        }

        .treeUser {
            margin: 0;
            border: 1px solid #ddd;

            p {
                background: #f4f4f4;
                padding: 0 20px;
                margin-bottom: 5px;
            }
        }

        .treeUserb {
            width: calc(100% - 80px);
            border: 1px solid #ddd;
            background: #f4f4f4;
            border-radius: 3px;
            height: auto;
            overflow: hidden;

            p {
                display: inline-block;
                padding: 0 20px;
                margin-bottom: 5px;
            }
        }
    }

    .adv-type {
        margin-top: 20px;
        display: flex;
        justify-content: space-between;
        flex-wrap: wrap;
        // border: 1px solid #ddd;
        border-radius: 5px;
        padding: 20px;
        box-shadow: 0 2px 12px 0 rgba(0, 0, 0, .1);

        div {
            width: 33%;
            text-align: center;
            height: 80px;
            overflow: hidden;
            min-width: 100px;
            cursor: pointer;
            padding-top: 10px;
            margin: 10px 0;
        }

        div:hover {
            background: #CFE8FC;
            border-radius: 5px;
        }

        span {
            width: 100%;
            display: inline-block;
            height: 40px;

            // line-height: 40px;
            i {
                color: #0074D9;
                font-size: 36px;
            }
        }
    }

    .tempbox {
        // border: 1px solid #ddd;
        padding: 5px;
        margin-bottom: 10px;

        span {
            display: inline-block;
            width: 40%;
            padding: 0 10px;
        }

        span:first-child {
            width: 20%;
            text-align: center;
        }
    }

    .tempbox2 {

        border: 1px solid #ddd;
        border-bottom: 0;

        span {
            display: inline-block;
            width: 25%;
            padding: 0 10px;
            border-left: 1px solid #ddd;
            padding: 5px;
        }
    }

    .tempbox2:last-child {
        border-bottom: 1px solid #ddd;
    }

    .treeUserp {
        p {
            padding: 5px;
        }

        p:hover {
            background: #01BEF0;
            color: #fff;
            cursor: pointer;
        }
    }
</style>
