FlowNodeUserConfig.vue 4.89 KB
<template>
   <div style="margin-top: -8px;" class="flow-node-user-config">
     <div class="label-title">
       {{title}}({{nodeId}})
       <el-button  icon="el-icon-circle-plus-outline" @click="setNodeUser()" type="text">新增</el-button>
      </div>
      <div class="alert-danger alert" v-if="!nodeUsers||nodeUsers.length==0">&nbsp;&nbsp;尚未配置节点人员,请添加人员设置</div>
      <div v-for="(nodeCondition,$index) in nodeUsers" :key="$index" class="alert">
        <div>
          <el-tooltip
            v-if="$index === 0"
            class="item"
            effect="dark"
            content="批次顺序由上至下增大,第一批次无法获取到审批人时才会获取下一个批次审批人信息。"
            placement="left"
          >
            <span class="control-label left-label">
              <i class="el-icon-warning"></i>
            </span>
          </el-tooltip>

           {{nodeCondition.description}}
        </div>
        <div>
          <el-button  icon="el-icon-edit-outline" @click="setNodeUser($index)" circle></el-button>
          <el-button  icon="el-icon-arrow-up" @click="ArrayTool(nodeUsers,$index,'up')" circle></el-button>
          <el-button  icon="el-icon-arrow-down" @click="ArrayTool(nodeUsers,$index)" circle></el-button>
          <el-button  icon="el-icon-delete" @click="nodeUsers.remove(nodeUsers[$index])" circle></el-button>
        </div>
      </div>
    <FlowNodeUserCondition @nodeUserConditionConfirm="nodeUserConditionConfirm" ref="flowNodeUserCondition" />
   </div>
</template>

<script>
import flow from "@/api/flow.js";
import req from "@/request.js";
import { mapState, mapActions } from "vuex"; 
const FlowNodeUserCondition = () => import("@/components/flow/FlowNodeUserCondition.vue");
import utils from "@/hotent-ui-util.js"
export default {
  props: ["defId","title",'nodeId','defkey'],
  components: {FlowNodeUserCondition },
  data() {
    return {
        nodeUsers:[],
        curSetIndex:'-1'
    };
  },
  computed: mapState({
    defConfigData:state => state.flow.defConfigData
  }),
  watch: {
    nodeUsers: {
      handler(newValue, oldValue) {
        let path = 'nodeSetData.nodeUserMap.'+this.nodeId;
        let obj = {};
        obj[path] = newValue;
        if (newValue) {
          for (let index = 0; index < newValue.length; index++) {
            newValue[index].groupNo = index+1;
          }
        }
    this.$store.dispatch("flow/updateConfig",obj);
    },
      deep: true 
  }
  },
  methods: {
    dialogCancel(){

    },
    nodeUserConditionConfirm(res){
      if(res.calcs){
        if (this.curSetIndex !='-1') {
            this.nodeUsers.splice(this.curSetIndex,1,res);
        } else {
          this.nodeUsers.push(res);
       }
      }
    },
    ArrayTool(ary,idx,direct){
      direct = direct || "down";
      let part = ary[idx];
      if (!part || (part.constructor !== Object && part.constructor !== Array)) {
          return ary;
      }
      if (part.constructor === Object) {
          part = [part];
      }
      if (direct == "up") {
          part.forEach(m => {
              let index = ary.indexOf(m, 1);
              if (index > 0) {
                  let t=ary[index-1];
                  ary.splice(index - 1,1,ary[index]);
                  ary.splice(index,1,t);  
              }
          });
      } else if (direct == "down") {
          for (var i = part.length - 1, m; (m = part[i--]);) {
              let index = ary.indexOf(m, 0);
              if (index > -1 && index < ary.length - 1) {
                  let t=ary[index+1];
                  ary.splice(index + 1,1,ary[index]);
                  ary.splice(index,1,t);
              }
          }
      }
    },
    setNodeUser(index){
      let conf ={nodeId:this.nodeId};
      if (index || index ===0 ) {
         this.curSetIndex = index;
          conf.userRule = JSON.parse(JSON.stringify(this.nodeUsers[index]));
      }else{
        this.curSetIndex = -1;
      }
      this.$refs.flowNodeUserCondition.showDialog(conf);
    },
  },
  created() {
    this.utils = utils;
    if(this.defConfigData.nodeSetData.nodeUserMap && this.defConfigData.nodeSetData.nodeUserMap[this.nodeId]){
       this.nodeUsers = JSON.parse(JSON.stringify(this.defConfigData.nodeSetData.nodeUserMap[this.nodeId]));
    }
 }
};
</script>

<style lang="scss" scoped>
.flow-node-user-config {
  .label-title {
    color: #333;
    font-weight: bold;
    font-size: 14px;
    margin-bottom: 10px;
    button {
      margin-left: 8px;
    }
  }
}
.alert {
    display: flex;
    align-items: center;
    justify-content: space-between;
    color: #409EFF;
    background-color: #F6F6F6;
    padding: 10px;
    margin-bottom: 5px;
    border-radius: 2px;
    width: 100%;
}

.alert-danger {
    color: #a94442;
    background-color: #f2dede;
    border-color: #ebccd1;
}

.alert ::v-deep .el-button {
  padding: 6px 8px;
  margin-left:0px;
  margin-right:5px;
}

</style>