<template>
    <n-spin :show="dataLoading">
        <n-space class="container" vertical>
            <n-space justify="center">
                <h1>街道社区4-5级网格工作考核细则（以季度为考核周期）</h1>
            </n-space>
            <n-space class="search" vertical>
                <n-grid :cols="7" :x-gap="10">
                    <n-grid-item>
                        <n-select placeholder="请选择街道" v-model:value="search.select.area.value"
                            :options="search.select.area.options" :clearable="true" @update:value="onAreaValueUpdate" />
                    </n-grid-item>
                    <n-grid-item>
                        <n-select placeholder="请选择社区" v-model:value="search.select.community.value"
                            :options="search.select.community.options" :clearable="true" />
                    </n-grid-item>
                    <n-grid-item>
                        <n-input v-model:value="search.input.keywords" type="text" placeholder="姓名|手机号" />
                    </n-grid-item>
                    <n-grid-item>
                        <n-select placeholder="请选择年份" v-model:value="search.select.year.value"
                            :options="search.select.year.options" />
                    </n-grid-item>
                    <n-grid-item>
                        <n-select placeholder="请选择月份" v-model:value="search.select.month.value"
                            :options="search.select.month.options" />
                    </n-grid-item>
                    <n-grid-item>
                        <n-select placeholder="请选择网格员级别" v-model:value="search.select.wgy.value"
                            :options="search.select.wgy.options" :clearable="true" />
                    </n-grid-item>
                    <n-grid-item>
                        <n-space>
                            <n-button type="primary" @click="onSearchClick">搜索</n-button>
                            <n-button type="default" @click="onSaveClick">保存</n-button>
                            <n-button type="info" @click="onExportClick" :disabled="btnExportDisabled">导出</n-button>
                        </n-space>
                    </n-grid-item>
                </n-grid>
            </n-space>
            <n-space class="body">
                <n-data-table size="small" :columns="table.columns" :data="table.data" :bordered="true" :single-line="false"
                    :min-height="table.minHeight" :max-height="table.maxHeight" :scroll-x="table.scrollX" />
            </n-space>
        </n-space>
    </n-spin>
    <n-modal preset="dialog" style="width: 800px" :show="modal.distance.show" :show-icon="false" :mask-closable="true"
        :closable="false" :on-update-show="onDistancenCloseClick">
        <wgy-work :user-id="search.userId" :user-name="search.userName" :year="search.select.year.value"
            :month="search.select.month.value" :level="search.select.wgy.value" />
    </n-modal>
    <n-modal preset="dialog" style="width: 800px" :show="modal.reportDay.show" :show-icon="false" :mask-closable="true"
        :closable="false" :on-update-show="onReportDayCloseClick">
        <wgy-report-day />
    </n-modal>
    <n-modal preset="dialog" style="width: 600px" :title="`【${modal.scoring.userName}】${modal.scoring.title}打分`"
        :show="modal.scoring.show" :show-icon="false" :mask-closable="true" :closable="false"
        :on-update-show="onScroingCloseClick">
        <scoring :row-key="modal.scoring.rowKey" :row-index="modal.scoring.rowIndex" :score="modal.scoring.score"
            :reason="modal.scoring.reason" :min-score="modal.scoring.minScore" :max-score="modal.scoring.maxScore"
            @confirm="onScroingConfimClick" />
    </n-modal>
</template>

<script>
import { createElementBlock, h } from 'vue';
import {
    NSpace,
    NGrid,
    NGridItem,
    NSelect,
    NRadio,
    NInput,
    NButton,
    NDataTable,
    NModal,
    NSpin,
    useMessage,
    useDialog,
} from 'naive-ui';
import WgyWork from '../common/WgyWork.vue'
import WgyReportDay from '../common/WgyReportDay.vue'
import Scoring from '../common/Scoring.vue';
import { listYear, listMonth, getCurrentYear, getCurrentMonth, download } from '../utils/common'

