<template>
    <fullscreen :fullscreen.sync="fullscreen" class="container">
        <div class="container-box">
            <toolList @iconCli='iconCli' :tooltit='tooltit'></toolList>
            <div class="search">
                <mySearch :searchList="searchList" @searchInfo="searchInfo"></mySearch>
                <div>
                    <el-button type="primary" v-if="leader==='3'" @click="dialogCheck(2)" size="medium">下发</el-button>
                    <el-button type="primary" v-if="leader==='0'" @click="shenpiAll('1','1')">通过</el-button>
                    <el-button type="primary" v-if="leader==='0'" @click="shenpiAll('1','2')">打回</el-button>

                    <el-button type="primary" v-if="leader==='1'" @click="shenpiAll('2','1')">通过</el-button>
                    <el-button type="primary" v-if="leader==='1'" @click="shenpiAll('2','2')">打回</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%"
                          @selection-change="handleSelectionChange"
                >
                    <el-table-column
                        type="selection"
                        width="55">
                    </el-table-column>
                    <el-table-column show-overflow-tooltip prop="content"  label="稿件要求">
                    </el-table-column>
                    <el-table-column prop="beginTime" label="开始时间">
                    </el-table-column>
                    <el-table-column prop="endTime" label="结束时间">
                    </el-table-column>
                    <el-table-column prop="secname" label="科室">
                    </el-table-column>
                    <el-table-column prop="state" :formatter="stateFormat" label="状态">
                    </el-table-column>
                    <el-table-column prop="secLeaderName" label="科室负责人">
                        <template slot-scope="scope">
                            <span v-if="scope.row.state==='2'||scope.row.state==='0'" style="color: red">{{scope.row.secLeaderName}}</span>
                            <span v-if="!(scope.row.state==='2'||scope.row.state==='0')">{{scope.row.secLeaderName}}</span>
                        </template>
                    </el-table-column>
                    <el-table-column prop="departSlearderName" label="部门副总">
                        <template slot-scope="scope">
                            <span v-if="scope.row.state==='3'" style="color: red">
                            {{scope.row.departSlearderName}}
                            </span>
                            <span v-if="scope.row.state!='3'">{{scope.row.departSlearderName}}</span>
                        </template>
                    </el-table-column>
                    <el-table-column prop="workerName" label="填报人">
                        <template slot-scope="scope">
                            <span v-if="scope.row.state==='1'||scope.row.state==='5'" style="color: red">
                            {{scope.row.workerName==null?'待分配':scope.row.workerName}}
                            </span>
                            <span v-if="!(scope.row.state==='1'||scope.row.state==='5')">
                            {{scope.row.workerName==null?'待分配':scope.row.workerName}}
                            </span>
                        </template>
                    </el-table-column>
                    <el-table-column prop="createTime" label="下发时间">
                    </el-table-column>

                    <el-table-column label="操作" width="180px" align="center">
                        <template slot-scope="scope">
                            <el-button size="mini" type="primary" @click="dialogCheck(0,scope.row)">查看</el-button>
                            <el-button size="mini" type="primary" v-if="scope.row.state==4" @click="dialogCheck(3,scope.row)">导出</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>
        </div>

        <el-dialog :title="titname" :visible.sync="dialogStatus" width="60%" :destroy-on-close="true"
            :modal-append-to-body="false" :close-on-click-modal="false" :before-close="closedia">
            <div >
                <el-form :model="infolist" ref="infolist" :rules="rules">
                    <div>
                        <el-form-item prop="beginTime" class="info-line online">
                            <span>开始时间</span>
                            <el-date-picker v-model="infolist.beginTime" type="datetime" placeholder="开始时间">
                            </el-date-picker>
                        </el-form-item>
                        <el-form-item prop="endTime" class="info-line online">
                            <span>结束时间</span>
                            <el-date-picker v-model="infolist.endTime" type="datetime" placeholder="结束时间">
                            </el-date-picker>
                        </el-form-item>
                        <el-form-item prop="content" class="info-line online">
                            <span>要求</span>
                            <el-input type="textarea"  :rows="2" v-model="infolist.content" placeholder="要求" :disabled="disableStatus">
                            </el-input>
                        </el-form-item>
                        <el-form-item  prop="secIds" class="info-line online">
                            <span>接收人</span>
                            <el-select
                                placeholder="选择接收人"
                                v-model="infolist.secIds"
                                multiple
                                filterable
                            >
                                <el-option
                                    v-for="items in options"
                                    :key="items.value"
                                    :label="items.label"
                                    :value="items.value"
                                >
                                </el-option>
                            </el-select>
                        </el-form-item>
                    </div>
                </el-form>
                <div slot="footer" style="padding-bottom: 20px;text-align: right;">
                    <el-button type="primary" @click="dialogCliadd(2)">下 发</el-button>
                    <!--todo-->
                    <el-button @click="dialogCliadd(1)">取 消</el-button>
                </div>
            </div>
        </el-dialog>

        <!--工单处理-->
        <el-dialog :title="currentStateName" :visible.sync="dialogStatusadd" width="50%" :destroy-on-close="true"
                   :modal="false"  :before-close="closecldia" :fullscreen="true">
            <div >

                <el-form :model="infolist" ref="infolist" :rules="tbRules">
                    <el-form-item prop="beginTime" class="info-line online">
                        <span>开始时间</span>
                        <el-date-picker v-model="infolist.beginTime" type="datetime" placeholder="开始时间" disabled>
                        </el-date-picker>
                    </el-form-item>
                    <el-form-item prop="endTime" class="info-line online">
                        <span>结束时间</span>
                        <el-date-picker v-model="infolist.endTime" type="datetime" placeholder="结束时间" disabled>
                        </el-date-picker>
                    </el-form-item>
                    <el-form-item prop="content" class="info-line online">
                        <span>要求</span>
                        <el-input type="textarea"  :rows="2" v-model="infolist.content" placeholder="要求" disabled>
                        </el-input>
                    </el-form-item>
                    <el-form-item  prop="workerId" class="info-line online">
                        <span>填报人</span>

                        <el-select
                            placeholder="选择填报人 "
                            v-model="infolist.workerId"
                            filterable
                            :disabled="workIdDisabled"
                            clearable
                        >
                            <el-option
                                v-for="items in teamWorks"
                                :key="items.loginNoStr"
                                :label="items.loginNameStr"
                                :value="items.loginNoStr"
                            >
                            </el-option>
                        </el-select>
                    </el-form-item>
                    <el-form-item >
                        <div class="container-box">
                            <div class="search">
                                <mySearch :searchList="gjsearchList" @searchInfo="gjsearchInfo"></mySearch>
                                <div>
                                    <el-button type="primary" v-show="gjlistBtns" @click="dialogCheck(5)" size="medium">添加</el-button>
                                    <el-button type="primary"  @click="downloadzip({'parentId':parentId})" size="medium">打包下载</el-button>
                                </div>
                            </div>
                            <div class="tabbox">
                                <el-table height="300px" class="com-table" ref="multipleTable" :data="gjinfoTableData"
                                          tooltip-effect="dark" size="small" border style="width: 100%">
                                    <el-table-column show-overflow-tooltip prop="gjUserName"  label="撰稿人">
                                    </el-table-column>
                                    <el-table-column show-overflow-tooltip prop="content"  label="稿件说明">
                                    </el-table-column>
                                    <el-table-column prop="files"   label="文件">
                                        <template slot-scope="scope">
                                            <span v-html="fmtfiles(scope.row)"></span>
                                        </template>
                                    </el-table-column>
                                    <el-table-column label="操作" width="300px" align="center">
                                        <template slot-scope="scope">
                                            <el-button size="mini" type="primary" @click="dialogCheck(9,scope.row)">查看</el-button>
                                            <el-button size="mini" v-show="gjlistBtns" type="primary" @click="dialogCheck(6,scope.row)">编辑</el-button>
                                            <el-button size="mini" v-show="gjlistBtns" type="primary" @click="dialogCheck(7,scope.row)">删除</el-button>
                                            <el-button size="mini" type="primary" @click="downloadzip(scope.row)" >下载</el-button>
                                        </template>
                                    </el-table-column>
                                </el-table>
                                <el-pagination class="pageBox" @current-change="gjcurrchange" layout="prev, pager, next" background
                                               :total="gjTotal">
                                </el-pagination>
                            </div>
                        </div>
                    </el-form-item>
                </el-form>



                <div slot="footer" style="margin-top: 20px;margin-bottom: 20px;text-align: right;">
                    <!--科室负责人提交分配-->
                    <el-button v-show="assignDoneButton" @click="dialogCheck(4,infolist)">分配</el-button>
                    <!--处理人处理提交-->
                    <el-button v-show="addGjDoneButton" @click="dialogCheck(8,infolist)">提交审批</el-button>
                    <!--科室经理审批-->
                    <el-button v-show="ksPassBtn" @click="shenpi('3',infolist,'确定提交至部门副总审批？')">通过</el-button>
                    <el-button v-show="ksReturnBtn" @click="shenpi('5',infolist,'确定打回至填报人填报？')">打回</el-button>

                    <!--部门副总审批通过-->
                    <el-button v-show="departsPassBtn" @click="shenpi('4',infolist,'确定提交至归档？')">通过</el-button>

                    <el-button  @click="closecldia">取 消</el-button>
                </div>
            </div>
        </el-dialog>


        <el-dialog :title="titname" :visible.sync="gjdialogstatus" width="60%" :destroy-on-close="true"
                   :model="false" :append-to-body="true" :before-close="closegjdia">
            <div>
                <el-form :model="gjinfo" ref="gjinfo" :rules="gjRules">
                    <el-form-item prop="gjUserId" class="info-line online">
                        <span>撰稿人</span>
                        <el-select
                            placeholder="选择处理人 "
                            v-model="gjinfo.gjUserId"
                            filterable
                            :disabled="gjdisabled"
                        >
                            <el-option
                                v-for="items in teamWorks"
                                :key="items.loginNoStr"
                                :label="items.loginNameStr"
                                :value="items.loginNoStr"
                            >
                            </el-option>
                        </el-select>
                    </el-form-item>
                    <el-form-item prop="content" class="info-line online">
                        <span>稿件说明</span>
                        <el-input type="textarea"   :rows="2" v-model="gjinfo.content" placeholder="要求" :disabled="gjdisabled">
                        </el-input>
                    </el-form-item>
                    <el-form-item prop="files" class="info-line online">
                        <span>文件列表</span>
                        <!--upload-->
                        <uploadNew v-if="rst" :itemId="parentId" @handleResult="handleUploadResult" :fList="gjinfo.files" type="0" btn="btn" ></uploadNew>

                    </el-form-item>
                </el-form>
                <div slot="footer" style="padding-bottom: 20px;text-align: right;">
                    <el-button type="primary" :disabled="gjdisabled" @click="dialogGjadd()">提 交</el-button>
                    <el-button @click="closegjdia">取 消</el-button>
                </div>
            </div>
        </el-dialog>

        <myMessage :messTit='messTit' @closeMessage="closeMessage" :centerDialogVisible="centerDialogVisible"
            v-if="centerDialogVisible"></myMessage>
    </fullscreen>

