<style>
  .classinfo_Dialog .drawerTop {
    width: 100%;
    height: 50px;
    display: flex;
    justify-content: space-between;
    background-color: #F0F5FB;
    padding: 5px 10px;
    align-items: center;
  }

  .classinfo_Dialog .classFirst {
    color: #000000;
    font-weight: bold;
  }

  .classinfo_Dialog .className {
    margin-left: 10px;
  }

  .classinfo_Dialog .classStatus {
    padding: 3px 8px;
    background-color: #c8d7fc;
    color: #2961FE;
    font-size: 12px;
    border-radius: 2px;
    margin-left: 20px;
  }

  .classinfo_Dialog .normalName {
    color: #999999;
  }

  .classinfo_Dialog .normalInner {
    color: #111111;
  }

  .drop_NameDown {
    margin-top: 20px;
    width: 300px;
  }

  .processShenPi {
    position: relative;
    width: 92%;
    height: auto;
    margin: 0 20px 0 20px;
    background-color: #F7F7F7;
  }

  .processMain:first-child {
    margin-top: 20px;
  }

  .processPerson {
    position: absolute;
    width: 78px;
    height: 30px;
    left: 0;
    top: 0;
    background-color: #2961FE;
    color: #fff;
    text-align: center;
    line-height: 30px;
    font-weight: bold;
  }

  .processInner {
    padding: 20px;
    border-bottom: 1px solid #E2E2E2;
  }

  .process_Warm {
    color: #F93C1C;
    font-size: 12px;
  }

  .process_Warm i {
    font-size: 12px;
  }

  .process_Btn_List {
    display: flex;
    justify-content: flex-end;
    padding: 20px;
  }

  .processBtn_Cancel {
    width: 90px;
    height: 35px;
    border: 1px solid #A1AAB2;
    color: #000000;
    background-color: #fff;
    ;
    text-align: center;
    line-height: 35px;
    border-radius: 5px;
    cursor: pointer;
    margin-right: 20px;
  }

  .processBtn_Save {
    width: 90px;
    height: 35px;
    background-color: #2961FE;
    color: #FFF;
    text-align: center;
    line-height: 35px;
    border-radius: 5px;
    cursor: pointer;
  }

  .process_LineTwo {
    background-color: #fff;
    position: relative;
    display: flex;
    justify-content: center;
  }

  .process_InnerLine {
    width: 5px;
    height: 11px;
    position: absolute;
    background-color: #E9EFFF;
  }
  .process_InnerLineTwo{
    width: 5px;
    top:65px;
    height: 12px;
    position: absolute;
    background-color: #E9EFFF;
  }
  .processAddzhai {
    height: 50px;
    border: 1px dashed #2961FE !important;
    text-align: center;
    background-color: #fff;
    color: #2961FE;
    line-height: 50px;
    cursor: pointer;
    margin: 0 20px;
    border-radius: 5px !important;
  }
  .ProcessShanchu{
    position: absolute;
    right:10px;
    top:10px;
    color:red;
    cursor: pointer;
  }
</style>
<template>
  <q-dialog v-model="persistent" maximized full-height seamless position="right" @hide="closeProcess">
    <q-card style="margin-top:61px;width:500px" class="no-border-radius classinfo_Dialog">
      <div class="processMain" v-for="(aItem,aIndex) in saveObj.FlowNodeList[NodeIndex].FlowAduitList">
        <div class="processShenPi">
          <div class="processPerson">审批人{{aIndex+1}}</div>
          <div class="processInner">
            <div class="q-gutter-sm" style="padding-top:20px;">
              <q-radio left-label v-model="aItem.AuditType" :val="2" label="指定人员" />
              <q-radio left-label v-model="aItem.AuditType" :val="3" label="内置角色" />
            </div>
            <div style="margin:10px 0;">
              <q-select class="col-6 q-pb" v-if="aItem.AuditType==2" clearable filled stack-label use-input
                option-value="Id" option-label="EmployeeName" v-model="aItem.UserId" ref="ManagerId"
                :options="EmployeeList" label="指定人员名称" :dense="false" emit-value map-options @filter="filterFn"
                @input="changeType(aItem)">
                <template v-slot:no-option>
                  <q-item>
                    <q-item-section class="text-grey">
                      未找到相关数据
                    </q-item-section>
                  </q-item>
                </template>
              </q-select>
              <q-select class="col-6 q-pb" v-if="aItem.AuditType==3" clearable filled stack-label use-input
                option-value="Id" option-label="Name" v-model="aItem.PostType" ref="ManagerId" :options="roleList"
                label="选择角色" :dense="false" emit-value map-options @input="changeType(aItem)">
              </q-select>
            </div>
            <q-toggle
              v-if="saveObj.FlowNodeList[NodeIndex].FlowAduitList&&saveObj.FlowNodeList[NodeIndex].FlowAduitList.length>0 && aIndex==0"
              v-model="saveObj.FlowNodeList[NodeIndex].FlowAduitList[0].IsSpecNode" label="设定收损" left-label
              :true-value="1" :false-value="0"
              @input="changeSpecNode(saveObj.FlowNodeList[NodeIndex].FlowAduitList[0])" />
            <div class="process_Warm"
              v-if="saveObj.FlowNodeList[NodeIndex].FlowAduitList&&saveObj.FlowNodeList[NodeIndex].FlowAduitList.length>0 && aIndex==0">
              <i class="iconfont icon-jinggao"></i>
              只能由一个人开启，一旦开启其他关闭
            </div>
          </div>
          <i class="iconfont icon-shanchu ProcessShanchu" v-if="saveObj.FlowNodeList[NodeIndex].FlowAduitList&&saveObj.FlowNodeList[NodeIndex].FlowAduitList.length>0 && aIndex>0"
          @click="DelAduitInfo(aIndex)"></i>
        </div>
        <div class="process_LineTwo"
          v-if="saveObj.FlowNodeList[NodeIndex].FlowAduitList&&saveObj.FlowNodeList[NodeIndex].FlowAduitList.length>0"
          v-show="aIndex!=saveObj.FlowNodeList[NodeIndex].FlowAduitList.length-1">
          <div class="process_InnerLine"></div>
          <div style="width:100px;margin:10px 0">
            <q-select class="col=3 q-pb" filled stack-label option-value="Id" option-label="Name"
              v-model="saveObj.FlowNodeList[NodeIndex].FlowAduitList[0].AuditWay" :options="auditWayList" label=""
              :dense="false" emit-value map-options>
            </q-select>
          </div>
          <div class="process_InnerLineTwo"></div>
        </div>
        <!-- <a v-if="saveObj.FlowNodeList[NodeIndex].FlowAduitList&&saveObj.FlowNodeList[NodeIndex].FlowAduitList.length>0 && aIndex>0"
          @click="DelAduitInfo(aIndex)">删除</a> -->
      </div>
      <div class="processAddzhai" @click="AddAduitInfo">新增审核人</div>
      <div class="process_Btn_List">
        <div class="processBtn_Cancel" @click="closeProcess">关闭</div>
        <div class="processBtn_Save" @click="setBackClassFlow">保存</div>
      </div>
    </q-card>
    <div class="dialog-out-close" @click="closeProcess"
      style="height:40px !important;border-top-left-radius: 4px !important;border-bottom-left-radius: 4px !important;">
      <q-icon name="iconfont icon-jujue1" size="26px" />
    </div>
  </q-dialog>
