<template>
    <fullscreen :fullscreen.sync="fullscreen" class="container" style="margin: 0;width: 100%;">
        <div class="container-box">
            <!-- <toolList @iconCli='iconCli' :tooltit='tooltit'></toolList> -->
            <div>
                <mySearch :searchList="searchList" @searchInfo="searchInfo"></mySearch>
                <!-- <div style="margin-top: 20px;float: right;" class="bigbtns">
                    <el-button style="margin-left: 20px;" class="btn-check" size="medium" type="primary"
                               @click="addNew()">新增模板
                    </el-button>
                </div> -->
            </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="reason" label="填报事由" align="center">
                    </el-table-column>
                    <el-table-column prop="precautions" label="填报注意事项" align="center">
                    </el-table-column>
                    <el-table-column prop="endTime" label="截至时间" align="center">
                    </el-table-column>
                    <el-table-column prop="createName" label="工单发起人" align="center">
                    </el-table-column>
                    <el-table-column prop="receiverName" label="接收人" align="center">
                        <template slot-scope="scope">
                            <span @click="toOneDialog(scope.row.id)" style="cursor:pointer;color: #007eff;">{{
                                scope.row.receiverName
                            }}</span>
                        </template>
                    </el-table-column>
                    <el-table-column prop="processName" label="当前处理人" align="center">
                    </el-table-column>
                    <el-table-column prop="createTime" label="发起时间" align="center">
                    </el-table-column>

                    <el-table-column prop="status" label="状态" align="center">
                        <template slot-scope="scope">
                            <!-- -1.已撤销 0.待处理 1.部门人员审批 2.部门领导审批 3.退回修改 4.已完成 -->
                            <span v-if="scope.row.status == -1">已撤销</span>
                            <span v-if="scope.row.status == 0">待处理</span>
                            <span v-if="scope.row.status == 1">部门人员审批</span>
                            <span v-if="scope.row.status == 2">部门领导审批</span>
                            <span v-if="scope.row.status == 3">退回修改</span>
                            <span v-if="scope.row.status == 4">已完成</span>
                        </template>
                    </el-table-column>
                    <el-table-column prop="superviseFlag" label="是否为督办" align="center">
                        <template slot-scope="scope">
                            <span v-if="scope.row.superviseFlag == 0">否</span>
                            <span v-if="scope.row.superviseFlag == null">否</span>
                            <span v-if="scope.row.superviseFlag == 1">是</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" @click="toChuli(scope.row)"
                                v-if="scope.row.status != 4 && (loginNo == scope.row.processId)">处理</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="issuedAddStatus" width="40%" :destroy-on-close="true"
                :modal-append-to-body="false" :close-on-click-modal="false" :fullscreen="false">
                <el-form :model="issuedParam" ref="addInfoList">
                    <div class="info-line">
                        <el-form-item prop="testInfo">
                            <span style="width: 6px;color: red">*</span><span>填报事由</span>
                            <el-input v-model="issuedParam.editReason" placeholder="填报事由"></el-input>
                        </el-form-item>
                    </div>
                    <div class="info-line">
                        <el-form-item prop="testInfo">
                            <span style="width: 6px;color: red">*</span><span>填报注意事项</span>
                            <el-input v-model="issuedParam.editRemark" placeholder="填报注意事项"></el-input>
                        </el-form-item>
                    </div>
                    <div class="info-line">
                        <el-form-item prop="testInfo">
                            <span style="width: 6px;color: red">*</span><span>截止时间</span>
                            <el-date-picker type="date" placeholder="截止时间" v-model="issuedParam.endTime"
                                :picker-options="pickerOptions" value-format="yyyy-MM-dd"></el-date-picker>
                        </el-form-item>
                    </div>
                </el-form>
                <div slot="footer" class="dialog-footer myfooter">

                    <el-button @click="issuedAddStatus = false">取消</el-button>
                    <el-button @click="processNewIssued()" type="primary">确定</el-button>
                </div>
            </el-dialog>
            <el-dialog :title="'回复详情'" :visible.sync="toOnevisible" width="50%" :destroy-on-close="true"
                :modal-append-to-body="false" :close-on-click-modal="false">
                <div style="height: 450px;">
                    <el-table height="calc(100% - 40px)" class="com-table" ref="multipleTable" :data="tableDataDialog"
                        tooltip-effect="dark" size="small" border style="width: 100%" v-loading="loadingDialog">
                        <el-table-column prop="receiveName" label="接收人" align="center">
                        </el-table-column>
                        <el-table-column prop="dept" label="接收人科室" align="center">
                        </el-table-column>
                        <el-table-column prop="arriveTime" label="到达时间" align="center">
                        </el-table-column>
                        <el-table-column prop="processTime" label="处理时间" align="center">
                        </el-table-column>
                        <el-table-column prop="selectionPath" label="选择路径" align="center">
                        </el-table-column>
                        <el-table-column prop="replyComments" label="回复意见" align="center">
                        </el-table-column>
                    </el-table>
                    <el-pagination class="pageBox" @current-change="currchangeDialog" layout="prev, pager, next" background
                        :total="totalDialog">
                    </el-pagination>
                </div>

                <div slot="footer" style="text-align: right;padding-bottom: 20px">
                    <el-button type="primary" @click="toOnevisible = false">确 定</el-button>
                </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 "./search.vue";
