<!--审批管理组件 -->
<template>
  <div class="yt-alc">
    <!-- 主页面 -->
    <div>
      <div class="yt-cst-top clearfix">
        <div >
          <el-form :inline="true" ref="searchForm"  :model="searchForm"  class="demo-form-inline sui-search-form">
            <el-form-item>
              <el-form-item prop="operatetimeStart" label="申请时间:">
                <el-date-picker
                  v-model="searchForm.operatetimeStart"
                  :clearable="false"
                  type="date"
                  placeholder="开始时间"
                  size="small"
                  format="yyyy-MM-dd"
                  value-format="yyyy-MM-dd"
                ></el-date-picker>
              </el-form-item>
              <el-form-item prop="operatetimeEnd" label="至">
                <el-date-picker
                  v-model="searchForm.operatetimeEnd"
                  :clearable="false"
                  type="date"
                  placeholder="结束时间"
                  size="small"
                  format="yyyy-MM-dd"
                  value-format="yyyy-MM-dd"
                ></el-date-picker>
              </el-form-item>
            </el-form-item>
            <el-form-item >
              <el-button type="primary" size="small" @click="doQuery" :loading="queryTopLoading">查询</el-button>
            </el-form-item>
          </el-form>
        </div>
      </div>
      <div>
        <div class="ytg-ps-title" >审批申请
          <div class="ytg-ps-title-btns" style="margin-left: 110px; right: 0">
             <el-button size="small" @click="addApply">添加申请</el-button>
          </div>
        </div>
        <div id="power_table">
          <el-table
            class="have"
            ref="table1"
            :height="tableTop"
            v-loading="queryTopLoading"
            :data="tableData_main"
            border
            highlight-current-row
            style="width: 100%;"
            :icorePanelShown="100"
            @cell-click='changeapply'
            :icore-filter-flag="icoreFilterFlag"
            :exchangeFilterMap="{
              'status':{'1':'待发送', '2':'审核中', '3': '通过', '4': '未通过'}
            }"
          >
            <el-table-column type="index" label="序号" align="center" width="60"></el-table-column>
            <el-table-column
              prop="approvalTime"
              label="申请时间"
              sortable
              :show-overflow-tooltip="true"
              min-width="150">
            </el-table-column>
            <el-table-column
              prop="approvalContent"
              label="申请内容"
              sortable
              :show-overflow-tooltip="true"
              min-width="130">
            </el-table-column>
            <el-table-column
              prop="cause"
              label="申请事由"
              sortable
              :show-overflow-tooltip="true"
              min-width="170">
            </el-table-column>
            <el-table-column
              prop="createManName"
              label="申请人"
              sortable
              align="center"
              :show-overflow-tooltip="true"
              min-width="80">
            </el-table-column>
            <el-table-column
              prop="typeName"
              label="申请类型"
              sortable
              :show-overflow-tooltip="true"
              min-width="100"
            >
            </el-table-column>
            <el-table-column
              prop="departmentNaem"
              label='部门'
              sortable
              :show-overflow-tooltip="true"
              min-width="130"
            >
            </el-table-column>
            <el-table-column
              prop="agent"
              label="经办人"
              sortable
              align="center"
              :show-overflow-tooltip="true"
              min-width="90">
            </el-table-column>
            <el-table-column
              prop="departmentOpinion"
              label="部门意见"
              sortable
              align="center"
              :show-overflow-tooltip="true"
              min-width="90">
            </el-table-column>
            <el-table-column
              prop="leaderOpinion"
              label="领导意见"
              sortable
              align="center"
              :show-overflow-tooltip="true"
              min-width="90">
            </el-table-column>
            <el-table-column
              prop="status"
              label="状态"
              sortable
              align="center"
              :show-overflow-tooltip="true"
              min-width="80">
              <template slot-scope="{row}">
                <span>{{row.status == 1 ? '待发送' : row.status == 2 ? '审核中' : row.status == 3 ? '通过' : row.status == 4 ? '未通过' : ''}}</span>
              </template>
            </el-table-column>
            <el-table-column
              prop="memo"
              label="备注"
              align="left"
              sortable
              :show-overflow-tooltip="true"
              min-width="110">
            </el-table-column>
          </el-table>
        </div>
        <div class="yt-table-page">
          <el-pagination
            @size-change="handleSizeChangeMain"
            @current-change="handleCurrentChangeMain"
            :current-page= "pageIndex_main"
            :page-sizes="[10, 20, 30, 40, 100 , 200]"
            :page-size= "pageSize_main"
            layout="total, sizes, prev, pager, next, jumper"
            :total= "total_main">
          </el-pagination>
        </div>
      </div>
    </div>
