<template>
  <j-modal
    :title="title"
    :width="700"
    :visible="visible"
    :mask-closable="false"
    cancel-text="关闭"
    @close="close"
  >
    <a-form-model ref="form" :label-col="labelCol" :wrapper-col="wrapperCol" :rules="validatorRules" :model="model">
      <a-form-model-item label="员工姓名:" prop="nickName">
        <a-input v-model="model.nickName" />
      </a-form-model-item>
      <a-form-model-item label="数据权限" prop="qj">
        <j-dict-select-tag
          type="radioButton"
          v-model="model.zxqwqn"
          dict-code="word_type"
        />
      </a-form-model-item>
      <a-form-model-item label="登录账号:" prop="zzh">
        <a-input v-model="model.zzh" />
      </a-form-model-item>
      <a-form-model-item label="所属部门" prop="bm">
        <a-tree-select
          v-model="model.zzh"
          show-search
          style="width: 100%"
          :dropdown-style="{ maxHeight: '400px', overflow: 'auto' }"
          placeholder="选择部门"
          allow-clear
          tree-default-expand-all
        ></a-tree-select>
      </a-form-model-item>
      <a-form-model-item label="职工职务" prop="bm">
      </a-form-model-item>
      <a-form-model-item label="职工工号" prop="qj">
        <a-input v-model="model.zzh" />
      </a-form-model-item>
      <a-form-model-item label="手机号码" prop="qj">
        <a-input v-model="model.zzh" />
      </a-form-model-item>
      <a-form-model-item label="微信账号" prop="qj">
        <a-input v-model="model.zzh" />
      </a-form-model-item>
      <a-form-model-item label="邮箱地址" prop="qj">
        <a-input v-model="model.zzh" />
      </a-form-model-item>
      <a-form-model-item label="出生日期" prop="zzxh">
        <a-input v-model="model.zzh" />
      </a-form-model-item>
      <a-form-model-item label="性别" prop="zxqwqn">
        <j-dict-select-tag
          type="radioButton"
          v-model="model.zxqwqn"
          dict-code="word_type"
        />
      </a-form-model-item>
    </a-form-model>
  </j-modal>
</template>
<script>
import { httpAction } from '@/api/request'
import JModal from '@/components/JModal'
export default {
  name: 'CheckAndEditModel',
  components: {
    JModal
  },
  data() {
    return {
      labelCol: { span: 4 },
      wrapperCol: { span: 19 },
      dataSource: [],
      title: '',
      visible: false,
      isCheck: false,
      model: {},
      validatorRules: {
        name: [{ required: true, message: '请输入' }],
        type: [{ required: true, message: '请选择' }]
      },
      url: {
        add: '/system/user',
        edit: '/system/user'
      }
    }
  },
  created() {
  },
  methods: {
    add() {
      this.model = {}
      this.visible = true
    },
    edit(record) {
      debugger
      this.model = Object.assign({}, record)
      this.visible = true
    },
    close(isSubmit) {
      if (isSubmit) {
        this.checkData()
      } else {
        this.visible = false
      }
    },
    checkData() {
      this.$refs.form.validate(valid => {
        if (valid) {
          this.saveData()
        } else {
          return false
        }
      })
    },
    saveData() {
      let url, type
      if (!this.model.id) {
        url = this.url.add
        type = 'post'
      } else {
        debugger
        url = this.url.edit
        type = 'put'
      }
      httpAction(url, this.model, type).then((res) => {
        if (res.code === 200) {
          this.$message.success(res.msg)
          this.$emit('ok')
          this.visible = false
        } else {
          console.log(res)
        }
      })
    }
  }
}
</script>
