<template>
  <div class="app-container">
    <div class="filter-container">
      <sticky style="margin-bottom: 10px;">
        <div class="sub-navbar">
          <el-button type="success" @click="batchSend">
            <svg-icon icon-class="send" />
            发 送
          </el-button>
          <el-button type="danger" icon="el-icon-delete" @click="deleteApply">
            删除申请
          </el-button>
          <el-button type="danger" icon="el-icon-refresh" @click="withdrawApply('0')">
            撤回申请
          </el-button>
        </div>
      </sticky>
      <el-form>
        <el-form-item>
          <el-input
            v-model="listQuery.baogaobianhao"
            placeholder="报告编号"
            clearable
            style="width: 200px"
            @keyup.enter.native="handleFilter"
          />
          <br>
          <span class="radio-group-label">操作类型：</span>
          <el-radio-group v-model="listQuery.renlingren" @change="handleFilter">
            <el-radio label="all">
              全部（查看）
            </el-radio>
            <el-radio :label="$store.getters.userId">
              可操作（功能）
            </el-radio>
            <el-radio label="withdraw">
              可撤回（功能）
            </el-radio>
            <el-radio label="end">
              已审批（查看）
            </el-radio>
          </el-radio-group>
          <el-button type="primary" icon="el-icon-search" @click="handleFilter">
            查询
          </el-button>
        </el-form-item>
      </el-form>
    </div>
    <el-table
      ref="list"
      :data="list"
      border
      highlight-current-row
      size="small"
      height="40rem"
      width="100%"
      @row-click="onRowClick"
      @selection-change="handleSelectionChange"
    >
      <el-table-column type="selection" fixed="left" width="50px;" />
      <el-table-column align="center" label="序号" type="index" fixed="left" width="50px;" />
      <el-table-column align="center" label="报告编号" fixed="left" prop="baogaobianhao" width="150px;" />
      <el-table-column align="center" label="状态" prop="status" width="180px;">
        <template slot-scope="scope">
          <el-tag v-if="scope.row.state=== '4'" type="success">
            检验中
          </el-tag>
          <el-tag v-if="scope.row.state=== '5'" type="danger">
            待质量师审核
          </el-tag>
          <el-tag v-if="scope.row.state=== '6'" type="danger">
            待业务面技术负责人审核
          </el-tag>
          <el-tag v-if="scope.row.state=== '7'" type="danger">
            待授权签字人审批
          </el-tag>
          <el-tag v-if="scope.row.state=== '8'" type="warning">
            已审批
          </el-tag>
        </template>
      </el-table-column>
      <el-table-column
        :formatter="formatter.getChineseName"
        align="center"
        label="检验员"
        prop="jianyanrenyuan"
        width="120px;"
      />
      <el-table-column align="center" label="检验员时间" prop="jianyanriqi" width="140px;" />
      <el-table-column
        :formatter="formatter.getChineseName"
        align="center"
        label="质量师"
        prop="zhijianrenyuan"
        width="120px;"
      />
      <el-table-column align="center" label="质量师审核时间" prop="zhijianriqi" width="140px;" />
      <el-table-column
        :formatter="formatter.getChineseName"
        align="center"
        label="业务面技术负责人"
        prop="jijianrenyuan"
        width="120px;"
      />
      <el-table-column align="center" label="业务面技术负责人时间" prop="jijianriqi" width="160px;" />
      <el-table-column
        :formatter="formatter.getChineseName"
        align="center"
        label="授权签字人"
        prop="shenpirenyuan"
        width="120px;"
      />
      <el-table-column align="center" label="授权签字人审批时间" prop="shenpiriqi" width="140px;" />
      <el-table-column align="center" label="驳回意见" prop="rejection" width="150px;" />
      <el-table-column align="center" label="操作" fixed="right" width="100px;">
        <template slot-scope="scope">
          <el-button v-if="scope.row.type === 3" type="danger" @click="showRestart(scope.row)">
            更正
          </el-button>
          <el-button v-else type="primary" @click="showRestart(scope.row)">
            详情
          </el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="totalCount>0"
      :total="totalCount"
      :page-num.sync="listQuery.pageNum"
      :page-row.sync="listQuery.pageSize"
      style="float: left;"
      @pagination="getList"
    />
    <!--签名窗口-->
    <el-dialog title="签名" :visible.sync="dialogFormVisible" @close="closeDialog">
      <div class="sub-navbar">
        <sticky>
          <el-button type="primary" @click="qianming">
            确 认
          </el-button>
          <el-button type="warning" icon="el-icon-refresh" @click="withdrawApply('1')">
            驳回申请
          </el-button>
        </sticky>
      </div>
      <el-form class="small-space" label-position="left" label-width="100px">
        <fieldset style="width: auto">
          <legend>{{ type === 1 ? '补充检验原因' : '报告、证书更改内容及原因' }}：</legend>
          <el-row :gutter="9">
            <el-input v-model="reason" type="textarea" :autosize="{ minRows: 4, maxRows: 4}" disabled />
          </el-row>
        </fieldset>
        <fieldset style="width: auto">
          <legend>意见</legend>
          <el-row :gutter="9">
            <el-input v-model="handleData.opinion" type="textarea" :autosize="{ minRows: 4, maxRows: 4}" />
          </el-row>
        </fieldset>
        <fieldset style="width: auto">
          <legend>签名</legend>
          <el-row :gutter="9">
            <el-col :span="12">
              <el-form-item label="签名密码">
                <el-input v-model="passForm.password" type="password" />
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="签名日期">
                <el-date-picker
                  v-model="handleData.qianmingriqi"
                  type="date"
                  placeholder="选择日期"
                  disabled
                />
              </el-form-item>
            </el-col>
          </el-row>
        </fieldset>
      </el-form>
    </el-dialog>
    <!-- 打开发送选择人员窗口 -->
    <el-dialog :visible.sync="dialogFormVisibleUser" title="下一环节处理人" @close="closeDialogUser">
      <el-table
        ref="flowUserList"
        :data="flowUserList"
        border
        fit
        highlight-current-row
        @row-click="onRowClickLink"
        @selection-change="handleSelectionChangeLink"
      >
        <el-table-column type="selection" width="40" />
        <el-table-column align="center" label="序号" width="60" type="index" />
        <el-table-column align="center" label="处理人" prop="nickname" min-width="40" />
      </el-table>
      <div slot="footer" class="dialog-footer">
        <el-button @click="dialogFormVisibleUser = false">
          取 消
        </el-button>
        <el-button type="success" @click="confirmSend">
          确认
        </el-button>
      </div>
    </el-dialog>
    <!--详情展示-->
    <el-dialog
      :visible.sync="dialogResetFlow"
      :title="resetData.type === 1 ? '补充检验审批记录' : '检验报告（证书）更改审批表'"
      @close="closeDialogResetFlow"
    >
      <el-form
        ref="resetData"
        :model="resetData"
        label-width="120px"
        size="small"
        inline
        style="height: 600px;overflow: auto;"
      >
        <fieldset style="width: auto">
          <legend>基本信息</legend>
          <el-form-item label="业务科室">
            <el-input v-model="departmentName" size="small" style="width: 250px;" type="text" disabled />
          </el-form-item>
          <el-form-item label="检验员">
            <el-input
              v-model="resetData.jianyanrenyuan"
              size="small"
              style="width: 250px;"
              type="text"
              disabled
            />
          </el-form-item>
          <el-form-item label="受检单位">
            <el-input v-model="zzdwName" size="small" style="width: 250px;" disabled />
          </el-form-item>
          <el-form-item label="设备型号">
            <el-input v-model="resetData.guigexinghao" size="small" style="width: 250px;" disabled />
          </el-form-item>
          <el-form-item label="报告编号">
            <el-input v-model="resetData.baogaobianhao" size="small" style="width: 250px;" disabled />
          </el-form-item>
          <el-form-item label="检验日期">
            <el-input v-model="resetData.jianyanjieshuriqi" size="small" style="width: 250px;" disabled />
          </el-form-item>
        </fieldset>
        <fieldset style="width: auto">
          <legend>{{ resetData.type === 1 ? '补充检验原因' : '报告、证书更改内容及原因' }}：</legend>
          <el-row>
            <el-input
              v-model="resetData.reason"
              type="textarea"
              :autosize="{ minRows: 4, maxRows: 4}"
              disabled
            />
          </el-row>
          <div style="margin: 20px 0;" />
          <el-row>
            <el-col :span="10" :offset="4">
              <el-form-item label="检验员：">
                <el-input
                  v-model="resetData.jianyanrenyuan"
                  style="width: 150px;"
                  type="text"
                  disabled
                />
              </el-form-item>
            </el-col>
            <el-col :span="10">
              <el-form-item label="日期：" prop="jianyanriqi">
                <el-date-picker
                  v-model="resetData.jianyanriqi"
                  type="date"
                  placeholder="选择日期"
                  disabled
                  style="width: 150px;"
                />
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="10" :offset="4">
              <el-form-item label="质量师：">
                <el-input
                  v-model="resetData.zhijianrenyuan"
                  style="width: 150px;"
                  type="text"
                  disabled
                />
              </el-form-item>
            </el-col>
            <el-col :span="10">
              <el-form-item label="日期：" prop="jianyanriqi">
                <el-date-picker
                  v-model="resetData.zhijianriqi"
                  type="date"
                  placeholder="选择日期"
                  disabled
                  style="width: 150px;"
                />
              </el-form-item>
            </el-col>
          </el-row>
        </fieldset>
        <fieldset style="width: auto">
          <div style="margin: 10px 0;" />
          <legend>审核意见：</legend>
          <el-row>
            <el-input
              v-model="resetData.opinion1"
              type="textarea"
              :autosize="{ minRows: 2, maxRows: 2}"
              disabled
            />
          </el-row>
          <div style="margin: 20px 0;" />
          <el-row>
            <el-col :span="10" :offset="4">
              <el-form-item label-width="140px" label="业务面技术负责人：">
                <el-input v-model="resetData.jijianrenyuan" style="width: 150px;" type="text" disabled />
              </el-form-item>
            </el-col>
            <el-col :span="10">
              <el-form-item label="日期：">
                <el-date-picker
                  v-model="resetData.jijianriqi"
                  type="date"
                  placeholder="选择日期"
                  style="width: 150px;"
                  disabled
                />
              </el-form-item>
            </el-col>
          </el-row>
        </fieldset>
        <fieldset style="width: auto">
          <legend>批准意见：</legend>
          <div style="margin: 10px 0;" />
          <el-row>
            <el-input
              v-model="resetData.opinion2"
              type="textarea"
              :autosize="{ minRows: 2, maxRows: 2}"
              disabled
            />
          </el-row>
          <div style="margin: 20px 0;" />
          <el-row>
            <el-col :span="10" :offset="4">
              <el-form-item label="授权签字人：">
                <el-input v-model="resetData.shenpirenyuan" style="width: 150px;" type="text" disabled />
              </el-form-item>
            </el-col>
            <el-col :span="10">
              <el-form-item label="日期：">
                <el-date-picker
                  v-model="resetData.shenpiriqi"
                  type="date"
                  placeholder="选择日期"
                  style="width: 150px;"
                  disabled
                />
              </el-form-item>
            </el-col>
          </el-row>
        </fieldset>
        <fieldset style="width: auto">
          <legend>备注：</legend>
          <div style="margin: 10px 0;" />
          <el-row>
            <el-input
              v-model="resetData.remarks"
              type="textarea"
              :autosize="{ minRows: 2, maxRows: 2}"
              disabled
            />
          </el-row>
        </fieldset>
      </el-form>
    </el-dialog>
    <!--第三种情况的详情展示-->
    <el-dialog :visible.sync="dialogReason" :modal-append-to-body="false" width="60%" title="更改原因或内容" @close="closeDialogReason">
      <div v-show="resetData.state !== '8'" class="sub-navbar">
        <sticky>
          <el-upload
            v-if="resetData.state === '4'"
            style="float: left; margin-right: 9px;"
            :show-file-list="false"
            :before-upload="uploadExcel0"
            accept="application/vnd.ms-excel"
            action="123"
          >
            <el-button type="warning" icon="el-icon-upload2" size="small">
              上传记录数据
            </el-button>
          </el-upload>
          <el-upload
            v-if="resetData.state === '4'"
            style="float: left; margin-right: 9px;"
            :show-file-list="false"
            :before-upload="uploadExcel1"
            accept="application/vnd.ms-excel"
            action="123"
          >
            <el-button type="warning" icon="el-icon-upload2" size="small">
              上传其他附件数据
            </el-button>
          </el-upload>
          <el-button v-show="resetData.state === '4'" size="small" icon="el-icon-download" type="primary" @click="downloadExcel(0)">
            导出记录数据
          </el-button>
          <el-button v-show="resetData.state === '4'" size="small" icon="el-icon-download" type="primary" @click="downloadExcel(1)">
            导出其他附件数据
          </el-button>
          <el-button type="success" size="small" icon="el-icon-view" @click="common.viewRestartApply(resetData.ysjlId, 'YSJL_RESTART')">
            预览记录
          </el-button>
          <el-button type="success" size="small" icon="el-icon-view" @click="common.viewRestartApply(resetData.ysjlId, 'OTHER_RESTART')">
            预览其他附件
          </el-button>
        </sticky>
      </div>
      <el-form
        ref="resetData"
        :model="resetData"
        label-width="120px"
        size="small"
        inline
        style="height: 600px;overflow: auto;"
      >
        <fieldset style="width: auto">
          <legend>基本信息</legend>
          <el-form-item label="业务科室">
            <el-input v-model="departmentName" size="small" style="width: 250px;" type="text" disabled />
          </el-form-item>
          <el-form-item label="检验员">
            <el-input
              v-model="resetData.jianyanrenyuan"
              size="small"
              style="width: 250px;"
              type="text"
              disabled
            />
          </el-form-item>
          <el-form-item label="受检单位">
            <el-input v-model="zzdwName" size="small" style="width: 250px;" disabled />
          </el-form-item>
          <el-form-item label="设备型号">
            <el-input v-model="resetData.guigexinghao" size="small" style="width: 250px;" disabled />
          </el-form-item>
          <el-form-item label="报告编号">
            <el-input v-model="resetData.baogaobianhao" size="small" style="width: 250px;" disabled />
          </el-form-item>
          <el-form-item label="检验日期">
            <el-input v-model="resetData.jianyanjieshuriqi" size="small" style="width: 250px;" disabled />
          </el-form-item>
        </fieldset>
        <fieldset style="width: auto">
          <legend>更改原因或内容：</legend>
          <el-row>
            <el-input
              v-model="resetData.reason"
              type="textarea"
              :autosize="{ minRows: 4, maxRows: 4}"
              disabled
            />
          </el-row>
          <div style="margin: 20px 0;" />
          <el-row>
            <el-col :span="10" :offset="4">
              <el-form-item label="检验员：">
                <el-input
                  v-model="resetData.jianyanrenyuan"
                  style="width: 150px;"
                  type="text"
                  disabled
                />
              </el-form-item>
            </el-col>
            <el-col :span="10">
              <el-form-item label="日期：" prop="jianyanriqi">
                <el-date-picker
                  v-model="resetData.jianyanriqi"
                  type="date"
                  placeholder="选择日期"
                  disabled
                  style="width: 150px;"
                />
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="10" :offset="4">
              <el-form-item label="质量师：">
                <el-input
                  v-model="resetData.zhijianrenyuan"
                  style="width: 150px;"
                  type="text"
                  disabled
                />
              </el-form-item>
            </el-col>
            <el-col :span="10">
              <el-form-item label="日期：" prop="jianyanriqi">
                <el-date-picker
                  v-model="resetData.zhijianriqi"
                  type="date"
                  placeholder="选择日期"
                  disabled
                  style="width: 150px;"
                />
              </el-form-item>
            </el-col>
          </el-row>
        </fieldset>
      </el-form>
    </el-dialog>
  </div>
