<template>
    <div class="testdiv">
        <div class="divborder newSearchDiv">
            <div class="filter">
                <label>{{$t('100000')}}：</label>
                <Select v-model="depart" clearable class="searchSelect" @on-change="getItemlist">
                    <Option
                        v-for="item in departList"
                        :value="item.id"
                        :key="item.id"
                    >{{ item.title }}</Option>
                </Select>
            </div>
            <div class="filter">
                <label>{{$t('950384')}}：</label>
				        <Select v-model="kpiIndex" clearable class="searchSelect">
                    <Option
                        v-for="item in kpiItemList"
                        :value="item.id"
                        :key="item.title"
                    >{{ item.title }}</Option>
                </Select>
            </div>
            <div class="searchBtn">
                <Button
                    class="twoWord"
                    type="primary"
                    icon="ios-search"
                    @click="search(page,pagesize)"
                >{{$t('1001')}}</Button>
                <Button type="success" class="twoWord" icon="md-add-circle" @click="add()">{{$t('1002')}}</Button>
                <Button type="warning" class="twoWord" icon="ios-create-outline" @click="edit()">{{$t('1003')}}</Button>
                <Button type="error" class="twoWord" icon="md-close-circle" @click="del()">{{$t('1004')}}</Button>
            </div>
        </div>

        <!-- 添加 start-->
        <!-- 模态框 -->
        <Modal
             class="newModalClass"
            :title="$t(1002)"
            v-model="addmodal"
            :styles="{width:'1000px'}"
        >
            <div
                class="modal_body"
                style="padding-right:40px;min-height:320px!important;"
            >
                <div class="report_setting" style="width:1000px;float:left;height:100%;padding-left:0px;">
                    <div class="filter">
                        <label id="部门">
                            <i>*</i>{{$t(100000)}}：
                        </label>
                        <Select
                            v-model="adddepart"
                            @on-change="getItemlist2(adddepart)"
                            clearable
                            class="searchSelect"
                        >
                            <Option
                                v-for="(item,index) in departListAdd"
                                :value="item.id"
                                :key="index"
                            >{{ item.title }}</Option>
                        </Select>
                    </div>
                    <div class="filter">
                        <label id="项目">
                           <i>*</i> {{$t(950169)}}：
                        </label>
                        <Select v-model="additem" clearable class="searchSelect">
                            <Option
                                v-for="(item,index) in kpiItemListAdd"
                                :value="item.item"
                                :key="index"
                            >{{ item.itemDesc }}</Option>
                        </Select>
                    </div>
                    <div class="filter">
                    <label>
                        <i>*</i>{{$t(90000077)}}：
                    </label>
                    <Input
                        class="searchInput"
                        type="number"
                        v-model="refresh"
                    />
                    </div>
                    <Row>
                        <Col span="11">
                            <div style="border:1px solid #ccc;margin-top:8px">
                                <Row>
                                    <Col span="24">
                                        <span>{{$t('960426')}}</span>
                                    </Col>
                                </Row>
                                <Row>
                                    <Col span="6">
                                        <div
                                            style="background:#1564F4; width:50px;"
                                            class="modalLabel"
                                        >
                                            <label style="color:#FFFFFF;" v-text="$t(800225)">等级</label>
                                        </div>
                                        <Steps
                                            direction="vertical"
                                            :current="6"
                                            status="finish"
                                            size="small"
                                        >
                                            <Step title="Level 1"></Step>
                                            <Step title="Level 2"></Step>
                                            <Step title="Level 3"></Step>
                                            <Step title="Level 4"></Step>
                                        </Steps>
                                    </Col>
                                    <Col span="6">
                                        <div
                                            style="background:#FF0000; width:90px;"
                                            class="modalLabel"
                                        >
                                            <label
                                                style="color:#FFFFFF;"
                                                v-text="$t(90000078)"
                                            >异常未处理</label>
                                        </div>

                                        <Input
                                            class="searchInput modalInput"
                                            disabled
                                            type="number"
                                            min="0"
                                            v-model="level1t1"
                                        />
                                        <Input
                                            class="searchInput modalInput"
                                            type="number"
                                            min="0"
                                            v-model="level2t1"
                                        />
                                        <Input
                                            class="searchInput modalInput"
                                            type="number"
                                            min="0"
                                            v-model="level3t1"
                                        />
                                        <Input
                                            class="searchInput modalInput"
                                            type="number"
                                            min="0"
                                            v-model="level4t1"
                                        />
                                    </Col>
                                    <Col span="6">
                                        <div
                                            style="background:#FFFF00;width:90px;"
                                            class="modalLabel"
                                        >
                                            <label v-text="$t(90000079)">异常已计划</label>
                                        </div>
                                        <Input
                                            class="searchInput modalInput"
                                            disabled
                                            v-model="level1t2"
                                            type="number"
                                            min="0"
                                        />
                                        <Input
                                            class="searchInput modalInput"
                                            v-model="level2t2"
                                            type="number"
                                            min="0"
                                        />
                                        <Input
                                            class="searchInput modalInput"
                                            v-model="level3t2"
                                            type="number"
                                            min="0"
                                        />
                                        <Input
                                            class="searchInput modalInput"
                                            v-model="level4t2"
                                            type="number"
                                            min="0"
                                        />
                                    </Col>
                                    <Col span="6">
                                        <div
                                            style="background:#66FF00;width:100px;"
                                            class="modalLabel"
                                        >
                                            <label v-text="$t(90000080)">异常处理结果</label>
                                        </div>

                                        <Input
                                            class="searchInput modalInput"
                                            disabled
                                            v-model="level1t3"
                                            type="number"
                                            min="0"
                                        />
                                        <Input
                                            class="searchInput modalInput"
                                            disabled
                                            v-model="level2t3"
                                            type="number"
                                            min="0"
                                        />
                                        <Input
                                            class="searchInput modalInput"
                                            disabled
                                            v-model="level3t3"
                                            type="number"
                                            min="0"
                                        />
                                        <Input
                                            class="searchInput modalInput"
                                            disabled
                                            v-model="level4t3"
                                            type="number"
                                            min="0"
                                        />
                                    </Col>
                                </Row>
                            </div>
                        </Col>
                        <Col span="11">
                            <div style="border:1px solid #ccc;margin-top:8px">
                                <Row>
                                    <Col span="24">
                                        <span>{{$t('960427')}}</span>
                                    </Col>
                                </Row>
                                <Row>
                                    <Col span="6">
                                        <div
                                            style="background:#1564F4; width:50px;"
                                            class="modalLabel"
                                        >
                                            <label style="color:#FFFFFF;" v-text="$t(800225)">等级</label>
                                        </div>
                                        <Steps
                                            direction="vertical"
                                            :current="6"
                                            status="finish"
                                            size="small"
                                        >
                                            <Step title="Level 1"></Step>
                                            <Step title="Level 2"></Step>
                                            <Step title="Level 3"></Step>
                                            <Step title="Level 4"></Step>
                                        </Steps>
                                    </Col>
                                    <Col span="18">
                                        <div
                                            style="background:#66FF20; width:70px;"
                                            class="modalLabel"
                                        >
                                            <label v-text="$t(100001)">岗位</label>
                                        </div>
                                        <Input
                                            class="searchInput"
                                            type="text"
                                            disabled
                                            style="width:290px;margin-bottom:12px"
                                            v-model="level1user.groupname"
                                        />
                                        <Button style="margin-bottom:12px;" icon="md-create" @click="onLevelEdit(1)"></Button>
                                        <Input
                                            class="searchInput"
                                            type="text"
                                            disabled
                                            style="width:290px;margin-bottom:12px"
                                            v-model="level2user.groupname"
                                        />
                                        <Button style="margin-bottom:12px;" icon="md-create" @click="onLevelEdit(2)"></Button>
                                        <Input
                                            class="searchInput"
                                            type="text"
                                            disabled
                                            style="width:290px;margin-bottom:12px"
                                            v-model="level3user.groupname"
                                        />
                                        <Button style="margin-bottom:12px;" icon="md-create" @click="onLevelEdit(3)"></Button>
                                        <Input
                                            class="searchInput"
                                            type="text"
                                            disabled
                                            style="width:290px;margin-bottom:12px"
                                            v-model="level4user.groupname"
                                        />
                                        <Button style="margin-bottom:12px;" icon="md-create" @click="onLevelEdit(4)"></Button>
                                    </Col>
                                </Row>
                            </div>
                        </Col>
                    </Row>
                </div>
            </div>
            <div slot="footer">
                <Button type="text" size="large" @click="cancleModal">{{$t('1033')}}</Button>
                <Button type="primary" size="large" @click="asyncAdd">确定</Button>
            </div>
        </Modal>
        <!-- 添加 end-->

        <!-- 修改 start-->
        <!-- 模态框 -->
        <Modal
            class="newModalClass"
            :title="$t(1003)"
            v-model="editmodal"
            :styles="{width:'1000px'}"
        >
            <div
                class="modal_body"
                style="padding-right:40px;min-height:320px!important;"
            >
                <div class="report_setting" style="width:1000px;float:left;height:100%;padding-left:0px;">
                    <div class="filter">
                        <label id="部门">
                            <i>*</i>{{$t(100000)}}：</label>
                        <Select
                            v-model="details.departid"
                            @on-change="getItemlist2(details.departid)"
                            clearable
                            class="searchSelect"
                        >
                            <Option
                                v-for="(item,index) in departListAdd"
                                :value="item.id"
                                :key="index"
                            >{{ item.title }}</Option>
                        </Select>
                    </div>
                    <div class="filter">
                        <label id="项目">
                            <i>*</i>{{$t(950169)}}：</label>
                        <Select v-model="details.kpiItemid" clearable class="searchSelect">
                            <Option
                                v-for="(item,index) in kpiItemListEdit"
                                :value="item.item"
                                :key="index"
                            >{{ item.itemDesc }}</Option>
                        </Select>
                    </div>
                    <div class="filter">
                    <label>
                        <i>*</i>{{$t(90000077)}}：</label>
                    <Input
                        class="searchInput"
                        type="number"
                        v-model="refresh"
                    />
                    </div>
                    <Row>
                        <Col span="11">
                            <div style="border:1px solid #ccc;margin-top:8px">
                                <Row>
                                    <Col span="24">
                                        <span>{{$t('960426')}}</span>
                                    </Col>
                                </Row>
                                <Row>
                                    <Col span="6">
                                        <div
                                            style="background:#1564F4; width:50px;"
                                            class="modalLabel"
                                        >
                                            <label style="color:#FFFFFF;" v-text="$t(800225)">等级</label>
                                        </div>
                                        <Steps
                                            direction="vertical"
                                            :current="6"
                                            status="finish"
                                            size="small"
                                        >
                                            <Step title="Level 1"></Step>
                                            <Step title="Level 2"></Step>
                                            <Step title="Level 3"></Step>
                                            <Step title="Level 4"></Step>
                                        </Steps>
                                    </Col>
                                    <Col span="6">
                                        <div
                                            style="background:#FF0000; width:90px;"
                                            class="modalLabel"
                                        >
                                            <label
                                                style="color:#FFFFFF;"
                                                v-text="$t(90000078)"
                                            >异常未处理</label>
                                        </div>
                                        <Input
                                            class="searchInput modalInput"
                                            type="number"
                                            min="0"
                                            disabled
                                            v-model="level1t1"
                                        />
                                        <Input
                                            class="searchInput modalInput"
                                            type="number"
                                            min="0"
                                            v-model="level2t1"
                                        />

                                        <Input
                                            class="searchInput modalInput"
                                            type="number"
                                            min="0"
                                            v-model="level3t1"
                                        />
                                        <Input
                                            class="searchInput modalInput"
                                            type="number"
                                            min="0"
                                            v-model="level4t1"
                                        />
                                    </Col>
                                    <Col span="6">
                                        <div
                                            style="background:#FFFF00;width:90px;"
                                            class="modalLabel"
                                        >
                                            <label v-text="$t(90000079)">异常已计划</label>
                                        </div>
                                        <Input
                                            class="searchInput modalInput"
                                            type="number"
                                            min="0"
                                            disabled
                                            v-model="level1t2"
                                        />
                                        <Input
                                            class="searchInput modalInput"
                                            v-model="level2t2"
                                            type="number"
                                            min="0"
                                        />
                                        <Input
                                            class="searchInput modalInput"
                                            v-model="level3t2"
                                            type="number"
                                            min="0"
                                        />
                                        <Input
                                            class="searchInput modalInput"
                                            v-model="level4t2"
                                            type="number"
                                            min="0"
                                        />
                                    </Col>
                                    <Col span="6">
                                        <div
                                            style="background:#66FF00;width:100px;"
                                            class="modalLabel"
                                        >
                                            <label v-text="$t(90000080)">异常处理结果</label>
                                        </div>
                                        <Input
                                            class="searchInput modalInput"
                                            type="number"
                                            min="0"
                                            disabled
                                            v-model="level1t3"
                                        />
                                        <Input
                                            class="searchInput modalInput"
                                            disabled
                                            v-model="level2t3"
                                            type="number"
                                            min="0"
                                        />
                                        <Input
                                            class="searchInput modalInput"
                                            disabled
                                            v-model="level3t3"
                                            type="number"
                                            min="0"
                                        />
                                        <Input
                                            class="searchInput modalInput"
                                            disabled
                                            v-model="level4t3"
                                            type="number"
                                            min="0"
                                        />
                                    </Col>
                                </Row>
                            </div>
                        </Col>
                        <Col span="11">
                            <div style="border:1px solid #ccc;margin-top:8px">
                                <Row>
                                    <Col span="24">
                                        <span>{{$t('960427')}}</span>
                                    </Col>
                                </Row>
                                <Row>
                                    <Col span="6">
                                        <div
                                            style="background:#1564F4; width:50px;"
                                            class="modalLabel"
                                        >
                                            <label style="color:#FFFFFF;" v-text="$t(800225)">等级</label>
                                        </div>
                                        <Steps
                                            direction="vertical"
                                            :current="6"
                                            status="finish"
                                            size="small"
                                        >
                                            <Step title="Level 1"></Step>
                                            <Step title="Level 2"></Step>
                                            <Step title="Level 3"></Step>
                                            <Step title="Level 4"></Step>
                                        </Steps>
                                    </Col>
                                    <Col span="18">
                                        <div
                                            style="background:#66FF20; width:70px;"
                                            class="modalLabel"
                                        >
                                            <label v-text="$t(100001)">岗位</label>
                                        </div>
                                        <Input
                                            class="searchInput"
                                            type="text"
                                            disabled
                                            style="width:290px;margin-bottom:12px"
                                            v-model="level1user.groupname"
                                        />
                                        <Button style="margin-bottom:12px" icon="md-create" @click="onLevelEdit(1)"></Button>
                                        <Input
                                            class="searchInput"
                                            type="text"
                                            disabled
                                            style="width:290px;margin-bottom:12px"
                                            v-model="level2user.groupname"
                                        />
                                        <Button style="margin-bottom:12px" icon="md-create" @click="onLevelEdit(2)"></Button>
                                        <Input
                                            class="searchInput"
                                            type="text"
                                            disabled
                                            style="width:290px;margin-bottom:12px"
                                            v-model="level3user.groupname"
                                        />
                                        <Button tyle="margin-bottom:12px" icon="md-create" @click="onLevelEdit(3)"></Button>
                                        <Input
                                            class="searchInput"
                                            type="text"
                                            disabled
                                            style="width:290px;margin-bottom:12px"
                                            v-model="level4user.groupname"
                                        />
                                        <Button style="margin-bottom:12px" icon="md-create" @click="onLevelEdit(4)"></Button>
                                    </Col>
                                </Row>
                            </div>
                        </Col>
                    </Row>
                </div>
            </div>
            <div slot="footer">
                <Button type="text" size="large" @click="cancleModal">{{$t('1033')}}</Button>
                <Button type="primary" size="large" @click="asyncEdit" v-text="$t(1011)">确定</Button>
            </div>
        </Modal>
        <!-- 修改 end-->

        <!-- 岗位 -->
        <Modal v-model="levelmodal" :styles="{top: '40px',width:'950px'}" class="edit">
            <div
                class="modal_body"
                style="width:900px!important;padding:0 10px;max-height:450px!important;overflow-y:scroll"
            >
                <div style="width:750px;float:left;height:100%;padding-left:0px;">
                    <Tree :data="usergroup" show-checkbox multiple check-directly ref="tree"></Tree>
                </div>
            </div>
            <div slot="footer">
                <Button type="text" size="large" @click="canclelevelmodal">{{$t('1033')}}</Button>
                <Button type="primary" @click="handleLevelChange">{{$t('1011')}}</Button>
            </div>
        </Modal>
        <!-- 岗位 end-->

        <div class="divborder newTableDiv">
            <Table
                class="tableClass"
                @on-current-change="handleRowChange"
                highlight-row
                :data="tableData1"
                :columns="tableColumns1"
            ></Table>
            <div class="pageDiv">
                <div class="pageDirection">
                    <Page
                        :total="total"
                        :current="page"
                        @on-change="changePage"
                        show-elevator
                        show-sizer
                        show-total
                        @on-page-size-change="handlePageSize"
                        :page-size-opts="[10,20,30,40,100]"
                    ></Page>
                </div>
            </div>
        </div>
    </div>
