<template>
    <div class="container-accountability infoManagerPage">
        <el-form ref="formData" :model="formData" :inline="true" class="search-bm-boder"  label-width="72px">
            <el-form-item label="信息标题:">
                <el-input v-model="formData.title" clearable placeholder='请输入' class="inputCompatible"></el-input>
            </el-form-item>
            <el-form-item label="上报年度:">
<!--                <el-select v-model="formData.year" placeholder="请选择" clearable class="inputCompatible">-->
<!--                    <el-option :key="item.index" :label="item" :value="item" v-for="item in dateyear"></el-option>-->
<!--                </el-select>-->
                <el-date-picker
                        type="year"
                        v-model="formData.year"
                        value-format="yyyy"
                        class="inputCompatible"
                        placeholder="请选择"
                ></el-date-picker>
            </el-form-item>
            <el-form-item label="状态:" label-width="44px">
                <el-select v-model="formData.status" clearable placeholder="请选择" class="inputCompatible">
                    <el-option v-for="(item,index) in typeData" :key="index" :label="item.name" :value="item.status"></el-option>
                </el-select>
            </el-form-item>
            <el-form-item>
                <div class="search-button">
                    <span class="search-line"></span>
                    <el-button type="primary" class="iconfont iconchaxun" size="small"  @click="queryFun">查询</el-button>
                    <el-button type="primary" size="small" class="iconfont iconzhongzhi" @click="resetFun">重置</el-button>
                </div>
            </el-form-item>
        </el-form>
        <el-row class="addBtnBg">
            <el-button type="primary" size="small" class="iconfont iconxinzeng" @click="goAdd">新增</el-button>
        </el-row>
        <el-row>
            <el-col :span="24">
                <!-- @row-click="tableRowClick" -->
                <el-table
                    :data="tableList"
                    v-loading="loading"
                    border
                    stripe
                    highlight-current-row
                >
                    <el-table-column align="center" label="序号" width="60">
                        <template slot-scope="scope">
                            <span>{{scope.$index+1}}</span>
                        </template>
                    </el-table-column>
                    <el-table-column prop="orgName" label="单位名称" align="center" sortable :show-overflow-tooltip="true"></el-table-column>
                    <el-table-column prop="title" label="信息标题" align="center" sortable :show-overflow-tooltip="true"></el-table-column>
                    <el-table-column prop="year" label="上报年度" align="center" sortable :show-overflow-tooltip="true"></el-table-column>
                    <el-table-column prop="publishtime" label="填报时间" align="center" sortable :show-overflow-tooltip="true" width="200"></el-table-column>
                    <el-table-column prop="status_value" label="状态" align="center" sortable :show-overflow-tooltip="true" width="200"></el-table-column>
                    <el-table-column label="操作" align="center" width="115">
                        <template slot-scope="scope">
                            <el-tooltip class="item" effect="light" content="查看" placement="top">
                                <el-button
                                    type="primary"
                                    size="small"
                                    class="iconfont iconchakan2 operate_show_btn"
                                    @click.stop="goSee(scope.row)"  
                                ></el-button>
                            </el-tooltip>
                            <el-tooltip class="item" effect="light" content="编辑" placement="top" v-if="buttonNameList.indexOf('编辑') > -1 && scope.row.status_value == '未提交'">
                                <el-button
                                    type="primary"
                                    size="small"
                                    class="iconfont iconxiugai1 operate_edit_btn"
                                    @click.stop="goEdit(scope.row)"
                                ></el-button>
                            </el-tooltip>
                            <el-tooltip class="item" effect="light" content="删除" placement="top" v-if="buttonNameList.indexOf('删除') > -1 && scope.row.status_value == '未提交'">
                                <el-button
                                    type="primary"
                                    size="small"
                                    class="iconfont iconshanchu operate_delete_btn"
                                    @click.stop="goDelete(scope.row)"
                                ></el-button>
                            </el-tooltip>
                        </template>
                    </el-table-column>
                </el-table>
                <div class="pag-right clearFix">
                    <el-pagination
                        class="right"
                        @size-change="handleSizeChange"
                        @current-change="handleCurrentChange"
                        :current-page.sync="page.page"
                        :page-sizes="[10,20,30,40]"
                        :page-size="page.size"
                        layout="total, sizes, prev, pager, next, jumper"
                        :total="page.total"
                        v-if="paginationShow"
                    ></el-pagination>
                </div>
            </el-col>
        </el-row>
    </div>