<!--    从右往左打开的drawer：-->
    <el-drawer
      custom-class="demo-drawer"
      ref="drawer"
      title="审批申请"
      :visible.sync="showDrawer"
      :direction="direction"
      :before-close="handleClose"
      size='50%'
    >
      <div class="scro" :style="`height:${upwidth}px`">
        <el-form :model="editForm" ref="editForm" :rules="ruleForm">
          <el-row :gutter="20">
            <el-col :span="24">
              <el-form-item label="申请类型" prop="type" :label-width="formLabelWidth">
                <el-select @change="valueChange"  filterable v-model="editForm.type" placeholder="申请类型" clearable size="small" style="width: 100%">
                  <el-option v-for="item in applyType" :label="item.baseName" :value="item.memo" :key="item.memo"></el-option>
                </el-select>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row :gutter="20">
            <el-col :span="24">
              <el-form-item label="审批科室" :label-width="formLabelWidth">
                <el-select :disabled='changedis'  filterable v-model="editForm.department" placeholder="审批科室" clearable size="small" style="width: 100%">
                  <el-option v-for="item in department" :label="item.baseName" :value="item.baseCode" :key="item.baseCode"></el-option>
                </el-select>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row :gutter="20">
            <el-col :span="24">
              <el-form-item label="" :label-width="formLabelWidth">
                <el-checkbox v-model="checked">是否领导审批</el-checkbox>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row :gutter="20">
            <el-col :span="24">
              <el-form-item label="申请内容" :label-width="formLabelWidth">
                <el-input
                  type="textarea"
                  :rows="3"
                  style="width:100%"
                  placeholder="请输入申请内容"
                  v-model="editForm.approvalContent"
                >
                </el-input>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row :gutter="20">
            <el-col :span="24">
              <el-form-item label="申请事由" :label-width="formLabelWidth">
                <el-input
                  type="textarea"
                  :rows="3"
                  placeholder="请输入申请事由"
                  v-model="editForm.cause"
                >
                </el-input>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row :gutter="20">
            <el-col :span="24">
              <el-form-item label="申请时间" :label-width="formLabelWidth">
                <el-date-picker
                  v-model="editForm.approvalTime"
                  :clearable="false"
                  type="date"
                  placeholder="申请时间"
                  style="width:100%"
                  size="small"
                  format="yyyy-MM-dd"
                  value-format="yyyy-MM-dd"
                ></el-date-picker>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row :gutter="20">
            <el-col :span="24">
              <el-form-item label="备注" :label-width="formLabelWidth">
                <el-input
                  type="textarea"
                  :rows="3"
                  placeholder="请输入备注"
                  v-model="editForm.memo"
                >
                </el-input>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row :gutter="20">
            <el-col :span="24">
              <el-form-item label="抄送人" prop="approvalManNo" :label-width="formLabelWidth">
                <el-select  multiple filterable v-model="editForm.approvalManNo" placeholder="抄送人" clearable size="small" style="width: 100%">
                  <el-option v-for="item in approver" :label="item.baseName" :value="item.baseCode" :key="item.baseCode"></el-option>
                </el-select>
              </el-form-item>
            </el-col>
          </el-row>
           <el-row :gutter="20">
            <el-col :span="8">
              <el-form-item label="上传附件"  :label-width="formLabelWidth">
                <el-button
                        type="primary"
                        size='mini'
                        @click="doUploadAgain_file"
                      >上传文件</el-button>
              </el-form-item>
            </el-col>
          </el-row>
                    <el-row>
            <el-col>
              <div style="height: auto; text-align: center">
        <!--        <div v-for="item in allFJ" :key="item.id">-->
        <!--          <el-button type="text" @click="fjRow(item)">{{item.annexNameOld}}</el-button>-->
        <!--        </div>-->
        <!--        将图片和文件分开放：-->
        <!--        文件：-->
        <!-- <div style="border-bottom: 1px solid #f51818; padding-bottom: 5px; color: #f51818">图片</div> -->
        <div v-for="(item,index) in flileArr" :key="item.id">
          <div v-if="item.isImage === '1' ? true : false "  style="overflow: hidden; width: 100px; height: 120px; display: inline-block; position: relative; border: 1px solid #1a9f17; margin: 5px" :title="item.annexNameOld" class="wrapOut" >
            <div style="">
              <img :src="action_prod + item.annexPath" :alt="item.annexNameOld" :title="item.annexNameOld" style="width: 100%">
              <!--              遮盖：-->
              <div class="wrap" @click="imgPreView(item)">
                <div style="float:right">
                  <el-button
                    type="text"
                    icon="el-icon-delete"
                    style="color:#fff;padding:0;"
                    @click.stop="deleteupData(item,index)"
                  >删除</el-button>
                </div>
              </div>
            </div>
            <div style="position:absolute; left: 0; bottom: 0; height: 20px; line-height: 20px; width: 100px; text-align: center; border-top: 1px solid #1a9f17; color: #1a9f17">{{item.annexNameOld}}</div>
          </div>
          <div  v-if="item.isImage === '2' ? true : false " class="fileClass" :title="item.annexNameOld">
          <el-button type="text" size="small" @click="fjRow(item)">{{item.annexNameOld}}</el-button>
          <i class="el-icon-delete del" @click="deleteupData(item,index)"></i>
        </div>
        </div>
        <!-- <div style="border-bottom: 1px solid #f51818; padding-bottom: 5px; color: #f51818">文件</div> -->
        <div style="text-align: center"></div>
        
      </div>
            </el-col>
          </el-row>
        </el-form>
        <div class="demo-drawer__footer">
          <div style="float:right;right:0">
            <!-- <el-button size="small">保存</el-button> -->
            <el-button size="small" @click="subapply('editForm')" type="primary" :loading="loading">{{ loading ? '提交中 ...' : '提交审核' }}</el-button>
          </div>
        </div>
      </div>
    </el-drawer>
    <el-drawer
      custom-class="demo-drawer"
      ref="drawer"
      title="审批修改"
      :visible.sync="showEdit"
      :direction="direction"
      :before-close="handleClose"
      size='50%'
    >
      <div class="scro" ref="scrowith">
        <el-form :model="editapply" ref="editapply" :rules="rule_editForm">
          <el-row :gutter="20">
            <el-col :span="24">
              <el-form-item label="申请类型" prop="type" :label-width="formLabelWidth">
                <el-select   filterable v-model="editapply.type" placeholder="申请类型" clearable size="small" style="width: 100%">
                  <el-option v-for="item in applyType" :label="item.baseName" :value="item.memo" :key="item.memo"></el-option>
                </el-select>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row :gutter="20">
            <el-col :span="24">
              <el-form-item label="申请内容" :label-width="formLabelWidth">
                <el-input
                  type="textarea"
                  :rows="3"
                  style="width:100%"
                  placeholder="请输入申请内容"
                  v-model="editapply.approvalContent"
                >
                </el-input>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row :gutter="20">
            <el-col :span="24">
              <el-form-item label="申请事由" :label-width="formLabelWidth">
                <el-input
                  type="textarea"
                  :rows="3"
                  placeholder="请输入申请事由"
                  v-model="editapply.cause"
                >
                </el-input>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row :gutter="20">
            <el-col :span="24">
              <el-form-item label="申请时间"  :label-width="formLabelWidth">
                <el-date-picker
                  v-model="editapply.approvalTime"
                  :clearable="false"
                  type="date"
                  placeholder="申请时间"
                  style="width:100%"
                  size="small"
                  format="yyyy-MM-dd"
                  value-format="yyyy-MM-dd"
                ></el-date-picker>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row :gutter="20">
            <el-col :span="24">
              <el-form-item label="备注" :label-width="formLabelWidth">
                <el-input
                  type="textarea"
                  :rows="3"
                  placeholder="请输入备注"
                  v-model="editapply.memo"
                >
                </el-input>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row :gutter="20">
            <el-col :span="24">
              <el-form-item label="抄送人" prop="approvalManNo" :label-width="formLabelWidth">
                <el-select multiple  filterable v-model="editapply.approvalManNo" placeholder="抄送人" clearable size="small" style="width: 100%">
                  <el-option v-for="item in approver" :label="item.baseName" :value="item.baseCode" :key="item.baseCode"></el-option>
                </el-select>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row :gutter="20">
            <el-col :span="12">
              <el-form-item label="附件"  :label-width="formLabelWidth">
                <el-button size='mini' type="primary" @click="doUploadAgain_file">上传文件</el-button>
              </el-form-item>
            </el-col>
            <!-- <el-col :span="12">
              <el-form-item>
                <el-button size='samll' type="primary"  @click="showFJ(editapply)">查看附件</el-button>
              </el-form-item>
            </el-col> -->
          </el-row>
          <el-row>
            <el-col>
              <div style="height: auto; text-align: center">
                <div >
                  <div v-for="item in allFJ[0]" style="overflow: hidden; width: 100px; height: 120px; display: inline-block; position: relative; border: 1px solid #1a9f17; margin: 5px" :title="item.annexNameOld" class="wrapOut" :key="item.id">
                    <div style="">
                      <img :src="action_prod + item.annexPath" :alt="item.annexNameOld" :title="item.annexNameOld" style="width: 100%">
                      <!--              遮盖：-->
                      <div class="wrap" @click="imgPreView(item)">
                        <div style="float:left">
                          <el-button type="text" icon="el-icon-download" style="color:#fff;padding:0;" @click.stop="fjRow(item)">下载</el-button>
                        </div>
                        <div style="float:right">
                          <el-button
                            type="text"
                            icon="el-icon-delete"
                            style="color:#fff;padding:0;"
                            @click.stop="deletePng(item)"
                          >删除</el-button>
                        </div>
                      </div>
                    </div>
                    <div style="position:absolute; left: 0; bottom: 0; height: 20px; line-height: 20px; width: 100px; text-align: center; border-top: 1px solid #1a9f17; color: #1a9f17">{{item.annexNameOld}}</div>
                  </div>
                </div>
                <!-- <div style="border-bottom: 1px solid #f51818; padding-bottom: 5px; color: #f51818">文件</div> -->
                <div style="text-align: center"></div>
                <div v-for="item in allFJ[1]" class="fileClass" :title="item.annexNameOld" :key="item.id">
                  <el-button type="text" size="small" @click="fjRow(item)">{{item.annexNameOld}}</el-button>
                  <i class="el-icon-delete del" @click="deletePng(item)"></i>
                </div>
              </div>
            </el-col>
          </el-row>
          <el-row>
            <el-col>
              <el-form-item  label="审批进度" :label-width="formLabelWidth">
                <ul style="display:block;list-style: none" v-for="(item, index) in approvals" :key="index">
                  <li class="box">
                    <div class="line"></div>
                    <div class="line_narmal"></div>
                    <div class="item_wrap">
                      <div class="item_content">
                        <span style="display:inline-block;width:50px">{{item.person_name || item.createManName}}</span>
                        <span style="display:inline-block;width:50px;margin: 0 10px">{{item.Flag === 1 ? (item.status == 1 ? '待发送' : item.status == 2 ? '已提交' : item.status == 3 ? '通过' : item.status == 4 ? '未通过' : '') : (item.valid_flag == 0 ? '审批中' : item.valid_flag == 1 ? '已拒绝' : item.valid_flag == 2 ? '已完成' : '') }}</span>
                        <span>{{item.approver_time || item.approvalTime}}</span>
                        </div>
                      <div class="item_memo">{{item.reason || item.memo}}</div>
                    </div>
                  </li>
                </ul>
              </el-form-item>
            </el-col>
          </el-row>
        </el-form>
        <div class="demo-drawer__footer clearfix" style="padding-bottom:20px">
          <div style="float:right;right:0">
            <!-- <el-button size="small">保存</el-button> -->
            <el-button size="small" @click="eapply('editapply')" type="primary" :loading="editloading">{{ editloading ? '提交中 ...' : '保存修改' }}</el-button>
            <el-button  size="small" type="primary" @click="subeapply('editapply')" :disabled='subdisable'>提交审核</el-button>
            <el-button class="myBtn_danger"  @click="deleteApply('editapply')" size="small" type="danger">删除</el-button>
          </div>
        </div>
      </div>
    </el-drawer>
    <el-dialog
      title="附件上传"
      :visible.sync="fileUploadShow_file"
      :close-on-click-modal="false"
      @close="closeBox('fileUploadShow_file', 'upload_file')"
    >
      <el-upload
        ref="upload_file"
        class="upload-demo"
        :action="actionUrl_prod"
        :on-preview="handlePreview_file"
        :before-upload="beforeUpload_file"
        :on-remove="handleRemove_file"
        :before-remove="beforeRemove_file"
        :on-success="handleSuccess_file"
        multiple
        :limit="10"
        :headers="token"
        :on-exceed="handleExceed_file"
        :file-list="fileList_file"
        :auto-upload="false"
        :on-change="change_file"
        @close="closeBox('fileUploadShow_file', 'upload_file')"
      >
        <el-button slot="trigger" size="small" type="primary">选取文件</el-button>
        <el-button style="margin-left: 10px; color: #fff" size="small" type="success" @click="submitUpload_file">上传到服务器</el-button>
        <!-- <div slot="tip" class="el-upload__tip">只能上传非图片文件</div> -->
      </el-upload>
    </el-dialog>
     <!--    查看附件dialog：-->
    <!--    查看附件dialog：-->
    <el-dialog
      title="所有附件"
      :visible.sync="showFJ_box"
      :close-on-click-modal="false"
      @close="closeBox_fj"
      width="800px"
    >
      <div style="height: auto; padding: 10px 30px; text-align: center">
        <!--        <div v-for="item in allFJ" :key="item.id">-->
        <!--          <el-button type="text" @click="fjRow(item)">{{item.annexNameOld}}</el-button>-->
        <!--        </div>-->
        <!--        将图片和文件分开放：-->
        <!--        文件：-->
        <div style="border-bottom: 1px solid #f51818; padding-bottom: 5px; color: #f51818">图片</div>
        <div >
          <div v-for="item in allFJ[0]" style="overflow: hidden; width: 100px; height: 120px; display: inline-block; position: relative; border: 1px solid #1a9f17; margin: 5px" :title="item.annexNameOld" class="wrapOut" :key="item.id">
            <div style="">
              <img :src="action_prod + item.annexPath" :alt="item.annexNameOld" :title="item.annexNameOld" style="width: 100%">
              <!--              遮盖：-->
              <div class="wrap" @click="imgPreView(item)">
                <div style="float:left">
                  <el-button type="text" icon="el-icon-download" style="color:#fff;padding:0;" @click.stop="fjRow(item)">下载</el-button>
                </div>
                <div style="float:right">
                  <el-button
                    type="text"
                    icon="el-icon-delete"
                    style="color:#fff;padding:0;"
                    @click.stop="deletePng(item)"
                  >删除</el-button>
                </div>
              </div>
            </div>
            <div style="position:absolute; left: 0; bottom: 0; height: 20px; line-height: 20px; width: 100px; text-align: center; border-top: 1px solid #1a9f17; color: #1a9f17">{{item.annexNameOld}}</div>
          </div>
        </div>
        <div style="border-bottom: 1px solid #f51818; padding-bottom: 5px; color: #f51818">文件</div>
        <div style="text-align: center"></div>
        <div v-for="item in allFJ[1]" class="fileClass" :title="item.annexNameOld" :key="item.id">
          <el-button type="text" size="small" @click="fjRow(item)">{{item.annexNameOld}}</el-button>
          <i class="el-icon-delete del" @click="deletePng(item)"></i>
        </div>
      </div>
      <div slot="footer" class="dialog-footer">
        <el-button @click="showFJ_box = false" size="small" type="primary">关 闭</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { formatDate, isStartEndDate, getCookie} from "@/utils/util.js";
