<template>
  <div class="app-container">
    <el-row :gutter="10" class="mb8">

      <el-col :span="1.5">
        <el-form :model="queryParams" ref="queryForm" :inline="true" label-width="68px">
          <el-form-item label="名称" prop="mailTheme">
            <el-input
              v-model="queryParams.mailTheme"
              placeholder="请输入名称"
              clearable
              size="small"
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
          <el-form-item>
            <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
            <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
          </el-form-item>
        </el-form>
      </el-col>
    </el-row>
    <el-table border  :data="infoList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="序号" type="index" width="55" align="center"></el-table-column>
      <el-table-column label="流程名称" width="180" align="center" prop="taskName" >
      </el-table-column>
      <el-table-column label="标题" align="center" prop="title" />
      <el-table-column label="当前处理" width="180" align="center" prop="name"/>
      <el-table-column label="创建时间" width="180" align="center" prop="createTime" >
        <template slot-scope="scope">
          <span>{{scope.row.createTime | format('yyyy-MM-dd hh:mm')}}</span>
        </template>
      </el-table-column>
      <el-table-column label="办理时间" width="180" align="center" prop="endTime" >
        <template slot-scope="scope">
          <span>{{scope.row.endTime | format('yyyy-MM-dd hh:mm')}}</span>
        </template>
      </el-table-column>
      <el-table-column label="操作" width="200" align="center" class-name="small-padding fixed-width" >
        <template slot-scope="scope">
          <el-button
            size="small"
            type="text"
            icon="el-icon-edit"
            @click="openactform(scope.row.processDfinitionId,scope.row.businessKey)"
          >详情</el-button>
          <el-button
            size="small"
            type="text"
            icon="el-icon-share"
            @click="detail(scope.row)"
          >审批记录</el-button>
        </template>
      </el-table-column>
    </el-table>
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
    <el-dialog title="审批记录" :visible.sync="dialogVisible" width="1200px">

      <el-tabs :tab-position="tabPosition" style="min-height: 200px;">
        <el-tab-pane>
          <span slot="label"><i class="el-icon-date"></i> 审批记录</span>
          <img :src="picUrl">
        </el-tab-pane>
        <el-tab-pane>
          <span slot="label"><i class="el-icon-date"></i> 审批详细</span>
          <el-table border :data="historyExamine" @selection-change="handleSelectionChange">
            <el-table-column label="序号" type="index" width="50" align="center"></el-table-column>
            <el-table-column label="任务名称" width="100" align="center" prop="activityName"/>
            <el-table-column label="审批人员" width="180"align="center" prop="assigneeName"/>
            <el-table-column label="到达时间"  align="center" prop="startTime">
              <template slot-scope="scope">
                <span>{{scope.row.startTime | format('yyyy-MM-dd hh:mm')}}</span>
              </template>
            </el-table-column>
            <el-table-column label="审批时间"  align="center" prop="endTime">
              <template slot-scope="scope">
                <span>{{scope.row.endTime | format('yyyy-MM-dd hh:mm')}}</span>
              </template>
            </el-table-column>
            <el-table-column label="审批耗时" width="180" align="center" prop="activityType">
              <template slot-scope="scope">
                <span>{{scope.row.activityType }}</span>
              </template>
            </el-table-column>
            <el-table-column label="审批意见" width="180" align="center" prop="comment"/>
          </el-table>
          <!--          formatTotalDateSub()-->

        </el-tab-pane>
      </el-tabs>
      <span slot="footer" class="dialog-footer">
           <el-button @click="cancel">关 闭</el-button>
      </span>
    </el-dialog>
    <el-dialog id="actform" title="流程详情" :visible.sync="actOpen" :before-close="cancel" append-to-body width="80%"
               top="10" height="90%">
      <!-- 动态引入组件-->
      <component :is="actForm" :data="details":actOpen="actOpen" @getList="getList" ></component>
    </el-dialog>
  </div>
</template>