</template>
<script>
import { authorityControl } from "@/api/login/login"; 
import * as management from "@/api/headResponsibility/infoManager"
export default {
    data() {
        return {
            year: '',
            dateyear: [],
            formData: {
                title: '',//主题
                status: '',//状态
                year: ''
            },
            typeData: [],
            paginationShow: true,
            tableList: [],
            loading: false,
            page: {
                page: 1,
                size: 10,
                total: 0
            },
            buttonNameList: []
        }
    },
    created() {
        this.getButtonList(sessionStorage.getItem("resourceCode"),sessionStorage.getItem("userCode")) 
        var date = new Date()
        this.year = date.getFullYear()
        for (var i = 0; i < 9; i++) {
            this.dateyear.push(this.year)
            this.year = this.year - 1
        }
        this.dateyear.unshift(this.dateyear[0]+1)
        this.getStatusType()
        this.getList('start')
    },
    methods: {
        getButtonList(menuCode,userCode) {
          let codeData = {
              resourceCode:menuCode,
              userId:userCode,
          }
          authorityControl(codeData).then(res => {
             let buttonNameList = []
             res.data.forEach(item => {
                 this.buttonNameList.push(item.resourceName)
             })
          })
        },
        getList(type) {
            if (type != "start") {//非初始化调用：查询、分页
                sessionStorage.setItem('searchData', JSON.stringify(this.formData))
                sessionStorage.setItem('pageData', JSON.stringify(this.page))
            } else {//初始化分两种情况，详情页等返回后的初始化，以及第一次进入此菜单的初始化
                if(JSON.parse(sessionStorage.getItem('searchData'))){//详情页返回后，将对应查询条件和分页的字段赋值，页面回显参数
                    this.formData = JSON.parse(sessionStorage.getItem('searchData'))
                    this.page = JSON.parse(sessionStorage.getItem('pageData'))
                }else {//第一次进去此菜单时，保存上方默认的data
                    sessionStorage.setItem('searchData', JSON.stringify(this.formData))
                    sessionStorage.setItem('pageData', JSON.stringify(this.page))
                }
            }
            this.loading = true
            management.infoManagerList(this.formData,this.page).then(res => {
                if(res.infoCode == 200) {
                    this.tableList = res.data.list
                    this.page.total = res.data.total
                }else {
                    this.$message({
                        type: 'error',
                        message: res.msg,
                        duration: 2000
                    })
                }
                this.loading = false
            })
        },
        queryFun() {//查询
            this.paginationShow = false;
            this.handleCurrentChange(1);
            this.$nextTick(() => {
                this.paginationShow = true;
            });
        },
        resetFun() {//重置
            this.formData = {
                title: '',//主题
                status: '',//状态
                year: ''
            }
            this.queryFun()
        },
        tableRowClick(row, column, event) {
            if (event.label != "操作") {
                // this.goSee(row)
            }
        },
        goAdd() {//新增
            this.$router.push({
                path: '/accountability/infoSubmitCityAdd'
            })
        },
        goSee(row) {//查看
            this.$router.push({
                path: '/accountability/infoSubmitCitySee',
                // path: '/accountability/infoSubmitCityAdd',
                query: {
                    id: row.id,
                    state: 'show'
                }
            })
        },  
        goEdit(row) {//修改
            this.$router.push({
                path: '/accountability/infoSubmitCityAdd',
                query: {
                    id: row.id,
                    state: 'upDate'
                }
            })
        },
        goDelete(row) {//删除
            this.$confirm("您确定要删除吗?", "提示", {
                confirmButtonText: "确定",
                cancelButtonText: "取消",
                type: "warning"
            }).then(() => {
                this.delUseFun([row.id])
            })
        },
        delUseFun(data) {//抽样删除用方法
            management.infoDelete(data).then(res => {
                if(res.infoCode == 200) {
                    this.$message({ type: "success", message: '删除成功', duration: 2000 })
                    this.getList()
                }else {
                    this.$message({
                        message: res.msg,
                        type: "error",
                        duration: 2000
                    });
                }
            });
        },
        handleSizeChange(val) {//条数改变
            this.page.size = val
            this.getList()
        },
        handleCurrentChange(val) {//页数改变
            this.page.page = val
            this.getList()
        },
        getStatusType() {//获取检验类别
            management.statusData().then((res) => {
                if(res.infoCode == 200) {
                    this.typeData = res.data
                }else {
                    this.$message({
                        message: res.msg,
                        type: 'error',
                        duration: 2000
                    })
                }
            })
        }
    }
}
</script>
<style lang="scss">
</style>