<template>
    <fullscreen :fullscreen.sync="fullscreen" class="container" style="margin: 0;width: 100%;">
        <div class="container-box">
            <toolList @iconCli='iconCli' :tooltit='tooltit'></toolList>
            <div class="search">
                <mySearch :searchList="searchList" @searchInfo="searchInfo"></mySearch>
            </div>
            <br/>
            <div>
                <span style="color: red">提示：查看回复信息请点击接收人名称查看</span>
            </div>
            <div class="tabbox">
                <el-table height="calc(100% - 40px)" class="com-table" ref="multipleTable" :data="tableData"
                          tooltip-effect="dark" size="small" border style="width: 100%" v-loading="loading">
                    <el-table-column prop="templateName" label="模板名称" align="center">
                    </el-table-column>
                    <el-table-column prop="editReason" label="填报事由" align="center">
                    </el-table-column>
                    <el-table-column prop="editRemark" label="填报注意事项" align="center">
                    </el-table-column>
                    <el-table-column prop="endTime" label="截止时间" align="center">
                    </el-table-column>
                    <el-table-column prop="addUserName" label="发起人" align="center">
                    </el-table-column>
                    <el-table-column label="接收人" align="center">
                        <template slot-scope="scope">
                            <span v-if="scope.row.userList == null"
                                  style="color: #0b82ff;cursor: pointer"
                                  @click="processIssuedLog(scope.row.id)">{{ scope.row.userName }}</span>
                            <div v-else v-for="item in scope.row.userList">
                                <span style="color: #0b82ff;cursor: pointer"
                                      @click="processIssuedLog(item.id)">{{ item.userName }}&nbsp;</span>
                            </div>
                        </template>
                    </el-table-column>
                    <el-table-column prop="opTime" label="发起时间" align="center">
                    </el-table-column>
                    <el-table-column prop="state" label="状态" align="center">
                        <template slot-scope="scope">
                            <span v-if="scope.row.state == 0 && scope.row.type != '3'">待处理</span>
                            <span v-if="scope.row.state == 0 && scope.row.type == '3'">待审批</span>
                            <span v-if="scope.row.state == 1">已完成</span>
                            <span v-if="scope.row.state == 2">待审批</span>
                            <span v-if="scope.row.state == 3">驳回</span>
                        </template>
                    </el-table-column>
                    <el-table-column label="操作" width="220px" align="center" fixed="right">
                        <template slot-scope="scope">
                            <el-button size="mini" @click="toView(scope.row)">查看</el-button>
                            <el-button size="mini" v-if="scope.row.state == 0 && scope.row.type == '1'"
                                       @click="checkDelete(scope.row)">删除
                            </el-button>
                            <el-button size="mini" @click="toEdit(scope.row)"
                                       v-if="scope.row.type == 2 && (scope.row.state == 0 || scope.row.state == 3)">处理
                            </el-button>
                            <el-button size="mini" @click="toAudit(scope.row)"
                                       v-if="scope.row.type == 3 && scope.row.state == 0">处理
                            </el-button>
                        </template>
                    </el-table-column>
                </el-table>
                <el-pagination class="pageBox" @current-change="currchange" layout="prev, pager, next" background
                               :total="total">
                </el-pagination>
            </div>

            <el-dialog :title="'收入信息处理'" :visible.sync="authDialog" width="50%" :destroy-on-close="true"
                       :modal-append-to-body="false" :close-on-click-modal="false">
                <el-form :model="testModel">
                    <div>
                        <div class="info-line">
                            <span style="margin-right: 20px;margin-left: 40px">选择路径：</span>
                            <el-select v-model="auditForm.authType" placeholder="选择路径">
                                <el-option v-for="(item,index) in auditBoxList" :key="index" :label="item.name"
                                           :value="item.value"></el-option>
                            </el-select>
                        </div>
                        <br/>
                        <div class="info-line" v-if="auditForm.authType == 1">
                            <span style="margin-right: 20px;margin-left: 40px">下一步处理人：</span>
                            <el-button type="primary" @click="checkexa = true;">选择处理人</el-button>
                            <span style="width: 80px;margin-right: 20px;margin-left: 20px">{{ auditUserName }}</span>
                        </div>
                        <br/>
                        <div class="info-line">
                            <span style="margin-right: 20px;margin-left: 40px;">意见内容：</span>
                            <el-input type="textarea" v-model="auditForm.auditRemark" style="width: 400px"></el-input>
                        </div>
                        <br/>
                        <div slot="footer" style="text-align: right;padding-bottom: 20px;padding-top: 20px">
                            <el-button @click="authDialog = false">取 消</el-button>
                            <el-button type="primary" @click="processAudit()">确 定</el-button>
                        </div>
                    </div>
                </el-form>
            </el-dialog>

            <el-dialog title="选择审批人" :visible.sync="checkexa" width="50%" :destroy-on-close="true"
                       :modal-append-to-body="false" :close-on-click-modal="false">
                <div>
                    <el-form :model="addInfoList" ref="addInfoList">
                        <el-form-item prop="processUserId" class="info-line online">
                            <span style="width: 80px">审批人员&nbsp;</span>
                            <deptTreeOnly class="tree" @treeCheck="treeCheckonly" :defaultList="defaultList"
                                          :type="depttype" :closeList="closeList"></deptTreeOnly>
                            <div class="tree treeUser">
                                <p>{{ treeListonly.leaderAuditName }}
                                    <i v-if="treeListonly.leaderAuditName" @click="treeDelete()"
                                       class="el-icon-error"></i>
                                </p>
                            </div>
                            <el-form-item style="margin-bottom:0;display:none;">
                                <el-input></el-input>
                            </el-form-item>
                        </el-form-item>
                    </el-form>

                    <div slot="footer" style="text-align: right;padding-bottom: 20px">
                        <el-button type="primary" @click="processAuditUser()">确 定</el-button>
                        <el-button @click="checkexa = false">取 消</el-button>
                    </div>
                </div>
            </el-dialog>

            <el-dialog title="回复详情" :visible.sync="issuedLogStatus" width="70%" :close-on-press-escape="false"
                       :show-close="true" :before-close="closeIssuedLog" :destroy-on-close="true"
                       :modal-append-to-body="false"
                       :close-on-click-modal="false" :fullscreen="true">
                <div class="tabbox" style="height: 500px">
                    <el-table height="calc(100% - 50px)" class="com-table" ref="multipleTable"
                              :data="issuedLogData"
                              tooltip-effect="dark" size="small" border style="width: 100%" v-loading="loading">
                        <el-table-column prop="beforeUserName" label="接收人">
                        </el-table-column>
                        <el-table-column prop="beforeUserDept" label="部门">
                        </el-table-column>
                        <el-table-column prop="opTime" label="回复时间">
                        </el-table-column>
                        <el-table-column prop="remark" label="审批记录">
                        </el-table-column>
                        <el-table-column prop="status" label="审批意见">
                        </el-table-column>
                    </el-table>
                    <el-pagination class="pageBox" @current-change="issuedLogChange"
                                   layout="prev, pager, next" background
                                   :total="issuedLogTotal">
                    </el-pagination>
                </div>
            </el-dialog>
        </div>
        <myMessageNew :messTit='deleteTag' @closeMessage="processDelete" :centerDialogVisible="centerDialogVisible"
                      v-if="centerDialogVisible" yes-btn-name="是" no-btn-name="否"></myMessageNew>
    </fullscreen>
