<template>
  <div>
    <el-dialog
      :before-close="handleClose"
      :close-on-click-modal="false"
      :title="title + '专业'"
      :visible="visible"
      custom-class="bbsl-location-dialog"
      top="25vh"
      width="35%"
    >
      <div>
        <el-form
          ref="formInfo"
          :model="parameter"
          :rules="rules"
          label-position="top"
          label-width="150px"
        >
          <el-row>
            <el-col :span="24">
              <el-form-item label="名称" prop="name">
                <el-input
                  v-model="parameter.name"
                  clearable
                  placeholder="请输入名称"
                ></el-input>
              </el-form-item>
            </el-col>
            <!-- <el-col :span="8">
							<el-form-item label="类型" prop="type">
								<el-select v-model="parameter.type" clearable placeholder="请选择类型">
									<el-option v-for="item in lxList" :key="item.value" :label="item.name"
										:value="item.value"></el-option>
								</el-select>
							</el-form-item>
						</el-col>
						<el-col :span="8">
							<el-form-item label="人员类别" prop="userTypeId">
								<el-select v-model="parameter.userTypeId" clearable placeholder="请选择人员类别">
									<el-option v-for="item in jobPageList" :key="item.id" :label="item.name"
										:value="item.id"></el-option>
								</el-select>
							</el-form-item>
						</el-col> -->
            <!-- <el-col :span="8">
              <el-form-item label="关联岗位" prop="positonVos">
                <el-select
                  v-model="positonVos"
                  collapse-tags
                  multiple
                  placeholder="请选择关联岗位"
                  @change="selectSystemChanged"
                  v-on:click.native="selectUsers"
                >
                  <el-option
                    v-for="(item, index) in positonVosList"
                    :key="index"
                    :label="item.positionName"
                    :value="item.positionId"
                  >
                  </el-option>
                </el-select>
              </el-form-item>
            </el-col> -->
          </el-row>

          <el-row>
            <el-col>
              <el-form-item label="备注" prop="memo">
                <el-input
                  v-model="parameter.memo"
                  :rows="2"
                  clearable
                  placeholder="请输入备注"
                  type="textarea"
                ></el-input>
              </el-form-item>
            </el-col>
          </el-row>
        </el-form>
      </div>
      <span slot="footer" class="dialog-footer">
        <el-button type="primary" @click="handleSave">确认</el-button>
        <el-button @click="handleClose">取 消</el-button>
      </span>
    </el-dialog>
    <!-- <relatedJobs ref="relatedJobs" @getUser="getUser"></relatedJobs> -->
  </div>
</template>

<script>
import dictUtils from '@/components/dict/DictSelectUtils.js'
import equSysMenu from '@/api/examination/equSysMenu.js'
// import relatedJobs from './relatedJobs.vue'

export default {
  components: {
    // relatedJobs
  },
  name: 'equSysMenuDialog',
  data() {
    return {
      lxList: [], //类型
      jobPageList: [], //人员类别
      title: '新增',
      rules: {
        // userTypeId: [{
        // 	required: true,
        // 	message: '请选择人员类别',
        // 	trigger: 'blur'
        // }],
        name: [
          {
            required: true,
            message: '请输入名称',
            trigger: 'blur'
          }
        ]
        // positonVos: [
        //   {
        //     required: true,
        //     message: '请输入名称',
        //     trigger: 'blur'
        //   }
        // ]
        // type: [{
        // 	required: true,
        // 	message: '请输入类型',
        // 	trigger: 'blur'
        // }]
      },
      queryParam: {
        pageBean: {
          page: 1,
          pageSize: -1
        }
      },
      roomStatusList: [],
      visible: false,
      parameter: {
        type: '',
        name: '',
        // positonVos: [],
        type: '',
        userTypeId: ''
      }
      // positonVosList: [],
      // positonVos: []
    }
  },
  created() {
    this.lxList = dictUtils.getDictItemsFromCache('lx')
  },
  mounted() {},
  methods: {
    edit(val) {
      this.getJobPage()
      this.title = '修改'
      this.visible = true
      equSysMenu.findById(val.id, res => {
        if (res) {
          this.parameter = res
          // this.positonVosList = res.positonVos
          // this.positonVosList.forEach(item => {
          //   this.positonVos.push(item.positionId)
          // })
        }
      })
    },
    add() {
      this.getJobPage()
      this.title = '新增'
      this.visible = true
    },
    // selectUsers() {

    //   this.$refs.relatedJobs.add(this.positonVosList)
    // },
    // 关闭新增人员窗口
    handleClose() {
      this.visible = false
      this.title = '新增'
      this.parameter = {
        type: '',
        name: '',
        // positonVos: [],
        type: '',
        userTypeId: ''
      }
      // this.positonVosList = []
      // this.positonVos = []
    },
    // getUser(item) {
    //   this.parameter.positonVos = []
    //   this.positonVosList = []
    //   this.positonVos = []
    //   item.forEach(e => {
    //     this.positonVosList.push({
    //       majorId: this.parameter.id,
    //       majorName: this.parameter.name,
    //       positionCode: e.positionCode,
    //       positionId: e.positionId,
    //       positionName: e.positionName
    //     })
    //     this.positonVos.push(e.positionId)
    //   })
    //   this.parameter.positonVos = this.positonVosList
    // },
    // selectSystemChanged(val) {
    //   let arr = JSON.parse(JSON.stringify(this.positonVosList))
    //   this.positonVosList = []
    //   arr.forEach((p, pi) => {
    //     val.forEach(v => {
    //       if (p.positionId == v) {
    //         this.positonVosList.push(p)
    //       }
    //     })
    //   })
    //   this.parameter.positonVos = this.positonVosList
    // },
    //获取人员类别
    getJobPage() {
      equSysMenu.getJobPage(this.queryParam, res => {
        if (res.rows) {
          this.jobPageList = res.rows
        }
      })
    },
    // 保存产品类型
    handleSave() {
      this.$refs.formInfo.validate(valid => {
        if (valid) {
          let method
          if (this.title === '新增') {
            method = equSysMenu.addEqeSys
          }
          if (this.title === '修改') {
            method = equSysMenu.editEqeSys
          }
          method(this.parameter, response => {
            if (response.state) {
              this.$notify({
                type: 'success',
                message: this.title + '成功',
                duration: 2000
              })
              this.handleClose()
              this.$emit('reload')
            } else {
              this.$message.warning(response.message)
            }
          })
        }
      })
    }
  }
}
</script>

<style lang="scss" scoped></style>
