<!--实验中心人员配置-添加-->
<template>
  <div class="addPage">
    <div class="addPage_title">
      <p>实验中心人员配置</p>
      <p class="inquire-button-one" style="width:120px;" @click="submitForm">提交</p>
      <p  class="reset-button-one" @click="backPage">返回</p>
    </div>
    <div style="margin: 20px">
      <el-form :model="form" ref="drawerForm" label-position="left" label-width="60px">
        <el-form-item label="姓名" prop="subjectId"  >
          <el-select
            style="width:300px;"
            v-model="form.userId"
            filterable
            remote
            reserve-keyword
            @change="selectChange"
            placeholder="请输入姓名关键词"
            :remote-method="userSelectList"
            :loading="loading">
            <el-option
              v-for="item in laboratoryOptions"
              :key="item.userId"
              :label="item.nickName"
              :value="item.userId">
            </el-option>
          </el-select>
        </el-form-item>
      </el-form>
      <div style="margin-left: 60px">
        <el-tag
          style="margin-right: 10px"
          :key="tag"
          v-for="tag in dynamicTags"
          closable
          :disable-transitions="false"
          @close="handleClose(tag)">
          {{tag}}
        </el-tag>
      </div>
    </div>



  </div>
</template>
<script>

import { getToken } from "@/utils/auth";
import {
  labCenterPersonAdd,
  selectUserListByName,
  storageInfoDetail,
} from '@/api/gasManage3_0/gasManage'

export default {
  name: "addPage",
  props:{
    pageData2: {},
  },
  data() {
    return {
      pageType:1,
      headers: {
        Authorization: "Bearer " + getToken(),
      },
      loading:false,
      form:{
        flowDetailList:[],
      },
      laboratoryOptions:[],
      flowDetailList:[],
      dynamicTags: [],
    };
  },
  methods: {
    handleClose(tag) {
      let _this=this;
      _this.dynamicTags.splice(this.dynamicTags.indexOf(tag), 1);
      _this.flowDetailList.forEach(function(item){
          if(tag==item.userName){
            _this.flowDetailList.splice(item, 1);
          }
      })
    },
    //实验室选择
    selectChange(e){
      let _this = this;
      console.log(e)
      for(let i=0;i<_this.laboratoryOptions.length;i++){
        if(_this.laboratoryOptions[i].userId == e){
          console.log(_this.laboratoryOptions[i].nickName)
          _this.dynamicTags.push(_this.laboratoryOptions[i].nickName);
          let item=_this.laboratoryOptions[i]
          _this.flowDetailList.push({'userNumber':item.userName,'userIds':item.userId,'userName':item.nickName,'userTelephone':item.phonenumber,'deptIds':item.deptId,'deptNames':item. deptName,})
        }
      }
    },
    //懒加载
    userSelectList(e){
      selectUserListByName({nickName:e,userType:11}).then(response => {
        this.laboratoryOptions = response.data;
      });
    },
    handleClick(index,row,doType){
      let _this=this;
      if(doType=='again'){//重新申请
        this.$parent.handleClick('','','again');
      }
    },    //提交
    submitForm(){
      let _this = this;
      _this.loading = true;
      let obj={}
      obj.flowDetailList=_this.flowDetailList
      labCenterPersonAdd(obj).then(res => {
        this.$message({
          type: 'success',
          message: '操作成功!',
          duration:2000,
          onClose:function(){
            _this.backPage();
            _this.loading = false;
          }
        });
      });

    },
    //返回
    backPage(){
      this.$parent.handleClick('','','back');
      this.$parent.getList();
    },

  },
  mounted() {
  }

};
</script>

<style scoped lang="scss">
.addPage {
  flex:1;
  display: flex!important;
  flex-direction: column;
  box-shadow: 0 0 8px 2px rgba(0, 0, 0, 0.1);
  border-radius:10px;
  /*顶部*/
  .addPage_title{
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid #E0E0E0;
    padding-top:20px;
    p:nth-child(1){
      flex: 1;
      line-height:60px;
      color: #0045AF;
      font-size:18px;
      margin:0 12px 0 20px;
    }
    p:nth-child(2){
      margin-right:20px;
    }
    p:nth-child(3){
      margin-right:20px;
    }
  }
  /*小标题*/
  .info_title{
    margin:20px 20px 0;
    font-size: 16px;
    font-family: Microsoft YaHei;
    font-weight: bold;
    color: #333333;
    line-height: 16px;
  }
  /*基本信息*/
  .info{
    display: flex;
    justify-content: flex-start;
    flex-wrap: wrap;
    align-items: center;
    border: 1px solid #E0E0E0;
    margin: 20px;
    >li{
      list-style-type: none;
      margin: 20px;
      >i{
        font-style: normal;
      }
      >i:nth-of-type(1){
        font-size: 16px;
        font-family: Microsoft YaHei;
        font-weight: 400;
        color: #999999;
        line-height: 16px;
      }
      >i:nth-of-type(2){
        font-size: 16px;
        font-family: Microsoft YaHei;
        font-weight: 400;
        color: #333333;
        line-height: 16px;
      }
    }
    .look_img{
      >i:nth-of-type(2){
        color: #0183FA;
      }
    }
  }
  .addPage_b{
    flex:1;
    display: flex!important;
    flex-direction: column;
    /*气瓶信息*/
    .addPage_b_t{
      flex:1;
      display: flex!important;
      flex-direction: column;
      padding: 0 20px;
      box-sizing: border-box;
      .addPage_b_t_title{
        font-size: 16px;
        font-family: Microsoft YaHei;
        font-weight: bold;
        color: #333333;
        line-height: 16px;
        margin: 40px 0 30px 0;
      }
    }
  }

}
</style>