</template>

<script>
import mySearch from "../../../components/search.vue";
import myUpload from "../../../components/upload";
import toolList from "../../../components/toolList";
import myMessageNew from "../../../components/myMessageNew.vue"
import deptTreeOnly from "../../../components/deptTreeOnly.vue"

export default {
    components: {
        myUpload,
        mySearch,
        toolList,
        myMessageNew,
        deptTreeOnly
    },
    data() {
        return {
            testModel: {},
            tableData: [{}],
            total: 0,
            params: {},
            deleteTag: '',
            centerDialogVisible: false,
            loading: false,
            tooltit: '收入信息收集',
            searchList: [{
                type: 'input',
                tit: '模板名称',
                value: '',
                width: '32%',
            }, {
                type: 'date',
                tit: '截止时间',
                width: '32%',
            }, {
                type: 'sel',
                tit: '状态',
                value: '',
                width: '32%',
                options: [
                    {
                        dataCode: "0",
                        dataName: "待处理"
                    },
                    {
                        dataCode: "1",
                        dataName: "已完成"
                    },
                    {
                        dataCode: "2",
                        dataName: "待审批"
                    },
                    {
                        dataCode: "3",
                        dataName: "驳回"
                    }
                ]
            },],
            nowUserId: '',
            auditBoxList: [{}],
            authDialog: false,
            auditForm: {},
            auditUserName: '',
            auditUserId: '',
            //选择审批人
            checkexa: false,
            //审批人用到的
            treeListonly: {},
            excelData: {},
            fullscreen: false,
            defaultList: [],
            addInfoList: [],
            closeList: [],
            depttype: '',
            issuedLogStatus: false,
            issuedLogData: [],
            issuedLogPageSize: 1,
            issuedLogParams: {},
            issuedLogTotal: 0,
            delIssuedUserId: ''
        }
    },
    methods: {
        processIssuedLog(row) {
            this.issuedLogParams = {
                issuedUserId: row
            };
            console.log(this.issuedLogParams);
            this.getIssuedLog(this.issuedLogParams, this.issuedLogPageSize);
            this.issuedLogStatus = true;
        },
        getIssuedLog(v, n) {
            this.issuedLogPageSize = n;
            this.loading = true;
            this.issuedLogData = [];
            this.$http({
                url: "/market/cIncomeExcelIssued/getIssuedLog",
                method: "post",
                headers: {
                    "Content-Type": "application/json",
                    "page": '{"pageNo":"' + n + '","pageSize":"10"}'
                },
                data: v,
            }).then((res) => {
                this.issuedLogData = res.data.data;
                this.issuedLogTotal = res.data.totalRecord;
                this.loading = false;
            });
        },
        issuedLogChange(v) {
            this.issuedLogPageSize = v;
            this.getIssuedLog(this.issuedLogParams, this.issuedLogPageSize);
        },
        closeIssuedLog() {
            this.issuedLogStatus = false;
        },
        //搜索数据
        searchInfo(v) {
            this.params = {};
            v[0] ? this.params.templateName = v[0] : '';
            v[1] ? this.params.endTime = this.$formatDate(v[1], "YYYY-MM-DD") : '';
            v[2] ? this.params.state = v[2] : '';
            this.getList(this.params, this.pageSize);
        },
        //功能栏
        iconCli(v) {
            if (v === 1) {
                this.getList(this.params, this.pageSize);
            }
            if (v === 2) {
                this.fullscreen = !this.fullscreen
            }
        },
        // 分页
        currchange(v) {
            this.pageSize = v;
            this.getList(this.params, this.pageSize);
        },
        getList(v, n) {
            this.pageSize = n;
            this.loading = true;
            this.tableData = [];
            let _this = this;
            this.$http({
                url: "/market/cIncomeExcelIssued/getIssuedList",
                method: "post",
                headers: {
                    "Content-Type": "application/json",
                    "page": '{"pageNo":"' + n + '","pageSize":"10"}'
                },
                data: v,
            }).then((res) => {
                this.tableData = res.data.data;
                this.total = res.data.totalRecord;
                this.loading = false;
            });
        },
        toView(row) {
            var _this = this;
            _this.jumpinfop('/incomeExcelInfo', 4, '查看收入信息', row.id);
        },
        checkDelete(row) {
            this.deleteTag = '确认删除吗？';
            this.centerDialogVisible = true;
            this.delIssuedUserId = row.id;
        },
        processDelete(v) {
            this.centerDialogVisible = false;
            var _this = this;
            if (v === 1) {
                this.$http({
                    url: "/market/cIncomeExcelIssued/deleteIssued",
                    method: "post",
                    headers: {
                        "Content-Type": "application/json",
                    },
                    data: {issuedUserId: this.delIssuedUserId},
                }).then((res) => {
                    if (res.data.result === 1) {
                        _this.$message({
                            message: '删除失败',
                            type: 'error'
                        });
                    } else {
                        _this.$message({
                            message: '删除成功',
                            type: 'success'
                        });
                        _this.getList({}, _this.pageSize);
                    }
                });
            }
        },
        toEdit(row) {
            var _this = this;
            _this.jumpinfop('/incomeExcelInfo', 5, '处理收入信息', row.id);
        },
        toAudit(row) {
            this.auditForm = {};
            this.auditUserId = '';
            this.auditUserName = '';
            this.auditBoxList = [{
                name: '提交审核',
                value: '1'
            }, {
                name: '退回修改',
                value: '3'
            }, {
                name: '结束',
                value: '2'
            }];
            this.nowUserId = row.id;
            this.authDialog = true;
        },
        processAuditUser() {
            console.log(this.treeListonly);
            this.auditUserId = this.treeListonly.leaderAuditNo;
            this.auditUserName = this.treeListonly.leaderAuditName;
            this.checkexa = false;
        },
        processAudit() {
            //检查选项
            if (this.auditForm.authType == null) {
                this.$message({
                    message: '请选择路径',
                    type: 'error'
                });
                return;
            }
            if (this.auditForm.authType == '1') {
                if (this.auditUserId == '') {
                    this.$message({
                        message: '请选择下一步处理人',
                        type: 'error'
                    });
                    return;
                }
            }
            if (this.auditForm.auditRemark
                && this.auditForm.auditRemark.length > 240) {
                this.$message({
                    message: '意见内容长度不能大于240字',
                    type: 'error'
                });
                return;
            }
            //提交
            var _this = this;
            var url = '/market/cIncomeExcelIssued/issuedUserProcessAuth';
            this.loading = true;
            this.$http({
                url: url,
                method: "post",
                headers: {
                    "Content-Type": "application/json",
                },
                data: {
                    issuedUserId: this.nowUserId,
                    type: this.auditForm.authType,
                    nextUserId: this.auditUserId,
                    auditRemark: this.auditForm.auditRemark
                },
            }).then((res) => {
                this.loading = false;
                if (res.data.result === 1) {
                    _this.$message({
                        message: res.data.desc,
                        type: 'error'
                    });
                } else {
                    this.authDialog = false;
                    _this.$message({
                        message: '处理成功',
                        type: 'success'
                    });
                    //刷新列表
                    this.getList({}, 1);
                }
            });

        },
        //跳转页面
        jumpinfop(p, v, n, id) {
            this.$router.push({
                path: p,
                query: {
                    type: v,
                    id: id
                }
            });
            this.setabList(n, p + '?type=' + v + '&id=' + id);
        },
        //新建一个页面
        setabList(n, p) {
            let params = {
                children: "",
                name: n,
                rountPath: p,
                target: "_self",
            };
            for (let i = 0; i < this.$store.state.tabList.length; i++) {
                if (this.$store.state.tabList[i].name === params.name) {
                    this.$store.state.tabList[i] = params;
                }
            }
            let set = new Set([...this.$store.state.tabList, params]);
            set.add(params);
            this.$store.commit("setDefaultActive", params.rountPath);
            this.$store.commit("setTabList", Array.from(set));
        },
        //填报人相关
        deletes(val, index) {
            this.treeList.splice(index, 1);
            this.closeList = this.treeList;
        },
        treeCheckonly(v) {
            this.treeList = v;
            this.treeListonly = v;
        },
        treeDelete() {
            this.treeListonly = {};
            this.closeList = !this.closeList;
        },
    },
    mounted() {
        this.getList({}, 1);
    },
    created() {

    }
}
</script>