import myUpload from "../../../components/upload";
import toolList from "../../../components/toolList";
import myMessageNew from "../../../components/myMessageNew.vue"

export default {
    components: {
        myUpload,
        mySearch,
        toolList,
        myMessageNew
    },
    data() {
        return {
            tableData: [{}],
            total: 0,
            params: {},
            deleteTag: '',
            loginNo: '',
            centerDialogVisible: false,
            loading: false,
            issuedAddStatus: false,
            issuedParam: {},
            pickerOptions: {
                disabledDate(time) {
                    return time.getTime() < Date.now();
                }
            },
            tooltit: '收入模板管理',
            searchList: [{
                type: 'input',
                tit: '模板名称',
                value: '',
                width: '22%',
            }, {
                type: 'date',
                tit: '截止时间',
                value: '',
                width: '22%',
            }, {
                type: 'sel',
                tit: '是否为督办',
                value: '',
                width: '22%',
                options: [
                    {
                        dataCode: "0",
                        dataName: "否"
                    },
                    {
                        dataCode: "1",
                        dataName: "是"
                    }
                ]
            },
            {
                type: 'sel',
                tit: '状态',
                value: '',
                width: '22%',
                options: [
                    {
                        dataName: "待处理",
                        dataCode: "0",
                    },
                    {
                        dataName: "部门人员审核",
                        dataCode: "1",
                    },
                    {
                        dataName: "部门领导审批",
                        dataCode: "2",
                    },

                    {
                        dataName: "已完成",
                        dataCode: "4",
                    },
                    {
                        dataName: "退回修改",
                        dataCode: "3",
                    },
                ]
            },],
            delTemplateId: '',
            fullscreen: false,
            toOnevisible: false,
            loadingDialog: false,
            totalDialog: 0,
            pageSize: 0,
            pageSizeDialog: 0,
            paramsDialog: {},
            tableDataDialog: [{}],
        }
    },
    methods: {
        checkDelete(row) {
            this.deleteTag = '确认删除吗？';
            this.centerDialogVisible = true;
            this.delTemplateId = row.id;
        },
        processDelete(v) {
            this.centerDialogVisible = false;
            var _this = this;
            if (v === 1) {
                this.$http({
                    url: "/market/cIncomeExcelTemplate/deleteTemplate",
                    method: "post",
                    headers: {
                        "Content-Type": "application/json",
                    },
                    data: { excelId: this.delTemplateId },
                }).then((res) => {
                    if (res.data.result === 1) {
                        _this.$message({
                            message: '删除失败',
                            type: 'error'
                        });
                    } else {
                        _this.$message({
                            message: '删除成功',
                            type: 'success'
                        });
                        _this.getList({}, _this.pageSize);
                    }
                });
            }
        },
        //搜索数据
        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.superviseFlag = v[2] : '';
            v[3] ? this.params.status = v[3] : '';
            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/Issued/queryPage",
                method: "post",
                headers: {
                    "Content-Type": "application/json",
                    "page": '{"pageNo":"' + n + '","pageSize":"10"}'
                },
                data: {
                    ...v,
                },
            }).then(({ data: { totalRecord, data } }) => {
                this.tableData = data;
                this.total = totalRecord;
                this.loading = false;
            });
        },
        toOneDialog(o) {
            this.toOnevisible = true
            this.paramsDialog.issuedId = o
            this.getListDialog(this.paramsDialog, 1);
        },
        // 分页
        currchangeDialog(v) {
            this.pageSizeDialog = v;
            this.getListDialog(this.paramsDialog, this.pageSizeDialog);
        },
        getListDialog(v, n) {
            this.pageSizeDialog = n;
            this.loadingDialog = true;
            this.tableDataDialog = [];
            let _this = this;
            this.$http({
                url: "/market/FileOperateLog/queryPage",
                method: "post",
                headers: {
                    "Content-Type": "application/json",
                    "page": '{"pageNo":"' + n + '","pageSize":"10"}'
                },
                data: {
                    ...v,
                },
            }).then(({ data: { totalRecord, data } }) => {
                this.tableDataDialog = data;
                this.totalDialog = totalRecord;
                this.loadingDialog = false;
            });
        },
        addNew() {
            var _this = this;
            _this.jumpinfop('/incomeExcelInfo', 1, '新增模板', "")
        },
        toEdit(row) {
            var _this = this;
            _this.jumpinfop('/incomeExcelInfo', 2, '修改模板', row.id);
        },
        toView(row) {
            var _this = this;
            _this.jumpinfop('/documentCollectionApprovalExcel', 5, '查看', row.id);
        },
        toChuli(row) {
            var _this = this;
            _this.jumpinfop('/documentCollectionApprovalExcel', 4, '处理', row.id, row.status);
        },
        addNewIssued(row) {
            this.issuedParam = {
                templateId: row.id,
            };
            this.issuedAddStatus = true;
        },
        processNewIssued() {
            if (!this.issuedParam.editReason) {
                this.$message({
                    message: '填报事由不能为空',
                    type: 'error'
                });
                return;
            }
            if (!this.issuedParam.editRemark) {
                this.$message({
                    message: '填报注意事项不能为空',
                    type: 'error'
                });
                return;
            }
            if (!this.issuedParam.endTime) {
                this.$message({
                    message: '截止时间不能为空',
                    type: 'error'
                });
                return;
            }
            if (this.issuedParam.editReason.length > 240) {
                this.$message({
                    message: '填报事由长度不能大于240字',
                    type: 'error'
                });
                return;
            }
            if (this.issuedParam.editRemark.length > 240) {
                this.$message({
                    message: '填报注意事项长度不能大于240字',
                    type: 'error'
                });
                return;
            }
            var _this = this;
            //执行下发
            this.$http({
                url: '/market/cIncomeExcelIssued/addNewIssued',
                method: "post",
                headers: {
                    "Content-Type": "application/json",
                },
                data: this.issuedParam,
            }).then((res) => {
                this.loading = false;
                if (res.data.result === 1) {
                    _this.$message({
                        message: res.data.desc,
                        type: 'error'
                    });
                } else {
                    _this.$message({
                        message: '下发成功',
                        type: 'success'
                    });
                    this.issuedAddStatus = false;
                    this.getList({}, 1);
                }
            });
        },
        //跳转页面
        jumpinfop(p, v, n, id, status) {
            this.$router.push({
                path: p,
                query: {
                    type: v,
                    id: id,
                    status: status,
                }
            });
            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));
        },
        getUrlKey(name) {
            return (
                decodeURIComponent(
                    (new RegExp("[?|&]" + name + "=" + "([^&;]+?)(&|#|;|$)").exec(
                        location.href
                    ) || [, ""])[1].replace(/\+/g, "%20")
                ) || null
            );
        },
    },
    mounted() {
        this.getList({
            id: this.getUrlKey("id"),//获取地址栏参数
        }, 1);
        this.loginNo = JSON.parse(window.sessionStorage.userInfo).loginNo
    },
    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;
}

.info-line {
    width: 100%;
    display: block;
    padding-left: 20px;

    div {
        width: 90%;
        display: inline-block;
    }

    span {
        width: 100px;
        display: inline-block;
        text-align: left;

        i {
            color: red;
            display: inline-block;
            padding-right: 5px;
        }
    }

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

.online {
    width: 100%;

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

    span {
        vertical-align: top;
    }

    .el-textarea {
        width: calc(100% - 100px);
    }
}
</style>

