<template>
    <div class="container" id="container" v-loading="loading">
        <fullscreen :fullscreen.sync="fullscreen" class="container" style="margin: 0;width: 100%;">
            <iframe height="100%" width="100%" src="/marketfront/static/views/performance.html" frameborder="0" ref="iframe"
                name="excelIframe" id="excelIframe"></iframe>
        </fullscreen>
        <el-dialog :title="'督办'" :visible.sync="dubanStatus" width="50%" :destroy-on-close="true"
            :modal-append-to-body="false" :close-on-click-modal="false" :before-close="closeduban">
            <el-form ref="form" :model="testModel" :rules="rules">
                <div>
                    <div style="padding: 10px 20%;">
                        <div style="text-align: center;margin-bottom: 10px;">注:设置督办后,系统会按照设定的周期自动派发</div>
                        <el-form-item label="派发周期:" label-width="100px" prop="distributeType">
                            <el-select v-model="testModel.distributeType" placeholder="选择派发周期" style="width: 100%;">
                                <el-option v-for="({ label, value }, index) in [
                                    { label: '月', value: '0' },
                                    { label: '季度', value: '1' },
                                    { label: '半年', value: '2' },
                                    { label: '年', value: '3' },
                                ]" :key="index" :label="label" :value="value"></el-option>
                            </el-select>
                        </el-form-item>
                        <el-form-item label="填报日期:" label-width="100px" prop="distributeTime">
                            <el-date-picker :append-to-body="false" v-model="testModel.distributeTime" size="medium"
                                type="datetime" placeholder="选择填报日期" @change="handleWrite" style="width: 100%"
                                :picker-options="pickWrite">
                            </el-date-picker>
                        </el-form-item>
                        <el-form-item label="截至日期:" label-width="100px" prop="distributeEndTime">
                            <el-date-picker :append-to-body="false" v-model="testModel.distributeEndTime" size="medium"
                                @change="handleEnd" :unlink-panels="true" type="datetime" placeholder="选择截至日期"
                                style="width: 100%" :picker-options="pickOptions">
                            </el-date-picker>
                        </el-form-item>
                    </div>
                    <div slot="footer" style="text-align: right;padding-bottom: 20px;padding-top: 20px">
                        <el-button @click="closeduban">取 消</el-button>
                        <el-button type="primary" @click="processAuthduban()">确 定</el-button>
                    </div>
                </div>
            </el-form>
        </el-dialog>
        <el-dialog :title="'权限设置'" :visible.sync="authSettingStatus" width="100%" :show-close="true"
            :modal-append-to-body="false" :before-close="closequanxian">
            <el-form :model="testModel" ref="addInfoList">
                <div>
                    <div class="info-line">
                        <el-radio v-if="type == '1' || type == '2'" v-model="authType" label="1"
                            style="margin: 10px">无特殊权限</el-radio>
                        <div id="noLimit" class="info-line">
                            <span style="margin-right:10px;margin-left: 10px">负责人：</span>
                            <el-button v-if="type == '1' || type == '2'" type="primary"
                                @click="noLimitUserAdd()">组织机构</el-button>
                            <span style="margin-right: 10px;margin-left: 10px;display: inline-block;color: blue;">{{
                                noLimitUserName }}</span>
                        </div>
                    </div>
                    <div class="info-line">
                        <el-radio v-if="type == '1' || type == '2'" v-model="authType" label="2"
                            style="margin: 10px">特殊权限</el-radio>
                        <div id="limit">
                            <div style="margin: 10px;display: inline-block;color: red;">注：分配的行的权限不能重复</div>
                            <div v-for="(item, index) in limitList">
                                <div style="margin-right: 10px;margin-left: 10px;display: inline-block;">负责人：</div>
                                <el-button v-if="type == '1' || type == '2'" type="primary"
                                    @click="limitUserAdd(index)">组织机构</el-button>
                                <div style="margin-right: 10px;margin-left: 10px;display: inline-block;color: blue;">{{
                                    item.userName }}
                                </div>
                                <div style="margin-right: 5px;margin-left: 5px;display: inline-block;">可编辑行：从</div>

                                <el-input v-if="type == '1' || type == '2'" v-model="item.editStart" style="width: 80px;"
                                    oninput="value=value=value.replace(/^(0+)|[^0-9]/g,'')"></el-input>
                                <div v-else style="margin-right: 5px;margin-left: 5px;display: inline-block;color: blue;">
                                    {{ item.editStart }}</div>

                                <div style="margin-right: 5px;margin-left: 5px;display: inline-block;">到</div>

                                <el-input v-if="type == '1' || type == '2'" v-model="item.editEnd" style="width: 80px;"
                                    oninput="value=value.replace(/^(0+)|[^0-9]/g,'')"></el-input>
                                <div v-else style="margin-right: 5px;margin-left: 5px;display: inline-block;color: blue;">
                                    {{ item.editEnd }}</div>

                                <div style="margin-right: 5px;margin-left: 5px;display: inline-block;">可编辑列：从</div>

                                <el-input v-if="type == '1' || type == '2'" v-model="item.editStartCol" style="width: 80px;"
                                    oninput="value=value.replace(/^(0+)|[^\a-\z\A-\Z0-9]/g,'')"></el-input>
                                <div v-else style="margin-right: 5px;margin-left: 5px;display: inline-block;color: blue;">
                                    {{ item.editStartCol }}</div>

                                <div style="margin-right: 5px;margin-left: 5px;display: inline-block;">到</div>

                                <el-input v-if="type == '1' || type == '2'" v-model="item.editEndCol" style="width: 80px;"
                                    oninput="value=value.replace(/^(0+)|[^\a-\z\A-\Z0-9]/g,'')"></el-input>
                                <div v-else style="margin-right: 5px;margin-left: 5px;display: inline-block;color: blue;">
                                    {{ item.editEndCol }}</div>
                                <br /><br />
                            </div>
                            <el-button style="width: 80px;margin-right: 20px;margin-left: 40px"
                                v-if="type == '1' || type == '2'" @click="addNewLimitAuth()">添加
                            </el-button>
                            <el-button style="width: 80px;margin-right: 20px;margin-left: 40px" type="danger"
                                v-if="(type == '1' || type == '2') && limitList.length > 1" @click="delNewLimitAuth()">删除
                            </el-button>
                        </div>
                    </div>
                    <div slot="footer" style="text-align: right;padding-bottom: 20px;padding-top: 20px">
                        <!-- <el-button @click="closeauthSettingStatus()">取 消</el-button> -->
                        <el-button type="primary" @click="processAuth()">确 定</el-button>
                    </div>
                </div>
            </el-form>
        </el-dialog>
        <el-dialog title="选择填报人" :visible.sync="noLimitDialog" width="100%" :destroy-on-close="true"
            :modal-append-to-body="false" :close-on-click-modal="false">
            <div style="max-height:500px ;">
                <!-- <deptTreeUserNew v-if="authType == '1'" @treeCheck="treeCheckonly" :defaultList="defaultList"
                    :type="depttype" :closeList="closeList" :oneORmore="authType" treeListType="1"></deptTreeUserNew> -->
                <deptTreeUserNew @treeCheck="treeCheckonly" :defaultList="defaultList" :type="depttype"
                    :closeList="closeList" oneORmore="2" treeListType="1"></deptTreeUserNew>

                <div slot="footer" style="text-align: right;padding-bottom: 20px">
                    <el-button @click="noLimitDialog = false">取 消</el-button>
                    <el-button type="primary" @click="processNoLimitUsers()">确 定</el-button>
                </div>
            </div>
        </el-dialog>
        <el-dialog :title="'提交'" :visible.sync="authDialog" width="50%" :destroy-on-close="true"
            :modal-append-to-body="false" :close-on-click-modal="false" :before-close="closetijiao">
            <el-form :model="testModel" ref="addInfoList">
                <div>
                    <div class="info-line">
                        <span style="margin-right: 20px;margin-left: 40px">选择路径：</span>
                        <el-select v-model="auditForm.authType" placeholder="选择路径" @change="treeListTypechange">
                            <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 || auditForm.authType == 2">
                        <span style="margin-right: 20px;margin-left: 40px">下一步处理人：</span>
                        <el-button type="primary" @click="auditUserAdd()">选择处理人</el-button>
                        <span style="width: 80px;margin-right: 20px;margin-left: 20px">{{
                            auditForm.receiverName
                        }}</span>
                    </div>
                    <br />
                    <div class="info-line">
                        <span style="margin-right: 20px;margin-left: 40px;">意见内容：</span>
                        <el-input type="textarea" v-model="auditForm.reviewOpinion" style="width: 400px"></el-input>
                    </div>
                    <br />
                    <div slot="footer" style="text-align: right;padding-bottom: 20px;padding-top: 20px">
                        <el-button @click="closetijiao()">取 消</el-button>
                        <el-button type="primary" @click="processAudit()" :disabled="BtnDisabled">确 定</el-button>
                    </div>
                </div>
            </el-form>
        </el-dialog>
        <el-dialog title="转派" :visible.sync="checkexa" width="100%" :destroy-on-close="true" :modal-append-to-body="false"
            :close-on-click-modal="false" v-if="checkexa">
            <div>
                <deptTreeUserNew @treeCheck="treeCheckonly" :defaultList="defaultList" :type="depttype"
                    :closeList="closeList" oneORmore="2" treeListType="1"></deptTreeUserNew>
                <div slot="footer" style="text-align: right;padding-bottom: 20px">
                    <el-button type="primary" @click="processAuditUser()" :disabled="BtnDisabled">确 定</el-button>
                    <el-button @click="checkexa = false">取 消</el-button>
                </div>
            </div>
        </el-dialog>
        <el-dialog title="选择下一步处理人" :visible.sync="checkexapeople" width="100%" :destroy-on-close="true"
            :modal-append-to-body="false" :close-on-click-modal="false" v-if="checkexapeople">
            <div>
                <deptTreeUserNew @treeCheck="treeCheckonly" :defaultList="defaultList" :type="depttype"
                    :closeList="closeList" oneORmore="2" :treeListType="treeListType"></deptTreeUserNew>
                <div slot="footer" style="text-align: right;padding-bottom: 20px">
                    <el-button type="primary" @click="processAuditUserpeople()">确 定</el-button>
                    <el-button @click="checkexapeople = false">取 消</el-button>
                </div>
            </div>
        </el-dialog>
    </div>