import { ajaxCtx, downloadFile } from '@/config/config.js';
  export default {
    name: 'examineManage',
    data () {
      return {
        editForm: { // drawer表单
          type:'',
          approvalContent:'',
          cause:'',
          approvalTime:'',
          memo:'',
          approvalManNo:[]
        },
        changedis:true,
        cheight: Number,
        fileUploadShow_file:false,
        formLabelWidth: '90px',
        loading: false, // drawer的loading
        editloading:false,
        showDrawer: false,
        showEdit:false,
        direction: 'rtl',
        searchForm: {
          operatetimeStart: '', // 开始时间
          operatetimeEnd: '' // 结束时间
        },
        checked:false,
        department:[],
        flileArr:[],
        upwidth: 0,
        ruleForm:{
        type: [{ required: true, message: "不能为空", trigger: "change" }],
        approvalManNo: [{ required: true, message: "不能为空", trigger: "change" }]
        },
        rule_editForm:{
        type:[{ required: true, message: "不能为空", trigger: "change" }],
        approvalManNo: [{ required: true, message: "不能为空", trigger: "change" }]
        },
        // actionUrl_prod: `${ajaxCtx}/file/upload`,
        // action_prod: downloadFile,
        actionUrl_prod: 'http://168.168.45.53:9003/v1/file/upload',
        action_prod: 'http://168.168.45.53:9003',
        token: { // touken值
          authorization: ''
        },
        subdisable: false,
        fileList_file: [],
        showFJ_box: false,
        allFJ: [],
        editapply:{},
        allCustomer: [], // 所有客户
        applyType:  [],
        approver:[],
        tableData_main: [],
        pageSize_main: 100,
        pageIndex_main: 1,
        total_main: 0,

        // 总计数
        theoryweightsum: '',
        factweightsum: '',
        theoryweightsum1: '',
        factweightsum1: '',
        approvals:[],
        objapprovals:{},
        tableLoading2: false, // 表格loading
        tableExportLoading: false, // 导出loading
        buttonLoading: false, // 入库确认loading
        tableData_dep: [],
        selectedData: [], // 已选中的数据
        selectedData1: [], // 从表已选中的数据
        pageSize_dep: 100,
        pageIndex_dep: 1,
        isFixed: 'left',
        tableTop: 0,
        tableBottom: 0,
        queryTopLoading: false, // 发货单tableLoading
        queryBotLoading: false, // 发货信息tableLoading
        icoreFilterFlag: true,
        total_fhxx: 0 // 发货信息合计条数
      }
    },
    created () {
      this.tableTop = window.innerHeight - 128;
      this.upwidth = window.innerHeight - 100
    },
    mounted () {
      this.searchForm.operatetimeStart = this.formatTime(new Date(new Date().setDate(1)));
      this.searchForm.operatetimeEnd = this.formatTime(new Date());
      this.editForm.approvalTime = this.formatTime(new Date());
      this.token = { // touken值
        authorization: 'Bearer ' + getCookie('accessToken')
      };
      // 默认查询一次：
      this.doQuery();
      //申请类型
      this.axios.post("/combaseinfos/getComBaseInfoDatas", {sortCode: "1060",baseName: ""}).then(response => {
        this.applyType = response.data.data;
      });
      //审批人
      this.axios.post("/combaseinfos/getComBaseInfoDatas", {sortCode: "1061",baseName: ""}).then(response => {
        this.approver = response.data.data;
      });
    },

    methods: {
      // drawer相关：
      handleClose (done) {
        if (this.flileArr.length > 0) {
          this.$confirm('检测到您已上传附件，此时关闭将放弃已上传的附件, 是否继续?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          this.flileArr = []
          done()
        }).catch(() => {
        });
        }else{
          done()
        }
      },
      // 格式化日期：
      formatTime (dt) {
        let year = dt.getFullYear().toString();
        let month = dt.getMonth() + 1;
        let day = dt.getDate();
        month = month < 10 ? '0' + month : month;
        day = day < 10 ? '0' + day : day;
        return `${year}-${month}-${day}`;
      },
      formatHour (dt) {
        let hour = dt.getHours();
        let minu = dt.getMinutes();
        let sec = dt.getSeconds();
        hour = hour < 10 ? '0' + hour : hour;
        minu = minu < 10 ? '0' + minu : minu;
        sec = sec < 10 ? '0' + sec : sec;
        return `${hour}:${minu}:${sec}`;
      },
      // 合计函数1：
      summary_fhxx ({columns, data}) {
        let allZd = ['diameter', 'shipmentsLength', 'pieceNumber', 'weight', 'shipmentsThick', 'shipmentsWidth'];
        let obj = {};
        allZd.forEach((itemOut) => {
          // 匹配索引:
          columns.forEach((itemIn, index) => {
            if (itemOut === itemIn.property) {
              obj[itemOut] = index;
            }
          })
        });
        const sums = [];
        sums[0] = '合计';
        sums[1] = `共${this.total_fhxx}条`;
        let sum = 0;
        let values, allStr;
        for (let key in obj) {
          values = data.map(item => item[key]);
          // 拿到列数据后：1.判断数据中是否存在有值为数字：
          allStr = values.every(item => isNaN(item));
          if (!allStr) {
            // 存在数据为数字
            sum = values.reduce((prev, current) => {
              if (!isNaN(current)) {
                // 为数字：
                return Number(prev) + Number(current);
              } else {
                return prev;
              }
            }, 0);
            sums[obj[key]] = sum.toFixed(3);
          }
        }
        return sums;
      },
      // ----------------------------------------
      // 发货单查询：
      doQuery () {
        this.pageIndex_main = 1;
        this.queryData();
      },
       // 图片预览：
      imgPreView (row) {
        var form = $('<form>'); // 定义一个form表单
        form.attr('id', 'downloadform');
        form.attr('style', 'display:none');
        form.attr('target', '_blank');
        form.attr('method', 'get');
        form.attr('action', this.action_prod + row.annexPath);
        var input1 = $('<input>');
        input1.attr('type', 'hidden');
        // input1.attr('name', 'param');
        // input1.attr('value', JSON.stringify(exportparams));
        form.append(input1);
        $('body').append(form); // 将表单放置在web中
        form.submit(); // 表单提交
        $('#downloadform').remove();
      },
      deleteupData(row,index){
        this.flileArr.splice(index,1)
      },
       // 附件删除：
      deletePng (row) {
        this.axios.post('/slmserviceobjannexs/deleteSlmServiceObjAnnexs', [row.id]).then(res => {
          // console.log(res, '删除返回!!!');
          this.$message.success(res.data.message);
          this.queryFJ(this.editapply);
        })
      },
        queryFJ (row) {
        let params = {
          objNo: row.approvalPk,
          objType: 'SlmAccraditation',
        };
        this.axios.post('/slmserviceobjannexs/getSlmServiceObjHeatPage', params).then(res => {
          console.log(res, 'res');
          if (res.data.code === '200') {
            // console.log(res, 'res');
            let data = res.data.data;
            let pngArr = [], fileArr = [];
            data.forEach(item => {
              item.isImage === '1' ? pngArr.push(item) : item.isImage === '2' ? fileArr.push(item) : '';
            })
            this.allFJ = [pngArr, fileArr];
          }
        })
      },
      // 附件点击：
      fjRow (row) {
        // var form = $('<form>'); // 定义一个form表单
        // form.attr('id', 'downloadform');
        // form.attr('style', 'display:none');
        // form.attr('target', '_blank');
        // form.attr('method', 'get');
        // form.attr('action', this.action_prod + row.annexPath);
        // var input1 = $('<input>');
        // input1.attr('type', 'hidden');
        // // input1.attr('name', 'param');
        // // input1.attr('value', JSON.stringify(exportparams));
        // form.append(input1);
        // $('body').append(form); // 将表单放置在web中
        // form.submit(); // 表单提交
        // $('#downloadform').remove();
        download(this.action_prod + row.annexPath, 'download.txt', 'text/plain', row.annexNameOld);
      },
       // 查看附件：
      showFJ (row) {
        this.showFJ_box = true;
        // console.log(row, '当前行data');
        this.queryFJ(row);
      },
      // 关闭附件dialog：
      closeBox_fj () {
        this.allFJ = [];
      },
      queryData () {
        this.queryTopLoading = true;
        let params = {
          'startTime': this.searchForm.operatetimeStart + ' 00:00:00',
          'endTime': this.searchForm.operatetimeEnd + ' 23:59:59'
        };
        this.axios.post('/slmaccraditations/getAccraditationPage', {'object': {},'startTime': params.startTime,'endTime': params.endTime, 'pageIndex': this.pageIndex_main, 'pageSize': this.pageSize_main}).then(res => {
          if (res.data.code === '200') {
            this.queryTopLoading = false;
            this.tableData_main = res.data.data.list;
            this.total_main = res.data.data.total;
          }
        }).catch(() => {
          this.queryTopLoading = false;
        })
      },
      // ====================================================
      // 上传文件：====================================================
      // 上传成功回调：
      handleSuccess_file (res, file, fileList) {
        if (res.code === '200') {
          this.$message.success('成功');
          // 保存：文件
          let params = {
            objNo: '',
            objType: 'SlmAccraditation',
            annexName: res.data[0].fileName,
            annexNameOld: res.data[0].oldFileName,
            annexPath: res.data[0].fileUrl,
            isImage: res.data[0].isImg
          };
          this.flileArr.push(params)
          this.fileUploadShow_file = false;
        }
      },
       // 关闭dialog：
      closeBox (name, ref) {
        console.log(name, 'name', ref);
        this.$refs[ref].clearFiles();
        this[name] = false;
      },
      // 手动点击上传：
      submitUpload_file () {
        if (!this.fileList_file.length) {
          this.$message.warning('请先选择文件');
          return false;
        }
        // this.fileList_file.forEach(item => {
        //   if (item.raw.type.indexOf('image') !== -1) {
        //     this.$message.warning('只能上传文件，不能上传图片');
        //     return false;
        //   }
        // })
        this.$refs.upload_file.submit();
      },
      beforeUpload_file (file) {
        // console.log(file, '上传之前：');
        // if (file.type.indexOf('image') !== -1) {
        //   this.$message.warning('只能上传文件，不能上传图片');
        //   return false;
        // }
      },
      handleRemove_file (file, fileList) {
        // console.log(file, fileList);
      },
      handlePreview_file (file) {
        // console.log(file);
      },
      handleExceed_file (files, fileList) {
        console.log(fileList, 'fileList');
        this.fileList_file = fileList;
        this.$message.warning(`当前限制选择 1 个文件，本次选择了 ${files.length} 个文件，共选择了 ${files.length + fileList.length} 个文件`);
      },
      change_file (file, fileList) {
        // console.log(fileList, 'fileList', file);
        if ((file.size / 1000 / 1000) > 20) {
          this.$message.error('上传的文件不能大于20MB!!!');
          this.$refs.upload_file.clearFiles();
          return;
        }
        this.fileList_file = fileList;
      },
      beforeRemove_file (file, fileList) {
        return this.$confirm(`确定移除 ${ file.name }？`);
      },
      doUploadAgain_file () {
        this.fileUploadShow_file = true;
      },
      addApply(){
        this.showDrawer = true
      },
       getmemo(code) {
        if (!code) {
          return '';
        }
        let targetRow = this.applyType.find(item => {
          return item.baseCode === code;
        });
        return targetRow ? targetRow.memo : '';
      },
      //审批的值改变
      valueChange(val){
        this.department = []
        this.changedis =true
        if (val) {
          let name = this.getCode(this.editForm.type, this.applyType, 'memo', 'baseName')
          this.axios.post('/slmaccraditations/queryAdministrative',{basename:name}).then(res => {
            if (res.data.code === 200 || res.data.code === '200') {
              this.changedis = res.data.data.length > 0 ? false : true
              this.department = res.data.data
            }
          }) 
        }     
      },
      //新增审核
      subapply(formName){
        this.$refs[formName].validate((valid) => {
          if (valid) {
           let typename = this.getCode(this.editForm.type, this.applyType, 'memo', 'baseName');
            this.loading = true
            let arr = []
            let tempApprovalManName = []
            this.editForm.approvalManNo.forEach(item =>{
              let tempobj = {}
              tempobj.copicdManName = this.getCode(item, this.approver, 'baseCode', 'baseName')
              tempobj.copicdManNo = item
              tempApprovalManName.push(tempobj.copicdManName)
              arr.push(tempobj)
              })
            let resetObj ={
                  type:'',
                  approvalContent:'',
                  cause:'',
                  approvalTime:this.formatTime(new Date()),
                  memo:'',
                  approvalManNo:[]
                }
            let tempObj = {
              typeName: typename,
              type: this.editForm.type,
              approvalContent: this.editForm.approvalContent,
              cause: this.editForm.cause,
              approvalTime: formatDate(this.editForm.approvalTime, "yyyy-MM-dd") + ' ' + this.formatHour(new Date()) ,
              memo: this.editForm.memo,
              list:arr,
              agent: tempApprovalManName.join(',')
            }
            let tempData = Object.assign(tempObj,{lso:this.flileArr})
            // this.axios.post("/api/addAccraditation", tempData).then(response => {
            //   if (response.data.code === '200' || response.data.code === 200) {
                // let subobj = Object.assign({approvalPk:response.data.data,status: "2"},tempObj)
                this.axios.post('/slmaccraditations/addAccraditation',tempObj).then(res => {
                if(res.data.code === '200') {
                  this.flileArr.forEach(item =>{
                    item.objNo = res.data.data
                  })
                  //附件与数据进行绑定保存
                  this.axios.post('/slmserviceobjannexs/addSlmServiceObjAnnexs', this.flileArr).then(res => {
                    if (res.data.code === '200') {
                      this.$message.success(res.data.message);
                    }
                  })
                  this.$message.success("提交审核成功");
                  this.$refs.upload_file.clearFiles();
                  this.flileArr = []
                  this.editForm = resetObj
                  this.loading = false
                  this.showDrawer = false
                  this.doQuery()
               }
              }).catch(() => {
                this.loading = false
             })
              }
            }).catch(err =>{
              this.loading = false
            });
        //   }
        // });
      },
      //选中修改审核数据
      changeapply(val){
        this.editapply = Object.assign({},val)
        this.$nextTick(() =>{
          if (this.$refs.scrowith.style.height == 0) {
            this.$refs.scrowith.style.height =  window.innerHeight - 100 + 'px'
          }
        })
        let temparr = []
        this.showEdit = true
        this.subdisable = this.editapply.status == 2 ? true : this.editapply.status == 3 ? true : false
        this.queryFJ(val)
        //获取抄送人
        this.axios.post('/slmaccraditations/getInfoById','approvalPk=' + this.editapply.approvalPk).then(res => {
            if (res.data.code === '200' || res.data.code === 200) {
              res.data.data.list.forEach(item =>{
                temparr.push(item.copicdManNo)
              })
              this.editapply.approvalManNo = temparr
            }
          }).catch(() => {
            this.editloading = false
            this.showEdit = false
          })
        //获取审批进度数据
        this.approvals = []
        this.axios.post('/api/queytation',{approvalPk:this.editapply.approvalPk}).then(res => {
            if (res.data.code === '200' || res.data.code === 200) {
              if (Array.isArray(res.data.data)) {
                this.approvals = res.data.data
              }else{
                let tempobj = res.data.data
                tempobj.Flag = 1
                this.approvals.push(tempobj)
              }
              
            }
          }).catch(() => {
            this.editloading = false
          })
      },
      //修改审核
      eapply(formName){
        this.$refs[formName].validate((valid) => {
          if (valid) {
            let typename = this.getCode(this.editapply.type, this.applyType, 'memo', 'baseName');
            this.editloading = true
            let arr = []
            let tempApprovalManName = []
            this.editapply.approvalManNo.forEach(item =>{
              let tempobj = {}
              tempobj.copicdManName = this.getCode(item, this.approver, 'baseCode', 'baseName')
              tempobj.copicdManNo = item
              tempApprovalManName.push(tempobj.copicdManName)
              arr.push(tempobj)
              })
            let tempObj = {
              typeName: typename,
              type: this.editapply.type,
              approvalContent: this.editapply.approvalContent,
              cause: this.editapply.cause,
              approvalTime: formatDate(this.editapply.approvalTime, "yyyy-MM-dd") + ' ' + this.formatHour(new Date()) ,
              memo: this.editapply.memo,
              list:arr,
              approvalPk:this.editapply.approvalPk,
              agent: tempApprovalManName.join(',')
            }
            this.axios.post('/slmaccraditations/updateAccraditation',tempObj).then(res => {
              if (res.data.code === '200') {
                //此处还需要修改
                this.flileArr.forEach(item =>{
                  item.objNo = this.editapply.approvalPk
                })
                this.axios.post('/slmserviceobjannexs/addSlmServiceObjAnnexs', this.flileArr).then(res => {
                  if (res.data.code === '200') {
                    this.$message.success(res.data.message);
                  }
                })
                this.$refs.upload_file.clearFiles();
                this.flileArr = []
                this.$message.success("修改成功");
                this.editloading = false
                this.doQuery()
              }
            }).catch(() => {
              this.editloading = false
            })
          }
        })
      },
      //提交审核
      subeapply(formName){
        this.$refs[formName].validate((valid) => {
          if (valid) {
            let typename = this.getCode(this.editapply.type, this.applyType, 'baseCode', 'baseName');
            let typememo = this.getmemo(this.editForm.type)
            this.editloading = true
            let arr = []
            let tempApprovalManName = []
            this.editapply.approvalManNo.forEach(item =>{
              let tempobj = {}
              tempobj.copicdManName = this.getCode(item, this.approver, 'baseCode', 'baseName')
              tempobj.copicdManNo = item
              tempApprovalManName.push(tempobj.copicdManName)
              arr.push(tempobj)
              })
            let tempObj = {
              typeName: typename,
              type: typememo,
              approvalContent: this.editapply.approvalContent,
              cause: this.editapply.cause,
              approvalTime: formatDate(this.editapply.approvalTime, "yyyy-MM-dd") + ' ' + this.formatHour(new Date()) ,
              memo: this.editapply.memo,
              list:arr,
              approvalPk:this.editapply.approvalPk,
              agent: tempApprovalManName.join(',')
            }
            this.axios.post('/slmaccraditations/addAccraditation',tempObj).then(res => {
              if (res.data.code === '200') {
                //此处还需要修改
                this.$refs.upload_file.clearFiles();
                this.flileArr = []
                this.$message.success("提交成功");
                this.editloading = false
                this.showEdit = false
                this.doQuery()
              }
            }).catch(() => {
              this.editloading = false
              this.showEdit = false
            })
          }
        })
      },
      //删除数据
      deleteApply(formName){
        this.$refs[formName].validate((valid) => {
          if (valid) {
              this.axios.post('/api/delAccraditation',this.editapply).then(res => {
              if (res.data.code === '200') {
                this.axios.post('/slmaccraditations/delAccad',{id:this.editapply.approvalPk}).then(res => {
                  if (res.data.code === '200') {
                    this.$refs.upload_file.clearFiles();
                    this.flileArr = []
                    this.$message.success("删除成功");
                    this.editloading = false
                    this.showEdit = false
                    this.doQuery()
                  }
                }).catch(() => {
                  this.editloading = false
                  this.showEdit = false
                })
              }
            }).catch(() => {
              this.editloading = false
            })
           
          }
        })
      },
      getCode (code, arr, codeKey, nameKey) {
        if (!code) {
          return '';
        }
        let targetRow = arr.find(item => {
          return item[codeKey] == code;
        });
        // console.log(targetRow, 'targetRow');
        return targetRow ? targetRow[nameKey] : '';
      },
      handleCurrentChangeMain (pageIndex) {
        this.pageIndex_main = pageIndex;
        this.queryData();
      },
      handleSizeChangeMain (pageSize) {
        this.pageIndex_main = 1;
        this.pageSize_main = pageSize;
        this.queryData();
      },
    },

  }