</template>

<script>
  import {
    queryEmployee
  } from '../../api/users/user'
  import {
    saveBackClassFlow
  } from '../../api/system/index'
  export default {
    props: {
      saveObj: {
        type: Object,
        default: null
      },
      //当前选中的节点
      NodeIndex: {
        type: Number,
        default: 0,
      }
    },
    components: {},
    data() {
      return {
        persistent: true,
        AllemployeeList: [], //所有员工列表
        EmployeeList: [], //员工列表
        //固定角色列表
        roleList: [{
            Name: '班级老师',
            Id: 1
          }, {
            Name: '关联销售',
            Id: 2
          }, {
            Name: '分校校长',
            Id: 3
          },
          {
            Name: '教务长',
            Id: 4
          }
        ],
        //审核类型
        auditWayList: [{
          Name: '会签',
          Id: 2
        }, {
          Name: '或签',
          Id: 3
        }]
      }
    },
    created() {
      this.getEmployee();
    },
    mounted() {

    },
    methods: {
      changeSpecNode(item) {
        if (item.IsSpecNode == 1) {
          this.saveObj.FlowNodeList.forEach(item => {
            if (item.FlowAduitList && item.FlowAduitList.length) {
              item.FlowAduitList.forEach(subItem => {
                subItem.IsSpecNode = 0;
              })
            }
          })
          item.IsSpecNode = 1;
        }
      },
      //选择切换
      changeType(item) {
        //指定人员
        if (item.AuditType == 2) {
          var chooseUser = this.AllemployeeList.filter(v => v.Id == item.UserId);
          if (chooseUser && chooseUser.length > 0) {
            item.AduitName = chooseUser[0].EmployeeName;
            item.PostType = 0;
          }
        }
        //内置角色
        else if (item.AuditType == 3) {
          var chooseRole = this.roleList.filter(v => v.Id == item.PostType);
          if (chooseRole && chooseRole.length > 0) {
            item.AduitName = chooseRole[0].Name;
            item.UserId = 0;
          }
        }
      },
      //新增审核人
      AddAduitInfo() {
        this.saveObj.FlowNodeList[this.NodeIndex].FlowAduitList.push({
          CheckId: 0,
          FlowId: 0,
          AuditWay: 2,
          AuditType: 3,
          AduitName: "",
          IsSpecNode: 0,
          NodeId: 0,
          PostType: 0,
          UserId: 0,
        });
      },
      //删除审核人
      DelAduitInfo(index) {
        this.saveObj.FlowNodeList[this.NodeIndex].FlowAduitList.splice(index, 1);
      },
      //关闭流程设置
      closeProcess() {
        this.persistent = false;
        this.$emit('close');
      },
      //获取员工列表
      getEmployee() {
        var qMsg = {
          EmployeeName: ""
        }
        queryEmployee(qMsg).then(res => {
          if (res.Code == 1) {
            var jsonData = res.Data;
            if (jsonData && jsonData.length > 0) {
              this.AllemployeeList = JSON.parse(JSON.stringify(jsonData));
              this.EmployeeList = JSON.parse(JSON.stringify(jsonData));;
            }
          }
        })
      },
      //筛选员工
      filterFn(val, update) {
        update(() => {
          if (val === '') {
            this.EmployeeList = JSON.parse(JSON.stringify(this.AllemployeeList))
          } else {
            const needle = val.toLowerCase();
            this.EmployeeList = this.AllemployeeList.filter(v => v.EmployeeName.toLowerCase().indexOf(needle) > -1);
          }
        })
      },
      //保存退课流程
      setBackClassFlow() {
        saveBackClassFlow(this.saveObj).then(res => {
          if (res.Code == 1) {
            this.$q.notify({
              icon: 'iconfont icon-chenggong',
              color: 'accent',
              timeout: 2000,
              message: '操作成功',
              position: 'top'
            })
            this.$emit('success');
          }
        })
      }
    }
  }

</script>
