<template>
    <div class="partyBuildingK" v-loading="loadingImport">
        <div class="partyBuildingBtn">
            <div class="collectSeach" :style="$utils.collectSeachSty()">
                <div class="exceed">
                    <span class="exceedSpan">业务属性：</span>
                    <el-select v-model="sectionStr" placeholder="请选择业务属性">
                        <el-option
                        v-for="item in moduleData"
                        :key="item.id"
                        :label="item.sectionName"
                        :value="item.id">
                        </el-option>
                    </el-select>
                </div>
                <div class="exceed">
                    <span class="exceedSpan">考评时间：</span>
                    <el-date-picker v-model="resAnnual"  value-format="YYYY" type="year" placeholder="选择时间" />
                </div>
                <seachs @handleSeach="getSeachData" @handleRest="resetSeach"></seachs>
            </div>
            <div class="PeriodBtn" :style="$utils.PeriodBtnSty()">
                <btns
                :showImport="$utils.havePurview('partBuildK:oneLevel:import')"
                :showExport="true"
                :showAdd="$utils.havePurview('partBuildK:oneLevel:add')"
                :showSave="$utils.havePurview('partBuildK:oneLevel:save')"
                :showDelete="$utils.havePurview('partBuildK:oneLevel:delete')"
                :disSave="changeDateSelect.length === 0 || changeDateSelect.length>1"
                :disDelete="changeDateSelect.length === 0"
                :disImport="false"
                :disExport="false"
                @handleAdd="handleAdd"
                @handleEdit="handleEdit"
                @handleDelete="handleDelete"
                @handleImport="handleImport"
                @handleExport="handleExport"
                ></btns>
            </div>
            <div class="partyBuildingTableData">
                <el-table :data="partyBuildingData" style="width: 100%" :class="partyBuildTableSty()"
                 @select="rowClick" @select-all="rowClick">
                    <el-table-column type="selection" label="操作" align="center"></el-table-column>
                    <el-table-column label="序号" type="index" />
                    <el-table-column label="单位名称" prop="organizationName" width="300" />
                    <el-table-column label="业务属性" prop="sectionName" />
                    <el-table-column label="年度" prop="year" />
                    <el-table-column label="党建系数" prop="multiplier">
                        <template #default="scope">
                            <span>{{scope.row.multiplier}}</span>
                        </template>
                    </el-table-column>
                    <el-table-column label="备注" prop="remarks" width="350" />
                </el-table>
                <el-pagination
                    @size-change="handleSizeChange"
                    @current-change="handleCurrentChange"
                    :current-page="page.currentPage"
                    :page-size="page.pagesize"
                    layout="total, prev, pager, next, jumper"
                    :total="page.total">
                </el-pagination>
            </div>
            <el-dialog :title="title" v-model="dialogVisible" width="600px" :close-on-click-modal="false">
                <div class="periodFrom">
                    <el-form :model="ruleForm" :rules="rules" ref="ruleForm" label-width="100px" class="demo-ruleForm" :validate-on-rule-change="false">
                        <el-form-item label="单位名称" prop="organizationName">
                            <el-select v-model="ruleForm.organizationName" filterable placeholder="请选择单位名称">
                                <el-option
                                v-for="item in companyDatas"
                                :key="item.id"
                                :label="item.shortName"
                                :value="item.id">
                                </el-option>
                            </el-select>
                        </el-form-item>
                        <el-form-item label="业务属性" prop="sectionName">
                            <el-select v-model="ruleForm.sectionName" placeholder="请选择业务属性">
                                <el-option
                                v-for="item in moduleData"
                                :key="item.id"
                                :label="item.sectionName"
                                :value="item.id">
                                </el-option>
                            </el-select>
                        </el-form-item>
                        <el-form-item label="年份" prop="year">
                            <el-date-picker
                                v-model="ruleForm.year"
                                type="year"
                                value-format="YYYY"
                                placeholder="请选择年份"
                                />
                        </el-form-item>
                        <el-form-item label="党建系数" prop="multiplier">
                            <el-input-number v-model="ruleForm.multiplier" :precision="2" :step="0.1" :min="0" :max="1" placeholder="请输入党建系数" />
                        </el-form-item>
                        <el-form-item label="描述" prop="remarks">
                            <el-input v-model="ruleForm.remarks" :rows="5" type="textarea" placeholder="请输入描述"></el-input>
                        </el-form-item>
                    </el-form>
                </div>
                <template #footer>
                    <span class="dialog-footer">
                        <el-button @click="dialogVisible = false">取 消</el-button>
                        <el-button type="primary" @click="saveevaluaStart('ruleForm')">确 定</el-button>
                    </span>
                </template>
            </el-dialog>
            <indicator-item ref="indicatorItem"></indicator-item>
        </div>
        <import-dailog ref="importPage" @successImport="successImport"></import-dailog>
    </div>
