<template>
    <div class="planFormulation">
        <el-row>
            <el-form :inline="true" :model="formInline" class="search-bm-boder" ref="formInline">
<!--                <el-form-item label="上报单位：" v-if="isSj">-->
<!--                    <el-select-->
<!--                            class="inputWidth"-->
<!--                            v-model="formInline.dwid"-->
<!--                            placeholder="请选择"-->
<!--                    >-->
<!--                        <el-option-->
<!--                                v-for="item in options"-->
<!--                                :key="item.value"-->
<!--                                :label="item.label"-->
<!--                                :value="item.value"-->
<!--                        ></el-option>-->
<!--                    </el-select>-->
<!--                </el-form-item>-->
                <el-form-item label="填报周期：">
<!--                    <el-date-picker-->
<!--                            type="year"-->
<!--                            class="inputWidth"-->
<!--                            value-format="yyyy"-->
<!--                            :picker-options="pickerOptions"-->
<!--                            placeholder="选择日期"-->
<!--                            v-model="formInline.tbnd"-->
<!--                    ></el-date-picker>-->
                    <quarter @getValue="getValue" :defaultValue="nowTime"  v-if="flag"></quarter>
                </el-form-item>

                <el-form-item>
                    <div class="search-button">
                        <span class="search-line"></span>
                        <el-button type="primary" size="small" class="iconfont iconchaxun" @click="doSearch">查询</el-button>
                        <el-button type="primary" @click="resetInfo('formInline')" size="small" class="iconfont iconzhongzhi"> 重置</el-button>
                    </div>
                </el-form-item>
            </el-form>
        </el-row>
        <el-row></el-row>
        <el-row class="addBtnBg">
<!--            <el-button type="primary" class="iconfont iconbaocun" size="small" @click="saveSubmit()"> 保存</el-button>-->
<!--            <el-button type="primary" class="iconfont icontijiao" size="small" @click="affirmSubmit()"> 确认</el-button>-->
<!--            <el-button type="primary" class="iconfont icontuijian1" size="small" @click="backSubmit()" v-if="isSj"> 退回</el-button>-->
            <el-button type="primary" class="iconfont icondaochu11" size="small" @click="exportSubmit()"> 导出</el-button>
        </el-row>
        <el-row>
            <h2 style="font-size: 20px;font-weight: 500;text-align:center;">{{tbnd}}第{{jd}}季度粮食流通监督检查执法案件信息统计表</h2>
        </el-row>
        <el-row id="pdfId">
            <el-row style="padding:10px"> 填报单位:
<!--                {{ resJcdwmc }} -->
            </el-row>
            <el-table
                    :data="tableData"
                    style="width: 100%;"
                    border
                    v-loading="loading"
            >
                <el-table-column type="index" label="序号" align="center"></el-table-column>
                <el-table-column label="案件来源" align="center">
                    <template slot-scope="scope">
                        <span v-if="isSj">{{scope.row.ajly}}</span>
                        <el-input v-model="scope.row.ajly" v-else></el-input>
                    </template>
                </el-table-column>
                <el-table-column label="主办单位" align="center">
                    <template slot-scope="scope">
                        <span v-if="isSj">{{scope.row.zbdw}}</span>
                        <el-input v-model="scope.row.zbdw" v-else></el-input>
                    </template>
                </el-table-column>
                <el-table-column label="案件类型" align="center">
                    <template slot-scope="scope">
                        <span v-if="isSj">{{scope.row.ajlx}}</span>
                        <el-input v-model="scope.row.ajlx" v-else></el-input>
                    </template>
                </el-table-column>
                <el-table-column label="涉案单位" align="center">
                    <template slot-scope="scope">
                        <span v-if="isSj">{{scope.row.sadw}}</span>
                        <el-input v-model="scope.row.sadw" v-else></el-input>
                    </template>
                </el-table-column>
                <el-table-column label="案件概要" align="center">
                    <template slot-scope="scope">
                        <span v-if="isSj">{{scope.row.ajgy}}</span>
                        <el-input v-model="scope.row.ajgy" v-else></el-input>
                    </template>
                </el-table-column>
                <el-table-column label="处理结果" align="center">
                    <el-table-column label="罚款" align="center">
                        <el-table-column label="金额（万元）" align="center">
                            <template slot-scope="scope">
                                <span v-if="isSj">{{scope.row.fkje}}</span>
                                <el-input v-model="scope.row.fkje" v-else></el-input>
                            </template>
                        </el-table-column>
                        <el-table-column label="违规粮食（吨）" align="center">
                            <template slot-scope="scope">
                                <span v-if="isSj">{{scope.row.wgls}}</span>
                                <el-input v-model="scope.row.wgls" v-else></el-input>
                            </template>
                        </el-table-column>
                    </el-table-column>
                    <el-table-column label="取消粮食收购资格" align="center">
                        <template slot-scope="scope">
                            <span v-if="isSj">{{scope.row.qxsgzg}}</span>
                            <el-input v-model="scope.row.qxsgzg" v-else></el-input>
                        </template>
                    </el-table-column>
                    <el-table-column label="取消政策性粮食收储资格" align="center">
                        <template slot-scope="scope">
                            <span v-if="isSj">{{scope.row.qxsczg}}</span>
                            <el-input v-model="scope.row.qxsczg" v-else></el-input>
                        </template>
                    </el-table-column>
                    <el-table-column label="移交其他部门" align="center">
                        <template slot-scope="scope">
                            <span v-if="isSj">{{scope.row.yjqtbm}}</span>
                            <el-input v-model="scope.row.yjqtbm" v-else></el-input>
                        </template>
                    </el-table-column>
                    <el-table-column label="其他" align="center">
                        <template slot-scope="scope">
                            <span v-if="isSj">{{scope.row.qt}}</span>
                            <el-input v-model="scope.row.qt" v-else></el-input>
                        </template>
                    </el-table-column>
                </el-table-column>
            </el-table>
        </el-row>

    </div>
