<template>
  <el-dialog :title="formTitle" :visible.sync="dialogFormVisible"  width="63%">
    <el-form :model="form" ref="form" :rules="rules" label-width="130px">
     <el-row :gutter="24">
        <el-col :span="24">
        <el-form-item label="账号 : " prop="mobile">
          <el-input v-model="form.mobile" placeholder="用户手机号"         maxlength="11"
                    :disabled="form.id !==  0"></el-input>
        </el-form-item>
      </el-col>
    </el-row>
    <el-row :gutter="24">
      <el-col :span="24">
        <el-form-item label="姓名 : " prop="name">
          <el-input v-model="form.name" placeholder="用户姓名"></el-input>
        </el-form-item>
      </el-col>
    </el-row> 
    <el-row :gutter="24">
      <el-col :span="24">
      <el-form-item label="角色 : " prop="role_ids">
        <el-checkbox-group v-model="form.role_ids" @change="changeRole">
          <el-checkbox v-for="( item,index) in roles" :key="index" :label="item.id" :value="item.id">{{item.name}}
          </el-checkbox>
        </el-checkbox-group>
      </el-form-item>
      </el-col>
    </el-row>
    <el-row :gutter="24">
      <el-col :span="16">
        <el-form-item label="职称 : ">
          <el-select v-model="form.user_type" placeholder="用户类型">
            <el-option
              v-for="item in user_types"
              :label="item.name"
              :value="item.index"
              :key="item.index"
            ></el-option>
          </el-select>

          <el-select v-model="form.user_title" placeholder="用户职称">
            <el-option
              v-for="item in user_titles"
              :label="item.name"
              :value="item.index"
              :key="item.index"
            ></el-option>
          </el-select>
        </el-form-item>
      </el-col>
       <el-col :span="8">
        <el-form-item label="科室:">
          <el-select v-model="form.department_id" placeholder="科室">
            <el-option
              v-for="item in departMent"
              :label="item.name"
              :value="item.id"
              :key="item.id"
            ></el-option>
          </el-select>
        </el-form-item>
    </el-col>
   </el-row>
   <el-row :span="24">
      <el-col :span="24">
      <el-form-item label="职位: ">
        <el-input v-model="form.user_title_name" placeholder="输入职位"></el-input>
      </el-form-item>
    </el-col>
   </el-row>
   <el-row :span="24">
      <el-col :span="8">
       <el-form-item label="医保医师编码:">
        <el-input v-model="form.doctor_number"></el-input>
       </el-form-item>
    </el-col>
    <el-col :span="8">
       <el-form-item label="工号:">
           <el-input v-model="form.job_number" style="width:180px;"></el-input>
       </el-form-item>
    </el-col>
   </el-row>
  
  <div v-show="show">
   <el-row :span="24">
    <el-col :span="8">
      <el-form-item label="性别:">
        <el-select v-model="form.sex" placeholder="性别" style="width:180px;">
              <el-option
                v-for="item in sexList"
                :label="item.name"
                :value="item.id"
                :key="item.id"
              ></el-option>
      </el-select>
     </el-form-item>
    </el-col>
    <el-col :span="8">
      <el-form-item label="年龄:">
         <el-input v-model="form.age" style="width:180px;"></el-input>
      </el-form-item>
    </el-col>
    <el-col :span="8">
      <el-form-item label="执业状态">
           <el-select v-model="form.active_status" placeholder="执业状态" style="width:180px;">
              <el-option
                v-for="item in activeStausList"
                :label="item.name"
                :value="item.id"
                :key="item.id"
              ></el-option>
          </el-select>
      </el-form-item>
      </el-col>
  </el-row>


  <el-row :gutter="24">
    <el-col :span="8">
       <el-form-item label="民族:">
          <el-input v-model="form.nation" style="width:180px;"></el-input>
       </el-form-item>
    </el-col>
     <el-col :span="8">
       <el-form-item label="身份类型:" >
           <el-select v-model="form.card_type" placeholder="性别" style="width:180px;">
              <el-option
                v-for="item in cardList"
                :label="item.name"
                :value="item.id"
                :key="item.id"
              ></el-option>
          </el-select>
       </el-form-item>
    </el-col>
    <el-col :span="8">
       <el-form-item label="身份证号:">
          <el-input v-model="form.id_card" style="width:180px;"></el-input>
       </el-form-item>
    </el-col>
  </el-row>

   <el-row :gutter="24">
    <el-col :span="8">
       <el-form-item label="学历:">
           <el-select v-model="form.education" placeholder="性别" style="width:180px;">
              <el-option
                v-for="item in educationList"
                :label="item.name"
                :value="item.id"
                :key="item.id"
              ></el-option>
          </el-select>
        
       </el-form-item>
    </el-col>
     <el-col :span="8">
       <el-form-item label="所学专业:">
           <el-input v-model="form.study_major_name" style="width:180px;"></el-input>
       </el-form-item>
    </el-col>
    <el-col :span="8">
       <el-form-item label="从事专业:">
          <el-input v-model="form.work_major_name" style="width:180px;"></el-input>
       </el-form-item>
    </el-col>
  </el-row>


  <el-row :gutter="24">
    <el-col :span="8">
       <el-form-item label="人员类别:">
           <el-select v-model="form.role_type" placeholder="人员类别" @change="changeRoleType" style="width:150px;">
              <el-option
                v-for="item in roleList"
                :label="item.name"
                :value="item.id"
                :key="item.id"
              ></el-option>
          </el-select>
        
       </el-form-item>
    </el-col>
     <el-col :span="8">
       <el-form-item label="医药师资格证编码:">
           <el-input v-model="form.medical_code" style="width:170px;"></el-input>
       </el-form-item>
    </el-col>
    <el-col :span="8">
       <el-form-item label="医药师职业证编码:">
          <el-input v-model="form.doctor_code" style="width:170px;"></el-input>
       </el-form-item>
    </el-col>
  </el-row>


  <el-row :gutter="24">
    <el-col :span="8">
       <el-form-item label="多点执业标志:">
           <el-select v-model="form.licensing" placeholder="多点执业标志" style="width:180px;">
              <el-option
                v-for="item in List"
                :label="item.name"
                :value="item.id"
                :key="item.id"
              ></el-option>
          </el-select>
        
       </el-form-item>
    </el-col>
   
    <el-col :span="8">
       <el-form-item label="处方资格标志:">
           <el-select v-model="form.prescription_qualification_identification" placeholder="处方资格标志" style="width:180px;">
              <el-option
                v-for="item in List"
                :label="item.name"
                :value="item.id"
                :key="item.id"
              ></el-option>
          </el-select>
       </el-form-item>
    </el-col>
  </el-row>


  <el-row :gutter="24">
    <el-col :span="8">
       <el-form-item label="门诊医生大病标志:">
           <el-select v-model="form.identification_outpatients" placeholder="门诊医生大病标志" style="width:180px;">
              <el-option
                v-for="item in List"
                :label="item.name"
                :value="item.id"
                :key="item.id"
              ></el-option>
          </el-select>
        
       </el-form-item>
    </el-col>
     <el-col :span="8">
       <el-form-item label="开始时间:">
            <el-date-picker
              v-model="form.start_time"
              prefix-icon="el-icon-date"
              :editable="false"
              style="width:180px;"

              type="date"
              placeholder="选择开始时间"
              align="right"
              format="yyyy-MM-dd"
              value-format="yyyy-MM-dd">
            </el-date-picker>
       </el-form-item>
    </el-col>
    <el-col :span="8">
       <el-form-item label="药师执业范围代码:">
          <el-select v-model="form.medical_range_code" placeholder="药师执业范围代码" style="width:180px;">
              <el-option
                v-for="item in medicalRangeList"
                :label="item.name"
                :value="item.id"
                :key="item.id"
              ></el-option>
          </el-select>
       </el-form-item>
    </el-col>
  </el-row>