</template>

<script>
import importDailog from '../importPage/importDailog.vue'
// import partyBuildingDetail from './partyBuildingKDetail.vue'
import btns from '../elbuttonS.vue'
import seachs from '../seachGroup.vue'
import {apiGetpartybuildingList, apiDeletepartyBuildRemove,apiGetbinsectionList,
 apiGetorganizationgetTree, apiPostpartybuildSave} from '../../api/api'
export default {
  components: { btns, importDailog, seachs },
    data() {
        return {
            dialogVisible: false,
            title: '',
            isSave: false,
            changeDateSelect: [],
            sectionStr: '',
            resAnnual: '',
            partyBuildingData:[],
            departmentDataAll: [],
            companyDatas: [],
            moduleData: [],
            ruleForm: {
                organizationName: '',
                sectionName: '',
                year: '',
                multiplier: 0,
                remarks: ''
            },
            rules: {
                organizationName: [
                    { required: true, message: '请选择单位名称', trigger: 'change' }
                ],
                sectionName: [
                    { required: true, message: '请选择业务属性', trigger: 'change' }
                ],
                year: [
                    { required: true, message: '请选择年份', trigger: 'change' }
                ],
                multiplier: [
                    { required: true, message: '请输入党建系数', trigger: 'blur' }
                ],
                remarks: [
                    { required: true, message: '请输入描述', trigger: 'blur' }
                ]
            },
            page:{
                pagesize: 12,
                currentPage: 1,
                total: 0
            },
            evalradio: {},
            loadingImport: false,
            winPix: window.devicePixelRatio,
            innerWidth: window.innerWidth
        }
    },
    created() {
        this.resAnnual = new Date().getFullYear().toString()
        this.getpartyBuildingData()
        this.getOrganizetionData()
        this.getBinSectionS()
    },
    methods:{
        getpartyBuildingData() {
            let that = this
            let params = {
                pageNum: that.page.currentPage,
                pageSize: that.page.pagesize,
                sectionId: that.sectionStr,
                year: that.resAnnual
            }
            apiGetpartybuildingList(params).then(datas =>{
                if (datas && datas.data) {
                    that.partyBuildingData = datas.data.records
                    that.page.total = datas.data.total
                }
            })
        },
        // 查询业务属性
        getBinSectionS() {
            let that = this
            apiGetbinsectionList().then(datas =>{
                if (datas && datas.data) {
                    that.moduleData = datas.data
                }
            })
        },
        //查询组织数据
        getOrganizetionData() {
            let that = this
            let params = {
                id: '23031000',
                num: 1
            }
            apiGetorganizationgetTree(params).then(datas =>{
                if (datas && datas.data && datas.data[0].children.length>0) {
                    that.companyDatas = datas.data[0].children
                }
            })
        },
        handleAdd() {
            this.dialogVisible = true
            this.isSave = false
            this.title = '新增党建考核系数'
            this.ruleForm = {
                organizationName: '',
                sectionName: '',
                year: '',
                multiplier: 0,
                remarks: ''
            }
        },
        handleEdit() {
            this.dialogVisible = true
            this.isSave = true
            this.title = '修改党建考核系数'
            this.evalradio = this.changeDateSelect[0]
            this.ruleForm = {
                organizationName: this.evalradio.departId,
                sectionName: this.evalradio.sectionId,
                year: this.evalradio.year,
                multiplier: this.evalradio.multiplier,
                remarks: this.evalradio.remarks
            }
        },
        saveevaluaStart(formName) {
            let that = this
            that.$refs[formName].validate((valid) => {
                if (valid) {
                    that.saveAndEditpartBuildData()
                }
            });
        },
        saveAndEditpartBuildData() {
            let that = this
            let userMes = JSON.parse(window.sessionStorage.getItem('user'))
            let comName = ''
            that.companyDatas.forEach(item =>{
                if (item.id === that.ruleForm.organizationName) {
                    comName = item.shortName
                }
            })
            let params = {                
                departId: that.ruleForm.organizationName,
                organizationName: comName,
                sectionId: that.ruleForm.sectionName,
                year: that.ruleForm.year,
                multiplier: that.ruleForm.multiplier,
                remarks: that.ruleForm.remarks,
                createOrgId: userMes.unitId,
                createOrgName: userMes.unitName,
                createBy: userMes.id,
                createName: userMes.name
            }
            if (that.isSave) {
                params.id = that.evalradio.id
            }
            apiPostpartybuildSave(params).then(datas =>{
                if (!datas.success) {
                    that.$message({
                        message: datas.message,
                        type: 'error'
                    });
                } else {
                    if (!that.isSave) {
                        that.$message({
                            message: '党建考核系数新增成功',
                            type: 'success'
                        });
                    } else {
                        that.$message({
                            message: '党建考核系数修改成功',
                            type: 'success'
                        });
                    }
                    that.dialogVisible = false
                    that.changeDateSelect = []
                    that.getpartyBuildingData()
                }
            })
        },
        //删除指标数据
        handleDelete() {
            this.$confirm('此操作将永久删除该数据, 是否继续?', '提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning'
            }).then(() => {
                let that = this
                let paramsArr = []
                that.changeDateSelect.forEach(it =>{
                    paramsArr.push(it.id)
                })
                apiDeletepartyBuildRemove(paramsArr.join(',')).then(datas =>{
                    if (datas) {
                        that.$message({
                            type: 'success',
                            message: '删除成功!'
                        });
                        that.changeDateSelect = []
                        that.getpartyBuildingData()
                    }
                })
            })
        },        
        rowClick(selection, row) {
            this.changeDateSelect = selection
        },
        getSeachData() {
            this.page.currentPage = 1
            this.getpartyBuildingData()
        },
        resetSeach() {
            this.page.currentPage = 1
            this.sectionStr = ''
            this.resAnnual = ''
            this.getpartyBuildingData()
        },
        successImport(val) {
            this.loadingImport = false
            this.getpartyBuildingData()
        },
        handleSizeChange(val){
            this.page.pagesize = val
            this.getpartyBuildingData()
        },
        handleCurrentChange(val){
            this.page.currentPage =val
            this.getpartyBuildingData()
        },
        handleImport() {
            this.$refs.importPage.upload.title = "党建考核系数信息导入"
            this.$refs.importPage.upload.open = true
            this.$refs.importPage.upload.url = '/party-building-multiplier/import'
        },
        handleExport() {
            this.$utils.downloadPer('party-building-multiplier/export1', '党建考核系数信息数据.xlsx')
        },
        partyBuildTableSty() {
            if (this.winPix === 1.25 || this.innerWidth < 1800) {
                return 'partyBuild125Table'
            } else {
                return 'partyBuild100Table'
            }
        }
    }
}
</script>