export default {
    name: 'Wgy',
    components: {
        NSpace,
        NGrid,
        NGridItem,
        NSelect,
        NRadio,
        NInput,
        NButton,
        NDataTable,
        NModal,
        NSpin,

        WgyWork,
        WgyReportDay,
        Scoring,
    },
    data() {
        let vueSelf = this;
        return {
            message: useMessage(),
            dialog: useDialog(),
            dataLoading: false,
            btnExportDisabled: false,
            isEdit: false,
            search: {
                userId: null,
                userName: null,
                select: {
                    area: {
                        value: null,
                        options: [
                            { label: '稀土路街道', value: 'xtl' }
                        ]
                    },
                    community: {
                        value: null,
                        options: [
                            { label: '社区', value: 'sq' }
                        ]
                    },
                    year: {
                        value: null,
                        options: [
                            { label: '2023年', value: '2023' }
                        ]
                    },
                    month: {
                        value: null,
                        options: [
                            { label: '1月', value: '1' }
                        ]
                    },
                    wgy: {
                        value: 4,
                        options: [
                            { label: '5级网格员', value: 4 },
                            { label: '4级网格员', value: 3 }
                        ]
                    }
                },
                input: {
                    keywords: ''
                }
            },
            table: {
                minHeight: 300,
                maxHeight: 300,
                scrollX: 2420,
                columns: [
                    {
                        align: 'center',
                        title: '序号',
                        key: 'A',
                        keyName: 'key',
                        fixed: 'left',
                        width: 60
                    },
                    {
                        align: 'center',
                        title: '姓名(网格数)',
                        key: 'B',
                        keyName: 'name',
                        fixed: 'left',
                        width: 140,
                        render(row) {
                            return `${row.B}(${row.gridCount})`
                        }
                    },
                    {
                        align: 'center',
                        title: '片区巡查（40分）',
                        key: 'C',
                        keyName: 'distance',
                        fixed: 'left',
                        width: 80,
                        className: 'score-plus',
                        render(row, index) {
                            return h('a', {
                                href: 'javascript:void(0);',
                                onClick() {
                                    vueSelf.onDistanceClick(row, index);
                                }
                            }, row.C);
                        }
                    },
                    {
                        align: 'center',
                        title: '巡查上报、案件受理过程质量',
                        key: 'quality',
                        children: [
                            {
                                align: 'center',
                                title: '基础分',
                                key: 'D',
                                keyName: 'baseScore',
                                width: 80
                            },
                            {
                                align: 'center',
                                title: '本月应报案件数',
                                key: 'E',
                                keyName: 'shouldReportCount',
                                width: 60,
                            },
                            {
                                align: 'center',
                                title: '本月单个案件分值',
                                key: 'F',
                                keyName: 'caseSingleScore',
                                width: 60
                            },
                            {
                                align: 'center',
                                title: '复杂案件数量',
                                key: 'complex',
                                keyName: 'complexScore',
                                width: 60
                            },
                            {
                                align: 'center',
                                title: '本月实报案件',
                                key: 'report',
                                children: [
                                    {
                                        align: 'center',
                                        title: '数量',
                                        key: 'G',
                                        keyName: 'reportCount',
                                        width: 60
                                    },
                                    {
                                        align: 'center',
                                        title: '得分',
                                        key: 'H',
                                        keyName: 'reportScore',
                                        width: 60,
                                        className: 'score-plus',
                                    }
                                ]
                            },
                            {
                                align: 'center',
                                title: '本月少报案件',
                                key: 'missReport',
                                children: [
                                    {
                                        align: 'center',
                                        title: '数量',
                                        key: 'I',
                                        keyName: 'missReportCount',
                                        width: 60
                                    },
                                    {
                                        align: 'center',
                                        title: '得分',
                                        key: 'J',
                                        keyName: 'missReportScore',
                                        width: 60,
                                        className: 'score-minus',
                                    }
                                ]
                            },
                            {
                                align: 'center',
                                title: '本月多报案件',
                                key: 'moreReport',
                                children: [
                                    {
                                        align: 'center',
                                        title: '数量',
                                        key: 'K',
                                        keyName: 'moreReportCount',
                                        width: 60
                                    },
                                    {
                                        align: 'center',
                                        title: '得分',
                                        key: 'L',
                                        keyName: 'moreReportScore',
                                        width: 60,
                                        className: 'score-plus',
                                    }
                                ]
                            },
                            {
                                align: 'center',
                                title: '凡属下列情况之一经核准予以扣分',
                                key: 'noDeduct',
                                children: [
                                    {
                                        align: 'center',
                                        title: '应上报却未上报案件',
                                        key: 'M',
                                        keyName: 'shouldButNo',
                                        width: 80,
                                        className: 'score-minus',
                                        render(row, index) {
                                            return h('a', {
                                                href: 'javascript:void(0);',
                                                onClick() {
                                                    vueSelf.onShouldButNoClick(row, index);
                                                }
                                            }, row.M);
                                        }
                                    },
                                    {
                                        align: 'center',
                                        title: '平台立案上报不标准不及时的',
                                        key: 'N',
                                        keyName: 'timeout',
                                        width: 80,
                                        className: 'score-minus',
                                        render(row, index) {
                                            return h('a', {
                                                href: 'javascript:void(0);',
                                                onClick() {
                                                    vueSelf.onTimeoutClick(row, index);
                                                }
                                            }, row.N);
                                        }
                                    },
                                    {
                                        align: 'center',
                                        title: '恶意退单',
                                        key: 'O',
                                        keyName: 'maliciousChargeback',
                                        width: 50,
                                        className: 'score-minus',
                                        render(row, index) {
                                            return h('a', {
                                                href: 'javascript:void(0);',
                                                onClick() {
                                                    vueSelf.onMaliciousChargebackClick(row, index);
                                                }
                                            }, row.O);
                                        }
                                    },
                                    {
                                        align: 'center',
                                        title: '其它情况',
                                        key: 'P',
                                        keyName: 'noDeductOthers',
                                        width: 50,
                                        className: 'score-minus',
                                        render(row, index) {
                                            return h('a', {
                                                href: 'javascript:void(0);',
                                                onClick() {
                                                    vueSelf.onNoDeductOthersClick(row, index);
                                                }
                                            }, row.P);
                                        }
                                    }
                                ]
                            },
                        ]
                    },
                    /*{
                        align: 'center',
                        title: '案件处置实效（指挥协调实效）',
                        key: 'dispatch',
                        children: [
                            {
                                align: 'center',
                                title: '结案情况得分',
                                key: 'Q',
                                keyName: 'overScore',
                                width: 60,
                                className: 'score-plus',
                                render(row, index) {
                                    return h('a', {
                                        href: 'javascript:void(0);',
                                        onClick() {
                                            vueSelf.onOverScoreClick(row, index);
                                        }
                                    }, row.Q);
                                }
                            },
                            {
                                align: 'center',
                                title: '督察案件结案情况',
                                key: 'supervise',
                                children: [
                                    {
                                        align: 'center',
                                        title: '督查次数',
                                        key: 'R',
                                        keyName: 'superviseCount',
                                        width: 60,
                                        render(row, index) {
                                            return h('a', {
                                                href: 'javascript:void(0);',
                                                onClick() {
                                                    vueSelf.onSuperviseCountClick(row, index);
                                                }
                                            }, row.R);
                                        }
                                    },
                                    {
                                        align: 'center',
                                        title: '督查扣分',
                                        key: 'S',
                                        keyName: 'superviseDeductScore',
                                        width: 60,
                                        className: 'score-minus',
                                        render(row, index) {
                                            vueSelf.computeS(row);
                                        }
                                    }
                                ]
                            },
                            {
                                align: 'center',
                                title: '案件处置过程质量',
                                key: 'handle',
                                children: [
                                    {
                                        align: 'center',
                                        title: '网格员24小时未核查扣分',
                                        key: 'T',
                                        keyName: 'unCheckIn24Hours',
                                        width: 80,
                                        className: 'score-minus',
                                    },
                                    {
                                        align: 'center',
                                        title: '反馈虚假信息',
                                        key: 'U',
                                        keyName: 'fakeInfo',
                                        width: 60,
                                        className: 'score-minus',
                                        render(row, index) {
                                            return h('a', {
                                                href: 'javascript:void(0);',
                                                onClick() {
                                                    vueSelf.onFakeInfoClick(row, index);
                                                }
                                            }, row.U);
                                        }
                                    },
                                    {
                                        align: 'center',
                                        title: '其他情况',
                                        key: 'V',
                                        keyName: 'handleOthers',
                                        width: 60,
                                        className: 'score-minus',
                                        render(row, index) {
                                            return h('a', {
                                                href: 'javascript:void(0);',
                                                onClick() {
                                                    vueSelf.onHandleOthersClick(row, index);
                                                }
                                            }, row.V);
                                        }
                                    }
                                ]
                            },
                        ]
                    },*/
                    {
                        align: 'center',
                        title: '人口信息管理',
                        key: 'population',
                        children: [
                            {
                                align: 'center',
                                title: '社区基数人口数',
                                key: 'communityBasePopulationCount',
                                keyName: 'communityBasePopulationCount',
                                width: 80,
                            },
                            {
                                align: 'center',
                                title: '社区人口数',
                                key: 'communityPopulationCount',
                                keyName: 'communityPopulationCount',
                                width: 80,
                            },
                            {
                                align: 'center',
                                title: '社区人口录入比例',
                                key: 'communityPopulationRate',
                                keyName: 'communityPopulationRate',
                                width: 80,
                            },
                            {
                                align: 'center',
                                title: '人口信息录入(15)',
                                key: 'W',
                                keyName: 'populationSave',
                                width: 80,
                                className: 'score-plus',
                                render(row, index) {
                                    return h('a', {
                                        href: 'javascript:void(0);',
                                        onClick() {
                                            vueSelf.onPopulationSaveClick(row, index);
                                        }
                                    }, row.W);
                                }
                            },
                            {
                                align: 'center',
                                title: '人口信息质量管理(15)',
                                key: 'X',
                                keyName: 'populationQuality',
                                width: 80,
                                className: 'score-plus',
                                render(row, index) {
                                    return h('a', {
                                        href: 'javascript:void(0);',
                                        onClick() {
                                            vueSelf.onPopulationQualityClick(row, index);
                                        }
                                    }, row.X);
                                }
                            },
                            /*{
                                align: 'center',
                                title: '人口信息维护(4)',
                                key: 'Y',
                                keyName: 'populationEdit',
                                width: 80,
                                className: 'score-plus',
                                render(row, index) {
                                    return h('a', {
                                        href: 'javascript:void(0);',
                                        onClick() {
                                            vueSelf.onPopulationEditClick(row, index);
                                        }
                                    }, row.Y);
                                }
                            },*/
                            {
                                align: 'center',
                                title: '抽查情况',
                                key: 'Z',
                                keyName: 'populationSpotCheck',
                                width: 80,
                                className: 'score-minus',
                                render(row, index) {
                                    return h('a', {
                                        href: 'javascript:void(0);',
                                        onClick() {
                                            vueSelf.onPopulationSpotCheckClick(row, index);
                                        }
                                    }, row.Z);
                                }
                            },
                        ]
                    },
                    /*{
                        align: 'center',
                        title: '党组织建设',
                        key: 'party',
                        children: [
                            {
                                align: 'center',
                                title: '党建信息上报(3)',
                                key: 'AA',
                                keyName: 'partySave',
                                width: 80,
                                className: 'score-plus',
                                render(row, index) {
                                    return h('a', {
                                        href: 'javascript:void(0);',
                                        onClick() {
                                            vueSelf.onPartySaveClick(row, index);
                                        }
                                    }, row.AA);
                                }
                            },
                            {
                                align: 'center',
                                title: '党建信息质量管理(3)',
                                key: 'AB',
                                keyName: 'partyQuality',
                                width: 80,
                                className: 'score-plus',
                                render(row, index) {
                                    return h('a', {
                                        href: 'javascript:void(0);',
                                        onClick() {
                                            vueSelf.onPartyQualityClick(row, index);
                                        }
                                    }, row.AB);
                                }
                            },
                            {
                                align: 'center',
                                title: '党建信息维护(4)',
                                key: 'AC',
                                keyName: 'partyEdit',
                                width: 80,
                                className: 'score-plus',
                                render(row, index) {
                                    return h('a', {
                                        href: 'javascript:void(0);',
                                        onClick() {
                                            vueSelf.onPartyEditClick(row, index);
                                        }
                                    }, row.AC);
                                }
                            },
                            {
                                align: 'center',
                                title: '抽查情况',
                                key: 'AD',
                                keyName: 'partySpotCheck',
                                width: 80,
                                className: 'score-minus',
                                render(row, index) {
                                    return h('a', {
                                        href: 'javascript:void(0);',
                                        onClick() {
                                            vueSelf.onPartySpotCheckClick(row, index);
                                        }
                                    }, row.AD);
                                }
                            },
                        ]
                    },*/
                    {
                        align: 'center',
                        title: '总得分',
                        key: 'AE',
                        keyName: 'totalScore',
                        fixed: 'right',
                        width: 100,
                        render(row, index) {
                            return vueSelf.computeAE(row);
                        }
                    },
                    {
                        align: 'center',
                        title: '评级',
                        key: 'AH',
                        keyName: 'evaluation',
                        fixed: 'right',
                        width: 100,
                        render(row, index) {
                            return vueSelf.computeAH(row);
                        }
                    },
                    {
                        align: 'center',
                        title: '应发(浮动)绩效工资',
                        key: 'AF',
                        keyName: 'shouldPay',
                        fixed: 'right',
                        width: 100,
                        render(row, index) {
                            let score = vueSelf.computeAE(row);
                            if(score <= 100 && score >= 85) {
                                return `${333 * row.gridCount}(${500 * row.gridCount})`;
                            } else if(score >= 75) {
                                return `${333 * row.gridCount}(${333 * row.gridCount})`;
                            } else if(score >= 60) {
                                return `${333 * row.gridCount}(${233 * row.gridCount})`;
                            }
                            return `${333 * row.gridCount}(0)`;
                        }
                    },
                    {
                        align: 'center',
                        title: '实发绩效工资',
                        key: 'AG',
                        keyName: 'actualPay',
                        fixed: 'right',
                        width: 100,
                        render(row, index) {
                            return ((vueSelf.computeAE(row) * vueSelf.computeAF(row) / 100) + vueSelf.computeComplex(row)).toFixed(2);
                        }
                    }
                ],
                data: []
            },
            modal: {
                distance: {
                    show: false
                },
                reportDay: {
                    show: false
                },
                scoring: {
                    show: false,
                    userName: null,
                    title: null,
                    rowKey: null,
                    rowIndex: null,
                    score: 0,
                    reason: '',
                    minScore: null,
                    maxScore: null
                }
            }
        }
    },
    methods: {
        // 打分确定
        onScroingConfimClick(key, index, { score, reason, userId, userName, date }) {
            this.modal.scoring.show = false;
            this.table.data[index][key] = score;
            this.table.data[index][`reason${key}`] = reason;
        },
        // 打分关闭
        onScroingCloseClick() {
            this.modal.scoring.show = false;
        },
        // 打分打开
        onScroingClick(type, row, index) {
            this.modal.scoring.show = false;
        },
        // 本月应上报案件数关闭
        onReportDayCloseClick() {
            this.modal.reportDay.show = false;
        },
        // 本月应上报案件数打开
        onReportDayClick(row, index) {
            this.modal.reportDay.show = true;
        },
        // 考勤模态框关闭
        onDistancenCloseClick() {
            this.modal.distance.show = false;
        },
        // 片区巡查打开
        onDistanceClick(row, index) {
            let distance = row.C;
            this.search.userId = row.userId;
            this.search.userName = row.B;
            this.modal.distance.show = true;
        },
        // 4、5级网格员单选
        onSearchRadioLevelValueChange(e) {
            this.search.radio.level.value = parseInt(e.target.value);
        },
        // 应上报却未上报案件 -
        onShouldButNoClick(row, index) {
            let shouldButNo = row.M;
            this.modal.scoring.show = true;
            this.modal.scoring.rowKey = 'M';
            this.modal.scoring.rowIndex = index;
            this.modal.scoring.score = shouldButNo;
            this.modal.scoring.reason = row.reasonM;
            this.modal.scoring.maxScore = null;
            this.modal.scoring.minScore = null;
            this.modal.scoring.userName = row.B;
            this.modal.scoring.title = '应上报却未上报案件';
        },
        // 平台立案上报不标准不及时的 -
        onTimeoutClick(row, index) {
            let timeout = row.N;
            this.modal.scoring.show = true;
            this.modal.scoring.rowKey = 'N';
            this.modal.scoring.rowIndex = index;
            this.modal.scoring.score = timeout;
            this.modal.scoring.reason = row.reasonN;
            this.modal.scoring.maxScore = null;
            this.modal.scoring.minScore = null;
            this.modal.scoring.userName = row.B;
            this.modal.scoring.title = '平台立案上报不标准不及时的';
        },
        // 恶意退单 -
        onMaliciousChargebackClick(row, index) {
            let maliciousChargeback = row.O;
            this.modal.scoring.show = true;
            this.modal.scoring.rowKey = 'O';
            this.modal.scoring.rowIndex = index;
            this.modal.scoring.score = maliciousChargeback;
            this.modal.scoring.reason = row.reasonO;
            this.modal.scoring.maxScore = null;
            this.modal.scoring.minScore = null;
            this.modal.scoring.userName = row.B;
            this.modal.scoring.title = '恶意退单';
        },
        // 扣分其它情况 -
        onNoDeductOthersClick(row, index) {
            let noDeductOthers = row.P;
            this.modal.scoring.show = true;
            this.modal.scoring.rowKey = 'M';
            this.modal.scoring.rowIndex = index;
            this.modal.scoring.score = noDeductOthers;
            this.modal.scoring.reason = row.reasonP;
            this.modal.scoring.maxScore = null;
            this.modal.scoring.minScore = null;
            this.modal.scoring.userName = row.B;
            this.modal.scoring.title = '扣分其它情况';
        },
        // 结案情况得分 -
        onOverScoreClick(row, index) {
            let overScore = row.Q;
            this.modal.scoring.show = true;
            this.modal.scoring.rowKey = 'Q';
            this.modal.scoring.rowIndex = index;
            this.modal.scoring.score = overScore;
            this.modal.scoring.reason = row.reasonQ;
            this.modal.scoring.userName = row.B;
            this.modal.scoring.maxScore = 10;
            this.modal.scoring.minScore = 0;
            this.modal.scoring.title = '结案情况得分';
        },
        // 督察扣分 -
        onSuperviseCountClick(row, index) {
            let superviseCount = row.R;
            this.modal.scoring.show = true;
            this.modal.scoring.rowKey = 'R';
            this.modal.scoring.rowIndex = index;
            this.modal.scoring.score = superviseCount;
            this.modal.scoring.reason = row.reasonR;
            this.modal.scoring.userName = row.B;
            this.modal.scoring.title = '督察扣分';
        },
        // 反馈虚假信息 -
        onFakeInfoClick(row, index) {
            let fakeInfo = row.U;
            this.modal.scoring.show = true;
            this.modal.scoring.rowKey = 'U';
            this.modal.scoring.rowIndex = index;
            this.modal.scoring.score = fakeInfo;
            this.modal.scoring.reason = row.reasonU;
            this.modal.scoring.maxScore = null;
            this.modal.scoring.minScore = null;
            this.modal.scoring.userName = row.B;
            this.modal.scoring.title = '反馈虚假信息';
        },
        // 处置其他情况 -
        onHandleOthersClick(row, index) {
            let handleOthers = row.V;
            this.modal.scoring.show = true;
            this.modal.scoring.rowKey = 'V';
            this.modal.scoring.rowIndex = index;
            this.modal.scoring.score = handleOthers;
            this.modal.scoring.reason = row.reasonV;
            this.modal.scoring.maxScore = null;
            this.modal.scoring.minScore = null;
            this.modal.scoring.userName = row.B;
            this.modal.scoring.title = '处置其他情况';
        },
        // 人口信息录入 +
        onPopulationSaveClick(row, index) {
            let populationSave = row.W;
            this.modal.scoring.show = true;
            this.modal.scoring.rowKey = 'W';
            this.modal.scoring.rowIndex = index;
            this.modal.scoring.score = populationSave;
            this.modal.scoring.reason = row.reasonW;
            this.modal.scoring.maxScore = 15;
            this.modal.scoring.minScore = 0;
            this.modal.scoring.userName = row.B;
            this.modal.scoring.title = '人口信息录入';
        },
        // 人口信息质量 +
        onPopulationQualityClick(row, index) {
            let populationQuality = row.X;
            this.modal.scoring.show = true;
            this.modal.scoring.rowKey = 'X';
            this.modal.scoring.rowIndex = index;
            this.modal.scoring.score = populationQuality;
            this.modal.scoring.reason = row.reasonX;
            this.modal.scoring.maxScore = 15;
            this.modal.scoring.minScore = 0;
            this.modal.scoring.userName = row.B;
            this.modal.scoring.title = '人口信息质量';
        },
        // 人口信息维护 +
        onPopulationEditClick(row, index) {
            let populationEdit = row.Y;
            this.modal.scoring.show = true;
            this.modal.scoring.rowKey = 'Y';
            this.modal.scoring.rowIndex = index;
            this.modal.scoring.score = populationEdit;
            this.modal.scoring.reason = row.reasonY;
            this.modal.scoring.maxScore = 4;
            this.modal.scoring.minScore = 0;
            this.modal.scoring.userName = row.B;
            this.modal.scoring.title = '人口信息维护'
        },
        // 人口信息抽查 -
        onPopulationSpotCheckClick(row, index) {
            let populationSpotCheck = row.Z;
            this.modal.scoring.show = true;
            this.modal.scoring.rowKey = 'Z';
            this.modal.scoring.rowIndex = index;
            this.modal.scoring.score = populationSpotCheck;
            this.modal.scoring.reason = row.reasonZ;
            this.modal.scoring.maxScore = 4;
            this.modal.scoring.minScore = 0;
            this.modal.scoring.userName = row.B;
            this.modal.scoring.title = '人口信息抽查';
        },
        // 党建信息录入 +
        onPartySaveClick(row, index) {
            let partySave = row.AA;
            this.modal.scoring.show = true;
            this.modal.scoring.rowKey = 'AA';
            this.modal.scoring.rowIndex = index;
            this.modal.scoring.score = partySave;
            this.modal.scoring.reason = row.reasonAA;
            this.modal.scoring.maxScore = null;
            this.modal.scoring.minScore = null;
            this.modal.scoring.userName = row.B;
            this.modal.scoring.title = '党建信息录入';
        },
        // 党建信息质量 +
        onPartyQualityClick(row, index) {
            let partyQuality = row.AB;
            this.modal.scoring.show = true;
            this.modal.scoring.rowKey = 'AB';
            this.modal.scoring.rowIndex = index;
            this.modal.scoring.score = partyQuality;
            this.modal.scoring.reason = row.reasonAB;
            this.modal.scoring.maxScore = 3;
            this.modal.scoring.minScore = 0;
            this.modal.scoring.userName = row.B;
            this.modal.scoring.title = '党建信息质量';
        },
        // 党建信息维护 +
        onPartyEditClick(row, index) {
            let partyEdit = row.AC;
            this.modal.scoring.show = true;
            this.modal.scoring.rowKey = 'AC';
            this.modal.scoring.rowIndex = index;
            this.modal.scoring.score = partyEdit;
            this.modal.scoring.reason = row.reasonAC;
            this.modal.scoring.maxScore = 4;
            this.modal.scoring.minScore = 0;
            this.modal.scoring.userName = row.B;
            this.modal.scoring.title = '党建信息维护';
        },
        // 党建信息抽查 -
        onPartySpotCheckClick(row, index) {
            let partySpotCheck = row.AD;
            this.modal.scoring.show = true;
            this.modal.scoring.rowKey = 'AD';
            this.modal.scoring.rowIndex = index;
            this.modal.scoring.score = partySpotCheck;
            this.modal.scoring.reason = row.reasonAD;
            this.modal.scoring.maxScore = 3;
            this.modal.scoring.minScore = 0;
            this.modal.scoring.userName = row.B;
            this.modal.scoring.title = '党建信息抽查';
        },
        computeS(row) {
            return (row.R * 0.2).toFixed(2);
        },
        computeAE(row) {
            let s = this.computeS(row);
            // let result = row.C + row.H + row.L - row.M - row.N - row.O - row.P + row.Q - s - row.T - row.U - row.V + row.W + row.X + row.Y - row.Z + row.AA + row.AB + row.AC - row.AD;
            let result = row.C + row.H + row.L - row.M - row.N - row.O - row.P + row.W + row.X - row.Z;
            result = Math.min(result, 100);
            return result < 0 ? 0 : result.toFixed(2);
        },
        computeComplex(row) {
            let complex = row.complex;
            return complex * 200;
        },
        computeAF(row) {
            let score = this.computeAE(row);
            if(score <= 100 && score >= 85) {
                return 500 * row.gridCount;
            } else if(score >= 75) {
                return 333 * row.gridCount;
            } else if(score >= 60) {
                return 233 * row.gridCount;
            }
            return 0
        },
        computeAH(row) {
            let score = this.computeAE(row);
            if(score <= 100 && score >= 85) {
                return '优';
            } else if(score >= 75) {
                return '良';
            } else if(score >= 60) {
                return '合格';
            }
            return '不合格';
        },
        onSearchClick() {
            this.listData();
        },
        onSaveClick() {
            let vueSelf = this;
            let tableDatas = [];
            vueSelf.table.data.forEach(item => {
                item.AE = vueSelf.computeAE(item);
                item.AF = vueSelf.computeAF(item);
                item.AG = (item.AE * item.AF / 100).toFixed(2);
                item.AH = vueSelf.computeAH(item);
                tableDatas.push({...item});
            })
            vueSelf.dialog.warning({
                title: "提示",
                content: "确定更新吗？",
                positiveText: "确定",
                negativeText: "取消",
                onPositiveClick: () => {
                    vueSelf.dataLoading = true;
                    vueSelf.$axios.put(`api/kpi/khxz/update-wgy/${vueSelf.search.select.wgy.value}`, {
                        datas: tableDatas
                    }).then( resp => {
                        vueSelf.message.info('保存成功');
                    }).catch( ({data}) => {
                        console.error(resp);
                        vueSelf.message.error(data.data.msg);
                    }).finally(() => {
                        vueSelf.dataLoading = false;
                    });
                },
                onNegativeClick: () => {
                }
            })
        },
        onExportClick() {
            let vueSelf = this;
            vueSelf.btnExportDisabled = true;
            download(vueSelf.$axios, `api/kpi/khxz/export-wgy`, vueSelf.getQuery(), () => {
                vueSelf.btnExportDisabled = false;
            });
        },
        getQuery() {
            return {
                areaId: this.search.select.area.value,
                communityId: this.search.select.community.value,
                khYear: this.search.select.year.value,
                khMonth: this.search.select.month.value,
                wgyLevel: this.search.select.wgy.value,
                keywords: this.search.input.keywords
            }
        },
        resize() {
            let body = document.body;
            this.table.minHeight = body.clientHeight - 408;
            this.table.maxHeight = body.clientHeight - 408;
            this.table.scrollX = body.clientWidth;
        },
        listArea() {
            let vueSelf = this;
            vueSelf.$axios.get(`api/kpi/list-area`, {
            }).then(({ data }) => {
                let optionArray = [];
                data.forEach((item, index) => {
                    optionArray.push({
                        label: item.dictName,
                        value: item.dictId
                    })
                })
                vueSelf.search.select.area.options = optionArray;
            }).catch(resp => {
                vueSelf.message.error(resp.data.msg);
            })
        },
        onAreaValueUpdate(value) {
            this.listCommunity(value);
        },
        listCommunity(areaId) {
            let vueSelf = this;
            vueSelf.search.select.community.value = null;
            if (!areaId) {
                vueSelf.search.select.community.options = [];
                return;
            }
            vueSelf.$axios.get(`api/kpi/list-community/area-id/${areaId}`, {
            }).then(({ data }) => {
                let optionArray = [];
                data.forEach((item, index) => {
                    optionArray.push({
                        label: item.communityName,
                        value: item.communityId
                    })
                })
                vueSelf.search.select.community.options = optionArray;
            }).catch(resp => {
                vueSelf.message.error(resp.data.msg);
            })
        },
        listData() {
            let vueSelf = this;
            vueSelf.dataLoading = true;
            vueSelf.$axios.get(`api/kpi/khxz/list-wgy`, {
                params: vueSelf.getQuery()
            }).then(({ data }) => {
                let totalGridCount = 0;
                data.forEach((item, index) => {
                    item.A = index + 1;
                    item.F = item.E === 0 ? 0 : parseFloat((item.D / item.E).toFixed(2));
                    item.H = Math.min(item.F * item.G, item.D);
                    item.J = Math.min(item.F * item.I, item.D);
                    item.L = (item.K > 10 ? 10 : item.K) * 0.5;
                    /*item.Q = item.communityPopulationRate >= 0.75 ? 10 : (item.communityPopulationRate >= 0.6 ? 5 : 0);*/
                    // 人口信息管理
                    // 未录入数据数量 = 社区基数人口数 - 社区人口数
                    /*var differenceValue = item.communityBasePopulationCount - item.communityPopulationCount;
                    var no100Score;
                    if(differenceValue > 0 && differenceValue <= 15) {
                      no100Score = differenceValue;
                    }else {
                      no100Score = 0;
                    }
                    item.W = item.communityPopulationRate === 1 ? 15 : no100Score;*/
                    item.W = item.communityPopulationRate * 15;
                    item.X = 15;
                    // item.Y = parseFloat((4 * item.communityPopulationRate).toFixed(2));
                    // 党组织建设(去掉)
                    /*item.AA = item.communityPopulationRate >= 0.75 ? 3 : (item.communityPopulationRate >= 0.6 ? 1.5 : 0);
                    item.AB = item.communityPopulationRate >= 0.75 ? 3 : (item.communityPopulationRate >= 0.6 ? 1.5 : 0);
                    item.AC = item.communityPopulationRate >= 0.75 ? 4 : (item.communityPopulationRate >= 0.6 ? 2 : 0);*/
                    /*item.S = item.R * 0.2;*/
                    totalGridCount += item.gridCount;
                    if(null == item.complex || '' == item.complex || typeof(item.complex) == 'undefined') {
                        item.complex = 0;
                    }
                })
                console.log(data)
                this.table.data = data;
                console.log(`totalGridCount: ${totalGridCount}`)
            }).catch(({ data }) => {
                vueSelf.message.error(data.msg);
            }).finally(() => {
                vueSelf.dataLoading = false;
            });
        },
        init() {
            this.search.select.year.options = listYear();
            this.search.select.year.value = getCurrentYear();
            this.search.select.month.options = listMonth();
            this.search.select.month.value = getCurrentMonth();
            this.listArea();
            this.listData();
        }
    },
    computed() {
    },
    mounted() {
        let vueSelf = this;
        vueSelf.init();
        vueSelf.resize();
        window.onresize = this.resize;
    }
}
</script>

<style lang="stylus" scoped>
.container
    padding 0 10px
:deep(.n-data-table-thead th)
    background-color rgba(196, 196, 196, 1)
// :deep(.score-plus)
//     background-color yellow
// :deep(.score-minus)
//     background-color red
</style>