<template>
  <div class="app-container">
    <!--工具栏-->
    <div class="head-container">
      <eHeader :permission="permission" />
    </div>
    <!--表格渲染-->
    <el-table ref="table" v-loading="crud.loading" :data="crud.data" style="width: 100%;" @selection-change="crud.selectionChangeHandler">
      <el-table-column prop="name" label="NAME" />
      <el-table-column prop="key" label="KEY" />
      <el-table-column prop="createTime" label="创建日期" />
      <el-table-column prop="lastUpdateTime" label="最后更新时间" />
      <!--   编辑与删除   -->
      <el-table-column
        v-if="checkPer(['admin','activiti:edit','activiti:del'])"
        label="操作"
        width="130px"
        align="center"
        fixed="right"
      >
        <template slot-scope="scope">
          <el-button-group>
            <el-button id="designBtn" size="mini" @click="toEditPage(scope.row.id)"> 设计 </el-button>
            <el-button id="deployBtn" size="mini" type="primary" @click="toDeploy(scope.row.id)"> 部署 </el-button>
            <el-button id="delBtn" size="mini" type="danger" @click="toDelete(scope.row.id)"> 删除 </el-button>
          </el-button-group>
        </template>

      </el-table-column>
    </el-table>
    <!--分页组件-->
    <pagination />
    <!--表单渲染-->
    <eForm />
    <!--弹窗-->
    <acticitiDialog
      :page-url.sync="activitiEditorUrl"
      :activiti-editor-visible.sync="activitiEditorVisible"
    />
  </div>
</template>

<script>
import crudActiviti from '@/api/activiti/activiti'
import eHeader from './module/header'
import eForm from './module/form'
import CRUD, { presenter } from '@crud/crud'
import pagination from '@crud/Pagination'
import acticitiDialog from './module/activiti-dialog'
import { Notification } from 'element-ui'
export default {
  name: 'Activiti',
  components: { eHeader, eForm, pagination, acticitiDialog },
  cruds() {
    return CRUD({
      title: '岗位',
      url: 'api/activiti/model/list',
      crudMethod: { ...crudActiviti }
    })
  },
  mixins: [presenter()],
  data() {
    return {
      permission: {
        add: ['admin', 'activiti:add'],
        edit: ['admin', 'activiti:edit'],
        del: ['admin', 'activiti:del']
      },
      activitiEditorVisible: false,
      activitiEditorUrl: ''
    }
  },
  methods: {
    ...crudActiviti,
    toEditPage(modelId) {
      this.activitiEditorVisible = true
      this.activitiEditorUrl = process.env.VUE_APP_BASE_API + '/static/modeler.html?modelId=' + modelId
    },
    toDeploy(modelId) {
      this.$confirm(`确认部署当前流程模型数据?`, '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.deploy(modelId).then(res => {
          Notification.success({
            title: '部署成功',
            duration: 5000
          })
          console.info('部署 res ==>> ' + res)
          // 刷新列表数据
          // this.refreshList();
        })
      })
    },
    toDelete(modelId) {
      this.$confirm(`确认删除当前流程模型数据?`, '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.del(modelId).then(res => {
          Notification.success({
            title: '删除成功',
            duration: 5000
          })
          console.info('删除 res ==>> ' + res)
          // 刷新列表数据
          this.refreshList()
        })
      })
    },
    refreshList() {
      console.log('重新刷新页面数据信息')
      this.crud.refresh()
    }
  }
}
</script>
<style rel="stylesheet/scss" lang="scss" scoped>
 ::v-deep .el-input-number .el-input__inner {
    text-align: left;
  }

 ::v-deep .el-dialog{
    margin-top: 10vh !important;
  }
</style>