<el-row :gutter="24">
    <el-col :span="8">
       <el-form-item label="药师级别:" v-show="showOne">
           <el-select v-model="form.medical_level" placeholder="药师级别" style="width:180px;">
              <el-option
                v-for="item in doctorRangeList"
                :label="item.name"
                :value="item.id"
                :key="item.id"
              ></el-option>
          </el-select>
        
       </el-form-item>
    </el-col>
     <el-col :span="8">
       <el-form-item label="药师执业类别:" label-width="130px" v-show="showOne">
          
             <el-select v-model="form.medical_type_job" placeholder="药师执业类别" style="width:180px;">
              <el-option
                v-for="item in doctorLevelList"
                :label="item.name"
                :value="item.id"
                :key="item.id"
              ></el-option>
          </el-select>
       </el-form-item>
    </el-col>
    <el-col :span="8" >
       <el-form-item label="执业药师注册证编号:" v-show="showOne">
           <el-input v-model="form.pharmacist_registration_number" style="width:180px;"></el-input>
       </el-form-item>
    </el-col>
  </el-row>






   <el-row :gutter="24">
    <el-col :span="8">
       <el-form-item label="医师执业范围代码:" v-show="showTwo">
           <el-select v-model="form.doctor_range_code" placeholder="医生执业范围代码">
              <el-option
                v-for="item in doctorRangeList"
                :label="item.name"
                :value="item.id"
                :key="item.id"
              ></el-option>
          </el-select>
        
       </el-form-item>
    </el-col>
     <el-col :span="8">
       <el-form-item label="医生级别:" label-width="130px" v-show="showTwo">
          
             <el-select v-model="form.doctor_level" placeholder="医生级别">
              <el-option
                v-for="item in doctorLevelList"
                :label="item.name"
                :value="item.id"
                :key="item.id"
              ></el-option>
          </el-select>
       </el-form-item>
    </el-col>
    <el-col :span="8">
       <el-form-item label="执业类别:" v-show="showTwo">
            <el-select v-model="form.doctor_type_job" placeholder="执业类别">
              <el-option
                v-for="item in typeJobList"
                :label="item.name"
                :value="item.id"
                :key="item.id"
              ></el-option>
          </el-select>
       </el-form-item>
    </el-col>
  </el-row>


  <el-row :gutter="24">
   
     <el-col :span="8">
       <el-form-item label="门诊大病类别:" label-width="130px">
            <el-select v-model="form.outpatient_illnessCategory" placeholder="门诊大病类别">
              <el-option
                v-for="item in numberList"
                :label="item.name"
                :value="item.id"
                :key="item.id"
              ></el-option>
          </el-select>
       </el-form-item>
    </el-col>
    <el-col :span="8">
       <el-form-item label="在职状态:">
           <el-select v-model="form.is_active" placeholder="在职状态">
              <el-option
                v-for="item in activeList"
                :label="item.name"
                :value="item.id"
                :key="item.id"
              ></el-option>
          </el-select>
       </el-form-item>
    </el-col>
  </el-row>