</template>
<script>
import axios from '@/libs/api.request';
export default {
    components: {},
    data () {
        return {
            usergroup: [],
            departList: [],
            depart: 0, // 部门
            departList: [], // 部门列表
            departListAdd: [], // 部门列表
            tableData1: [], // 列表数据
            kpiIndex: 0, // kpi指标
            kpiItemList: [], // item
            kpiIndexAdd: 0,
            kpiItemListAdd: [], // item
            kpiItemListEdit: [], // item
            refresh: 0,
            adddepart: 0,
            additem: 0,
            addmodal: false,

            editmodal: false,
            levelmodal: false,
            details: {},

            level1t1: 0,
            level1t2: 0,
            level1t3: 0,

            level2t1: 0,
            level2t2: 0,
            level2t3: 0,

            level3t1: 0,
            level3t2: 0,
            level3t3: 0,

            level4t1: 0,
            level4t2: 0,
            level4t3: 0,
            cruentlevel: 0,
            level1user: { level: 1, usergroup: [], groupname: [] }, // level1 用户组
            level2user: { level: 2, usergroup: [], groupname: [] }, // level2 用户组
            level3user: { level: 3, usergroup: [], groupname: [] }, // level3 用户组
            level4user: { level: 4, usergroup: [], groupname: [] }, // level4 用户组

            page: 1,
            pagesize: 10,
            total: 0,
            tableColumns1: [
                {
                    type: 'index2',
                    title: this.$t(1008),
                    key: 'xuhao',
                    render: (h, params) => {
                        return h(
                            'span',
                            params.index + (this.page - 1) * this.pagesize + 1
                        );
                    },
                    width: 60
                },
                {
                    title: this.$t(100000),
                    key: 'depart'
                },
                {
                    title: this.$t(950384),
                    key: 'kpiItem'
                },
                {
                    title: this.$t(920139),
                    key: 'user'
                },
                {
                    title: this.$t(920138),
                    key: 'dateTime'
                }
            ]
        };
    },
    created () {
        this.getDepartList(); // 获取部门
        this.search(this.page, this.pagesize);
        // 格式化表格样式
	  this.tableColumns1 = this.$time.initTableTitle(this.tableColumns1)
    },
    methods: {
    // 获取部门

        getDepartList () {
            axios
                .request({
                    url: '/config/ProjectUser/getUserDepartment',
                    method: 'get'
                })
                .then(res => {
                    this.departList = [];
                    if (res.data.ret == 1) {
                        if (res.data.data.length != 0) {
                            this.departList = res.data.data;
                        }
                    }
                });
        },
        getDepartList2 () {
            axios
                .request({
                    url: '/config/ProjectUser/getUserDepartment',
                    method: 'get'
                })
                .then(res => {
                    this.departList = [];
                    if (res.data.ret === 1) {
                        if (res.data.data.length !== 0) {
                            this.departListAdd = res.data.data;
                        }
                    }
                });
        },
        search (page, pagesize) {
            var params = {
                section: this.depart,
                item: this.kpiIndex,
                pagesize: this.pagesize,
                page: this.page
            };
            axios
                .request({
                    url: '/kpi/PushSetting/GetSettingList',
                    params,
                    method: 'get'
                })
                .then(res => {
                    if (res.data.ret === 1) {
                        this.total = res.data.total;
                        this.mockTableData1(res.data.data);
                    }
                });
        },
        mockTableData1 (tablelist) {
            let data = [];
            tablelist.forEach(item => {
                if (item) {
                    data.push({
                        id: item.id,
                        processcode: item.processCode,
                        departid: item.departId,
                        depart: item.depart,
                        refresh: item.refresh,
                        kpiItemid: item.kpiItemId,
                        kpiItem: item.kpiItem,
                        flowDetails: item.flowDetails,
                        user: item.user,
                        dateTime: item.dateTime,
                        level1: item.level1,
                        level2: item.level2,
                        level3: item.level3,
                        level4: item.level4
                    });
                }
            });
            this.tableData1 = data;
        },
        handleRowChange (currentRow, oldCurrentRow) {
            this.details = currentRow; // 选中行
        },
        handlePageSize (value) {
            this.pagesize = value;
            this.tableData1 = this.search(this.page, this.pagesize);
        },
        changePage (value) {
            this.page = value;
            this.tableData1 = this.search(this.page, this.pagesize);
        },

        // 根据部门-项目指标
        getItemlist (val) {
            let section = 0;
            section = val;
            axios
                .request({
                    url: '/kpi/ItemDisplay/GetItem?section=' + section,
                    method: 'get'
                })
                .then(res => {
                    if (res.data.ret == 1) {
                        console.log(res.data.data);
                        this.kpiItemList = res.data.data;
                    }
                });
        },
        // 根据部门-项目指标 （添加）
        getItemlist2 (sectionid) {
            console.log('come in');

            var params = {
                section: sectionid
            };
            axios
                .request({
                    url: '/kpi/Item/GetItemBySection',
                    params,
                    method: 'get'
                })
                .then(res => {
                    if (res.data.ret === 1 && res.data.data.length !== 0) {
                        this.kpiItemListAdd = res.data.data;
                        this.kpiItemListEdit = res.data.data;
                    }
                });
        },
        add () {
            this.clear();
            this.addmodal = true;
            this.getDepartList2();
        },
        cancleModal () {
            this.addmodal = false;
            this.editmodal = false;
        },
        validData (type) {
            if (type === 1) {
                if (this.adddepart === 0) {
                    this.$Message.error(this.$t(930016));
                    return false;
                }
                if (this.additem === 0) {
                    this.$Message.error(this.$t(930017));
                    return false;
                }
            } else {
                if (
                    this.details.departid === undefined ||
                    this.details.kpiItemid === undefined ||
                    this.details.departid === 0 ||
                    this.details.kpiItemid === 0
                ) {
                    this.$Message.error(this.$t(930018));
                    return false;
                }
            }

            if (this.refresh === 0) {
                this.$Message.error(this.$t(930019));
                return false;
            }
            if (
                this.level2t1 === 0 &&
                this.level2t2 === 0 &&
                // this.level2t3 === 0 ||
                this.level3t1 === 0 &&
                this.level3t2 === 0 &&
                // this.level3t3 === 0 ||
                this.level4t1 === 0 &&
                this.level4t2 === 0
                // this.level4t3 === 0
            ) {
                this.$Message.error(this.$t(930020));
                return false;
            }

            // if ( this.level1user.groupname == '') {
            //   this.$Message.error('请选择层级1岗位！')
            //   return false
            // }
            if (this.level2t1 != 0 && this.level2user.groupname == '') {
                this.$Message.error(this.$t(930021));
                return false;
            }
            if (this.level2t2 != 0 && this.level2user.groupname == '') {
                this.$Message.error(this.$t(930021));
                return false;
            }
            if (this.level3t1 != 0 && this.level3user.groupname == '') {
                this.$Message.error(this.$t(930022));
                return false;
            }
            if (this.level3t2 != 0 && this.level3user.groupname == '') {
                this.$Message.error(this.$t(930022));
                return false;
            }
            if (this.level4t1 != 0 && this.level4user.groupname == '') {
                this.$Message.error(this.$t(930023));
                return false;
            }
            if (this.level4t2 != 0 && this.level4user.groupname == '') {
                this.$Message.error(this.$t(930023));
                return false;
            }
            return true;
        },
        asyncAdd () {
            if (!this.validData(1)) {
                return;
            }
            var data = {
                Depart: this.adddepart,
                KpiItem: this.additem,
                Refresh: this.refresh,
                Level1: {
                    type1: {
                        Min: this.level1t1
                    },
                    type2: {
                        Min: this.level1t2
                    },
                    type3: {
                        Min: this.level1t3
                    },
                    Sections: this.level1user.usergroup
                },
                Level2: {
                    type1: {
                        Min: this.level2t1
                    },
                    type2: {
                        Min: this.level2t2
                    },
                    type3: {
                        Min: this.level2t3
                    },
                    Sections: this.level2user.usergroup
                },
                Level3: {
                    type1: {
                        Min: this.level3t1
                    },
                    type2: {
                        Min: this.level3t2
                    },
                    type3: {
                        Min: this.level3t3
                    },
                    Sections: this.level3user.usergroup
                },
                Level4: {
                    type1: {
                        Min: this.level4t1
                    },
                    type2: {
                        Min: this.level4t2
                    },
                    type3: {
                        Min: this.level4t3
                    },
                    Sections: this.level4user.usergroup
                }
            };
            axios
                .request({
                    url: '/kpi/PushSetting/Add',
                    data,
                    method: 'post'
                })
                .then(res => {
                    if (res.data.ret === 1) {
                        this.$Message.success(this.$t(1055));
                        this.settingmodal = false;
                        this.page = 1;
                        this.search();
                        this.modal = false;
                    } else {
                        this.$Message.error(
                            this.$t(1056) + this.$t(res.data.msg)
                        );
                        this.search();
                    }
                });
            this.clear();
            this.addmodal = false;
        },
        // 清理赋值
        clear () {
            this.adddepart = 0;
            this.additem = 0;

            this.level1t1 = 0;
            this.level1t2 = 0;
            this.level1t3 = 0;

            this.level2t1 = 0;
            this.level2t2 = 0;
            this.level2t3 = 0;

            this.level3t1 = 0;
            this.level3t2 = 0;
            this.level3t3 = 0;

            this.level4t1 = 0;
            this.level4t2 = 0;
            this.level4t3 = 0;
            this.cruentlevel = 0;
            this.level1user = { level: 1, usergroup: [], groupname: [] }; // level1 用户组
            this.level2user = { level: 2, usergroup: [], groupname: [] }; // level2 用户组
            this.level3user = { level: 3, usergroup: [], groupname: [] }; // level3 用户组
            this.level4user = { level: 4, usergroup: [], groupname: [] }; // level4 用户组
        },
        edit () {
            if (this.details.id === undefined || this.details.id === 0) {
                this.$Message.error(this.$t(200231));
                return false;
            }
            console.log(this.details);
            this.getDepartList2();
            this.getItemlist2(this.details.departid);

            // return false;
            this.refresh = this.details.refresh;
            if (this.details.level1 != null) {
                this.level1t1 = this.details.level1.type1.min;
                this.level1t2 = this.details.level1.type2.min;
                this.level1t3 = this.details.level1.type3.min;
                this.level1user = this.details.level1.sections;
            }
            if (this.details.level2 != null) {
                this.level2t1 = this.details.level2.type1.min;
                this.level2t2 = this.details.level2.type2.min;
                this.level2t3 = this.details.level2.type3.min;
                this.level2user = this.details.level2.sections;
            }
            if (this.details.level3 != null) {
                this.level3t1 = this.details.level3.type1.min;
                this.level3t2 = this.details.level3.type2.min;
                this.level3t3 = this.details.level3.type3.min;
                this.level3user = this.details.level3.sections;
            }
            if (this.details.level4 != null) {
                this.level4t1 = this.details.level4.type1.min;
                this.level4t2 = this.details.level4.type2.min;
                this.level4t3 = this.details.level4.type3.min;
                this.level4user = this.details.level4.sections;
            }
            // this.level1user = this.details.level1.sections
            // this.level2user = this.details.level2.sections
            // this.level3user = this.details.level3.sections
            // this.level4user = this.details.level4.sections
            this.editmodal = true;
        },
        asyncEdit () {
            var data = {
                Id: this.details.id,
                Depart: this.details.departid,
                KpiItem: this.details.kpiItemid,
                Refresh: this.refresh,
                Level1: {
                    type1: {
                        Min: this.level1t1
                    },
                    type2: {
                        Min: this.level1t2
                    },
                    type3: {
                        Min: this.level1t3
                    },
                    Sections: this.level1user.usergroup
                },
                Level2: {
                    type1: {
                        Min: this.level2t1
                    },
                    type2: {
                        Min: this.level2t2
                    },
                    type3: {
                        Min: this.level2t3
                    },
                    Sections: this.level2user.usergroup
                },
                Level3: {
                    type1: {
                        Min: this.level3t1
                    },
                    type2: {
                        Min: this.level3t2
                    },
                    type3: {
                        Min: this.level3t3
                    },
                    Sections: this.level3user.usergroup
                },
                Level4: {
                    type1: {
                        Min: this.level4t1
                    },
                    type2: {
                        Min: this.level4t2
                    },
                    type3: {
                        Min: this.level4t3
                    },
                    Sections: this.level4user.usergroup
                }
            };
            if (!this.validData(2)) {
                return;
            }
            axios
                .request({
                    url: '/kpi/PushSetting/Modify',
                    data,
                    method: 'post'
                })
                .then(res => {
                    if (res.data.ret === 1) {
                        this.$Message.success(this.$t(1055));
                        this.settingmodal = false;
                        this.page = 1;
                        this.search();
                        this.details = {};
                    } else {
                        this.$Message.error(
                            this.$t(1056) + this.$t(res.data.msg)
                        );
                        this.search();
                    }
                });
            this.clear();
            this.editmodal = false;
        },
        del () {
            if (this.details.id === undefined || this.details.id === 0) {
                this.$Message.error(this.$t(200231));
                return false;
            }
            if (this.details.id === '' || this.details.id === undefined) {
                this.$Message.error(this.$t('1017'));
                return false;
            } else {
                if (confirm(this.$t('1018'))) {
                    axios
                        .request({
                            url: '/kpi/PushSetting/Del?id=' + this.details.id,
                            method: 'get'
                        })
                        .then(res => {
                            if (res.data.ret === 1) {
                                this.$Message.success(this.$t('1058'));
                                this.search(this.page, this.pagesize);
                                this.details = {};
                            } else {
                                this.$Message.error(this.$t(res.data.msg));
                            }
                        });
                }
            }
        },
        // 点击岗位
        onLevelEdit (level) {
            this.cruentlevel = level;
            this.levelmodal = true;
            this.initUserGroup();
        },
        initUserGroup () {
            axios
                .request({
                    url: '/config/ProjectUserGroup/ListSectionUsergroup',
                    method: 'get'
                })
                .then(res => {
                    var data = res.data.data;
                    var ret = [];
                    var group = [];
                    switch (this.cruentlevel) {
                    case 1:
                        group = this.level1user.usergroup;
                        break;
                    case 2:
                        group = this.level2user.usergroup;
                        break;
                    case 3:
                        group = this.level3user.usergroup;
                        break;
                    case 4:
                        group = this.level4user.usergroup;
                        break;
                    }
                    data.forEach(item => {
                        var level = {};
                        level.title = item.title;
                        level.value = item.value;
                        level.children = this.handleGroupData(
                            item.children,
                            group
                        );
                        level.disableCheckbox = true;
                        ret.push(level);
                    });
                    this.usergroup = ret;
                });
        },
        handleGroupData (children, group) {
            var ret = [];
            if (children != null && children.length > 0) {
                children.forEach(element => {
                    var data = {};
                    if (group.indexOf(element.groupID) !== -1) {
                        data.checked = true;
                    }
                    data.title = element.groupTitle;
                    data.value = element.groupID;
                    data.children = this.handleGroupData(
                        element.children,
                        group
                    );
                    ret.push(data);
                });
            }
            return ret;
        },
        canclelevelmodal () {
            this.levelmodal = false;
        },
        handleLevelChange () {
            var data = this.$refs.tree.getCheckedNodes();
            var newgroupname = [];
            var newusergroup = [];

            data.forEach(item => {
                if (item.children.length > 0) {
                    // this.$Message.error('请选择子级部门！')
                    return;
                }
                newusergroup.push(item.value);
                newgroupname.push(item.title);
            });
            switch (this.cruentlevel) {
            case 1:
                this.level1user.usergroup = newusergroup;
                this.level1user.groupname = newgroupname;
                break;
            case 2:
                this.level2user.usergroup = newusergroup;
                this.level2user.groupname = newgroupname;
                break;
            case 3:
                this.level3user.usergroup = newusergroup;
                this.level3user.groupname = newgroupname;
                break;
            case 4:
                this.level4user.usergroup = newusergroup;
                this.level4user.groupname = newgroupname;
                break;
            }
            this.levelmodal = false;
        }
    }
};
</script>
<style lang="less" scoped>
.modalLabel {
    margin: 20px 0px 20px 0px;
    width: 60px;
    height: 20px;
}
.modalInput {
    width: 70px;
    margin-bottom: 13px;
}
.report_setting{
  label{
    text-align: left!important;
    padding-left:5px;
  }
  .filter{
    label{
      text-align: right!important;
    }
  }
}
</style>