</template>
<script>
import Sticky from '@/components/Sticky'
import Pagination from '@/components/Pagination'

export default {
  name: 'FlowRestart',
  components: { Sticky, Pagination },
  data() {
    return {
      totalCount: 0, // 分页组件--数据总条数
      list: [], // 表格的数据
      listQuery: {
        pageNum: 1, // 页码
        pageSize: 20, // 每页条数
        orderBy: 'id desc',
        status: 1,
        renlingren: this.$store.getters.userId
      },
      multipleSelection: [],
      handleData: {
        userId: '',
        opinion: '同意。',
        qianmingriqi: this.formatter.dateFormat('YYYY-MM-dd', new Date()),
        renlingren: '',
        rpIds: []
      },
      passForm: {},
      resetData: {},
      ysjl: {},
      reason: '',
      flowUserList: [],
      inspectors: [],
      dialogFormVisible: false,
      dialogFormVisibleUser: false,
      dialogResetFlow: false,
      dialogReason: false,
      multipleSelectionLink: [],
      isShow: this.notHasRole('RQZZJYY'),
      departmentName: '',
      zzdwName: '',
      type: ''
    }
  },
  created() {
    this.getList()
    this.getInspectorsList()
  },
  mounted() {
    const that = this
    this.common.$on('restartProcess-list', function() {
      that.getList()
    })
  },
  methods: {
    getList() {
      // 查询列表
      this.api({
        url: '/restartProcess/list',
        method: 'get',
        params: this.listQuery
      }).then(data => {
        this.list = data.list
        this.totalCount = data.total
      })
    },
    withdrawApply(item) {
      if (item === '0' && this.listQuery.renlingren !== 'withdraw') {
        this.$message('无权限撤回！')
        return false
      }
      if (item === '1' && this.listQuery.renlingren !== this.$store.getters.userId) {
        this.$message('无权限驳回！')
        return false
      }
      let name = '撤回'
      let rejection = null
      if (item === '1') {
        name = '驳回'
        rejection = this.handleData.opinion
      }
      if (this.multipleSelection.length === 0) {
        if (item === '0') {
          this.$message({ type: 'error', message: '请选择需要撤回的申请！' })
        } else {
          this.$message({ type: 'error', message: '请选择需要驳回的申请！' })
        }
        return false
      } else {
        this.$confirm('确定' + name + '当前选中申请?', '提示', {
          confirmButtonText: '确定',
          showCancelButton: true,
          type: 'warning'
        }).then(() => {
          if (this.ifBooleanWithdraw(item)) {
            if (item === '0') {
              if (this.listQuery.renlingren !== 'withdraw') {
                this.$message({ type: 'error', message: '当前申请尚未发送，无法撤回！' })
              } else {
                this.$message({ type: 'error', message: '当前申请已审批状态，无法撤回！' })
              }
              return false
            } else {
              if (this.listQuery.renlingren === 'withdraw') {
                this.$message({ type: 'error', message: '当前申请已发送，无法驳回！' })
              } else {
                this.$message({ type: 'error', message: '当前申请尚未进入流转状态，无法驳回！' })
              }
              return false
            }
          } else {
            const ids = []
            const qs = require('qs')
            this.multipleSelection.forEach(data => {
              ids.push(data.id)
            })
            this.api({
              url: '/restartProcess/withdraw',
              method: 'post',
              params: { ids: ids, type: item, rejection: rejection },
              paramsSerializer: function(params) {
                return qs.stringify(params, { indices: false })
              }
            }).then(() => {
              this.$message.success(name + '成功！')
              if (item === '1') {
                this.dialogFormVisible = false
              }
              this.getList()
            })
          }
        })
      }
    },
    reject() {

    },
    deleteApply() {
      if (this.multipleSelection.length === 0) {
        this.$message({ type: 'error', message: '请选择需要删除的申请！' })
        return false
      } else {
        this.$confirm('确定删除当前选中申请?', '提示', {
          confirmButtonText: '确定',
          showCancelButton: true,
          type: 'warning'
        }).then(() => {
          const ids = []
          const qs = require('qs')
          this.multipleSelection.forEach(data => {
            ids.push(data.id)
          })
          if (this.ifBoolean()) {
            this.$message({ type: 'error', message: '申请已发送其他流转状态，无法删除！' })
            return false
          } else {
            this.api({
              url: '/restartProcess/delete',
              method: 'delete',
              params: { ids: ids },
              paramsSerializer: function(params) {
                return qs.stringify(params, { indices: false })
              }
            }).then(() => {
              this.$message.success('删除成功！')
              this.getList()
            })
          }
        })
      }
    },
    ifBoolean() {
      let bol = false
      this.multipleSelection.forEach(data => {
        if (data.state !== '4') {
          bol = true
        }
      })
      return bol
    },
    ifBooleanWithdraw(item) {
      let bol = false
      this.multipleSelection.forEach(ms => {
        if (item === '0') { // 撤回
          if (this.listQuery.renlingren !== 'withdraw' || ms.renlingren === this.$store.getters.userId + '' || ms.state === '4') {
            bol = true
          }
        } else { // 驳回
          if (this.listQuery.renlingren === 'withdraw' || ms.renlingren !== this.$store.getters.userId + '' || ms.state === '4') {
            bol = true
          }
        }
      })
      return bol
    },
    batchSend() {
      if (this.listQuery.renlingren !== this.$store.getters.userId) {
        this.$message('无权限发送！')
        return false
      }
      if (this.multipleSelection.length === 0) {
        this.$message('请在列表选择要发送的申请。')
        return false
      }
      if (this.multipleSelection.length > 1) {
        this.$message({ message: '请选择单条要发送的申请!' })
        return false
      }
      if (this.multipleSelection[0].state === '8') {
        this.$message({ type: 'error', message: '存在已完成重启审批报告!' })
        return false
      }
      this.handleData.rpIds.push(this.multipleSelection[0].id)
      this.reason = this.multipleSelection[0].reason
      this.type = this.multipleSelection[0].type
      let isfasong = true
      if (this.multipleSelection[0].state === '4') {
        isfasong = false
      }
      if (isfasong) {
        this.dialogFormVisible = true
      } else {
        this.fasong(this.multipleSelection[0].ysjlId, this.multipleSelection[0].state, this.multipleSelection[0].type)
      }
    },
    qianming() {
      if (!this.passForm.password || this.passForm.password === '') {
        this.$message({ type: 'error', message: '未输入签名密码！' })
        return false
      }
      this.api({
        url: '/user/validationPwd',
        method: 'post',
        data: {
          id: this.$store.getters.userId,
          signPassword: this.passForm.password
        }
      }).then(() => {
        this.$message({
          type: 'success',
          message: '签名成功!'
        })
        this.handleData.userId = this.$store.getters.userId
        this.dialogFormVisible = false
        this.fasong(this.multipleSelection[0].ysjlId, this.multipleSelection[0].state, this.multipleSelection[0].type)
      })
    },
    fasong(ysjlId, state, type) {
      this.api({
        url: '/flow/getUserRestart',
        method: 'get',
        params: {
          id: ysjlId,
          flowstatus: state,
          bglx: '4'
        }
      }).then(data => {
        if (type === 3) {
          if (state === '5') {
            // 办结
            this.handleData.state = '8'
            this.end(ysjlId, true)
          } else if (data.length > 0) {
            this.flowUserList = data
            this.dialogFormVisibleUser = true
          }
        } else {
          if (data.length > 0) {
            this.flowUserList = data
            this.dialogFormVisibleUser = true
          } else {
            // 办结
            this.handleData.state = '8'
            this.end()
          }
        }
      })
    },
    confirmSend() {
      if (this.multipleSelectionLink.length !== 1) {
        this.$message('只能选择单人处理下一环节。')
        return false
      }
      this.handleData.renlingren = this.multipleSelectionLink[0].userId
      this.handleData.state = this.multipleSelectionLink[0].nextValue
      this.api({
        url: '/restartProcess/update',
        method: 'post',
        data: this.handleData
      }).then(() => {
        this.dialogFormVisibleUser = false
        this.$message.success('发送成功。')
        this.getList()
      })
    },
    /**
     *  办结
     * @param ysjlId  原始记录主键
     * @param ifEnd 是否重新生成预览文件
     */
    end(ysjlId, ifEnd) {
      this.$confirm('确定办结当前选中报告?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.api({
          url: '/restartProcess/update',
          method: 'post',
          data: this.handleData
        }).then(() => {
          this.$message.success('已办结')
          if (ysjlId && ifEnd) {
            this.preview({
              url: '/print/batchGeneratePDF',
              method: 'post',
              data: {
                ids: ysjlId,
                generateType: 'END'
              }
            })
          }
          this.getList()
        })
      })
    },
    //  导出数据文件
    downloadExcel(type) {
      this.preview({
        url: '/download/downloadRestartApplyData',
        method: 'get',
        params: { ysjlId: this.resetData.ysjlId, type: type }
      }).then(data => {
        console.log(data)
        if (data) {
          window.open(data)
        } else {
          this.$message.error('暂无上传文件！')
        }
      })
    },
    uploadExcel0(file) {
      const isExcel = file.type === 'application/vnd.ms-excel' || file.type === 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'
      if (!isExcel) {
        this.$notify.error('只能上传xls/xlsx格式的文件')
        return false
      }
      const fd = new FormData()
      fd.append('file', file)
      fd.append('type', 0)
      fd.append('ysjlId', this.resetData.ysjlId)
      this.uploadData(fd)
    },
    uploadExcel1(file) {
      const isExcel = file.type === 'application/vnd.ms-excel' || file.type === 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'
      if (!isExcel) {
        this.$notify.error('只能上传xls/xlsx格式的文件')
        return false
      }
      const fd = new FormData()
      fd.append('file', file)
      fd.append('type', 1)
      fd.append('ysjlId', this.resetData.ysjlId)
      this.uploadData(fd)
    },
    //  上传数据文件
    uploadData(fd) {
      this.preview({
        method: 'post',
        url: '/upload/uploadRestartApply',
        data: fd
      }).then(() => {
        this.$message.success('上传成功！')
      })
    },
    onRowClickLink(row) {
      this.$refs.flowUserList.toggleRowSelection(row)
    },
    handleSelectionChangeLink: function(val) {
      this.multipleSelectionLink = val
    },
    showRestart(restart) {
      this.resetData = restart
      this.getDepartmentNameById(this.resetData.departmentId)
      this.getZzdwNameById(this.resetData.zzdwId)
      this.resetData.jianyanrenyuan = this.formatter.getChineseName(null, null, restart.jianyanrenyuan)
      this.resetData.zhijianrenyuan = this.formatter.getChineseName(null, null, restart.zhijianrenyuan)
      this.resetData.jijianrenyuan = this.formatter.getChineseName(null, null, restart.jijianrenyuan)
      this.resetData.shenpirenyuan = this.formatter.getChineseName(null, null, restart.shenpirenyuan)
      if (restart.type === 3) {
        this.dialogReason = true
      } else {
        this.dialogResetFlow = true
      }
    },
    // 获得检验科室名称
    getDepartmentNameById(departmentId) {
      this.api({
        url: '/department',
        method: 'get',
        params: { depId: departmentId }
      }).then(data => {
        this.departmentName = data.name
      })
    },
    // 获得单位名称
    getZzdwNameById(zzdwId) {
      this.api({
        url: '/dwxx/getById',
        method: 'get',
        params: { id: zzdwId }
      }).then(data => {
        this.zzdwName = data.zhizaodanwei
      })
    },
    getInspectorsList() {
      this.api({
        url: '/user/getUserListByAdminIsNull',
        method: 'get',
        params: {}
      }).then(data => {
        this.inspectors = data
      })
    },
    // 查询事件
    handleFilter() {
      this.listQuery.pageNum = 1
      this.getList()
    },
    onRowClick(row) {
      this.$refs.list.toggleRowSelection(row)
    },
    handleSelectionChange: function(val) {
      this.multipleSelection = val
    },
    closeDialog() {
      this.dialogFormVisible = false
    },
    closeDialogUser() {
      this.dialogFormVisibleUser = false
    },
    closeDialogResetFlow() {
      this.dialogResetFlow = false
    },
    closeDialogReason() {
      this.dialogReason = false
    }
  }
}
</script>