</div>
  <!-- <el-row :gutter="24">
    <el-col :span="8">
      <el-form-item label="执业状态">
           <el-select v-model="form.active_status" placeholder="执业状态">
              <el-option
                v-for="item in activeStausList"
                :label="item.name"
                :value="item.id"
                :key="item.id"
              ></el-option>
          </el-select>
      </el-form-item>
     </el-col>
  </el-row>      -->
   <el-row :gutter="24">
     <el-col :span="24">
      <el-form-item label="介绍 : ">
        <Tinymce :height="400" menubar ref="editor" v-model="form.intro" :show_upload_img="false"/>
      </el-form-item>
      </el-col>
   </el-row>
   </el-form>
  
    <div slot="footer" class="dialog-footer">
      <el-button @click="dialogFormVisible = false">取 消</el-button>
      <el-button type="primary" @click="submitAction">保 存</el-button>
    </div>
  </el-dialog>
</template>

<script>
  import axios from 'axios'
  import { uParseTime } from '@/utils/tools'
  import Tinymce from '@/components/Tinymce'
  import { addAdmin, getAddAdminInitData, getModifyAdminInitData, modifyAdmin } from '@/api/role/admin'
  import { getAllDePartmentList } from "@/api/project/project"
  export default {
    name: 'AdminInfoForm',
    components: {
      Tinymce
    },
    data() {
      var checkMobile = (rule, value, callback) => {
        if (!value || value.length == 0) {
          return callback(new Error('手机号不能为空'))
        }
        if (/^1\d{10}$/.test(value) == false) {
          return callback(new Error('手机号格式错误'))
        } else {
          callback()
        }
      }
      var checkName = (rule, value, callback) => {
        if (!value || value.length == 0) {
          return callback(new Error('姓名不能为空'))
        } else {
          callback()
        }
      }
      return {
        admin_id: 0,
        dialogFormVisible: false,

        user_types: [
          { index: 2, name: '医生' },
          { index: 3, name: '护士' },
          { index:4,name:'行政'},
          { index:5,name:'其他'}
        ],
        user_titles: [
          { index: 1, name: '医士' },
          { index: 2, name: '医师' },
          { index: 3, name: '住院医师' },
          { index: 4, name: '主治医师' },
          { index: 5, name: '副主任医师' },
          { index: 6, name: '主任医师' },
          { index: 7, name: '护士' },
          { index: 8, name: '护师' },
          { index: 9, name: '主管护师' },
          { index: 10, name: '副主任护师' },
          { index: 11, name: '主任护师' },
          { index: 12, name: '运营专员' },
          { index: 13, name: '运营主管' }
        ],
        roles: [], // [{id, name, intro, status}]
        loading: true,
        qntoken: '',
        formTitle: '',
        isSubSuperAdmin:false,
        org:null,
        form: {
          role_ids: [],
          user_title_name: '',
          id: 0,
          mobile: '',
          name: '',
          user_type: '',
          user_title: '',
          role: '', // 其实应该是 int 类型
          intro: '',
          department:'',
          department_id:"",
          sex:"", //性别
          age:"", //年龄
          nation:"", //民族
          card_type:"", //身份类型
          id_card:"",//身份证
          education:"",//学历
          study_major_name:"",//所学专业
          work_major_name:"",//从事专业
          role_type:"",//人员类别
          medical_code:"",//医药师资格证编码
          doctor_code:"",// 执业证编码
          licensing:"",//多点执业编制
          job_number:"",//工号
          prescription_qualification_identification:"",//处方资格标志
          identification_outpatients:"",//门诊大病资格标志
          start_time:"",//开始时间
          medical_range_code:"",//药师执业范围编码
         
          medical_level:"",//药师级别
          medical_type_job:"",//药师执业类别
          pharmacist_registration_number:"",//执业药师注册证编号
          doctor_range_code:"",//医师执业范围代码
          doctor_level:"",//医师级别
          doctor_type_job:"",//医师执业类别
          doctor_number:"",//医保医生编号
          outpatient_illnessCategory:"",//门诊大病类别
          is_active:"",//在职状态
          active_status:"",//执业状态
        },
        departMent:[],
        sexList:[
          {id:1,name:"男"},
          {id:2,name:"女"}
         ],
         //id号按深圳社保编号命名
         cardList:[
          {id:1,name:"内地身份证"},
          {id:90,name:"社保卡"},
          {id:8,name:"护照"},
          {id:4,name:"港澳身份证号"},
          {id:2,name:"居官证"},
          {id:6,name:"台胞证"}
         ],
         educationList:[
           {id:31,name:"大专"},
           {id:21,name:"本科"},
           {id:14,name:"硕士"},
           {id:11,name:"博士"},
         ],
         roleList:[
           {id:1,name:"医师"},
           {id:2,name:"药师"}
         ],
         List:[
           {id:1,name:"是"},
           {id:2,name:"否"},
         ],
         medicalRangeList:[
           {id:1,name:"药品生产"},
           {id:2,name:"药品经营"},
           {id:3,name:"药品使用"}
         ],
        doctorRangeList:[
          {id:101,name:"内科专业"},
          {id:102,name:"外科专业"},
          {id:103,name:"妇产科专业"},
          {id:104,name:"儿科专业"},
          {id:105,name:"眼耳鼻咽喉科专业"},
          {id:106,name:"皮肤科与性病专业"},
          {id:107,name:"精神卫生专业"},
          {id:108,name:"职业病专业"},
          {id:109,name:"医学影像和放射治理专业"},
          {id:110,name:"医学检验、病理专业"},
          {id:111,name:"全科医学专业"},
          {id:112,name:"急救医学专业"},
          {id:113,name:"康复医学专业"},
          {id:114,name:"预防保健专业"},
          {id:115,name:"特种医学与军事医学专业"},
          {id:116,name:"计划生育技术服务专业"},
          {id:199,name:"省级以上卫生行政部门规定的其他专业"},
          {id:201,name:"口腔专业"},
          {id:299,name:"省级以上卫生行政部门规定的其他专业"},
          {id:301,name:"公共卫生类别专业"},
          {id:399,name:"省级以上卫生行政部门规定的其他专业"},
          {id:401,name:"中医专业"},
          {id:402,name:"中西医结合专业"},
          {id:403,name:"蒙医专业"},
          {id:404,name:"藏医专业"},
          {id:405,name:"维医专业"},
          {id:406,name:"傣医专业"},
          {id:499,name:"省级以上卫生行政部门规定的其他专业"}
        ],
        doctorLevelList:[
          {id:1,name:"执业医师"},
          {id:2,name:"执业助理医师"},
          {id:3,name:"执业药师"},
          {id:4,name:"从业药师"}
        ],
        typeJobList:[
         {id:1,name:"临床"},
         {id:2,name:"口腔"},
         {id:3,name:"公共卫生"},
         {id:4,name:"中医"}
        ],
        numberList:[
          {id:1,name:"肺结核专科门诊治疗"},
          {id:2,name:"艾滋病门诊专科治疗"},
          {id:3,name:"再生障碍性贫血"},
          {id:4,name:"地中海贫血"},
          {id:5,name:"血友病"},
          {id:6,name:"精神分裂症门诊专科治疗"},
          {id:7,name:"分裂情感性障碍门诊专科治疗"},
          {id:8,name:"持久的妄想性障碍（偏执性精神病）门诊专科治疗"},
          {id:9,name:"双相（情感）障碍门诊专科治疗"},
          {id:10,name:"癫痫所致精神障碍门诊专科治疗"},
          {id:11,name:"精神发育迟滞伴发精神障碍门诊专科治疗"},
          {id:12,name:"颅内良性肿瘤专科治疗"},
          {id:13,name:"器官移植后抗排斥"},
          {id:14,name:"放、化、核素治疗"},
          {id:15,name:"恶性肿瘤放疗"},
          {id:16,name:"恶性肿瘤化疗 "},
          {id:17,name:"恶性肿瘤介入或核素治疗 "},
          {id:18,name:"肾衰腹透 "},
          {id:19,name:"肾衰血透 "},
          {id:20,name:"肺结核专科门诊治疗"},
          {id:21,name:"放、化、核素治疗"}
        ],
        activeList:[
          {id:1,name:"在职"},
          {id:2,name:"离职"},
          {id:3,name:"返聘"},
          {id:4,name:"临聘"}
        ],
        activeStausList:[
          {id:1,name:"正常"},
          {id:2,name:"注销"},
          {id:3,name:"暂停"}
        ],
        rules: {
          mobile: [{ required: true, validator: checkMobile, trigger: 'blur' }],
          name: [{ required: true, validator: checkName, trigger: 'blur' }],
          role_ids: [
            { type: 'array', required: true, message: '请至少选择一个角色', trigger: 'change' }
          ]
        },
        show:false,
        showOne:false,
        showTwo:true
      }
    },
    methods: {
      open: function(adminId) {
        this.admin_id = adminId
        if (this.admin_id < 0) {
          this.$message.error('参数错误')
          this.loading = false
          return
        }
         // let localthis.$store.getters.xt_user.user.id
        let local_user_id = this.$store.getters.xt_user.user.id
        this.form.id = this.admin_id
        if (this.admin_id === 0) {
          let tempForm = {
            role_ids: [],
            user_title_name: '',
            id: 0,
            mobile: '',
            name: '',
            user_type: '',
            user_title: '',
            role: '', // 其实应该是 int 类型
            intro: ''
          }
          this.form = tempForm
          this.formTitle = '新增员工'
          this.form.user_type = this.user_types[0].index
          this.form.user_title = this.user_titles[0].index
          getAddAdminInitData()
            .then(rs => {
              this.loading = false
              var resp = rs.data
              
              if (resp.state === 1) {
                // this.roles.push(...resp.data.roles)
                this.roles = resp.data.roles
                this.qntoken = resp.data.qntoken

                this.isSubSuperAdmin = resp.data.isSubSuperAdmin
                this.org = resp.data.org

                //如果当前用户是子管理员则，则需要将子管理员角色去除，因为子管理员不能添加子管理员
                if(this.isSubSuperAdmin){
                  for (let i =0 ; i < this.roles.length; i++){
                    if(this.roles[i].is_system == 1 && this.roles[i].role_name == "子管理员"){
                      this.roles.splice(i, 1)
                      i--
                    }
                  }
                }

              } else {
                this.$message.error(resp.msg)
              }
            })
            .catch(err => {
              this.loading = false
              this.$message.error(err)
            })
        } else {
          this.formTitle = '编辑用户'
          getModifyAdminInitData(this.form.id).then(rs => {
              this.loading = false
              var resp = rs.data
              if (resp.state === 1) {
                this.roles = []
                this.roles.push(...resp.data.roles)
                this.qntoken = resp.data.qntoken
                var org = resp.data.org


                var admin = resp.data.admin
                console.log("admin2222222",admin)
                this.form.name = admin.user_name
                this.form.mobile = admin.admin.mobile
                this.form.user_type = admin.user_type
                if(admin.user_type == 1){
                  this.form.user_type = ""
                }
                this.form.user_title = admin.user_title
                this.form.role = admin.role_ids
               
                this.form.department_id = admin.department_id
                if(admin.department_id == 0){
                   this.form.department_id = ""
                }
                this.form.role_ids = []
                for (let i = 0; i < this.form.role.split(",").length; i++) {
                  if (this.form.role.split(',')[i].length > 0) {
                    this.form.role_ids.push(parseInt(this.form.role.split(',')[i]))
                  }
                }

               
              
                this.form.intro = admin.intro
                this.form.user_title_name = admin.user_title_name

                if(this.form.user_type == 2){
                   this.show = true
                }else{
                  this.show = false
                }
                if(admin.role_type == 1){
                   this.showTwo = true
                   this.showOne = false
                }
                if(this.role_type == 2){
                  this.showOne = true
                   this.showTwo = false
                   
                }
                this.isSubSuperAdmin = resp.data.isSubSuperAdmin
                this.org = resp.data.org
                
               
                this.form.sex = admin.sex
                if(admin.sex == 0){
                   this.form.sex = ""
                }
                this.form.age = admin.age
                if(admin.age == 0){
                  this.form.age = ""
                }
                this.form.nation = admin.nation
                this.form.card_type = admin.card_type
                if(admin.card_type == 0){
                  this.form.card_type = ""
                }
                this.form.id_card = admin.id_card
                this.form.education = admin.education
                if(admin.education == 0){
                  this.form.education = ""
                }
                this.form.study_major_name = admin.study_major_name
                this.form.work_major_name = admin.work_major_name
                this.form.role_type = admin.role_type
                if(admin.role_type == 0){
                  this.form.role_type = ""
                }
                this.form.medical_code = admin.medical_code
                this.form.doctor_code = admin.doctor_code
                this.form.licensing = admin.licensing
                if(admin.licensing == 0){
                  this.form.licensing = ""
                }
                this.form.job_number = admin.job_number
                this.form.prescription_qualification_identification = admin.prescription_qualification_identification
                if(admin.prescription_qualification_identification == 0){
                   this.form.prescription_qualification_identification = ""
                }
                this.form.identification_outpatients = admin.identification_outpatients
                if(admin.identification_outpatients == 0){
                   this.form.identification_outpatients = ""
                }
                this.form.start_time = this.getTime(admin.start_time)
                this.form.medical_range_code = admin.medical_range_code
                if(admin.medical_range_code == 0){
                  this.form.medical_range_code = ""
                }
                this.form.medical_level =admin.medical_level
                if(admin.medical_level == 0){
                  this.form.medical_level = ""
                }
                this.form.medical_type_job = admin.medical_type_job
                this.form.pharmacist_registration_number = admin.pharmacist_registration_number
                this.form.doctor_range_code = admin.doctor_range_code
                if(admin.doctor_range_code == 0){
                  this.form.doctor_range_code = ""
                }
                this.form.doctor_level = admin.doctor_level
                if(this.form.doctor_level == 0){
                    this.form.doctor_level = ""
                }
                this.form.doctor_type_job = admin.doctor_type_job
                if(admin.doctor_type_job == 0){
                   this.form.doctor_type_job = ""
                }
                this.form.doctor_number = admin.doctor_number
                this.form.is_active = admin.is_active
                console.log("2222222",this.form.is_active)
                if(admin.is_active == 0){
                   this.form.is_active = ""
                }
                this.form.active_status = admin.active_status
                if(admin.active_status == 0){
                   this.form.active_status = ""
                }
              
                var id = 0
                for(let i=0;i<this.numberList.length;i++){
                   if(this.numberList[i].name == admin.outpatient_illness_category){
                        id = this.numberList[i].id
                   }
                }
                console.log("id2222222",id)
                this.form.outpatient_illnessCategory = id
                 if(this.form.outpatient_illnessCategory == 0){
                   this.form.outpatient_illnessCategory = ""
                 }
                //如果当前用户是超级管理员而且编辑自己的信息

                if(!this.isSubSuperAdmin) {
                  if (this.form.id == org.creator) {
                    for (let i = 0; i < this.roles.length; i++) {
                      if (this.roles[i].is_system == 1 && this.roles[i].name == "子管理员") {
                        this.roles.splice(i, 1)
                        i--
                      }
                    }
                  }
                }else{
                  for (let i = 0; i < this.roles.length; i++) {
                    if (this.roles[i].is_system == 1 && this.roles[i].name == "子管理员") {
                      this.roles.splice(i, 1)
                      i--
                    }
                  }

                }

              } else {
                this.$message.error('该用户不存在')
              }
            }).catch(err => {
              this.loading = false
              this.$message.error('该用户不存在')
            })
        }

        this.dialogFormVisible = true
      },
      submitAction: function() {   
        
        var department = ""
        for(let i=0;i<this.departMent.length;i++){
          if(this.form.department_id == this.departMent[i].id){
              department = this.departMent[i].name
          }
        }
        this.form.department = department
        
        if (this.admin_id < 0) {
          return
        }
        this.$refs.form.validate(valid => {
          if (valid) {
            if(this.form.user_type == "" || this.form.user_type == 0 ){
              this.$message.error("职称不能为空")
              return
            }

            this.loading = true
            
            var name = ""
            for(let i=0;i<this.numberList.length;i++){
               if(this.form.outpatient_illnessCategory == this.numberList[i].id){
                   name = this.numberList[i].name
               }
            }
            if (this.form.id === 0) {
              this.form.role = this.form.role_ids.join(',')
              var params = {
                mobile:this.form.mobile,
                name:this.form.name,
                type:this.form.user_type,
                title:this.form.user_title,
                role:this.form.role,
                intro:this.form.intro,
                user_title_name:this.form.user_title_name,
                department:this.form.department,
                department_id:this.form.department_id,
                

                sex:this.form.sex, //性别
                age:parseInt(this.form.age), //年龄
                nation:this.form.nation, //民族
                card_type:this.form.card_type, //身份类型
                id_card:this.form.id_card,//身份证
                education:this.form.education,//学历
                study_major_name:this.form.study_major_name,//所学专业
                work_major_name:this.form.work_major_name,//从事专业
                role_type:this.form.role_type,//人员类别
                medical_code:this.form.medical_code,//医药师资格证编码
                doctor_code:this.form.doctor_code,// 执业证编码
                licensing:this.form.licensing,//多点执业编制
                job_number:this.form.job_number,//工号
                prescription_qualification_identification:this.form.prescription_qualification_identification,//处方资格标志
                identification_outpatients:this.form.identification_outpatients,//门诊大病资格标志
                start_time:this.form.start_time,//开始时间
                medical_range_code:this.form.medical_range_code,//药师执业范围编码
              
                medical_level:this.form.medical_level,//药师级别
                medical_type_job:this.form.medical_type_job,//药师执业类别
                pharmacist_registration_number:this.form.pharmacist_registration_number,//执业药师注册证编号
                doctor_range_code:this.form.doctor_range_code,//医师执业范围代码
                doctor_level:this.form.doctor_level,//医师级别
                doctor_type_job:this.form.doctor_type_job,//医师执业类别
                doctor_number:this.form.doctor_number,//医保医生编号
                outpatient_illnessCategory:name,//门诊大病类别
                is_active:this.form.is_active,//在职状态
                active_status:this.form.active_status,//执业状态
                
              }
              console.log("params",params)
             
              addAdmin(params).then(rs => {
                  this.loading = false
                  var resp = rs.data
                  if (resp.state === 1) {
                    this.$store.dispatch('DidChangeAdmins')
                    var _this = this
                    setTimeout(() => {
                      _this.$store.dispatch('RecoverAdminsChangeState')
                    }, 500)
                    this.dialogFormVisible = false
                  } else {
                    this.$message.error(resp.msg)
                  }
                })
                .catch(err => {
                  this.loading = false
                  this.$message.error(err)
                })
            } else {
              this.form.role = this.form.role_ids.join(',')
             
               var department = ""
               for(let i=0;i<this.departMent.length;i++){
                if(this.form.department_id == this.departMent[i].id){
                    department = this.departMent[i].name
                }
              }
              this.form.department = department
               var name = ""
              for(let i=0;i<this.numberList.length;i++){
                if(this.form.outpatient_illnessCategory == this.numberList[i].id){
                    name = this.numberList[i].name
                }
              }
              var params = {
                uid:this.form.id,
                name:this.form.name,
                type:this.form.user_type,
                title:this.form.user_title,
                role:this.form.role,
                intro:this.form.intro,
                user_title_name:this.form.user_title_name,
                sort:0,
                department:this.form.department,
                department_id:this.form.department_id,


                sex:this.form.sex, //性别
                age:parseInt(this.form.age), //年龄
                nation:this.form.nation, //民族
                card_type:this.form.card_type, //身份类型
                id_card:this.form.id_card,//身份证
                education:this.form.education,//学历
                study_major_name:this.form.study_major_name,//所学专业
                work_major_name:this.form.work_major_name,//从事专业
                role_type:this.form.role_type,//人员类别
                medical_code:this.form.medical_code,//医药师资格证编码
                doctor_code:this.form.doctor_code,// 执业证编码
                licensing:this.form.licensing,//多点执业编制
                job_number:this.form.job_number,//工号
                prescription_qualification_identification:this.form.prescription_qualification_identification,//处方资格标志
                identification_outpatients:this.form.identification_outpatients,//门诊大病资格标志
                start_time:this.form.start_time,//开始时间
                medical_range_code:this.form.medical_range_code,//药师执业范围编码
              
                medical_level:this.form.medical_level,//药师级别
                medical_type_job:this.form.medical_type_job,//药师执业类别
                pharmacist_registration_number:this.form.pharmacist_registration_number,//执业药师注册证编号
                doctor_range_code:this.form.doctor_range_code,//医师执业范围代码
                doctor_level:this.form.doctor_level,//医师级别
                doctor_type_job:this.form.doctor_type_job,//医师执业类别
                doctor_number:this.form.doctor_number,//医保医生编号
                outpatient_illnessCategory:name,//门诊大病类别
                is_active:this.form.is_active,//在职状态
                active_status:this.form.active_status,//执业状态

              }
              console.log("params2222222",params)
              modifyAdmin(params).then(rs => {
                  this.loading = false
                  var resp = rs.data
                  if (resp.state === 1) {
                   if(resp.data.approle.active_status == 2){
                      let params = {
                       'id':resp.data.approle.id,
                       'is_mark':1, 
                       }
                     var that = this
                      axios.get('http://127.0.0.1:9532/sz/api/medical/get',{params:params}).then(function(response) {
                      if (response.data.state == 0) {
                          that.$message.error(response.data.msg)
                          return false
                        } else {
                          that.$message({ message: '撤销成功', type: 'success' })
                          }
                        }).catch(function(error) {
                      })
                    }
                    this.$store.dispatch('DidChangeAdmins')
                    var _this = this
                    setTimeout(() => {
                      _this.$store.dispatch('RecoverAdminsChangeState')
                    }, 500)

                    this.dialogFormVisible = false
                  } else {
                    this.$message.error(resp.msg)
                  }
                })
                .catch(err => {
                  this.loading = false
                  this.$message.error(err)
                })
            }
          } else {
            return false
          }
        })
      },

      getlist(){
        getAllDePartmentList().then(response=>{
         if(response.data.state == 1){
           var department =   response.data.data.departMent
           console.log("department2222",department)
           this.departMent = department
         
         }
        })
      },
      changeRole(arr){
        var varName = []
        for(let i=0;i<this.roles.length;i++){
          for(let j=0;j<arr.length;j++){
             if(this.roles[i].id == arr[j]){
                 varName.push(this.roles[i].name)
             }
          }
        }
        this.form.role_type = 1
        var ids = varName.join(";")
        console.log("valee22222",ids)
        if(ids.indexOf("医生")!=-1){
           this.show = true
        }else{
           this.show = false
        }
      },
       getTime(val) {
         if(val < 0){
           return ""
         }
         if(val == ""){
          return ""
         }else {
          return uParseTime(val, '{y}-{m}-{d}')
         }
      },
      changeRoleType(val){
        console.log("val",val)
        if(val == 1){
          this.showTwo = true
          this.showOne = false
          
        }
        if(val == 2){
          this.showTwo =false
          this.showOne = true
        }
      }
    },

    created(){
     
        //获取所有科室
       this.getlist()
    }
  }
</script>