<style lang="less">
.partyBuildingK{
    .partyBuildingBtn{
        .collectSeach{
            display: flex;
            padding: 24px 20px;
            border-bottom: 1px solid#D6DBEA;
                .exceed{
                    display: flex;
                    .exceedSpan{
                        width: 80px;
                        height: 12px;
                        font-size: 14px;
                        font-family: Microsoft YaHei;
                        font-weight: 400;
                        color: #8991B0;
                        line-height: 12px;
                        margin-top: 14px;
                    }
                    .el-select{
                        margin-right:10px;
                        line-height: 40px !important;
                        .el-input__inner, .is-disabled{
                            height:40px !important;
                        }
                        .el-input__suffix{
                            .el-select__caret{
                                line-height:40px;
                            }
                        }
                    }
                    .el-input{
                        margin-right:10px;
                        height: 40px;
                        .el-input__inner{
                            height:40px;
                        }
                        .el-input__suffix{
                            .el-select__caret{
                                line-height:30px;
                            }
                        }
                    }
                }
        }
        span{
            font-size:14px;
        }
        .PeriodBtn{
            display: flex;
            justify-content: flex-end;
            padding: 20px 0;
        }
        .el-button{
            height: 30px;
            // width:100px;
            padding: 0 30px ;
            // padding-top: 8px;
            span{
                margin:0;
            }
        }
        .partyBuildingTableData{
            .partyBuild125Table{
                .el-table__body-wrapper{
                    height: 53vh !important;
                }
            }
            .partyBuild100Table{
                .el-table__body-wrapper{
                    height: 60vh !important;
                }
            }
            .el-table{
                .el-input__inner{
                    height: 30px !important;
                }
                .el-radio__label{
                    display: none;
                }
                
                .indicitem{
                    color: #409EFF;
                    font-size: 12px;
                    margin-right: 20px;
                    cursor:pointer;
                    &:hover{
                        text-decoration: underline;
                    }
                }
            }
            .el-pagination{
                margin-top: 20px;
                text-align: end;
                position: relative;
            }
        }
        .el-overlay{
            .el-dialog{
                .el-dialog__body{
                    padding: 30px 60px 30px 20px !important;
                    .periodFrom{
                        .el-select, .el-input{
                            width: 100%;
                        }
                        .el-input{
                            height: 30px;
                        }
                    }
                }
            }
        }
    }
}
</style>