<script>
  import { havedInfo } from "@/api/activiti/form/fw";
  import { recordImg, examineHistory } from '@/api/system/meapply/meapply'
  import {getStartFormKey } from '@/api/activiti/process/startprocess'
  export default {
    name: 'havedone',
    data(){
      return {
        //流程遮罩层
        actOpen: false,
        //传入到下一页面的值
        details:{getactkey: '',
          formId:'',
        flg:'2'},
        actForm: null,
        // 遮罩层
        loading: true,
        // 选中数组
        ids: [],
        flgs: [],
        // 非单个禁用
        single: true,
        // 非多个禁用
        multiple: true,
        // 总条数
        total: 0,
        // 【请填写功能名称】表格数据
        infoList: [],
        // 弹出层标题
        title: "",
        // 是否显示弹出层
        open: false,
        // 查询参数
        queryParams: {
          pageNum: 1,
          pageSize: 10,
          orderByColumn: "createTime",
          isAsc:"desc",//排序方式
        },
        // 表单参数
        form: {},
        // 表单校验
        rules: {
        },
        picUrl: '',
        tabPosition: 'left',

        //弹窗
        dialogVisible:false,
        //审批历史
        historyExamine: [
          {
            activityName: '',
            assignee: '',
            assigneeName: '',
            comment: '',
            startTime: '',
            endTime: '',
            activityType: ''
          }

        ],
      };
    },
    created() {
      this.getList();
    },
    methods: {
      //通过流程key查询启动的表单fromkey
      openactform(actkey,id) {
        let vue = this
        actkey=actkey.split(":")[0];
        this.details.getactkey = actkey//动态传参到下面的页面
        this.details.formId = id//动态传参到下面的页面
        getStartFormKey(actkey).then(response => {
          var path = response.msg
          this.actForm = () => Promise.resolve().then(() => require(`@/views/${path}`))
        })
        this.actOpen = true
        return vue.actForm = this.actForm
      },
      detern(row){
        this.reset();
        const actkey = row.taskid || this.ids
        const form = row || this.form
        this.$router.push({path:'/actwork/havedone/havedetails',query: {bd:form,id:actkey }})
      },
      detail(row){
        this.dialogVisible = true
        //查看图片
        var formdata = new FormData
        formdata.append('pProcessInstanceId', row.processInstanceId)
        recordImg(formdata).then(response => {
          this.picUrl = window.URL.createObjectURL(response)
        })
        examineHistory(row.processInstanceId,row.businessKey).then(response => {
          this.historyExamine = response.rows;
          console.log(response.rows)
        })

      },


      /** 查询列表 */
      getList() {
        this.loading = true;
        havedInfo(this.queryParams).then(response => {
          this.infoList = response.rows;
          this.total = response.total;
          this.loading = false;
          this.actOpen=false;
        });
      },
      // 取消按钮
      cancel() {
        this.open = false;
        this.dialogVisible = false;
        this.actOpen = false;
        this.reset();
      },
      // 表单重置
      reset() {
        this.form = {
          mailGuid: undefined,
          senderName: undefined,
          senderAccount: undefined,
          receiverName: undefined,
          receiverAccount: undefined,
          mailTheme: undefined,
          mailContent: undefined,
          createTime: undefined,
          status: "0",
          deleteTime: undefined
        };
        this.resetForm("form");
      },
      /** 搜索按钮操作 */
      handleQuery() {
        this.queryParams.pageNum = 1;
        this.getList();
      },
      /** 重置按钮操作 */
      resetQuery() {
        this.resetForm("queryForm");
        this.handleQuery();
      },
      // 多选框选中数据
      handleSelectionChange(selection) {
        this.ids = selection.map(item => item.mailGuid)
        this.flgs = selection.map(item => item.flg)
        this.single = selection.length!=1
        this.multiple = !selection.length
      },
      /** 新增按钮操作 */
      handleAdd() {
        this.reset();
        this.open = true;
        this.title = "添加【请填写功能名称】";
      },
      /** 修改按钮操作 */
      handleUpdate(row) {
        this.reset();
        const mailGuid = row.mailGuid || this.ids
        getInfo(mailGuid).then(response => {
          this.form = response.data;
          this.open = true;
          this.title = "修改";
        });
      },
      handleUpdate1(row) {
        this.reset();
        const mailGuid = row.mailGuid || this.ids
        this.$router.push({path:'/email/draftList/draftinfo',query: {id:mailGuid }})
        getInfo(mailGuid).then(response => {
          this.form = response.data;
          // this.open = true;
          // this.title = "修改";
        });
      },
      /** 删除按钮操作 */
      handleDelete(row) {
        const mailGuids = row.mailGuid || this.ids;
        const flg = row.flg || this.ids;
        let len = flg.length;
        this.$confirm('是否确认删除这' + len + '封邮件?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return delInfo(mailGuids);
        }).then(() => {
          this.getList();
          this.msgSuccess("删除成功");
        }).catch(function() {});
      },
    }
  }
</script>

<style scoped>

</style>