</template>

<script>
    import htmlToPdf from '@/utils/htmlToPdf'
    import {inspectionUnit, getList, updateList, backList} from "@/api/jdjcbb/paracticable"
    import quarter from '@/components/quarter/index'
    import moment from "moment";
    export default {
        name: 'index',
        components: {
            quarter
        },
        data() {
            return {
                resJcdwmc: null,
                isSj: true,
                multipleSelection: [],
                formInline: {
                    tbnd: null,
                    tblx: 0,
                    dwid: '',
                    dwmc: '',
                },
                tbnd: null,
                options:[],
                loading: false,
                pickerOptions:{
                    disabledDate(time) {
                        return time.getTime() > Date.now()-8.64e7;
                    },
                },
                tableData: [],
                tree: [],
                jd: null,
                nowTime: '',
                flag: true
            }
        },
        created() {
            this.initTbnd()
            // this.getList() //有确定数据再打开
            if(sessionStorage.getItem('orgCode').length == 5){
                // this.isSj = true
                // this.getSbdw()
            }else{
                // this.isSj = false
                // this.formInline.dwid = sessionStorage.getItem('orgCode')
                // this.resJcdwmc = sessionStorage.getItem('orgName')
            }
            // this.formInline.dwid = sessionStorage.getItem('orgCode')
            // this.resJcdwmc = sessionStorage.getItem('orgName')
        },
        methods: {
            initTbnd(){
                //默认上个季度
                let lastM = moment().subtract(3, 'month').calendar();//06/01/2020
                let timeArr = lastM.split('/')
                this.tbnd = timeArr[2]
                let jdTime = ''
                if(timeArr[0] == '01' || timeArr[0] == '02' || timeArr[0] == '03'){
                    this.jd = 1
                    jdTime = '03'
                }else if(timeArr[0] == '04' || timeArr[0] == '05' || timeArr[0] == '06'){
                    this.jd = 2
                    jdTime = '06'
                }else if(timeArr[0] == '07' || timeArr[0] == '09' || timeArr[0] == '09'){
                    this.jd = 3
                    jdTime = '09'
                }else{
                    this.jd = 4
                    jdTime = '12'
                }
                this.nowTime = this.tbnd+'-'+jdTime
                this.formInline.tbnd = this.tbnd+'-'+jdTime
                this.nj = this.tbnd + '第' + this.jd +'季度'
            },
            getValue(val){
                this.nj = val
            },
            selectInit(row,index){
                if(row.sjzt == '0'){
                    return false  //不可勾选
                }else{
                    return true  //可勾选
                }
            },
            disabledFun(sjzt){
                return (sessionStorage.getItem('orgCode').length == 5 && sjzt == '0')? false: true
            },
            //获取上报单位
            getSbdw(){
                //组织单位树 --检查单位列表
                inspectionUnit(sessionStorage.getItem("orgCode")).then(res=>{
                    if (sessionStorage.getItem("orgCode").length > 5) {
                        delete res.data.children;
                    } else {
                        for (let key in res.data) {
                            if (key == "children") {
                                for (let k = 0; k < res.data[key].length; k++) {
                                    delete res.data[key][k].children;
                                }
                            }
                        }
                        //截取16个区粮办
                        let children = res.data.children.slice(0, 16);
                        // children.forEach((item,index)=>{
                        // 	children[index].orgName = item.orgName.split("区")[0] + "区发改委"
                        // })
                        res.data.children = children;
                    }
                    this.options.push({
                        value: res.data.orgCode,
                        label: res.data.orgName,
                    });
                    if(res.data.children && res.data.children.length){
                        res.data.children.forEach(item=>{
                            this.options.push({
                                value: item.orgCode,
                                label: item.orgName,
                            });
                        })
                    }
                    this.options.unshift({
                        value: '',
                        label: '合计',
                    });
                }).catch()
            },
            //重置
            resetInfo(){
                this.flag = false;
                this.$nextTick(() => {
                    this.flag = true;
                });
                this.initTbnd()
                this.getList()
            },
            //查询
            doSearch(){
                this.formInline.tbnd = this.nj.substring(0,4) + '-' + (this.nj.substring(5,6)*3<10?'0'+this.nj.substring(5,6)*3:this.nj.substring(5,6)*3)
                this.tbnd = this.nj.substring(0,4)
                this.jd = this.nj.substring(5,6)
                this.getList()
            },
            //获取列表
            getList() {
                let tbnd = this.formInline.tbnd
                let timeArr = this.nowTime.split('-')
                let nowY = timeArr[0]
                let nowJ = Math.floor(timeArr[1]/3) + 1
                if(nowY == tbnd.split('-')[0] && nowJ == (Math.floor(tbnd.split('-')[1]/3))){
                    tbnd = this.nowTime
                }
                let data = {
                    tbnd
                };
                getList(data)
                    .then(res => {
                        if (res.infoCode == 200) {
                            this.tableData = res.data.list;
                        } else {
                            this.$message({
                                type: 'error',
                                message: res.msg
                            });
                        }
                    }).catch()
            },
            //获取此次更改的数据
            returnDataFun(){
                let saveData = []
                if(this.changeIndex.length){
                    this.tableData.forEach((item,index)=>{
                        this.changeIndex.forEach(val=>{
                            if(val == index){
                                saveData.push(item)
                            }
                        })
                    })
                }
                return saveData
            },
            //保存
            saveSubmit() {
                let obj = this.returnDataFun()
                let params = obj
                // updateList(params).then(res=>{
                //     if(res){
                //         this.$message.success('保存成功')
                //     }else{
                //         this.$message.error('保存失败')
                //     }
                // }).catch()
            },
            //提交
            affirmSubmit() {
                let params = this.returnDataFun()
                // updateList(params).then(res=>{
                //     if(res){
                //         this.$message.success('提交成功')
                //     }else{
                //         this.$message.error('提交失败')
                //     }
                // }).catch()
            },
            //退回
            backSubmit() {
                // this.multipleSelection1 //
                // this.multipleSelection2
                // this.multipleSelection3
                let params = []
                this.multipleSelection.forEach(item=>{
                    params.push(item.dwid)
                })
                // backList(params).then(res=>{
                //     if(res.infoCode && res.infoCode == 200){
                //         this.$message.success('退回成功')
                //     }else{
                //         this.$message.error('退回失败')
                //     }
                // }).catch()
            },
            //导出
            exportSubmit(){

            },
            formatDateTime(date) {
                let y = date.getFullYear();
                let m = date.getMonth() + 1;
                m = m < 10 ? "0" + m : m;
                let d = date.getDate();
                d = d < 10 ? "0" + d : d;
                let h = date.getHours();
                h = h < 10 ? "0" + h : h;
                let minute = date.getMinutes();
                minute = minute < 10 ? "0" + minute : minute;
                let second = date.getSeconds();
                second = second < 10 ? "0" + second : second;
                return y + '-' + m;
            },
        }
    }
</script>

<style scoped>
    .planFormulation {
        overflow-y: auto;
        margin: 10px;
        border: 1px solid #f4f5f8;
        padding: 10px;
        min-width: 960px;
    }
    .header {
        width: 100%;
    }
    .table {
        margin-left: 20px;
    }
    .moreSelect {
        position: relative;
        display: inline-block;
        margin-left: 20px;
    }
    .moreSelect::before {
        content: '';
        display: block;
        position: absolute;
        left: -10px;
        width: 0px;
        border-left: 1px dashed #75b5fa;
        height: 35px;
    }
</style>