</template>
<script>
import myMessage from "../../../components/myMessage.vue"
import deptTreeUserNew from "./newTree.vue"
import deptTreeOnly from "../../../components/deptTreeOnly.vue"

export default {
    components: {
        myMessage,
        deptTreeUserNew,
        deptTreeOnly,
    },
    data() {
        let _self = this
        return {
            pickOptions: {
                disabledDate(time) {
                    return time.getTime() < new Date().getTime() - 8.64e6;
                },
            },
            pickWrite: {
                disabledDate(time) {
                    return time.getTime() < new Date().getTime() - 8.64e6;
                },
            },
            rules: {
                distributeType: [
                    {
                        required: true,
                        trigger: "change",
                        message: "请选择派发周期",
                    },
                ],
                distributeTime: [
                    {
                        required: true,
                        trigger: "blur",
                        message: "请选择填报日期",
                    },
                ],
                distributeEndTime: [
                    {
                        required: true,
                        trigger: "blur",
                        message: "请选择截至日期",
                    },
                ],
            },
            testModel: {},
            authSettingStatus: false,
            dubanStatus: false,
            BtnDisabled: false,
            authType: '1',
            oneORmore: 'one',
            noLimitUserName: '',
            treeListType: '',
            id: '',
            noLimitUsers: [],
            noLimitDialog: false,
            exaList: {},
            auditForm: {},
            defaultList: [],
            treeList: [],
            closeList: false,
            success: false,
            depttype: 0,
            limitUserIndex: -1,
            limitList: [{}],
            type: '',
            loading: false,
            auditBoxList: [{}],
            authDialog: false,
            auditUserName: '',
            auditUserId: '',
            issuedId: '',
            issuedstatus: '',
            //选择审批人
            checkexa: false,
            checkexapeople: false,
            //审批人用到的
            treeListonly: {},
            excelData: {},
            fullscreen: false,
            addInfoList: []
        }
    },
    methods: {
        closequanxian() {
            this.authSettingStatus = false
            this.limitList = [{}]
            this.noLimitUserName = ''
            this.authType = '2'
        },
        closeduban() {
            this.dubanStatus = false
            this.testModel = {}
        },
        // 填报日期
        handleWrite(value) {
            if (value) {//
                let time = value.getTime() + 86400000
                let range =
                    new Date().getTime() > time
                        ? new Date().getTime()
                        : time;
                this.pickOptions = {
                    disabledDate(time) {
                        return time.getTime() < range;
                    },
                };
            } else {
                this.pickOptions = {
                    disabledDate(time) {
                        return time.getTime() < new Date().getTime() - 8.64e6;
                    },
                };
            }
        },
        handleEnd(value) {
            // if (value) {
            //     console.log(3);
            //     this.pickWrite = {
            //         disabledDate(time) {
            //             return time.getTime() > value.getTime();
            //         },
            //     };
            //     let write = new Date(this.testModel.distributeTime).getTime();
            //     if (this.testModel.distributeTime && value.getTime() < write) {
            //         this.testModel.distributeEndTime = "";
            //     }
            // } else {
            //     this.pickWrite = {
            //         disabledDate(time) {
            //             return time.getTime() - 8.64e6 < new Date().getTime();
            //         },
            //     };
            // }
        },
        closetijiao() {
            this.authDialog = false;
            this.treeListType = '';
            this.auditForm.receiverName = '';
            this.auditForm.authType = ''
        },
        auditUserAdd() {
            this.checkexapeople = true;
        },
        treeListTypechange(v) {
            console.log(v);
            if (v == 1) {
                this.treeListType = '3'
            } else if (v == 2) {
                this.treeListType = '2'
            }

        },
        processAuditUser() {//转派确定
            this.BtnDisabled = true
            console.log(this.treeListonly);
            this.$http({
                url: "/market/Issued/forwardIssued",
                method: "post",
                headers: {
                    "Content-Type": "application/json",
                },
                data: {
                    id: this.issuedId,
                    receiverId: this.treeListonly[0].key,
                    receiverName: this.treeListonly[0].label,
                    excelData: this.excelData,
                },
            }).then((res) => {
                if (res.data.result === 1) {
                    this.$message({
                        message: res.data.desc,
                        type: 'error'
                    });
                } else {
                    this.$message({
                        message: '转派成功',
                        type: 'success'
                    });
                }
                this.checkexa = false;
                this.BtnDisabled = false
                this.$router.push("documentCollectionApproval");
            });
        },
        processAuditUserpeople() {//选人确定
            console.log(this.treeListonly);
            this.auditForm.receiverId = this.treeListonly[0].key
            this.auditForm.receiverName = this.treeListonly[0].label
            this.checkexapeople = false;
        },
        toAudit(sheetName, excelData) {
            console.log('提交开启');
            this.excelData = excelData;
            this.authDialog = true;

        },
        openAuditWindow(sheetName, excelData) {
            //  0待处理
            //              1部门人员审批
            //         2部门领导审批
            //            3退回修改
            if (this.issuedstatus == '0') {
                this.auditBoxList = [{//转派；部门人员审核；部门领导审批；结束
                    name: '部门人员审核',
                    value: '1'
                }, {
                    name: '部门领导审批',
                    value: '2'
                }, {
                    name: '结束',
                    value: '4'
                }];
            } else if (this.issuedstatus == '1') {//退回修改；部门人员审核；部门领导审批；结束
                this.auditBoxList = [{
                    name: '退回修改',
                    value: '3'
                }, {
                    name: '部门人员审核',
                    value: '1'
                }, {
                    name: '部门领导审批',
                    value: '2'
                }, {
                    name: '结束',
                    value: '4'
                }];
            } else if (this.issuedstatus == '2') {//退回修改；部门领导审批；结束
                this.auditBoxList = [{
                    name: '退回修改',
                    value: '3'
                }, {
                    name: '部门领导审批',
                    value: '2'
                }, {
                    name: '结束',
                    value: '4'
                }];
            } else if (this.issuedstatus == '3') {//转派；部门人员审核；部门领导审批
                this.auditBoxList = [{
                    name: '部门人员审核',
                    value: '1'
                }, {
                    name: '部门领导审批',
                    value: '2'
                }];
            }
            this.authDialog = true;
            this.excelData = excelData;
        },
        processAudit() {
            //检查选项
            if (this.auditForm.authType == null) {
                this.$message({
                    message: '请选择路径',
                    type: 'error'
                });
                return;
            }
            if (this.auditForm.authType == '1' || this.auditForm.authType == '2') {
                if (this.receiverId == '') {
                    this.$message({
                        message: '请选择下一步处理人',
                        type: 'error'
                    });
                    return;
                }
            }
            if (this.auditForm.reviewOpinion
                && this.auditForm.reviewOpinion.length > 240) {
                this.$message({
                    message: '意见内容长度不能大于240字',
                    type: 'error'
                });
                return;
            }
            //提交
            this.BtnDisabled = true
            var _this = this;
            var url = '/market/Issued/completeIssued';
            this.loading = true;
            this.$http({
                url: url,
                method: "post",
                headers: {
                    "Content-Type": "application/json",
                },
                data: {
                    reviewType: this.auditForm.authType,
                    excelData: this.excelData,
                    id: this.getUrlKey("id"),
                    receiverId: this.auditForm.receiverId,
                    receiverName: this.auditForm.receiverName,
                    reviewOpinion: this.auditForm.reviewOpinion
                },
            }).then((res) => {
                this.loading = false;
                if (res.data.desc == '请编辑回复内容后提交') {
                    _this.$message({
                        message: res.data.desc,
                        type: 'error'
                    });
                } else if (res.data.result === 1) {
                    _this.$message({
                        message: res.data.desc,
                        type: 'error'
                    });
                } else {
                    this.authDialog = false;
                    _this.$message({
                        message: '处理成功',
                        type: 'success'
                    });

                    //没找到关闭标签页之前的临时处理措施
                    // const newUrl = '#' + this.$route.path + '?type=5&id=' + this.getUrlKey("id");
                    // console.log(newUrl);
                    // window.history.replaceState('', '', newUrl);
                    // document.getElementById('excelIframe').contentWindow.location.reload();
                    //关闭这个窗口，得找找怎么关闭
                    //this.$router.go(-1);
                    this.$router.push("documentCollectionApproval");
                }
                this.BtnDisabled = false
            });

        },
        addNewTemplate(sheetName, excelData, templateType) {
            //console.log(sheetName);
            //console.log(excelData);
            //console.log(templateType);
            //处理一下数据，提交给后端
            var authUser = [];
            if (this.authType == '1') {
                console.log(this.noLimitUsers);
                this.noLimitUsers.map((o) => {
                    authUser.push({
                        principalId: o.key,
                        principalName: o.label,
                        dept: o.groupName,
                        type: 1
                    })
                });
            } else {
                //外层是权限组
                this.limitList.map((o) => {
                    //内层是权限用户
                    console.log(this.limitList);
                    // authUser.push({
                    //         principalId: o1.key,
                    //         principalName: o1.label,
                    //         dept: o1.groupName,
                    //         type: 2,
                    //         allowEditingColumns: o.editStartCol + ',' + o.editEndCol,
                    //         rowNum: o.editStart + ',' + o.editEnd,
                    //     })
                    console.log(o.userIds);
                    o.userIds.map((o1) => {
                        authUser.push({
                            principalId: o1.key,
                            principalName: o1.label,
                            dept: o1.groupName,
                            type: 2,
                            allowEditingColumns: o.editStartCol + ',' + o.editEndCol,
                            rowNum: o.editStart + ',' + o.editEnd,
                        })
                    })
                });
            }
            //console.log(authUser);
            //提交
            var _this = this;
            var url = '/market/FileTemplate/add';
            // var recordTime = this.$formatDate(new Date().getTime(), "YYYY-MM-DD HH:mm:ss") 
            if (this.type == '2') {
                url = '/market/FileTemplate/update';
                // recordTime = ''
            }
            this.loading = true;
            this.$http({
                url: url,
                method: "post",
                headers: {
                    "Content-Type": "application/json",
                },
                data: {
                    fileTemplateAuthorities: authUser,//选人字段
                    fileTemplate: {
                        id: this.getUrlKey('id'),
                        templateName: sheetName,
                        excelData: excelData,
                        templateType: templateType,
                        status: "0",
                        distributeEndTime: this.testModel.distributeEndTime ? this.$formatDate(this.testModel.distributeEndTime, "YYYY-MM-DD HH:mm:ss") : '',
                        distributeTime: this.testModel.distributeTime ? this.$formatDate(this.testModel.distributeTime, "YYYY-MM-DD HH:mm:ss") : '',
                        distributeType: this.testModel.distributeType,
                        superviseFlag: this.testModel.superviseFlag ? this.testModel.superviseFlag : '0',
                        // recordTime: recordTime,
                    },
                },
            }).then((res) => {
                this.loading = false;
                if (res.data.result === 1) {
                    _this.$message({
                        message: res.data.desc,
                        type: 'error'
                    });
                } else {
                    var msgText = '新增成功';
                    if (this.type == '2') {
                        msgText = '修改成功';
                    }
                    _this.$message({
                        message: msgText,
                        type: 'success'
                    });

                    // if (this.type == '1') {
                    //     const newUrl = '#' + this.$route.path + '?type=2&id=' + res.data.body;
                    //     console.log(newUrl);
                    //     window.history.replaceState('', '', newUrl);
                    //     this.type = '2';
                    //     document.getElementById('excelIframe').contentWindow.location.reload();
                    // }
                    //this.$store.dispatch('tagsView/delView',this.$route)
                    // this.$router.go(-1);
                    this.$router.push("documentCollectionApprovalIssuedMoud");
                }
            });
        },
        toZhuanpai(sheetName, excelData) {
            console.log('转派开启');
            this.checkexa = true;
            this.excelData = excelData;

        },

        zancunClick(sheetName, excelData, templateType) {
            //console.log(sheetName);
            //console.log(excelData);
            //console.log(templateType);
            //处理一下数据，提交给后端
            var authUser = [];
            if (this.authType == '1') {
                console.log(this.noLimitUsers);
                this.noLimitUsers.map((o) => {
                    authUser.push({
                        principalId: o.key,
                        principalName: o.label,
                        dept: o.groupName,

                        type: 1
                    })
                });
            } else {
                //外层是权限组
                this.limitList.map((o) => {
                    //内层是权限用户
                    o.userIds.map((o1) => {
                        authUser.push({
                            principalId: o1.key,
                            principalName: o1.label,
                            dept: o1.groupName,
                            type: 2,
                            allowEditingColumns: o.editStartCol + ',' + o.editEndCol,
                            rowNum: o.editStart + ',' + o.editEnd,
                        })
                    })
                });
            }
            //console.log(authUser);
            //暂存
            var _this = this;
            var url = '/market/FileTemplate/add';
            // var recordTime = this.$formatDate(new Date().getTime(), "YYYY-MM-DD HH:mm:ss") 
            if (this.type == '2') {
                url = '/market/FileTemplate/update';
                // recordTime = ''
            }
            this.loading = true;
            this.$http({
                url: url,
                method: "post",
                headers: {
                    "Content-Type": "application/json",
                },
                data: {
                    fileTemplateAuthorities: authUser,//选人字段
                    fileTemplate: {
                        status: "2",
                        id: this.getUrlKey('id'),
                        templateName: sheetName,
                        excelData: excelData,
                        templateType: templateType,
                        distributeEndTime: this.testModel.distributeEndTime ? this.$formatDate(this.testModel.distributeEndTime, "YYYY-MM-DD HH:mm:ss") : '',
                        distributeTime: this.testModel.distributeTime ? this.$formatDate(this.testModel.distributeTime, "YYYY-MM-DD HH:mm:ss") : '',
                        distributeType: this.testModel.distributeType,
                        superviseFlag: this.testModel.superviseFlag ? this.testModel.superviseFlag : '0',
                        // recordTime: recordTime,
                    },
                },
            }).then((res) => {
                this.loading = false;
                if (res.data.result === 1) {
                    _this.$message({
                        message: res.data.desc,
                        type: 'error'
                    });
                } else {
                    var msgText = '暂存成功';
                    if (this.type == '2') {
                        msgText = '修改成功';
                    }
                    _this.$message({
                        message: msgText,
                        type: 'success'
                    });

                    // if (this.type == '1') {
                    //     const newUrl = '#' + this.$route.path + '?type=2&id=' + res.data.body;
                    //     console.log(newUrl);
                    //     window.history.replaceState('', '', newUrl);
                    //     this.type = '2';
                    //     document.getElementById('excelIframe').contentWindow.location.reload();
                    // }
                    //this.$store.dispatch('tagsView/delView',this.$route)
                    //this.$router.go(-1);
                    this.$router.push("documentCollectionApprovalIssuedMoud");
                }
            });
        },
        showAuthDialog() {
            this.authSettingStatus = true;
        },
        showdubanDialog() {
            this.dubanStatus = true;
        },
        getOutUrl() {
            this.$router.go(-1);
        },
        closeauthSettingStatus() {
            this.success = true;
            if (this.authType == '1') {
                if (this.noLimitUsers.length == 0) {
                    this.success = false;
                }
            } else if (this.authType == '2') {
                this.limitList.map((o) => {
                    let str = o.editStartCol + o.editEndCol
                    if (o.userIds == null || o.userIds[0].key == null) {
                        this.success = false;
                    }
                    if (o.editStart == '' || o.editEnd == '' || o.editStart == undefined || o.editEnd == undefined) {
                        this.success = false;
                    }
                    if (o.editStartCol == '' || o.editEndCol == '' || o.editStartCol == undefined || o.editEndCol == undefined) {
                        this.success = false;
                    }
                    if (/^[A-Za-z]*$/.test(str)) {
                        o.editEndCol = o.editEndCol.toUpperCase()
                        o.editStartCol = o.editStartCol.toUpperCase()
                    }
                    if (parseInt(o.editEnd) <= parseInt(o.editStart)) {
                        let a = ''
                        a = o.editStart
                        o.editStart = o.editEnd
                        o.editEnd = a
                    }
                    if (/^[0-9]+$/.test(str)) {//列信息都为数字
                        if (parseInt(o.editEndCol) <= parseInt(o.editStartCol)) {
                            let a = ''
                            a = o.editStartCol
                            o.editStartCol = o.editEndCol
                            o.editEndCol = a
                        }
                    } else if (/^[A-Za-z]*$/.test(str)) {//列信息都为字母
                        if (o.editStartCol.length > o.editEndCol.length) {
                            let a = ''
                            a = o.editStartCol
                            o.editStartCol = o.editEndCol
                            o.editEndCol = a
                        } else if (o.editStartCol.length == o.editEndCol.length) {
                            Array.from(o.editStartCol).map((item, index) => {
                                if (o.editEndCol[index].charCodeAt() < o.editStartCol[index].charCodeAt()) {
                                    let a = ''
                                    a = o.editStartCol
                                    o.editStartCol = o.editEndCol
                                    o.editEndCol = a
                                    return;
                                }
                            })
                        }
                    } else {
                        this.success = false;
                    }
                })
            }
            if (this.success) {
                if (this.type == '1') {
                    this.$refs.iframe.contentWindow.enableUpload('abc');
                } else if (this.type == '2') {
                    this.$refs.iframe.contentWindow.enableSave('def');
                }
            }
            this.authSettingStatus = false;
        },
        processAuth() {
            // console.log(this.limitList);
            //判断一下
            this.success = true;
            if (this.authType == '1') {
                if (this.noLimitUsers.length == 0) {
                    this.$message({
                        message: '请选择无特殊权限的负责人',
                        type: 'error'
                    });
                    this.success = false;
                    return;
                }
            } else if (this.authType == '2') {
                this.limitList.map((o) => {
                    // console.log(o.userIds);
                    console.log(o.editStart);
                    console.log(o.editEnd);
                    let str = o.editStartCol + o.editEndCol
                    if (o.userIds == null || o.userIds[0].key == null) {
                        this.$message({
                            message: '请选择特殊权限的负责人',
                            type: 'error'
                        });
                        this.success = false;
                        return;
                    }
                    if (o.editStart == '' || o.editEnd == '' || o.editStart == undefined || o.editEnd == undefined) {
                        this.$message({
                            message: '请填写可编辑行',
                            type: 'error'
                        });
                        this.success = false;
                        return;
                    }
                    if (o.editStartCol == '' || o.editEndCol == '' || o.editStartCol == undefined || o.editEndCol == undefined) {
                        this.$message({
                            message: '请填写可编辑列',
                            type: 'error'
                        });
                        this.success = false;
                        return;
                    }
                    if (/^[A-Za-z]*$/.test(str)) {
                        o.editEndCol = o.editEndCol.toUpperCase()
                        o.editStartCol = o.editStartCol.toUpperCase()
                    }
                    if (parseInt(o.editEnd) <= parseInt(o.editStart)) {
                        let a = ''
                        a = o.editStart
                        o.editStart = o.editEnd
                        o.editEnd = a
                    }
                    if (/^[0-9]+$/.test(str)) {//列信息都为数字
                        if (parseInt(o.editEndCol) <= parseInt(o.editStartCol)) {
                            let a = ''
                            a = o.editStartCol
                            o.editStartCol = o.editEndCol
                            o.editEndCol = a
                        }
                    } else if (/^[A-Za-z]*$/.test(str)) {//列信息都为字母
                        if (o.editStartCol.length > o.editEndCol.length) {
                            let a = ''
                            a = o.editStartCol
                            o.editStartCol = o.editEndCol
                            o.editEndCol = a
                            console.log('前长');
                        } else if (o.editStartCol.length == o.editEndCol.length) {
                            Array.from(o.editStartCol).map((item, index) => {
                                // console.log(o.editStartCol[index]);
                                // console.log(o.editEndCol[index]);
                                // console.log(o.editEndCol[index].charCodeAt() > o.editStartCol[index].charCodeAt());
                                if (o.editEndCol[index].charCodeAt() < o.editStartCol[index].charCodeAt()) {
                                    let a = ''
                                    a = o.editStartCol
                                    o.editStartCol = o.editEndCol
                                    o.editEndCol = a
                                    return;
                                }
                            })
                            console.log('等长');
                        }
                    } else {
                        this.$message({
                            message: '列信息请保持一致',
                            type: 'error'
                        });
                        this.success = false;
                        return;
                    }
                })
                // let arr = []
                // this.limitList.map((o) => {
                //     for (var i = o.editStart; i <= o.editEnd; i++) {
                //         arr.push(i);
                //     }
                // })
                // console.log(arr);

                // let arr2 = arr.sort();
                // for (let i = 0; i < arr2.length; i++) {

                //     if (typeof (arr2[i]) === 'number') {
                //         arr2[i] = arr2[i].toString()
                //     }
                //     if (typeof (arr2[i + 1]) === 'number') {
                //         arr2[i + 1] = arr2[i + 1].toString()
                //     }
                //     console.log(typeof (arr2[i]));
                //     console.log((arr2[i]));
                //     if (arr2[i] === arr2[i + 1]) {
                //         this.$message({
                //             message: '分配的行的权限不能重复',
                //             type: 'error'
                //         });
                //         this.success = false;
                //         return;
                //     }
                // }
                console.log(this.limitList);
            }
            if (this.success) {
                if (this.type == '1') {
                    this.$refs.iframe.contentWindow.enableUpload('abc');
                } else if (this.type == '2') {
                    this.$refs.iframe.contentWindow.enableSave('def');
                }
                this.authSettingStatus = false;
            }
        },
        processAuthduban() {
            console.log(this.limitList);
            this.testModel.superviseFlag = '1'
            this.$refs.form.validate((valid) => {
                if (valid) {
                    this.dubanStatus = false
                    if (this.success) {
                        if (this.type == '1') {
                            this.$refs.iframe.contentWindow.enableUpload('abc');
                        } else if (this.type == '2') {
                            this.$refs.iframe.contentWindow.enableSave('def');
                        }
                        this.authSettingStatus = false;
                    }
                } else {
                    // this.$message.error("请完善表单信息");
                    return false;
                }
            });
        },
        addNewLimitAuth() {
            var _this = this;
            if (this.authType == '2') {
                console.log(_this.limitList);
                if (_this.limitList.length == 0) {
                    _this.limitList.push({
                        index: 1
                    });
                } else {
                    var lastLimitUserList = _this.limitList[_this.limitList.length - 1].userIds[0].key;
                    if (lastLimitUserList == null) {
                        _this.$message({
                            message: '请先选择上一条记录的负责人',
                            type: 'error'
                        });
                    } else {
                        _this.limitList.push({
                            userIds: [{
                                key: null
                            }]
                        });
                    }
                }
            } else {
                _this.$message({
                    message: '请先选择特殊权限再添加',
                    type: 'error'
                });
            }

        },
        delNewLimitAuth() {
            this.limitList.pop()
        },
        processNoLimitUsers() {
            // console.log(this.treeList);
            // console.log(this.treeListonly);
            var userNameString = '';
            if (this.authType == '1') {
                this.noLimitUsers = [];
                this.treeList.map((o) => {
                    this.noLimitUsers.push({ key: o.key, label: o.label, groupName: o.groupName });
                    userNameString += o.label += ' ';
                });
                this.noLimitUserName = userNameString;
            } else {
                this.limitList[this.limitUserIndex].userIds = [];
                this.treeList.map((o) => {
                    this.limitList[this.limitUserIndex].userIds.push({ key: o.key, groupName: o.groupName, label: o.label });
                    userNameString += o.label += ' ';
                });
                this.limitList[this.limitUserIndex].userName = userNameString;
            }
            this.exaList = {};
            this.defaultList = [];
            this.treeList = [];
            this.noLimitDialog = false;
        },
        noLimitUserAdd() {
            if (this.authType == '1') {
                this.noLimitDialog = true;
            } else {
                this.$message({
                    message: '请先选择无特殊权限，再添加负责人',
                    type: 'error'
                });
            }
        },
        limitUserAdd(index) {
            if (this.authType == '2') {
                this.limitUserIndex = index;
                this.noLimitDialog = true;
            } else {
                this.$message({
                    message: '请先选择特殊权限，再添加负责人',
                    type: 'error'
                });
            }
        },
        setAuth(id) {
            console.log('1111');
            var _this = this;
            this.id = id
            this.$http({
                // url: '/market/cIncomeExcelTemplate/getAuthInfo',
                url: '/market/FileTemplate/query',
                method: "post",
                headers: {
                    "Content-Type": "application/json",
                },
                data: {
                    id: id,
                    type: this.type
                },
            }).then((res) => {
                if (res.data.result === 1) {
                    _this.$message({
                        message: '获取负责人信息失败',
                        type: 'error'
                    });
                } else {
                    console.log(res.data);
                    var authUsers = res.data.body.fileTemplateAuthorities ? res.data.body.fileTemplateAuthorities : [{}];
                    var i = -1;
                    var nowStart = '';
                    var nowEnd = '';
                    this.limitList = [];
                    this.testModel = res.data.body.excelInfo;
                    this.noLimitUsers = [];
                    this.noLimitUserName = '';
                    if (authUsers.length != 0) {
                        authUsers.map((o) => {
                            console.log(o.type);
                            //无特殊权限的简单一点，有特殊权限的，需要把相同可编辑行的放在一起
                            if (o.type == '1') {
                                this.authType = '1';
                                this.noLimitUsers.push({ key: o.principalId, label: o.principalName, groupName: o.dept });
                                this.noLimitUserName += o.principalName += ' ';
                            } else {
                                this.authType = '2';
                                // if (o.editStart == nowStart && o.editEnd == nowEnd) {
                                //     var processLimitUser = this.limitList[i];
                                //     processLimitUser.userIds.push(o.principalId);
                                //     processLimitUser.userName += o.principalName += ' ';
                                // } else {
                                // var principalId = [o.principalId];
                                // var principalName = o.principalName += ' ';
                                console.log(o.allowEditingColumns);
                                // console.log(o.rowNum.split(','));
                                this.limitList.push({
                                    userIds: [{ key: o.principalId, groupName: o.dept, label: o.principalName }],
                                    userName: o.principalName,
                                    editStart: o.rowNum ? o.rowNum.split(',')[0] : '',
                                    editEnd: o.rowNum ? o.rowNum.split(',')[1] : '',
                                    editStartCol: o.allowEditingColumns ? o.allowEditingColumns.split(',')[0] : '',
                                    editEndCol: o.allowEditingColumns ? o.allowEditingColumns.split(',')[1] : '',
                                })
                                // nowStart = o.editStart;
                                // nowEnd = o.editEnd;
                                // i++;
                                // }
                                console.log(this.limitList);
                            }
                        });
                    }

                }
            });
        },
        //填报人相关
        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;
        },
        getUrlKey(name) {
            return (
                decodeURIComponent(
                    (new RegExp("[?|&]" + name + "=" + "([^&;]+?)(&|#|;|$)").exec(
                        location.href
                    ) || [, ""])[1].replace(/\+/g, "%20")
                ) || null
            );
        },
        processFullScreen() {
            this.fullscreen = !this.fullscreen;
        },
    },
    mounted() {
        this.type = this.getUrlKey("type")
        this.issuedId = this.getUrlKey("id")
        this.issuedstatus = this.getUrlKey("status")
    },
    created() {
        window['fullScreen'] = (rp) => {
            this.processFullScreen(rp);
        }
        window['showAuthDialog'] = (rp) => {
            this.showAuthDialog(rp);
        }
        window['dubanBtnDialog'] = (rp) => {
            this.showdubanDialog(rp);
        }
        window['getOutUrl'] = (rp) => {
            this.getOutUrl(rp);
        }
        window['addNewTemplate'] = (sheetName, excelData, templateType) => {
            this.addNewTemplate(sheetName, excelData, templateType);
        };
        window['toAudit'] = (sheetName, excelData,) => {
            this.toAudit(sheetName, excelData,);
        };
        window['toZhuanpai'] = (sheetName, excelData) => {
            this.toZhuanpai(sheetName, excelData);
        };
        window['zancunClick'] = (sheetName, excelData, templateType) => {
            this.zancunClick(sheetName, excelData, templateType);
        };
        window['setAuth'] = (id) => {
            this.setAuth(id);
        };
        window['openAuditWindow'] = (sheetName, excelData) => {
            this.openAuditWindow(sheetName, excelData);
        };
    }
}
</script>
<style lang="scss" scoped>
.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>
<style scoped lang="scss">
.containerr {
    background: #fff;
    height: calc(100vh);
    width: calc(100vw);
    position: fixed;
    left: 0;
    top: 0;
    overflow: hidden;
}

span {
    width: 80px;
}

::v-deep .el-button--text {
    display: none !important;
}
</style>
