<template>
    <div style="overflow: auto;background-color: #FFFFFF;">
      <div class="row" v-for="(i,row) in defnames">
        <div :class="row.id === selectdata.actid ? 'item selectIndex' : 'item'" @click="getdefname(row)" >
          {{ row.defname }}
          <br>
          {{i === (defnames.length) - 1 ? row.sendtime : row.finishtime}}
        </div>
        <div class="arrow glyphicon glyphicon-menu-down" v-if="i !== defnames.length-1" aria-hidden="true"></div>
      </div>
    </div>
</template>

<script>
  import  {HttpResetClass} from 'vue-client'
  import {isEmpty} from '../../Util'
  export default {
    title: "流程节点",
    props:['selectdata'],
    data(){
      return{
        defnames: [] // 所有节点
      }
    },
    created () {
      this.initial()
    },
    methods :{
      async initial () {
        // 获取流程节点信息

        let data = {
          processid: this.selectdata.f_process_id
        }


        let res = await this.$resetpost(
          'rs/sql/getAllNode',
          {data: data},
          {resolveMsg: null, rejectMsg: '流程节点信息获取失败！！！'}
        )

        this.defnames = res.data
      },
      //点击获取节点名
      getdefname (row) {
        // 发起节点都可查看
        if(row.defname === this.$workflow_vue.start_activity){
          row = Object.assign({},this.selectdata,row)
          this.$dispatch('apply', row)
          return
        }
        if(this.check(row.actorexpression)){
          row = Object.assign({},this.selectdata,row)
          this.$dispatch('apply', row)
          return
        }
        this.$showMessage("对不起，您没有查看此节点的权限！")
      },
      // 检测是否有权限
      check (actorexpression){
        let str = null

        if (isEmpty(actorexpression)) {
          return true
        }
        return true
        if (actorexpression.indexOf('D') === 0) {
          str = actorexpression.substring(2, actorexpression.length-1)
          return this.$login.f.f_department_name.includes(str)
        }
        if (actorexpression.indexOf('RS') === 0) {
          for (str of actorexpression.substring(3, actorexpression.length-1).split(',')) {
            return this.$login.f.rolesnames.includes(str)
          }
        }

        if (actorexpression.indexOf('R') === 0) {
          str = actorexpression.substring(2, actorexpression.length-1)
          return this.$login.f.rolesnames.includes(str)
        }

        if (actorexpression.indexOf('PI') === 0) {
          str = actorexpression.substring(3, actorexpression.length-1)
          return this.$login.f.id.includes(str)
        }
        if (actorexpression.indexOf('P') === 0) {
          str = actorexpression.substring(2, actorexpression.length-1)
          return this.$login.f.name.includes(str)
        }

        return this.$login.f.rolesnames.includes('流程监控')
      }
    },
    watch:{
    }
  }
</script>

<style scoped>
.row{
  text-align: center;
  height: auto;
  margin-right: 20px;
}
.item{
  border-radius: 2em;
  border: 1px solid silver;
  line-height: 25px;
}
.arrow{
  width: 100%;
  color: #5ac0d9;
  font-weight: bold;
}
  .selectIndex{
    background-color: #5ac0d9;
    color: #ffffff;
  }
</style>