</template>
<script>
    import mySearch from "../../../components/search.vue";
    import myMessage from "../../../components/myMessage.vue"
    import toolList from '../../../components/toolList'
    import uploadNew from '../../../components/uploadNew.vue'
    import {strToFileList} from "@/utils/tv.js"

    export default {
        components: {
            mySearch,
            myMessage,
            toolList,
            uploadNew
        },
        data() {
            const beginTime = (rule, value, callback) => {
                if (!this.infolist.beginTime) {
                    callback(new Error('不能为空'))
                } else {
                    callback()
                }
            }
            const endTime = (rule, value, callback) => {
                if (!this.infolist.beginTime) {
                    callback(new Error('不能为空'))
                } else {
                    callback()
                }
            }
            const content = (rule, value, callback) => {
                if (!this.infolist.content) {
                    callback(new Error('不能为空'))
                } else {
                    callback()
                }
            }
            const secIds = (rule, value, callback) => {
                console.info('valid secIds -> ',this.infolist.secIds)
                if (!this.infolist.secIds||this.infolist.secIds.length==0) {
                    callback(new Error('不能为空'))
                } else {
                    callback()
                }
            }
            const workIds = (rule, value, callback) => {
                console.info('valid workerId -> ',this.infolist.workerId)
                if (!this.infolist.workerId||this.infolist.workerId=='') {
                    callback(new Error('不能为空'))
                } else {
                    callback()
                }
            }
            const gjUserId = (rule, value, callback) => {
                if (!this.gjinfo.gjUserId) {
                    callback(new Error('不能为空'))
                } else {
                    callback()
                }
            }
            const gjContent = (rule, value, callback) => {
                if (!this.gjinfo.content) {
                    callback(new Error('不能为空'))
                } else {
                    callback()
                }
            }
            const files = (rule, value, callback) => {
                if (!this.gjinfo.files) {
                    callback(new Error('不能为空'))
                } else {
                    callback()
                }
            }
            return {
                //权限控制属性
                workIdDisabled:false,
                assignDoneButton:false,
                addGjDoneButton:false,
                ksPassBtn:false,
                ksReturnBtn:false,
                departsPassBtn:false,
                gjlistBtns:false,
                tbRules:{
                    workerId: [{
                        required: true,
                        trigger: 'change',
                        validator: workIds
                    }],
                },
                rules: {
                    beginTime: [{
                        required: true,
                        trigger: 'change',
                        validator: beginTime
                    }],
                    endTime: [{
                        required: true,
                        trigger: 'change',
                        validator: endTime
                    }],
                    content: [{
                        required: true,
                        trigger: 'change',
                        validator: content
                    }],
                    secIds: [{
                        required: true,
                        trigger: 'change',
                        validator: secIds
                    }],
                },
                gjRules: {
                    gjUserId: [{
                        required: true,
                        trigger: 'change',
                        validator: gjUserId
                    }],
                    content: [{
                        required: true,
                        trigger: 'change',
                        validator: gjContent
                    }],
                    files: [{
                        required: true,
                        trigger: 'change',
                        validator: files
                    }],
                },
                searchList: [{
                    type: 'input',
                    tit: '稿件要求',
                    value: '',
                    width: '98%'
                },{
                    type: 'sel',
                    tit: '工单状态',
                    value: '',
                    width: '98%',
                    options: [{dataName:'科室经理分配',dataCode:'0'},
                        {dataName:'填报人填报',dataCode:'1'},
                        {dataName:'科室经理审核',dataCode:'2'},
                        {dataName:'部门副总审核',dataCode:'3'},
                        {dataName:'归档',dataCode:'4'},
                        {dataName:'打回重新填写',dataCode:'5'}]
                }],
                gjsearchList: [{
                    type: 'input',
                    tit: '稿件说明',
                    value: '',
                    width: '98%'
                }],
                tooltit: '稿件管理',
                fullscreen: false,
                total: 0,
                pageSize: 1,
                tableData: [{}],
                gjinfoTableData:[{}],
                dialogStatus: false,
                disableStatus: false,
                titname: '',
                infolist: {
                    beginTime:'',
                    endTime:'',
                    content: '',
                    secid: '',
                    secname:'',
                    departSlearder:'',
                    departSlearderName:'',
                    secLeader:'',
                    secLeaderName:'',
                    deptTime: '',
                    workerId:'',
                    workerName:'',
                    createTime:'',
                    createUser:'',
                    secIds: []
                },
                userInfo: {},
                params: {},
                centerDialogVisible: false,
                messTit: '',
                loading: false,
                loadinged: false,
                dialogStatusadd: false,
                choleader: false,
                treeListonly: {},
                defaultList: [],
                closeList: false,
                visionchonly: false,
                depttype: 0,
                sts: 0,
                leader: '3',  //// 0 科室负责人， 1 副总 2 正总  3 发起人  4  提交人
                situation: '0',
                options: [],
                stateMap: {'0':'科室经理分配','1':'填报人填报','2':'科室经理审核','3':'部门副总审核','4':'归档','5':'打回重新填写'},
                roleMap: {},
                /**
                 * {'liujie5':0,
                    'zhaohongsong':0,
                    'lifangyan':0,
                    'chenliang1':0,
                    'sunzhen':0,
                    'sunchuan':0,
                    'weilinna':0,
                    'qiuyu':1,
                    'guopeng':1,
                    'zhudongzhao':1}
                 */
                type: this.$route.meta.type,
                teamWorks:[],
                rstfm: true,
                selWos:[],
                //gj
                gjdialogstatus:false,
                gjinfo:{
                    id:'',
                    gjUserId:'',
                    gjUserName:'',
                    content:'',
                    files:'',
                    parentId:'',
                    status:'',
                    createUser:'',
                    createTime:''
                },
                gjparams: {},
                gjTotal: 0,
                gjPageSize: 1,
                parentId:'',
                currentStateName:'',
                fileDataList: '',
                uploadstatus:false,
                gjdisabled:false,
                rst:false
            }
        },
        methods: {
            handleSelectionChange(val){
                this.selWos=val
            },
            closegjdia(){
                console.info('close gj dialog')
                this.gjinfo = {
                    id:'',
                    gjUserId:'',
                    gjUserName:'',
                    content:'',
                    files:'',
                    parentId:'',
                    status:'',
                    createUser:'',
                    createTime:''
                }
                this.gjdialogstatus=false
            },
            closecldia(){
                console.info('close gj dialog')
                this.dialogStatusadd=false
            },
            stateFormat(row) {
                return this.stateMap[row.state]
            },
            fmtfiles(row){

                if(row.files){
                    console.info('row.files --> ',row.files)
                    let fileStr=""
                    let files=strToFileList(row.files)
                    console.info('files -> ',files)
                    files.forEach(function(item){
                        fileStr+=item.name+' <br/>'
                    })
                    console.info('fileStr',fileStr)
                    return fileStr

                }
                return '-'
            },
            getOpations() {
                this.$http({
                    url: "/market/techcentergj/queryLeaderList",
                    method: "post",
                    headers: {
                        "Content-Type": "application/json",
                    },
                    data: {},
                }).then((res) => {
                    res.data.map((item) => {
                        this.options.push({
                            label: item.ou+'->'+item.secLeaderName,
                            value: item.secLeaderLogin,
                            secId: item.o,
                            secName: item.ou,
                            o: item.o,
                            ou: item.ou,
                            secLeaderLogin: item.secLeaderLogin,
                            secLeaderName: item.secLeaderName,
                            departSleaderLogin: item.departSleaderLogin,
                            departSleaderName: item.departSleaderName
                        });
                    });
                });
            },
            choseleader(v) {
                this.leader = v;
                if (v == 3) {
                    this.dialogCliadds(3);
                } else {
                    this.choleader = true;
                }
            },
            treeCheckonly(v) {
                this.treeListonly = v;
            },
            //搜索数据
            searchInfo(v) {
                this.params = {};
                v[0] ? this.params.content = v[0] : '';
                v[1] ? this.params.state = v[1] : '';
                this.getList(this.params, this.pageSize);
            },
            gjsearchInfo(v) {
                this.gjparams = {};
                v[0] ? this.gjparams.content = v[0] : '';
                this.getGjList(this.gjparams, this.pageSize);
            },
            closedia() {
                this.infolist = {
                    beginTime:'',
                    endTime:'',
                    content: '',
                    secid: '',
                    secname:'',
                    departSlearder:'',
                    departSlearderName:'',
                    secLeader:'',
                    secLeaderName:'',
                    deptTime: '',
                    workerId:'',
                    workerName:'',
                    createTime:'',
                    createUser:'',
                    secIds: []
                };

                this.dialogStatus = false;
            },
            rstSituation (n) {
                let state=n.state
                console.info('--this.leader-->',this.leader)
                console.info('----state----',state)
                //leader   0 科室负责人， 1 副总  2 正总  3 发起人  4  提交人
                //state  {'0':'科室经理分配','1':'填报人填报','2':'科室经理审核','3':'部门副总审核','4':'归档','5':'打回重新填写'}
                // 人   人可能遇到的各种情况 ==> 各种情况下的表单样式
                // '0' 科室负责人  0分配，2 审核， r 读，x 写
                this.currentStateName=this.stateMap[state]
                if(this.leader=='0'){
                    this.departsPassBtn=false
                    if(state=='0'){
                        //科室经理分配,操作
                        this.situation='00x'
                        this.workIdDisabled=false
                        this.assignDoneButton=true;
                        this.addGjDoneButton=false
                        //科室经理审批通过按钮
                        this.ksPassBtn=false
                        this.ksReturnBtn=false
                        this.gjlistBtns=false

                    }else if(state=='2'){
                        //审批，操作
                        this.situation='02x'
                        this.workIdDisabled=true;
                        this.assignDoneButton=false
                        this.addGjDoneButton=false
                        //科室经理审批通过，打回按钮
                        this.ksPassBtn=true
                        this.ksReturnBtn=true
                        this.gjlistBtns=false
                        //todo 科室经理分配给自己处理  state=1 workerId=loginNoStr
                    }else if((state=='1'||state=='5')&&this.userInfo.loginNoStr==n.workerId){
                        this.situation='41x'
                        this.workIdDisabled=true;
                        this.assignDoneButton=false
                        this.addGjDoneButton=true
                        this.gjlistBtns=true
                        //科室经理审批通过按钮
                        this.ksPassBtn=false
                        this.ksReturnBtn=false

                    }else{
                        //科室经理查看，没有操作权限，只读。
                        this.situation='0r'
                        this.workIdDisabled=true;
                        this.assignDoneButton=false
                        this.addGjDoneButton=false
                        this.gjlistBtns=false

                        //科室经理审批通过按钮
                        this.ksPassBtn=false
                        this.ksReturnBtn=false
                    }
                }else if(this.leader=='4'){

                    //科室经理审批通过按钮
                    this.ksPassBtn=false
                    this.ksReturnBtn=false
                    this.departsPassBtn=false
                    //提交人提交。
                    if(state=='1'||state=='5'){
                        //提交人提交,操作
                        this.situation='41x'
                        this.workIdDisabled=true;
                        this.assignDoneButton=false
                        this.addGjDoneButton=true
                        this.gjlistBtns=true
                    }else{
                        //提交人提交查看，只读
                        this.situation='4r'
                        this.workIdDisabled=true;
                        this.assignDoneButton=false
                        this.addGjDoneButton=false
                        this.gjlistBtns=false
                    }
                }else if(this.leader=='1'){
                    //科室经理审批通过按钮
                    this.ksPassBtn=false
                    this.gjlistBtns=false
                    this.addGjDoneButton=false
                    //副总
                    if(state=='3'){
                        //副总审核,操作
                        this.situation='3x'
                        this.workIdDisabled=true;
                        this.assignDoneButton=false
                        this.ksReturnBtn=true
                        this.departsPassBtn=true
                    }else{
                        //副总审核，只读
                        this.situation='1r'
                        this.workIdDisabled=true;
                        this.assignDoneButton=false
                        this.ksReturnBtn=false
                        this.departsPassBtn=false
                    }
                }else if(this.leader=='3'){

                    //科室经理审批通过按钮
                    this.ksPassBtn=false
                    this.ksReturnBtn=false
                    this.departsPassBtn=false
                    this.gjlistBtns=false
                    this.addGjDoneButton=false

                    //只读
                    this.situation='3r'
                    this.workIdDisabled=true;
                    this.assignDoneButton=false
                }

                //刷新表单
                this.rstfm = false
                this.$nextTick(() => {
                    this.rstfm = true
                })
                console.info(':---situation--->',this.situation)
            },
            resetRole(){
                //  处理按钮，根据  leader（角色）  和  state 决定展示什么按钮，控制页面权限。
                // 0 科室负责人， 1 副总 2 正总  3 发起人  4  提交人
                this.userInfo=JSON.parse(window.sessionStorage.userInfo)
                //看当前登陆人的角色是谁，决定查什么列表
                let type=this.$route.meta.type;
                //type=1 发起人查看的列表
                if(type==1){
                    console.info('---》type',type);
                    this.params.createUser=this.userInfo.loginNoStr
                    this.params.roleType='D'
                    this.leader='3'
                    this.type='1'

                }else{
                    //提交人，科室经理，部门副总
                    if(this.roleMap[this.userInfo.loginNoStr]){
                        this.leader=this.roleMap[this.userInfo.loginNoStr]

                        //科室经理
                        if(this.roleMap[this.userInfo.loginNoStr]=='0'){
                            this.params.secLeader=this.userInfo.loginNoStr
                        }else if(this.roleMap[this.userInfo.loginNoStr]=='1'){
                            //部门副总
                            this.params.departSlearder = this.userInfo.loginNoStr
                        }
                    }else{
                        this.params.workerId=this.userInfo.loginNoStr
                        this.leader='4'
                    }
                }
                console.info('rolesearchparam',this.params);
                //根据当前状态更新操作列表中，各个按钮的显示状态。当前登陆人角色，当前状态是当前登陆人需要处理的，则显示处理按钮，否则展示查看按钮。
                //resetbutton.
            },
            //获取列表
            getList(v, n) {
                //根据当前登陆人的角色。刷新查询条件。
                if(Object.keys (this.roleMap).length ===0){
                    let _that=this;
                    this.getShrole(function(){
                        console.info('yes in getlist,this.roleMap====',_that.roleMap)
                        _that.resetRole();
                        _that.pageSize = n;
                        console.info('begin query-->',_that.params)
                        _that.$http({
                            url: "/market/techcentergj/queryPage",
                            method: "post",
                            headers: {
                                "Content-Type": "application/json",
                                "page": '{"pageNo":"' + n + '","pageSize":"10"}'
                            },
                            data: _that.params,
                        }).then((res) => {
                            _that.tableData = res.data.data;
                            _that.total = res.data.totalRecord;
                        });
                    });
                }else{
                    this.resetRole();
                    this.pageSize = n;
                    this.$http({
                        url: "/market/techcentergj/queryPage",
                        method: "post",
                        headers: {
                            "Content-Type": "application/json",
                            "page": '{"pageNo":"' + n + '","pageSize":"10"}'
                        },
                        data: this.params,
                    }).then((res) => {
                        this.tableData = res.data.data;
                        this.total = res.data.totalRecord;
                    });
                }
            },
            //获取人员角色map.
            getShrole(callback){
                this.$http({
                    url: "/market/techcentergj/shrole",
                    method: "post",
                    headers: {
                        "Content-Type": "application/json",
                    },
                    data: {pdepartO:'00440063000000000000'},
                }).then((res) => {
                    this.roleMap = res.data.body
                    callback()

                });
            },
            // 分页
            currchange(v) {
                this.pageSize = v;
                this.getList(this.params, this.pageSize);
            },
            gjcurrchange(v){
                this.gjpageSize = v;
                this.getGjList(this.gjparams, this.gjpageSize);
            },
            //申请
            dialogCheck(v, n) {
                //0 查看 1 处理，判断当前环节，和当前人员。 2 下发
                console.info('row',n);
                if (v === 0) {
                    this.rstSituation(n)
                    this.titname = '查看';
                    this.dialogStatusadd = true;
                    this.disableStatus = false;
                    this.sts = 0
                    this.infolist=n
                    this.parentId=n.id
                    this.getGjList({},1)

                } else if (v === 1) {
                    this.titname = '处理';
                    this.dialogStatusadd = true;
                    this.disableStatus = false;
                    return
                } else if (v === 2) {
                    this.titname = '下发';
                    this.dialogStatus = true;
                    this.disableStatus = false;
                    return
                } else if (v===3) {
                    console.info('下载')
                    this.downloadzip({'parentId':n.id})
                } else if (v===4){
                    //科室负责人提交分配菜单。
                    this.infolist.state='1'
                    this.assign()
                } else if (v===5){
                    //添加稿件
                    this.gjdialogstatus=true
                    this.rst=false
                    this.$nextTick(()=>{
                        this.rst=true
                    })
                } else if(v===6){
                    //编辑稿件
                    this.gjdialogstatus=true
                    this.gjdisabled=false
                    this.gjinfo=n
                    this.rst=false
                    this.$nextTick(()=>{
                        this.rst=true
                    })
                } else if(v===7){
                    //删除稿件
                    this.dialogGjdel(n)
                } else if(v===8){
                    this.commitGj(n)
                } else if(v===9){
                    this.gjdialogstatus=true
                    this.gjdisabled=true
                    this.gjinfo=n
                    this.rst=false
                    this.$nextTick(()=>{
                        this.rst=true
                    })
                }
            },
            //添加
            dialogCliadd(v) {
                if (v == 1) {
                    this.infolist = {
                        beginTime:'',
                        endTime:'',
                        content: '',
                        secid: '',
                        secname:'',
                        departSlearder:'',
                        departSlearderName:'',
                        secLeader:'',
                        secLeaderName:'',
                        deptTime: '',
                        workerId:'',
                        workerName:'',
                        createTime:'',
                        createUser:'',
                        secIds: []
                    };
                    this.dialogStatus = false;
                    return
                }
                let _this = this;
                let info = this.infolist;
                info.createTime = _this.$formatDate(new Date(), "YYYY-MM-DD");
                info.createUser = this.userInfo.loginNo;
                info.beginTime = info.beginTime ? _this.$formatDate(info.beginTime, "YYYY-MM-DD HH:mm") : '';
                info.endTime = info.endTime ? _this.$formatDate(info.endTime, "YYYY-MM-DD HH:mm") : '';

                let secs = []
                this.infolist.secIds.map((item) => {
                    this.options.map((row) => {
                        if (item == row.value) {
                            secs.push(row);
                        }
                    });
                });
                info.secIds=secs
                console.info('secs',info.secIds)
                if (this.titname == '修改') {
                    this.submitInfo("/market/techcentergj/add", info);
                } else {
                    console.info('submitinfo',info);
                    this.submitInfo("/market/techcentergj/add", info);
                }
            },
            assign(){
                //分配  update
                console.info('asign:->',this.infolist)
                let info={}
                info.workerId=this.infolist.workerId
                info.state='1'
                info.id=this.infolist.id

                //workName
                this.teamWorks.map((item) => {
                    console.info('-->item:',item)
                    if(item.loginNoStr==info.workerId){
                        info.workerName=item.loginNameStr
                    }
                });

                console.info('----info---->',info)

                this.submitInfo("/market/techcentergj/update", info);
            },
            //提交人 提交审批
            commitGj(n){

                //确定提交么
                this.$confirm("确定提交到科室经理审批?", "提示", {
                    confirmButtonText: "确定",
                    cancelButtonText: "取消",
                    type: "warning",
                }).then(() => {
                    console.info('---->commitGj',n)
                    if(this.gjinfoTableData.length==0){
                        this.$message('请添加稿件！')
                        return
                    }
                    let info={}
                    //info.workerId=this.infolist.workerId
                    info.state='2'
                    info.id=this.infolist.id
                    this.submitInfo("/market/techcentergj/update", info);
                }).catch(() => {});
            },
            //审批
            shenpi(dstState,n,message){
                //确定提交么
                this.$confirm(message, "提示", {
                    confirmButtonText: "确定",
                    cancelButtonText: "取消",
                    type: "warning",
                }).then(() => {
                    console.info('---->shenhe',n)
                    let info={}
                    info.state=dstState
                    info.id=this.infolist.id
                    this.submitInfo("/market/techcentergj/update", info);
                }).catch(() => {});
            },
            //type 1 科室经理审批 state （通过  2->3  打回  2-》5） ，2 部门副总审批 （通过 3-》4 ，打回 3-》5）
            //act 1 通过 2 打回
            shenpiAll(type,act){

                if(this.selWos.length===0){
                    this.$message({message: '请选择待审批工单！',
                        type: 'error'})
                    return
                }

                let destState='';
                let msg='';
                if(type=='1'&&act=='1'){
                    destState='3'
                    msg='确定批量通过所选工单？'
                }else if(type=='1'&&act=='2'){
                    destState='5'
                    msg='确定批量打回所选工单？'
                }else if(type=='2'&&act=='1'){
                    destState='4'
                    msg='确定批量通过所选工单？'
                }else if(type=='2'&&act=='2') {
                    destState = '5'
                    msg = '确定批量打回所选工单？'
                }else{
                    this.$message('error');
                    return
                }

                let _this=this
                let done=true;
                this.selWos.forEach(function(item){
                    if(type=='1'&&item.state!='2'){
                        _this.$message({
                            message: '请选择：【科室经理审核】 状态的工单！',
                            type: 'error'
                        })
                        done=false
                        return
                    }

                    if(type=='2'&&item.state!='3'){
                        _this.$message({
                            message: '请选择：【部门副总审核】 状态的工单！',
                            type: 'error'
                        })
                        done=false
                        return
                    }
                    item.state=destState
                })

                //提交。
                if(done){
                    this.$confirm(msg, "提示", {
                        confirmButtonText: "确定",
                        cancelButtonText: "取消",
                        type: "warning",
                    }).then(() => {
                        this.$http({
                            url: '/market/infotech/updateBatch',
                            method: "post",
                            headers: {
                                "Content-Type": "application/json",
                            },
                            data: JSON.stringify(this.selWos),
                        }).then((res) => {
                            if (res.data.result === 1) {
                                _this.$message({
                                    message: res.data.desc,
                                    type: 'error'
                                });
                            } else {
                                _this.$message({
                                    message: '成功',
                                    type: 'success'
                                });
                                _this.getList(this.params, this.pageSize);
                            }
                        });
                    }).catch(() => {});
                }


            }
            //添加
            ,submitInfo(u, v) {
                let _this = this;
                this.$refs.infolist.validate(valid => {
                    if (valid) {
                        this.$http({
                            url: u,
                            method: "post",
                            headers: {
                                "Content-Type": "application/json",
                            },
                            data: v,
                        }).then((res) => {
                            if (res.data.result === 1) {
                                _this.$message({
                                    message: res.data.desc,
                                    type: 'error'
                                });
                            } else {
                                _this.$message({
                                    message: '成功',
                                    type: 'success'
                                });
                                _this.closedia();
                                _this.infolist = {
                                    beginTime:'',
                                    endTime:'',
                                    content: '',
                                    secid: '',
                                    secname:'',
                                    departSlearder:'',
                                    departSlearderName:'',
                                    secLeader:'',
                                    secLeaderName:'',
                                    deptTime: '',
                                    workerId:'',
                                    workerName:'',
                                    createTime:'',
                                    createUser:'',
                                    secIds: []
                                };
                                _this.dialogStatusadd = false;
                                _this.choleader = false;
                                _this.getList(this.params, this.pageSize);
                            }

                        });
                    }
                })
            },
            //功能栏
            iconCli(v) {
                if (v === 1) {
                    this.getList(this.params, this.pageSize);
                }
                if (v === 2) {
                    this.fullscreen = !this.fullscreen
                }
            },
            //获取自己部门的员工，用于分配处理人。 todo 考虑分配给自己的情况。好麻烦。
            getDepartUsers(o){
                let userInfo=JSON.parse(window.sessionStorage.userInfo)
                console.info('userInfo->',userInfo)
                this.$http({
                    url: "/sysmgr/sysuserinfo/queryList",
                    method: "post",
                    headers: {
                        "Content-Type": "application/json",
                    },
                    data: {
                        groupId: userInfo.groupId,
                    },
                }).then((ress) => {
                    this.teamWorks=ress.data
                    console.info('----->teamWorks:',this.teamWorks)
                });
            },

            //gjinfo 相关function ------>
            getGjList(v, n) {
                //根据当前登陆人的角色。刷新查询条件。
                //this.resetRole();
                //gj 当前的pageNum
                this.gjparams.parentId=this.parentId
                this.gjPageSize = n;
                this.$http({
                    url: "/market/infotechgjinfo/queryPage",
                    method: "post",
                    headers: {
                        "Content-Type": "application/json",
                        "page": '{"pageNo":"' + n + '","pageSize":"10"}'
                    },
                    data: this.gjparams,
                }).then((res) => {
                    this.gjinfoTableData = res.data.data;
                    this.gjTotal = res.data.totalRecord;
                });
            },
            //添加稿件
            dialogGjadd(){
                let info = this.gjinfo;
                info.createTime = this.$formatDate(new Date(), "YYYY-MM-DD");
                info.createUser = this.userInfo.loginNo;
                //gjUserName
                //parentId
                //status
                info.parentId=this.parentId
                info.status='0'
                this.teamWorks.map((item) => {
                    if(item.loginNoStr==info.gjUserId){
                        info.gjUserName=item.loginNameStr
                    }
                });

                let _this=this
                let url='/market/infotechgjinfo/add'
                if(this.gjinfo.id){
                    url='/market/infotechgjinfo/update'
                }
                console.info('dialogGjadd -> ',info)
                this.$refs.gjinfo.validate(valid => {
                    if (valid) {
                        this.$http({
                            url: url,
                            method: "post",
                            headers: {
                                "Content-Type": "application/json",
                            },
                            data: info,
                        }).then((res) => {
                            if (res.data.result === 1) {
                                _this.$message({
                                    message: res.data.desc,
                                    type: 'error'
                                });
                            } else {
                                _this.$message({
                                    message: '成功',
                                    type: 'success'
                                });
                                _this.closegjdia();
                                _this.getGjList(this.gjparams, this.gjPageSize);
                            }

                        });
                    }
                })

            },
            dialogGjdel(row){
                let _this=this

                this.$confirm("确定删除?", "提示", {
                    confirmButtonText: "确定",
                    cancelButtonText: "取消",
                    type: "warning",
                }).then(() => {
                    this.$http({
                        url: '/market/infotechgjinfo/del',
                        method: "post",
                        headers: {
                            "Content-Type": "application/json",
                        },
                        data: row,
                    }).then((res) => {
                        if (res.data.result === 1) {
                            _this.$message({
                                message: res.data.desc,
                                type: 'error'
                            });
                        } else {
                            _this.$message({
                                message: '成功',
                                type: 'success'
                            });
                            _this.getGjList(this.gjparams, this.gjPageSize);
                        }
                    });
                }).catch(() => {});

            },
            downloadzip(gjinfo){
                this.$http({
                    url: '/market/techcentergj/zip',
                    method: "post",
                    responseType: 'blob',
                    headers: {
                        "Content-Type": "application/json",
                    },
                    data: gjinfo,
                }).then((response) => {
                    if (window.navigator && window.navigator.msSaveOrOpenBlob) {
                        let blob = new Blob([response.data], {
                            type: response.data.type
                        });
                        window.navigator.msSaveOrOpenBlob(blob,  'download.zip');
                    } else {
                        /* 火狐谷歌的文件下载方式 */
                        var blob = new Blob([response.data])
                        var downloadElement = document.createElement('a')
                        var href = window.URL.createObjectURL(blob);
                        downloadElement.href = href;
                        downloadElement.download =  'download.zip';
                        document.body.appendChild(downloadElement);
                        downloadElement.click();
                        document.body.removeChild(downloadElement);
                        window.URL.revokeObjectURL(href);
                    }
                });
            },
            handleUploadResult(file){
                console.info('-----------------------------------------------')
                this.gjinfo.files=JSON.stringify(file.files)
                console.info('handleUploadResult',file)
            }
        },
        mounted() {
            this.getList({}, 1);
        },
        created() {
            this.getOpations()
            this.getDepartUsers()
        }
    }
</script>
<style scoped lang="scss">
    .onetab {
        margin-bottom: 20px;
        padding: 0 20px;
    }

    .titbox {
        div {
            float: right;

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

    .tabbox {
        margin-top: 15px;
    }

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

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

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

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

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

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

    .online {
        width: 100%;

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

        span {
            vertical-align: top;
        }

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

        .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;
            }
        }
    }

    .adv-type {
        margin-top: 20px;
        display: flex;
        justify-content: space-between;
        flex-wrap: wrap;
        // border: 1px solid #ddd;
        border-radius: 5px;
        padding: 20px;
        box-shadow: 0 2px 12px 0 rgba(0, 0, 0, .1);

        div {
            width: 33%;
            text-align: center;
            height: 80px;
            overflow: hidden;
            min-width: 100px;
            cursor: pointer;
            padding-top: 10px;
            margin: 10px 0;
        }

        div:hover {
            background: #CFE8FC;
            border-radius: 5px;
        }

        span {
            width: 100%;
            display: inline-block;
            height: 40px;

            // line-height: 40px;
            i {
                color: #0074D9;
                font-size: 36px;
            }
        }
    }
</style>
