<template>
  <div class="app-container">

    <el-form :inline="true">

      <el-form-item label="标题">
        <el-input
          v-model="queryParams.title"
          placeholder="请输入标题"
          clearable
          size="small"
          style="width: 240px"
          @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 type="info" icon="el-icon-refresh-right" size="mini" @click="reList">清空</el-button>
      </el-form-item>
    </el-form>
    <el-table v-loading="loading" ref="multipleTable" :data="tableData" @selection-change="handleSelectionChange">
      <el-table-column
        type="selection"
        width="55">
      </el-table-column>
      <el-table-column label="序号" type="index" align="center">
        <template slot-scope="scope">
          <span>{{ (queryParams.pageNum-1) * queryParams.pageSize + (scope.$index + 1) }}</span>
        </template>
      </el-table-column>
      <el-table-column label="模型key" prop="modelKey"/>
      <el-table-column label="表单名称" prop="fName"/>
      <el-table-column label="创建时间" prop="createTime"/>
      <el-table-column label="操作" align="center">
          <template slot-scope="scope">
            <el-button
              size="mini" type="success"
              @click="showForms(scope.$index, scope.row)">查看
            </el-button>
            <el-button
              size="mini" type="warning"
              @click="showImage(scope.$index, 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="forms.title" :visible.sync="forms.open" width="1000px" >
      <!--历史表单组件-->
      <addEnterprise  ref="addEnterprise"/>
    </el-dialog>
    <el-dialog :title="activitiImg.title" :visible.sync="activitiImg.open" width="1000px">
      <el-image :src="activitiImg.src"></el-image>
    </el-dialog>

  </div>
</template>

<script>
  import { list ,delTitle } from '@/api/activiti/processedNew.js';
  //流程历史表单组件
  import  addEnterprise from "@/views/activiti/formsActiviti/index.vue";

  export default {
    //注册组件
    components:{
      addEnterprise
    },
    data: function() {
      return {
        instanceId:'',
        dialogVisible: false,
        //表格数据
        // 查询参数
        queryParams: {
          pageNum: 1,
          pageSize: 10
        },
        // 分页参数
        total: 0,
        pageNum: 1,
        pageSize: 10,
        tableData: [],
        //删除id
        multipleSelection: [],
        // 表单参数
        // 弹出层标题
        title: '',
        // 是否显示弹出层
        open: false,
        processKey: '',
        //部署文件下拉
        leaveSelect: [],
        // 表单数据
        formEntity: {
          fId: {},
          modelKey: {},
          modulId: {},
          fName: {},
          instanceId: {},
          fKey: {},
          fVersion: {},
          applyUser: {},
          jsonData: {}
        },
        //动态表单数据
        formObj: {
          // 表单数据
          formData: {},
          formDesc: {},
          rules: {}
        },
        forms:{
          title:'查看审核流程',
          open:false,
          data:[]
        },
        activitiImg:{
          title:'查看审核流程图',
          open:false,
          src:"",
        }
      }
    },

    // 初始化方法
    created() {
      //表格初始化
      this.getList()

    },
    methods: {
      handleSelectionChange(val) {
        this.multipleSelection = []
        for (let i = 0; i < val.length; i++) {
          this.multipleSelection[i] = val[i].id
        }
      },

      /** 查询角色列表 */
      getList() {
        this.loading = true
        list(this.addDateRange(this.queryParams)).then(
          response => {
            this.tableData = response.rows
            this.total = response.total
            this.loading = false
          }
        )
      }
      ,
      deleteTi() {
        this.$confirm('此操作将永久删除该文件, 是否继续?', '提示', {
          confirmButtonText: '确定 ',
          cancelButtonText: '取消 ',
          type: 'warning',
          center: true
        }).then(() => {
          let ids = this.multipleSelection
          if (ids.length === 0) {
            this.msgError('你没有选择文章')
            return
          }
          delTitle(ids)
          this.msgSuccess('成功')
          this.reIds()
          this.reList()
        }).catch(() => {
          this.msgSuccess('已取消删除')
        })
      }
      ,
      reIds() {
        this.multipleSelection = []
      }
      ,
      /** 搜索按钮操作 */
      handleQuery() {
        this.queryParams.pageNum = 1
        this.getList()
      }
      ,
      reList() {
        this.queryParams = {
          pageNum: 1,
          pageSize: 10
        }
        this.getList()
      },
      /*
      *显示流程表单
      * */
      showForms(index, row){
        this.forms.open = false
        this.forms.open = true
        this.forms.title = '查看审核流程'
        this.$nextTick(()=>{
          this.$refs.addEnterprise.showForms(row.instanceId)
        })
      },
      showImage(index, row) {
        let instanceId = row.instanceId
        let modelKey = row.modelKey
        let version = row.modelVersion
        instanceId = process.env.VUE_APP_BASE_URL + '/leaveNew/read-resource?processDefinitionKey=' + modelKey +'&version=' +version+ '&processInstanceId=' + instanceId+ '&t='+Math.random()
        this.activitiImg.open = true
        this.activitiImg.src = instanceId
      },
      /**
       * 新增或跟新表单数据
       */
      handleRequest(data) {
        return Promise.resolve()
      },
      handleRequestSuccess() {
        this.$message.success('发送成功')
        this.getList()
        this.open = false
      },
    }
  }
</script>
<style scoped>
  .activiti-image-class {
    width: auto;
  }
  .el-upload-list--picture-card .el-upload-list__item-actions span+span {
    margin-left: 0;
  }
  .el-upload-list__item-actions .el-icon-delete{
    display: none;
    width:0;
    height:0
  }
</style>