<style scoped lang="scss">
.titbox {
    div {
        float: right;

        i {
            font-size: 22px;
            margin-left: 20px;
            cursor: pointer;
        }
    }
}

.tabbox {
    margin-top: 16px;
}

.pageBox {
    text-align: right;
    margin-top: 10px;
}


.online {
    width: 100%;

    .el-select {
        width: calc(100% - 100px);
    }

    span {
        vertical-align: top;
    }

    .el-textarea {
        width: calc(100% - 100px);
    }

    .tree {
        width: calc(50% - 60px);
        display: inline-block;
        margin-right: 20px;
        height: 300px;
        overflow-y: scroll;

        .el-icon-error {
            float: right;
            font-size: 20px;
            margin-top: 9px;
            cursor: pointer;
        }
    }

    .treeUser {
        margin: 0;
        border: 1px solid #ddd;

        p {
            background: #f4f4f4;
            padding: 0 20px;
            margin-bottom: 5px;
        }
    }

    .treeUserb {
        width: calc(100% - 100px);
        border: 1px solid #ddd;
        background: #f4f4f4;
        border-radius: 3px;
        height: auto;
        overflow: hidden;

        p {
            display: inline-block;
            padding: 0 20px;
            margin-bottom: 5px;
        }
    }
}
</style>