</script>
<!--yt-alc -->
<style scoped>
  .yt-alc{
    padding: 10px 20px;
  }
   .wrapOut {
    width: 100px; height: 100px; overflow: hidden;
  }
  .wrapOut:hover .wrap {
    display: block;
  }
  .wrap {
    display: none;
    width: 100%;
    height: 100%;
    color:#fff !important;
    position:absolute;
    left: 0;
    top: 0;
    background-color: rgba(0, 0, 0, .4);
  }
  .fileClass {
    overflow: hidden;
    width: 60%;
    border: 1px solid #ccc;
    margin: 5px auto;
    background-color: rgba(255, 250, 206, 0.41);
    border-radius: 10px;
    position: relative;
  }
  .del {
    display: none;
    color: rgba(255, 171, 82, 0.32);
    position: absolute;
    right: 12px;
    top: 8px;
    cursor: pointer;
  }
  .fileClass:hover .del {
    display: block;
    color: red;
  }
  .scro{
    overflow-y: auto;
  }
  .clearfix:after{
    content: '';
    display: block;
    visibility: hidden;
    height: 0;
    clear: both;
  }
  .clearfix{
    zoom: 1;
  }
  .box{
    position: relative;
    font-size: 14px;
    padding-bottom: 10px;
  }
  .line{
    position: absolute;
    left: 4px;
    height: 100%;
    border-left: 2px solid #e4e7ed;
  }
  .line_narmal{
    left: -1px;
    width: 12px;
    height: 12px;
    position: absolute;
    background-color: #409eff;
    border-radius: 50%;
    display: flex;
    justify-content: center;
    align-items: center;
  }
  .item_wrap{
    position: relative;
    padding-left: 28px;
    top: -3px;
  }
  .item_content{
    color: #303133;
  }
  .item_memo {
    color: #909399;
    line-height: 1;
    font-size: 13px;
  }
</style>
