<!--
 * @Author: 曹捷
 * @Date: 2019-08-19 15:24:34
 * @LastEditors: 曹捷
 * @LastEditTime: 2021-06-09 10:59:01
 * @Description: file content
 -->
<template>
  <a-modal class="obit-modal-default" v-if="showModal" :maskClosable="false" :title="showTitle" v-model:visible="showModal"
    @cancel="closeDialog" @ok="saveInfo" cancelText="取消" okText="确认" width="40%">
    <a-form :inline="true" :model="formData" :rules="rules" ref="formRef" :label-col="{span: 4}"
      :wrapper-col="{span:18}">
      <a-form-item label="岗位名称" name="postName">
        <a-input :maxlength="10" placeholder="请输入岗位名称" show-word-limit v-model:value="formData.postName"></a-input>
      </a-form-item>
      <a-form-item label="岗位编码" name="postCode">
        <a-input :maxlength="10" placeholder="请输入岗位编码" show-word-limit v-model:value="formData.postCode"></a-input>
      </a-form-item>
      <a-form-item label="排序" name="postSort">
        <a-input-number id="inputNumber" placeholder="排序" v-model:value.number="formData.postSort" :min="1"
          :max="999999999999999" style="width: 150px;" />
      </a-form-item>
      <!-- <a-form-item label="岗位状态">
        <a-radio-group name="radioGroup" v-model:value="formData.status">
          <a-radio value="0">正常</a-radio>
          <a-radio value="1">停用</a-radio>
        </a-radio-group>
      </a-form-item> -->
      <a-form-item  label="岗位状态">
        <obit-dict dictCode="sys_normal_disable" type="radio" v-model:value="formData.status">
        </obit-dict>
      </a-form-item>
      <a-form-item label="备注">
        <a-textarea :maxlength="10" placeholder="请输入备注" show-word-limit v-model:value="formData.remark" />
      </a-form-item>
    </a-form>
  </a-modal>
</template>
<script>
import { computed, inject, reactive, ref, toRefs, watch } from 'vue'
import { util } from '../../../entery'
import obitOrg from '../../../components/obit-org/obit-org.vue'
export default {
  components: { obitOrg },
  props: {
    open: {
      type: Boolean
    },
    addType: {
      type: String,
    },
    detailsInfo: {
      type: Object,
    },
  },
  setup (props, context) {
    let http = inject('http')
    let _data = reactive({
      showModal: props.open,
      formData: {},
      formRef: null,
      rules: {
        postName: [
          { required: true, message: '请输入岗位名称', trigger: 'blur' }
        ],
        postCode: [
          { required: true, message: '请输入岗位编码', trigger: 'blur' }
        ],
        postSort: [
          // { required: true, message: '请输入排序', trigger: 'blur', type: 'number' ,transform(value){return Number(value)}, whitespace:true,} ,
          { required: true, message: '请输入排序', }
        ],
      },
    })
    let _computed = {
      showTitle: computed(() => props.addType === 'add' ? '新增岗位' : '修改岗位')
    }
    let _methods = {
      saveInfo () {
        _data.formRef.validate().then(() => {
          let param = util.util.cloneObj(_data.formData)
          if (props.addType === 'add') {
            http.sysPost('system/post/add', param).then((res) => {
              context.emit('reload')
              _methods.closeDialog()
            })
          } else {
            http.sysPost('system/post/edit', param).then((res) => {
              context.emit('reload')
              _methods.closeDialog()
            })
          }

        })
      },
      closeDialog () {
        util.util.cleanObj(_data.formData)
        context.emit('update:open', false)
      }
    }
    watch(() => props.open, (value) => {
      if (value && props.addType === 'edit') {
        _data.formData = util.util.cloneObj(props.detailsInfo)
      } else {
        util.util.cleanObj(_data.formData)
        _data.formData.status = '0'
      }
    })
    return {
      ..._computed,
      ...toRefs(_data),
      ..._methods
    }
  },
}
</script>
<style lang="less">
</style>