<template>
  <div>
    <el-dialog
      :before-close="handleClose"
      :close-on-click-modal="false"
      :title="this.title + '课目考核'"
      :visible="visible"
      custom-class="bbsl-location-dialog"
      width="50%"
    >
      <div>
        <el-form
          ref="formInfo"
          :model="this.parameter"
          :rules="rules"
          label-position="top"
          label-width="150px"
        >
          <el-row :gutter="24">
            <el-col :span="8">
              <el-form-item label="年份" prop="year">
                <el-date-picker
                  style="width: 100%;"
                  v-model="parameter.year"
                  placeholder="请选择年份"
                  clearable
                  type="year"
                  value-format="yyyy"
                >
                </el-date-picker>
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="姓名" prop="userName">
                <el-input
                  v-model="parameter.userName"
                  clearable
                  placeholder="请输入姓名"
                >
                </el-input>
              </el-form-item>
            </el-col>

            <el-col :span="8">
              <el-form-item label="所属单位" prop="companyName">
                <el-input
                  v-model="parameter.companyName"
                  clearable
                  disabled
                  placeholder="请输入所属单位"
                >
                </el-input>
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="岗位" prop="post">
                <el-input
                  v-model="parameter.post"
                  clearable
                  disabled
                  placeholder="请输入岗位"
                >
                </el-input>
              </el-form-item>
            </el-col>

            <el-col :span="8">
              <el-form-item label="考核科目" prop="subjectName">
                <el-input
                  v-model="parameter.subjectName"
                  clearable
                  disabled
                  placeholder="请输入考核科目"
                >
                </el-input>
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="考核成绩" prop="score">
                <el-input
                  @input="formatNum(parameter.score, 'score')"
                  v-model="parameter.score"
                  clearable
                  placeholder="请输入考核成绩"
                >
                </el-input>
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="评定等级成绩" prop="companyName">
                <el-select
                  style="width: 100%;"
                  v-model="parameter.rateLevel"
                  clearable
                  placeholder="请选择评定等级成绩"
                >
                  <el-option
                    v-for="(item, i) in pjdjList"
                    :key="i"
                    :label="item.name"
                    :value="item.value"
                  ></el-option>
                </el-select>
              </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>
  </div>
</template>

<script>
import equSysMenu from '@/api/examDataMenu/examActivityData/equSysMenu.js'
import userTypeMenu from '@/api/examDataMenu/examActivityData/userTypeMenu'
import subMenu from '@/api/examDataMenu/examActivityData/subMenu'
import dictUtils from '@/components/dict/DictSelectUtils.js'
import moment from 'moment'
export default {
  components: {},
  name: 'subMenuDialog',
  data() {
    return {
      rules: {
        userName: [
          {
            required: true,
            message: '请输入课目名称',
            trigger: 'blur'
          }
        ]
      },
      visible: false,
      parameter: {
        userName: '',
        post: '',
        postId: '',
        year: ''
      },
      equList: [],
      // TrainTypeList: [],
      // TrainLevelList: [],
      pjdjList: [],
      positionList: [],
      jobPageList: [],
      //专业装备
      professionals: [],
      professionalsList: [],
      //所属岗位

      title: '',
      treeData: []
    }
  },
  created() {
    // this.TrainTypeList = dictUtils.getDictItemsFromCache('xllb')
    // this.TrainLevelList = dictUtils.getDictItemsFromCache('xljb')
    this.pjdjList = dictUtils.getDictItemsFromCache('dagl-pjdj')
  },
  mounted() {},
  methods: {
    formatNum(val, key) {
      let temp = val.toString()
      temp = temp.replace(/。/g, '.')
      temp = temp.replace(/[^\d.]/g, '') //清除"数字"和"."以外的字符
      temp = temp.replace(/^\./g, '') //验证第一个字符是数字
      temp = temp.replace(/\.{2,}/g, '') //只保留第一个, 清除多余的
      temp = temp
        .replace('.', '$#$')
        .replace(/\./g, '')
        .replace('$#$', '.')
      temp = temp.replace(/^(\-)*(\d+)\.(\d\d).*$/, '$1$2.$3') //只能输入两个小数
      this.parameter[key] = temp * 1
    },
    changeType(type) {
      this.type = type
    },

    // 获取装备系统
    getTreen() {
      equSysMenu.geteqTree(
        {
          id: '0'
        },
        res => {
          this.equList = res.value
        }
      )
    },

    // 获取岗位信息

    add(data) {
      console.log(data)

      this.parameter = data
      this.parameter.year = moment().format('YYYY')
      this.title = '新增'
      this.visible = true
    },
    edit(val) {
      console.log(val)
      // return
      this.title = '修改'
      this.visible = true

      subMenu.findById(val.id, res => {
        this.parameter = res
        console.log(res)
      })
    },

    // 关闭
    handleClose() {
      this.visible = false
      this.title = '新增'
      this.parameter = {
        userName: '',
        post: '',
        postId: ''
      }
    },
    // 保存
    handleSave() {
      this.$refs.formInfo.validate(valid => {
        if (valid) {
          let method
          if (this.title === '新增') {
            method = subMenu.addsubject
          }
          if (this.title === '修改') {
            method = subMenu.editSubject
          }
          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>
::v-deep .el-table__header-wrapper .el-checkbox {
  //找到表头那一行，然后把里面的复选框隐藏掉
  display: none;
}
</style>
